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 unsigned int ipr_fast_reboot
;
103 static DEFINE_SPINLOCK(ipr_driver_lock
);
105 /* This table describes the differences between DMA controller chips */
106 static const struct ipr_chip_cfg_t ipr_chip_cfg
[] = {
107 { /* Gemstone, Citrine, Obsidian, and Obsidian-E */
110 .cache_line_size
= 0x20,
114 .set_interrupt_mask_reg
= 0x0022C,
115 .clr_interrupt_mask_reg
= 0x00230,
116 .clr_interrupt_mask_reg32
= 0x00230,
117 .sense_interrupt_mask_reg
= 0x0022C,
118 .sense_interrupt_mask_reg32
= 0x0022C,
119 .clr_interrupt_reg
= 0x00228,
120 .clr_interrupt_reg32
= 0x00228,
121 .sense_interrupt_reg
= 0x00224,
122 .sense_interrupt_reg32
= 0x00224,
123 .ioarrin_reg
= 0x00404,
124 .sense_uproc_interrupt_reg
= 0x00214,
125 .sense_uproc_interrupt_reg32
= 0x00214,
126 .set_uproc_interrupt_reg
= 0x00214,
127 .set_uproc_interrupt_reg32
= 0x00214,
128 .clr_uproc_interrupt_reg
= 0x00218,
129 .clr_uproc_interrupt_reg32
= 0x00218
132 { /* Snipe and Scamp */
135 .cache_line_size
= 0x20,
139 .set_interrupt_mask_reg
= 0x00288,
140 .clr_interrupt_mask_reg
= 0x0028C,
141 .clr_interrupt_mask_reg32
= 0x0028C,
142 .sense_interrupt_mask_reg
= 0x00288,
143 .sense_interrupt_mask_reg32
= 0x00288,
144 .clr_interrupt_reg
= 0x00284,
145 .clr_interrupt_reg32
= 0x00284,
146 .sense_interrupt_reg
= 0x00280,
147 .sense_interrupt_reg32
= 0x00280,
148 .ioarrin_reg
= 0x00504,
149 .sense_uproc_interrupt_reg
= 0x00290,
150 .sense_uproc_interrupt_reg32
= 0x00290,
151 .set_uproc_interrupt_reg
= 0x00290,
152 .set_uproc_interrupt_reg32
= 0x00290,
153 .clr_uproc_interrupt_reg
= 0x00294,
154 .clr_uproc_interrupt_reg32
= 0x00294
160 .cache_line_size
= 0x20,
164 .set_interrupt_mask_reg
= 0x00010,
165 .clr_interrupt_mask_reg
= 0x00018,
166 .clr_interrupt_mask_reg32
= 0x0001C,
167 .sense_interrupt_mask_reg
= 0x00010,
168 .sense_interrupt_mask_reg32
= 0x00014,
169 .clr_interrupt_reg
= 0x00008,
170 .clr_interrupt_reg32
= 0x0000C,
171 .sense_interrupt_reg
= 0x00000,
172 .sense_interrupt_reg32
= 0x00004,
173 .ioarrin_reg
= 0x00070,
174 .sense_uproc_interrupt_reg
= 0x00020,
175 .sense_uproc_interrupt_reg32
= 0x00024,
176 .set_uproc_interrupt_reg
= 0x00020,
177 .set_uproc_interrupt_reg32
= 0x00024,
178 .clr_uproc_interrupt_reg
= 0x00028,
179 .clr_uproc_interrupt_reg32
= 0x0002C,
180 .init_feedback_reg
= 0x0005C,
181 .dump_addr_reg
= 0x00064,
182 .dump_data_reg
= 0x00068,
183 .endian_swap_reg
= 0x00084
188 static const struct ipr_chip_t ipr_chip
[] = {
189 { PCI_VENDOR_ID_MYLEX
, PCI_DEVICE_ID_IBM_GEMSTONE
, IPR_USE_LSI
, IPR_SIS32
, IPR_PCI_CFG
, &ipr_chip_cfg
[0] },
190 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_CITRINE
, IPR_USE_LSI
, IPR_SIS32
, IPR_PCI_CFG
, &ipr_chip_cfg
[0] },
191 { PCI_VENDOR_ID_ADAPTEC2
, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN
, IPR_USE_LSI
, IPR_SIS32
, IPR_PCI_CFG
, &ipr_chip_cfg
[0] },
192 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_OBSIDIAN
, IPR_USE_LSI
, IPR_SIS32
, IPR_PCI_CFG
, &ipr_chip_cfg
[0] },
193 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_OBSIDIAN_E
, IPR_USE_MSI
, IPR_SIS32
, IPR_PCI_CFG
, &ipr_chip_cfg
[0] },
194 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_SNIPE
, IPR_USE_LSI
, IPR_SIS32
, IPR_PCI_CFG
, &ipr_chip_cfg
[1] },
195 { PCI_VENDOR_ID_ADAPTEC2
, PCI_DEVICE_ID_ADAPTEC2_SCAMP
, IPR_USE_LSI
, IPR_SIS32
, IPR_PCI_CFG
, &ipr_chip_cfg
[1] },
196 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_CROC_FPGA_E2
, IPR_USE_MSI
, IPR_SIS64
, IPR_MMIO
, &ipr_chip_cfg
[2] },
197 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_CROCODILE
, IPR_USE_MSI
, IPR_SIS64
, IPR_MMIO
, &ipr_chip_cfg
[2] }
200 static int ipr_max_bus_speeds
[] = {
201 IPR_80MBs_SCSI_RATE
, IPR_U160_SCSI_RATE
, IPR_U320_SCSI_RATE
204 MODULE_AUTHOR("Brian King <brking@us.ibm.com>");
205 MODULE_DESCRIPTION("IBM Power RAID SCSI Adapter Driver");
206 module_param_named(max_speed
, ipr_max_speed
, uint
, 0);
207 MODULE_PARM_DESC(max_speed
, "Maximum bus speed (0-2). Default: 1=U160. Speeds: 0=80 MB/s, 1=U160, 2=U320");
208 module_param_named(log_level
, ipr_log_level
, uint
, 0);
209 MODULE_PARM_DESC(log_level
, "Set to 0 - 4 for increasing verbosity of device driver");
210 module_param_named(testmode
, ipr_testmode
, int, 0);
211 MODULE_PARM_DESC(testmode
, "DANGEROUS!!! Allows unsupported configurations");
212 module_param_named(fastfail
, ipr_fastfail
, int, S_IRUGO
| S_IWUSR
);
213 MODULE_PARM_DESC(fastfail
, "Reduce timeouts and retries");
214 module_param_named(transop_timeout
, ipr_transop_timeout
, int, 0);
215 MODULE_PARM_DESC(transop_timeout
, "Time in seconds to wait for adapter to come operational (default: 300)");
216 module_param_named(debug
, ipr_debug
, int, S_IRUGO
| S_IWUSR
);
217 MODULE_PARM_DESC(debug
, "Enable device driver debugging logging. Set to 1 to enable. (default: 0)");
218 module_param_named(dual_ioa_raid
, ipr_dual_ioa_raid
, int, 0);
219 MODULE_PARM_DESC(dual_ioa_raid
, "Enable dual adapter RAID support. Set to 1 to enable. (default: 1)");
220 module_param_named(max_devs
, ipr_max_devs
, int, 0);
221 MODULE_PARM_DESC(max_devs
, "Specify the maximum number of physical devices. "
222 "[Default=" __stringify(IPR_DEFAULT_SIS64_DEVS
) "]");
223 module_param_named(number_of_msix
, ipr_number_of_msix
, int, 0);
224 MODULE_PARM_DESC(number_of_msix
, "Specify the number of MSIX interrupts to use on capable adapters (1 - 16). (default:2)");
225 module_param_named(fast_reboot
, ipr_fast_reboot
, int, S_IRUGO
| S_IWUSR
);
226 MODULE_PARM_DESC(fast_reboot
, "Skip adapter shutdown during reboot. Set to 1 to enable. (default: 0)");
227 MODULE_LICENSE("GPL");
228 MODULE_VERSION(IPR_DRIVER_VERSION
);
230 /* A constant array of IOASCs/URCs/Error Messages */
232 struct ipr_error_table_t ipr_error_table
[] = {
233 {0x00000000, 1, IPR_DEFAULT_LOG_LEVEL
,
234 "8155: An unknown error was received"},
236 "Soft underlength error"},
238 "Command to be cancelled not found"},
240 "Qualified success"},
241 {0x01080000, 1, IPR_DEFAULT_LOG_LEVEL
,
242 "FFFE: Soft device bus error recovered by the IOA"},
243 {0x01088100, 0, IPR_DEFAULT_LOG_LEVEL
,
244 "4101: Soft device bus fabric error"},
245 {0x01100100, 0, IPR_DEFAULT_LOG_LEVEL
,
246 "FFFC: Logical block guard error recovered by the device"},
247 {0x01100300, 0, IPR_DEFAULT_LOG_LEVEL
,
248 "FFFC: Logical block reference tag error recovered by the device"},
249 {0x01108300, 0, IPR_DEFAULT_LOG_LEVEL
,
250 "4171: Recovered scatter list tag / sequence number error"},
251 {0x01109000, 0, IPR_DEFAULT_LOG_LEVEL
,
252 "FF3D: Recovered logical block CRC error on IOA to Host transfer"},
253 {0x01109200, 0, IPR_DEFAULT_LOG_LEVEL
,
254 "4171: Recovered logical block sequence number error on IOA to Host transfer"},
255 {0x0110A000, 0, IPR_DEFAULT_LOG_LEVEL
,
256 "FFFD: Recovered logical block reference tag error detected by the IOA"},
257 {0x0110A100, 0, IPR_DEFAULT_LOG_LEVEL
,
258 "FFFD: Logical block guard error recovered by the IOA"},
259 {0x01170600, 0, IPR_DEFAULT_LOG_LEVEL
,
260 "FFF9: Device sector reassign successful"},
261 {0x01170900, 0, IPR_DEFAULT_LOG_LEVEL
,
262 "FFF7: Media error recovered by device rewrite procedures"},
263 {0x01180200, 0, IPR_DEFAULT_LOG_LEVEL
,
264 "7001: IOA sector reassignment successful"},
265 {0x01180500, 0, IPR_DEFAULT_LOG_LEVEL
,
266 "FFF9: Soft media error. Sector reassignment recommended"},
267 {0x01180600, 0, IPR_DEFAULT_LOG_LEVEL
,
268 "FFF7: Media error recovered by IOA rewrite procedures"},
269 {0x01418000, 0, IPR_DEFAULT_LOG_LEVEL
,
270 "FF3D: Soft PCI bus error recovered by the IOA"},
271 {0x01440000, 1, IPR_DEFAULT_LOG_LEVEL
,
272 "FFF6: Device hardware error recovered by the IOA"},
273 {0x01448100, 0, IPR_DEFAULT_LOG_LEVEL
,
274 "FFF6: Device hardware error recovered by the device"},
275 {0x01448200, 1, IPR_DEFAULT_LOG_LEVEL
,
276 "FF3D: Soft IOA error recovered by the IOA"},
277 {0x01448300, 0, IPR_DEFAULT_LOG_LEVEL
,
278 "FFFA: Undefined device response recovered by the IOA"},
279 {0x014A0000, 1, IPR_DEFAULT_LOG_LEVEL
,
280 "FFF6: Device bus error, message or command phase"},
281 {0x014A8000, 0, IPR_DEFAULT_LOG_LEVEL
,
282 "FFFE: Task Management Function failed"},
283 {0x015D0000, 0, IPR_DEFAULT_LOG_LEVEL
,
284 "FFF6: Failure prediction threshold exceeded"},
285 {0x015D9200, 0, IPR_DEFAULT_LOG_LEVEL
,
286 "8009: Impending cache battery pack failure"},
288 "Logical Unit in process of becoming ready"},
290 "Initializing command required"},
292 "34FF: Disk device format in progress"},
294 "Logical unit not accessible, target port in unavailable state"},
295 {0x02048000, 0, IPR_DEFAULT_LOG_LEVEL
,
296 "9070: IOA requested reset"},
298 "Synchronization required"},
300 "IOA microcode download required"},
302 "Device bus connection is prohibited by host"},
304 "No ready, IOA shutdown"},
306 "Not ready, IOA has been shutdown"},
307 {0x02670100, 0, IPR_DEFAULT_LOG_LEVEL
,
308 "3020: Storage subsystem configuration error"},
310 "FFF5: Medium error, data unreadable, recommend reassign"},
312 "7000: Medium error, data unreadable, do not reassign"},
313 {0x03310000, 0, IPR_DEFAULT_LOG_LEVEL
,
314 "FFF3: Disk media format bad"},
315 {0x04050000, 0, IPR_DEFAULT_LOG_LEVEL
,
316 "3002: Addressed device failed to respond to selection"},
317 {0x04080000, 1, IPR_DEFAULT_LOG_LEVEL
,
318 "3100: Device bus error"},
319 {0x04080100, 0, IPR_DEFAULT_LOG_LEVEL
,
320 "3109: IOA timed out a device command"},
322 "3120: SCSI bus is not operational"},
323 {0x04088100, 0, IPR_DEFAULT_LOG_LEVEL
,
324 "4100: Hard device bus fabric error"},
325 {0x04100100, 0, IPR_DEFAULT_LOG_LEVEL
,
326 "310C: Logical block guard error detected by the device"},
327 {0x04100300, 0, IPR_DEFAULT_LOG_LEVEL
,
328 "310C: Logical block reference tag error detected by the device"},
329 {0x04108300, 1, IPR_DEFAULT_LOG_LEVEL
,
330 "4170: Scatter list tag / sequence number error"},
331 {0x04109000, 1, IPR_DEFAULT_LOG_LEVEL
,
332 "8150: Logical block CRC error on IOA to Host transfer"},
333 {0x04109200, 1, IPR_DEFAULT_LOG_LEVEL
,
334 "4170: Logical block sequence number error on IOA to Host transfer"},
335 {0x0410A000, 0, IPR_DEFAULT_LOG_LEVEL
,
336 "310D: Logical block reference tag error detected by the IOA"},
337 {0x0410A100, 0, IPR_DEFAULT_LOG_LEVEL
,
338 "310D: Logical block guard error detected by the IOA"},
339 {0x04118000, 0, IPR_DEFAULT_LOG_LEVEL
,
340 "9000: IOA reserved area data check"},
341 {0x04118100, 0, IPR_DEFAULT_LOG_LEVEL
,
342 "9001: IOA reserved area invalid data pattern"},
343 {0x04118200, 0, IPR_DEFAULT_LOG_LEVEL
,
344 "9002: IOA reserved area LRC error"},
345 {0x04118300, 1, IPR_DEFAULT_LOG_LEVEL
,
346 "Hardware Error, IOA metadata access error"},
347 {0x04320000, 0, IPR_DEFAULT_LOG_LEVEL
,
348 "102E: Out of alternate sectors for disk storage"},
349 {0x04330000, 1, IPR_DEFAULT_LOG_LEVEL
,
350 "FFF4: Data transfer underlength error"},
351 {0x04338000, 1, IPR_DEFAULT_LOG_LEVEL
,
352 "FFF4: Data transfer overlength error"},
353 {0x043E0100, 0, IPR_DEFAULT_LOG_LEVEL
,
354 "3400: Logical unit failure"},
355 {0x04408500, 0, IPR_DEFAULT_LOG_LEVEL
,
356 "FFF4: Device microcode is corrupt"},
357 {0x04418000, 1, IPR_DEFAULT_LOG_LEVEL
,
358 "8150: PCI bus error"},
360 "Unsupported device bus message received"},
361 {0x04440000, 1, IPR_DEFAULT_LOG_LEVEL
,
362 "FFF4: Disk device problem"},
363 {0x04448200, 1, IPR_DEFAULT_LOG_LEVEL
,
364 "8150: Permanent IOA failure"},
365 {0x04448300, 0, IPR_DEFAULT_LOG_LEVEL
,
366 "3010: Disk device returned wrong response to IOA"},
367 {0x04448400, 0, IPR_DEFAULT_LOG_LEVEL
,
368 "8151: IOA microcode error"},
370 "Device bus status error"},
371 {0x04448600, 0, IPR_DEFAULT_LOG_LEVEL
,
372 "8157: IOA error requiring IOA reset to recover"},
374 "ATA device status error"},
376 "Message reject received from the device"},
377 {0x04449200, 0, IPR_DEFAULT_LOG_LEVEL
,
378 "8008: A permanent cache battery pack failure occurred"},
379 {0x0444A000, 0, IPR_DEFAULT_LOG_LEVEL
,
380 "9090: Disk unit has been modified after the last known status"},
381 {0x0444A200, 0, IPR_DEFAULT_LOG_LEVEL
,
382 "9081: IOA detected device error"},
383 {0x0444A300, 0, IPR_DEFAULT_LOG_LEVEL
,
384 "9082: IOA detected device error"},
385 {0x044A0000, 1, IPR_DEFAULT_LOG_LEVEL
,
386 "3110: Device bus error, message or command phase"},
387 {0x044A8000, 1, IPR_DEFAULT_LOG_LEVEL
,
388 "3110: SAS Command / Task Management Function failed"},
389 {0x04670400, 0, IPR_DEFAULT_LOG_LEVEL
,
390 "9091: Incorrect hardware configuration change has been detected"},
391 {0x04678000, 0, IPR_DEFAULT_LOG_LEVEL
,
392 "9073: Invalid multi-adapter configuration"},
393 {0x04678100, 0, IPR_DEFAULT_LOG_LEVEL
,
394 "4010: Incorrect connection between cascaded expanders"},
395 {0x04678200, 0, IPR_DEFAULT_LOG_LEVEL
,
396 "4020: Connections exceed IOA design limits"},
397 {0x04678300, 0, IPR_DEFAULT_LOG_LEVEL
,
398 "4030: Incorrect multipath connection"},
399 {0x04679000, 0, IPR_DEFAULT_LOG_LEVEL
,
400 "4110: Unsupported enclosure function"},
401 {0x04679800, 0, IPR_DEFAULT_LOG_LEVEL
,
402 "4120: SAS cable VPD cannot be read"},
403 {0x046E0000, 0, IPR_DEFAULT_LOG_LEVEL
,
404 "FFF4: Command to logical unit failed"},
406 "Illegal request, invalid request type or request packet"},
408 "Illegal request, invalid resource handle"},
410 "Illegal request, commands not allowed to this device"},
412 "Illegal request, command not allowed to a secondary adapter"},
414 "Illegal request, command not allowed to a non-optimized resource"},
416 "Illegal request, invalid field in parameter list"},
418 "Illegal request, parameter not supported"},
420 "Illegal request, parameter value invalid"},
422 "Illegal request, command sequence error"},
424 "Illegal request, dual adapter support not enabled"},
426 "Illegal request, another cable connector was physically disabled"},
428 "Illegal request, inconsistent group id/group count"},
429 {0x06040500, 0, IPR_DEFAULT_LOG_LEVEL
,
430 "9031: Array protection temporarily suspended, protection resuming"},
431 {0x06040600, 0, IPR_DEFAULT_LOG_LEVEL
,
432 "9040: Array protection temporarily suspended, protection resuming"},
433 {0x060B0100, 0, IPR_DEFAULT_LOG_LEVEL
,
434 "4080: IOA exceeded maximum operating temperature"},
435 {0x060B8000, 0, IPR_DEFAULT_LOG_LEVEL
,
436 "4085: Service required"},
437 {0x06288000, 0, IPR_DEFAULT_LOG_LEVEL
,
438 "3140: Device bus not ready to ready transition"},
439 {0x06290000, 0, IPR_DEFAULT_LOG_LEVEL
,
440 "FFFB: SCSI bus was reset"},
442 "FFFE: SCSI bus transition to single ended"},
444 "FFFE: SCSI bus transition to LVD"},
445 {0x06298000, 0, IPR_DEFAULT_LOG_LEVEL
,
446 "FFFB: SCSI bus was reset by another initiator"},
447 {0x063F0300, 0, IPR_DEFAULT_LOG_LEVEL
,
448 "3029: A device replacement has occurred"},
449 {0x063F8300, 0, IPR_DEFAULT_LOG_LEVEL
,
450 "4102: Device bus fabric performance degradation"},
451 {0x064C8000, 0, IPR_DEFAULT_LOG_LEVEL
,
452 "9051: IOA cache data exists for a missing or failed device"},
453 {0x064C8100, 0, IPR_DEFAULT_LOG_LEVEL
,
454 "9055: Auxiliary cache IOA contains cache data needed by the primary IOA"},
455 {0x06670100, 0, IPR_DEFAULT_LOG_LEVEL
,
456 "9025: Disk unit is not supported at its physical location"},
457 {0x06670600, 0, IPR_DEFAULT_LOG_LEVEL
,
458 "3020: IOA detected a SCSI bus configuration error"},
459 {0x06678000, 0, IPR_DEFAULT_LOG_LEVEL
,
460 "3150: SCSI bus configuration error"},
461 {0x06678100, 0, IPR_DEFAULT_LOG_LEVEL
,
462 "9074: Asymmetric advanced function disk configuration"},
463 {0x06678300, 0, IPR_DEFAULT_LOG_LEVEL
,
464 "4040: Incomplete multipath connection between IOA and enclosure"},
465 {0x06678400, 0, IPR_DEFAULT_LOG_LEVEL
,
466 "4041: Incomplete multipath connection between enclosure and device"},
467 {0x06678500, 0, IPR_DEFAULT_LOG_LEVEL
,
468 "9075: Incomplete multipath connection between IOA and remote IOA"},
469 {0x06678600, 0, IPR_DEFAULT_LOG_LEVEL
,
470 "9076: Configuration error, missing remote IOA"},
471 {0x06679100, 0, IPR_DEFAULT_LOG_LEVEL
,
472 "4050: Enclosure does not support a required multipath function"},
473 {0x06679800, 0, IPR_DEFAULT_LOG_LEVEL
,
474 "4121: Configuration error, required cable is missing"},
475 {0x06679900, 0, IPR_DEFAULT_LOG_LEVEL
,
476 "4122: Cable is not plugged into the correct location on remote IOA"},
477 {0x06679A00, 0, IPR_DEFAULT_LOG_LEVEL
,
478 "4123: Configuration error, invalid cable vital product data"},
479 {0x06679B00, 0, IPR_DEFAULT_LOG_LEVEL
,
480 "4124: Configuration error, both cable ends are plugged into the same IOA"},
481 {0x06690000, 0, IPR_DEFAULT_LOG_LEVEL
,
482 "4070: Logically bad block written on device"},
483 {0x06690200, 0, IPR_DEFAULT_LOG_LEVEL
,
484 "9041: Array protection temporarily suspended"},
485 {0x06698200, 0, IPR_DEFAULT_LOG_LEVEL
,
486 "9042: Corrupt array parity detected on specified device"},
487 {0x066B0200, 0, IPR_DEFAULT_LOG_LEVEL
,
488 "9030: Array no longer protected due to missing or failed disk unit"},
489 {0x066B8000, 0, IPR_DEFAULT_LOG_LEVEL
,
490 "9071: Link operational transition"},
491 {0x066B8100, 0, IPR_DEFAULT_LOG_LEVEL
,
492 "9072: Link not operational transition"},
493 {0x066B8200, 0, IPR_DEFAULT_LOG_LEVEL
,
494 "9032: Array exposed but still protected"},
495 {0x066B8300, 0, IPR_DEFAULT_LOG_LEVEL
+ 1,
496 "70DD: Device forced failed by disrupt device command"},
497 {0x066B9100, 0, IPR_DEFAULT_LOG_LEVEL
,
498 "4061: Multipath redundancy level got better"},
499 {0x066B9200, 0, IPR_DEFAULT_LOG_LEVEL
,
500 "4060: Multipath redundancy level got worse"},
501 {0x06808100, 0, IPR_DEFAULT_LOG_LEVEL
,
502 "9083: Device raw mode enabled"},
503 {0x06808200, 0, IPR_DEFAULT_LOG_LEVEL
,
504 "9084: Device raw mode disabled"},
506 "Failure due to other device"},
507 {0x07278000, 0, IPR_DEFAULT_LOG_LEVEL
,
508 "9008: IOA does not support functions expected by devices"},
509 {0x07278100, 0, IPR_DEFAULT_LOG_LEVEL
,
510 "9010: Cache data associated with attached devices cannot be found"},
511 {0x07278200, 0, IPR_DEFAULT_LOG_LEVEL
,
512 "9011: Cache data belongs to devices other than those attached"},
513 {0x07278400, 0, IPR_DEFAULT_LOG_LEVEL
,
514 "9020: Array missing 2 or more devices with only 1 device present"},
515 {0x07278500, 0, IPR_DEFAULT_LOG_LEVEL
,
516 "9021: Array missing 2 or more devices with 2 or more devices present"},
517 {0x07278600, 0, IPR_DEFAULT_LOG_LEVEL
,
518 "9022: Exposed array is missing a required device"},
519 {0x07278700, 0, IPR_DEFAULT_LOG_LEVEL
,
520 "9023: Array member(s) not at required physical locations"},
521 {0x07278800, 0, IPR_DEFAULT_LOG_LEVEL
,
522 "9024: Array not functional due to present hardware configuration"},
523 {0x07278900, 0, IPR_DEFAULT_LOG_LEVEL
,
524 "9026: Array not functional due to present hardware configuration"},
525 {0x07278A00, 0, IPR_DEFAULT_LOG_LEVEL
,
526 "9027: Array is missing a device and parity is out of sync"},
527 {0x07278B00, 0, IPR_DEFAULT_LOG_LEVEL
,
528 "9028: Maximum number of arrays already exist"},
529 {0x07278C00, 0, IPR_DEFAULT_LOG_LEVEL
,
530 "9050: Required cache data cannot be located for a disk unit"},
531 {0x07278D00, 0, IPR_DEFAULT_LOG_LEVEL
,
532 "9052: Cache data exists for a device that has been modified"},
533 {0x07278F00, 0, IPR_DEFAULT_LOG_LEVEL
,
534 "9054: IOA resources not available due to previous problems"},
535 {0x07279100, 0, IPR_DEFAULT_LOG_LEVEL
,
536 "9092: Disk unit requires initialization before use"},
537 {0x07279200, 0, IPR_DEFAULT_LOG_LEVEL
,
538 "9029: Incorrect hardware configuration change has been detected"},
539 {0x07279600, 0, IPR_DEFAULT_LOG_LEVEL
,
540 "9060: One or more disk pairs are missing from an array"},
541 {0x07279700, 0, IPR_DEFAULT_LOG_LEVEL
,
542 "9061: One or more disks are missing from an array"},
543 {0x07279800, 0, IPR_DEFAULT_LOG_LEVEL
,
544 "9062: One or more disks are missing from an array"},
545 {0x07279900, 0, IPR_DEFAULT_LOG_LEVEL
,
546 "9063: Maximum number of functional arrays has been exceeded"},
548 "Data protect, other volume set problem"},
550 "Aborted command, invalid descriptor"},
552 "Target operating conditions have changed, dual adapter takeover"},
554 "Aborted command, medium removal prevented"},
556 "Command terminated by host"},
558 "Aborted command, command terminated by host"}
561 static const struct ipr_ses_table_entry ipr_ses_table
[] = {
562 { "2104-DL1 ", "XXXXXXXXXXXXXXXX", 80 },
563 { "2104-TL1 ", "XXXXXXXXXXXXXXXX", 80 },
564 { "HSBP07M P U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Hidive 7 slot */
565 { "HSBP05M P U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Hidive 5 slot */
566 { "HSBP05M S U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Bowtie */
567 { "HSBP06E ASU2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* MartinFenning */
568 { "2104-DU3 ", "XXXXXXXXXXXXXXXX", 160 },
569 { "2104-TU3 ", "XXXXXXXXXXXXXXXX", 160 },
570 { "HSBP04C RSU2SCSI", "XXXXXXX*XXXXXXXX", 160 },
571 { "HSBP06E RSU2SCSI", "XXXXXXX*XXXXXXXX", 160 },
572 { "St V1S2 ", "XXXXXXXXXXXXXXXX", 160 },
573 { "HSBPD4M PU3SCSI", "XXXXXXX*XXXXXXXX", 160 },
574 { "VSBPD1H U3SCSI", "XXXXXXX*XXXXXXXX", 160 }
578 * Function Prototypes
580 static int ipr_reset_alert(struct ipr_cmnd
*);
581 static void ipr_process_ccn(struct ipr_cmnd
*);
582 static void ipr_process_error(struct ipr_cmnd
*);
583 static void ipr_reset_ioa_job(struct ipr_cmnd
*);
584 static void ipr_initiate_ioa_reset(struct ipr_ioa_cfg
*,
585 enum ipr_shutdown_type
);
587 #ifdef CONFIG_SCSI_IPR_TRACE
589 * ipr_trc_hook - Add a trace entry to the driver trace
590 * @ipr_cmd: ipr command struct
592 * @add_data: additional data
597 static void ipr_trc_hook(struct ipr_cmnd
*ipr_cmd
,
598 u8 type
, u32 add_data
)
600 struct ipr_trace_entry
*trace_entry
;
601 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
603 trace_entry
= &ioa_cfg
->trace
[atomic_add_return
604 (1, &ioa_cfg
->trace_index
)%IPR_NUM_TRACE_ENTRIES
];
605 trace_entry
->time
= jiffies
;
606 trace_entry
->op_code
= ipr_cmd
->ioarcb
.cmd_pkt
.cdb
[0];
607 trace_entry
->type
= type
;
608 if (ipr_cmd
->ioa_cfg
->sis64
)
609 trace_entry
->ata_op_code
= ipr_cmd
->i
.ata_ioadl
.regs
.command
;
611 trace_entry
->ata_op_code
= ipr_cmd
->ioarcb
.u
.add_data
.u
.regs
.command
;
612 trace_entry
->cmd_index
= ipr_cmd
->cmd_index
& 0xff;
613 trace_entry
->res_handle
= ipr_cmd
->ioarcb
.res_handle
;
614 trace_entry
->u
.add_data
= add_data
;
618 #define ipr_trc_hook(ipr_cmd, type, add_data) do { } while (0)
622 * ipr_lock_and_done - Acquire lock and complete command
623 * @ipr_cmd: ipr command struct
628 static void ipr_lock_and_done(struct ipr_cmnd
*ipr_cmd
)
630 unsigned long lock_flags
;
631 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
633 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
634 ipr_cmd
->done(ipr_cmd
);
635 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
639 * ipr_reinit_ipr_cmnd - Re-initialize an IPR Cmnd block for reuse
640 * @ipr_cmd: ipr command struct
645 static void ipr_reinit_ipr_cmnd(struct ipr_cmnd
*ipr_cmd
)
647 struct ipr_ioarcb
*ioarcb
= &ipr_cmd
->ioarcb
;
648 struct ipr_ioasa
*ioasa
= &ipr_cmd
->s
.ioasa
;
649 struct ipr_ioasa64
*ioasa64
= &ipr_cmd
->s
.ioasa64
;
650 dma_addr_t dma_addr
= ipr_cmd
->dma_addr
;
653 hrrq_id
= ioarcb
->cmd_pkt
.hrrq_id
;
654 memset(&ioarcb
->cmd_pkt
, 0, sizeof(struct ipr_cmd_pkt
));
655 ioarcb
->cmd_pkt
.hrrq_id
= hrrq_id
;
656 ioarcb
->data_transfer_length
= 0;
657 ioarcb
->read_data_transfer_length
= 0;
658 ioarcb
->ioadl_len
= 0;
659 ioarcb
->read_ioadl_len
= 0;
661 if (ipr_cmd
->ioa_cfg
->sis64
) {
662 ioarcb
->u
.sis64_addr_data
.data_ioadl_addr
=
663 cpu_to_be64(dma_addr
+ offsetof(struct ipr_cmnd
, i
.ioadl64
));
664 ioasa64
->u
.gata
.status
= 0;
666 ioarcb
->write_ioadl_addr
=
667 cpu_to_be32(dma_addr
+ offsetof(struct ipr_cmnd
, i
.ioadl
));
668 ioarcb
->read_ioadl_addr
= ioarcb
->write_ioadl_addr
;
669 ioasa
->u
.gata
.status
= 0;
672 ioasa
->hdr
.ioasc
= 0;
673 ioasa
->hdr
.residual_data_len
= 0;
674 ipr_cmd
->scsi_cmd
= NULL
;
676 ipr_cmd
->sense_buffer
[0] = 0;
677 ipr_cmd
->dma_use_sg
= 0;
681 * ipr_init_ipr_cmnd - Initialize an IPR Cmnd block
682 * @ipr_cmd: ipr command struct
687 static void ipr_init_ipr_cmnd(struct ipr_cmnd
*ipr_cmd
,
688 void (*fast_done
) (struct ipr_cmnd
*))
690 ipr_reinit_ipr_cmnd(ipr_cmd
);
691 ipr_cmd
->u
.scratch
= 0;
692 ipr_cmd
->sibling
= NULL
;
693 ipr_cmd
->eh_comp
= NULL
;
694 ipr_cmd
->fast_done
= fast_done
;
695 init_timer(&ipr_cmd
->timer
);
699 * __ipr_get_free_ipr_cmnd - Get a free IPR Cmnd block
700 * @ioa_cfg: ioa config struct
703 * pointer to ipr command struct
706 struct ipr_cmnd
*__ipr_get_free_ipr_cmnd(struct ipr_hrr_queue
*hrrq
)
708 struct ipr_cmnd
*ipr_cmd
= NULL
;
710 if (likely(!list_empty(&hrrq
->hrrq_free_q
))) {
711 ipr_cmd
= list_entry(hrrq
->hrrq_free_q
.next
,
712 struct ipr_cmnd
, queue
);
713 list_del(&ipr_cmd
->queue
);
721 * ipr_get_free_ipr_cmnd - Get a free IPR Cmnd block and initialize it
722 * @ioa_cfg: ioa config struct
725 * pointer to ipr command struct
728 struct ipr_cmnd
*ipr_get_free_ipr_cmnd(struct ipr_ioa_cfg
*ioa_cfg
)
730 struct ipr_cmnd
*ipr_cmd
=
731 __ipr_get_free_ipr_cmnd(&ioa_cfg
->hrrq
[IPR_INIT_HRRQ
]);
732 ipr_init_ipr_cmnd(ipr_cmd
, ipr_lock_and_done
);
737 * ipr_mask_and_clear_interrupts - Mask all and clear specified interrupts
738 * @ioa_cfg: ioa config struct
739 * @clr_ints: interrupts to clear
741 * This function masks all interrupts on the adapter, then clears the
742 * interrupts specified in the mask
747 static void ipr_mask_and_clear_interrupts(struct ipr_ioa_cfg
*ioa_cfg
,
750 volatile u32 int_reg
;
753 /* Stop new interrupts */
754 for (i
= 0; i
< ioa_cfg
->hrrq_num
; i
++) {
755 spin_lock(&ioa_cfg
->hrrq
[i
]._lock
);
756 ioa_cfg
->hrrq
[i
].allow_interrupts
= 0;
757 spin_unlock(&ioa_cfg
->hrrq
[i
]._lock
);
761 /* Set interrupt mask to stop all new interrupts */
763 writeq(~0, ioa_cfg
->regs
.set_interrupt_mask_reg
);
765 writel(~0, ioa_cfg
->regs
.set_interrupt_mask_reg
);
767 /* Clear any pending interrupts */
769 writel(~0, ioa_cfg
->regs
.clr_interrupt_reg
);
770 writel(clr_ints
, ioa_cfg
->regs
.clr_interrupt_reg32
);
771 int_reg
= readl(ioa_cfg
->regs
.sense_interrupt_reg
);
775 * ipr_save_pcix_cmd_reg - Save PCI-X command register
776 * @ioa_cfg: ioa config struct
779 * 0 on success / -EIO on failure
781 static int ipr_save_pcix_cmd_reg(struct ipr_ioa_cfg
*ioa_cfg
)
783 int pcix_cmd_reg
= pci_find_capability(ioa_cfg
->pdev
, PCI_CAP_ID_PCIX
);
785 if (pcix_cmd_reg
== 0)
788 if (pci_read_config_word(ioa_cfg
->pdev
, pcix_cmd_reg
+ PCI_X_CMD
,
789 &ioa_cfg
->saved_pcix_cmd_reg
) != PCIBIOS_SUCCESSFUL
) {
790 dev_err(&ioa_cfg
->pdev
->dev
, "Failed to save PCI-X command register\n");
794 ioa_cfg
->saved_pcix_cmd_reg
|= PCI_X_CMD_DPERR_E
| PCI_X_CMD_ERO
;
799 * ipr_set_pcix_cmd_reg - Setup PCI-X command register
800 * @ioa_cfg: ioa config struct
803 * 0 on success / -EIO on failure
805 static int ipr_set_pcix_cmd_reg(struct ipr_ioa_cfg
*ioa_cfg
)
807 int pcix_cmd_reg
= pci_find_capability(ioa_cfg
->pdev
, PCI_CAP_ID_PCIX
);
810 if (pci_write_config_word(ioa_cfg
->pdev
, pcix_cmd_reg
+ PCI_X_CMD
,
811 ioa_cfg
->saved_pcix_cmd_reg
) != PCIBIOS_SUCCESSFUL
) {
812 dev_err(&ioa_cfg
->pdev
->dev
, "Failed to setup PCI-X command register\n");
821 * ipr_sata_eh_done - done function for aborted SATA commands
822 * @ipr_cmd: ipr command struct
824 * This function is invoked for ops generated to SATA
825 * devices which are being aborted.
830 static void ipr_sata_eh_done(struct ipr_cmnd
*ipr_cmd
)
832 struct ata_queued_cmd
*qc
= ipr_cmd
->qc
;
833 struct ipr_sata_port
*sata_port
= qc
->ap
->private_data
;
835 qc
->err_mask
|= AC_ERR_OTHER
;
836 sata_port
->ioasa
.status
|= ATA_BUSY
;
837 list_add_tail(&ipr_cmd
->queue
, &ipr_cmd
->hrrq
->hrrq_free_q
);
842 * ipr_scsi_eh_done - mid-layer done function for aborted ops
843 * @ipr_cmd: ipr command struct
845 * This function is invoked by the interrupt handler for
846 * ops generated by the SCSI mid-layer which are being aborted.
851 static void ipr_scsi_eh_done(struct ipr_cmnd
*ipr_cmd
)
853 struct scsi_cmnd
*scsi_cmd
= ipr_cmd
->scsi_cmd
;
855 scsi_cmd
->result
|= (DID_ERROR
<< 16);
857 scsi_dma_unmap(ipr_cmd
->scsi_cmd
);
858 scsi_cmd
->scsi_done(scsi_cmd
);
859 if (ipr_cmd
->eh_comp
)
860 complete(ipr_cmd
->eh_comp
);
861 list_add_tail(&ipr_cmd
->queue
, &ipr_cmd
->hrrq
->hrrq_free_q
);
865 * ipr_fail_all_ops - Fails all outstanding ops.
866 * @ioa_cfg: ioa config struct
868 * This function fails all outstanding ops.
873 static void ipr_fail_all_ops(struct ipr_ioa_cfg
*ioa_cfg
)
875 struct ipr_cmnd
*ipr_cmd
, *temp
;
876 struct ipr_hrr_queue
*hrrq
;
879 for_each_hrrq(hrrq
, ioa_cfg
) {
880 spin_lock(&hrrq
->_lock
);
881 list_for_each_entry_safe(ipr_cmd
,
882 temp
, &hrrq
->hrrq_pending_q
, queue
) {
883 list_del(&ipr_cmd
->queue
);
885 ipr_cmd
->s
.ioasa
.hdr
.ioasc
=
886 cpu_to_be32(IPR_IOASC_IOA_WAS_RESET
);
887 ipr_cmd
->s
.ioasa
.hdr
.ilid
=
888 cpu_to_be32(IPR_DRIVER_ILID
);
890 if (ipr_cmd
->scsi_cmd
)
891 ipr_cmd
->done
= ipr_scsi_eh_done
;
892 else if (ipr_cmd
->qc
)
893 ipr_cmd
->done
= ipr_sata_eh_done
;
895 ipr_trc_hook(ipr_cmd
, IPR_TRACE_FINISH
,
896 IPR_IOASC_IOA_WAS_RESET
);
897 del_timer(&ipr_cmd
->timer
);
898 ipr_cmd
->done(ipr_cmd
);
900 spin_unlock(&hrrq
->_lock
);
906 * ipr_send_command - Send driver initiated requests.
907 * @ipr_cmd: ipr command struct
909 * This function sends a command to the adapter using the correct write call.
910 * In the case of sis64, calculate the ioarcb size required. Then or in the
916 static void ipr_send_command(struct ipr_cmnd
*ipr_cmd
)
918 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
919 dma_addr_t send_dma_addr
= ipr_cmd
->dma_addr
;
921 if (ioa_cfg
->sis64
) {
922 /* The default size is 256 bytes */
923 send_dma_addr
|= 0x1;
925 /* If the number of ioadls * size of ioadl > 128 bytes,
926 then use a 512 byte ioarcb */
927 if (ipr_cmd
->dma_use_sg
* sizeof(struct ipr_ioadl64_desc
) > 128 )
928 send_dma_addr
|= 0x4;
929 writeq(send_dma_addr
, ioa_cfg
->regs
.ioarrin_reg
);
931 writel(send_dma_addr
, ioa_cfg
->regs
.ioarrin_reg
);
935 * ipr_do_req - Send driver initiated requests.
936 * @ipr_cmd: ipr command struct
937 * @done: done function
938 * @timeout_func: timeout function
939 * @timeout: timeout value
941 * This function sends the specified command to the adapter with the
942 * timeout given. The done function is invoked on command completion.
947 static void ipr_do_req(struct ipr_cmnd
*ipr_cmd
,
948 void (*done
) (struct ipr_cmnd
*),
949 void (*timeout_func
) (struct ipr_cmnd
*), u32 timeout
)
951 list_add_tail(&ipr_cmd
->queue
, &ipr_cmd
->hrrq
->hrrq_pending_q
);
953 ipr_cmd
->done
= done
;
955 ipr_cmd
->timer
.data
= (unsigned long) ipr_cmd
;
956 ipr_cmd
->timer
.expires
= jiffies
+ timeout
;
957 ipr_cmd
->timer
.function
= (void (*)(unsigned long))timeout_func
;
959 add_timer(&ipr_cmd
->timer
);
961 ipr_trc_hook(ipr_cmd
, IPR_TRACE_START
, 0);
963 ipr_send_command(ipr_cmd
);
967 * ipr_internal_cmd_done - Op done function for an internally generated op.
968 * @ipr_cmd: ipr command struct
970 * This function is the op done function for an internally generated,
971 * blocking op. It simply wakes the sleeping thread.
976 static void ipr_internal_cmd_done(struct ipr_cmnd
*ipr_cmd
)
978 if (ipr_cmd
->sibling
)
979 ipr_cmd
->sibling
= NULL
;
981 complete(&ipr_cmd
->completion
);
985 * ipr_init_ioadl - initialize the ioadl for the correct SIS type
986 * @ipr_cmd: ipr command struct
987 * @dma_addr: dma address
988 * @len: transfer length
989 * @flags: ioadl flag value
991 * This function initializes an ioadl in the case where there is only a single
997 static void ipr_init_ioadl(struct ipr_cmnd
*ipr_cmd
, dma_addr_t dma_addr
,
1000 struct ipr_ioadl_desc
*ioadl
= ipr_cmd
->i
.ioadl
;
1001 struct ipr_ioadl64_desc
*ioadl64
= ipr_cmd
->i
.ioadl64
;
1003 ipr_cmd
->dma_use_sg
= 1;
1005 if (ipr_cmd
->ioa_cfg
->sis64
) {
1006 ioadl64
->flags
= cpu_to_be32(flags
);
1007 ioadl64
->data_len
= cpu_to_be32(len
);
1008 ioadl64
->address
= cpu_to_be64(dma_addr
);
1010 ipr_cmd
->ioarcb
.ioadl_len
=
1011 cpu_to_be32(sizeof(struct ipr_ioadl64_desc
));
1012 ipr_cmd
->ioarcb
.data_transfer_length
= cpu_to_be32(len
);
1014 ioadl
->flags_and_data_len
= cpu_to_be32(flags
| len
);
1015 ioadl
->address
= cpu_to_be32(dma_addr
);
1017 if (flags
== IPR_IOADL_FLAGS_READ_LAST
) {
1018 ipr_cmd
->ioarcb
.read_ioadl_len
=
1019 cpu_to_be32(sizeof(struct ipr_ioadl_desc
));
1020 ipr_cmd
->ioarcb
.read_data_transfer_length
= cpu_to_be32(len
);
1022 ipr_cmd
->ioarcb
.ioadl_len
=
1023 cpu_to_be32(sizeof(struct ipr_ioadl_desc
));
1024 ipr_cmd
->ioarcb
.data_transfer_length
= cpu_to_be32(len
);
1030 * ipr_send_blocking_cmd - Send command and sleep on its completion.
1031 * @ipr_cmd: ipr command struct
1032 * @timeout_func: function to invoke if command times out
1038 static void ipr_send_blocking_cmd(struct ipr_cmnd
*ipr_cmd
,
1039 void (*timeout_func
) (struct ipr_cmnd
*ipr_cmd
),
1042 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
1044 init_completion(&ipr_cmd
->completion
);
1045 ipr_do_req(ipr_cmd
, ipr_internal_cmd_done
, timeout_func
, timeout
);
1047 spin_unlock_irq(ioa_cfg
->host
->host_lock
);
1048 wait_for_completion(&ipr_cmd
->completion
);
1049 spin_lock_irq(ioa_cfg
->host
->host_lock
);
1052 static int ipr_get_hrrq_index(struct ipr_ioa_cfg
*ioa_cfg
)
1054 if (ioa_cfg
->hrrq_num
== 1)
1057 return (atomic_add_return(1, &ioa_cfg
->hrrq_index
) % (ioa_cfg
->hrrq_num
- 1)) + 1;
1061 * ipr_send_hcam - Send an HCAM to the adapter.
1062 * @ioa_cfg: ioa config struct
1064 * @hostrcb: hostrcb struct
1066 * This function will send a Host Controlled Async command to the adapter.
1067 * If HCAMs are currently not allowed to be issued to the adapter, it will
1068 * place the hostrcb on the free queue.
1073 static void ipr_send_hcam(struct ipr_ioa_cfg
*ioa_cfg
, u8 type
,
1074 struct ipr_hostrcb
*hostrcb
)
1076 struct ipr_cmnd
*ipr_cmd
;
1077 struct ipr_ioarcb
*ioarcb
;
1079 if (ioa_cfg
->hrrq
[IPR_INIT_HRRQ
].allow_cmds
) {
1080 ipr_cmd
= ipr_get_free_ipr_cmnd(ioa_cfg
);
1081 list_add_tail(&ipr_cmd
->queue
, &ipr_cmd
->hrrq
->hrrq_pending_q
);
1082 list_add_tail(&hostrcb
->queue
, &ioa_cfg
->hostrcb_pending_q
);
1084 ipr_cmd
->u
.hostrcb
= hostrcb
;
1085 ioarcb
= &ipr_cmd
->ioarcb
;
1087 ioarcb
->res_handle
= cpu_to_be32(IPR_IOA_RES_HANDLE
);
1088 ioarcb
->cmd_pkt
.request_type
= IPR_RQTYPE_HCAM
;
1089 ioarcb
->cmd_pkt
.cdb
[0] = IPR_HOST_CONTROLLED_ASYNC
;
1090 ioarcb
->cmd_pkt
.cdb
[1] = type
;
1091 ioarcb
->cmd_pkt
.cdb
[7] = (sizeof(hostrcb
->hcam
) >> 8) & 0xff;
1092 ioarcb
->cmd_pkt
.cdb
[8] = sizeof(hostrcb
->hcam
) & 0xff;
1094 ipr_init_ioadl(ipr_cmd
, hostrcb
->hostrcb_dma
,
1095 sizeof(hostrcb
->hcam
), IPR_IOADL_FLAGS_READ_LAST
);
1097 if (type
== IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE
)
1098 ipr_cmd
->done
= ipr_process_ccn
;
1100 ipr_cmd
->done
= ipr_process_error
;
1102 ipr_trc_hook(ipr_cmd
, IPR_TRACE_START
, IPR_IOA_RES_ADDR
);
1104 ipr_send_command(ipr_cmd
);
1106 list_add_tail(&hostrcb
->queue
, &ioa_cfg
->hostrcb_free_q
);
1111 * ipr_update_ata_class - Update the ata class in the resource entry
1112 * @res: resource entry struct
1113 * @proto: cfgte device bus protocol value
1118 static void ipr_update_ata_class(struct ipr_resource_entry
*res
, unsigned int proto
)
1121 case IPR_PROTO_SATA
:
1122 case IPR_PROTO_SAS_STP
:
1123 res
->ata_class
= ATA_DEV_ATA
;
1125 case IPR_PROTO_SATA_ATAPI
:
1126 case IPR_PROTO_SAS_STP_ATAPI
:
1127 res
->ata_class
= ATA_DEV_ATAPI
;
1130 res
->ata_class
= ATA_DEV_UNKNOWN
;
1136 * ipr_init_res_entry - Initialize a resource entry struct.
1137 * @res: resource entry struct
1138 * @cfgtew: config table entry wrapper struct
1143 static void ipr_init_res_entry(struct ipr_resource_entry
*res
,
1144 struct ipr_config_table_entry_wrapper
*cfgtew
)
1148 struct ipr_ioa_cfg
*ioa_cfg
= res
->ioa_cfg
;
1149 struct ipr_resource_entry
*gscsi_res
= NULL
;
1151 res
->needs_sync_complete
= 0;
1154 res
->del_from_ml
= 0;
1155 res
->resetting_device
= 0;
1156 res
->reset_occurred
= 0;
1158 res
->sata_port
= NULL
;
1160 if (ioa_cfg
->sis64
) {
1161 proto
= cfgtew
->u
.cfgte64
->proto
;
1162 res
->res_flags
= cfgtew
->u
.cfgte64
->res_flags
;
1163 res
->qmodel
= IPR_QUEUEING_MODEL64(res
);
1164 res
->type
= cfgtew
->u
.cfgte64
->res_type
;
1166 memcpy(res
->res_path
, &cfgtew
->u
.cfgte64
->res_path
,
1167 sizeof(res
->res_path
));
1170 memcpy(&res
->dev_lun
.scsi_lun
, &cfgtew
->u
.cfgte64
->lun
,
1171 sizeof(res
->dev_lun
.scsi_lun
));
1172 res
->lun
= scsilun_to_int(&res
->dev_lun
);
1174 if (res
->type
== IPR_RES_TYPE_GENERIC_SCSI
) {
1175 list_for_each_entry(gscsi_res
, &ioa_cfg
->used_res_q
, queue
) {
1176 if (gscsi_res
->dev_id
== cfgtew
->u
.cfgte64
->dev_id
) {
1178 res
->target
= gscsi_res
->target
;
1183 res
->target
= find_first_zero_bit(ioa_cfg
->target_ids
,
1184 ioa_cfg
->max_devs_supported
);
1185 set_bit(res
->target
, ioa_cfg
->target_ids
);
1187 } else if (res
->type
== IPR_RES_TYPE_IOAFP
) {
1188 res
->bus
= IPR_IOAFP_VIRTUAL_BUS
;
1190 } else if (res
->type
== IPR_RES_TYPE_ARRAY
) {
1191 res
->bus
= IPR_ARRAY_VIRTUAL_BUS
;
1192 res
->target
= find_first_zero_bit(ioa_cfg
->array_ids
,
1193 ioa_cfg
->max_devs_supported
);
1194 set_bit(res
->target
, ioa_cfg
->array_ids
);
1195 } else if (res
->type
== IPR_RES_TYPE_VOLUME_SET
) {
1196 res
->bus
= IPR_VSET_VIRTUAL_BUS
;
1197 res
->target
= find_first_zero_bit(ioa_cfg
->vset_ids
,
1198 ioa_cfg
->max_devs_supported
);
1199 set_bit(res
->target
, ioa_cfg
->vset_ids
);
1201 res
->target
= find_first_zero_bit(ioa_cfg
->target_ids
,
1202 ioa_cfg
->max_devs_supported
);
1203 set_bit(res
->target
, ioa_cfg
->target_ids
);
1206 proto
= cfgtew
->u
.cfgte
->proto
;
1207 res
->qmodel
= IPR_QUEUEING_MODEL(res
);
1208 res
->flags
= cfgtew
->u
.cfgte
->flags
;
1209 if (res
->flags
& IPR_IS_IOA_RESOURCE
)
1210 res
->type
= IPR_RES_TYPE_IOAFP
;
1212 res
->type
= cfgtew
->u
.cfgte
->rsvd_subtype
& 0x0f;
1214 res
->bus
= cfgtew
->u
.cfgte
->res_addr
.bus
;
1215 res
->target
= cfgtew
->u
.cfgte
->res_addr
.target
;
1216 res
->lun
= cfgtew
->u
.cfgte
->res_addr
.lun
;
1217 res
->lun_wwn
= get_unaligned_be64(cfgtew
->u
.cfgte
->lun_wwn
);
1220 ipr_update_ata_class(res
, proto
);
1224 * ipr_is_same_device - Determine if two devices are the same.
1225 * @res: resource entry struct
1226 * @cfgtew: config table entry wrapper struct
1229 * 1 if the devices are the same / 0 otherwise
1231 static int ipr_is_same_device(struct ipr_resource_entry
*res
,
1232 struct ipr_config_table_entry_wrapper
*cfgtew
)
1234 if (res
->ioa_cfg
->sis64
) {
1235 if (!memcmp(&res
->dev_id
, &cfgtew
->u
.cfgte64
->dev_id
,
1236 sizeof(cfgtew
->u
.cfgte64
->dev_id
)) &&
1237 !memcmp(&res
->dev_lun
.scsi_lun
, &cfgtew
->u
.cfgte64
->lun
,
1238 sizeof(cfgtew
->u
.cfgte64
->lun
))) {
1242 if (res
->bus
== cfgtew
->u
.cfgte
->res_addr
.bus
&&
1243 res
->target
== cfgtew
->u
.cfgte
->res_addr
.target
&&
1244 res
->lun
== cfgtew
->u
.cfgte
->res_addr
.lun
)
1252 * __ipr_format_res_path - Format the resource path for printing.
1253 * @res_path: resource path
1255 * @len: length of buffer provided
1260 static char *__ipr_format_res_path(u8
*res_path
, char *buffer
, int len
)
1266 p
+= snprintf(p
, buffer
+ len
- p
, "%02X", res_path
[0]);
1267 for (i
= 1; res_path
[i
] != 0xff && ((i
* 3) < len
); i
++)
1268 p
+= snprintf(p
, buffer
+ len
- p
, "-%02X", res_path
[i
]);
1274 * ipr_format_res_path - Format the resource path for printing.
1275 * @ioa_cfg: ioa config struct
1276 * @res_path: resource path
1278 * @len: length of buffer provided
1283 static char *ipr_format_res_path(struct ipr_ioa_cfg
*ioa_cfg
,
1284 u8
*res_path
, char *buffer
, int len
)
1289 p
+= snprintf(p
, buffer
+ len
- p
, "%d/", ioa_cfg
->host
->host_no
);
1290 __ipr_format_res_path(res_path
, p
, len
- (buffer
- p
));
1295 * ipr_update_res_entry - Update the resource entry.
1296 * @res: resource entry struct
1297 * @cfgtew: config table entry wrapper struct
1302 static void ipr_update_res_entry(struct ipr_resource_entry
*res
,
1303 struct ipr_config_table_entry_wrapper
*cfgtew
)
1305 char buffer
[IPR_MAX_RES_PATH_LENGTH
];
1309 if (res
->ioa_cfg
->sis64
) {
1310 res
->flags
= cfgtew
->u
.cfgte64
->flags
;
1311 res
->res_flags
= cfgtew
->u
.cfgte64
->res_flags
;
1312 res
->type
= cfgtew
->u
.cfgte64
->res_type
;
1314 memcpy(&res
->std_inq_data
, &cfgtew
->u
.cfgte64
->std_inq_data
,
1315 sizeof(struct ipr_std_inq_data
));
1317 res
->qmodel
= IPR_QUEUEING_MODEL64(res
);
1318 proto
= cfgtew
->u
.cfgte64
->proto
;
1319 res
->res_handle
= cfgtew
->u
.cfgte64
->res_handle
;
1320 res
->dev_id
= cfgtew
->u
.cfgte64
->dev_id
;
1322 memcpy(&res
->dev_lun
.scsi_lun
, &cfgtew
->u
.cfgte64
->lun
,
1323 sizeof(res
->dev_lun
.scsi_lun
));
1325 if (memcmp(res
->res_path
, &cfgtew
->u
.cfgte64
->res_path
,
1326 sizeof(res
->res_path
))) {
1327 memcpy(res
->res_path
, &cfgtew
->u
.cfgte64
->res_path
,
1328 sizeof(res
->res_path
));
1332 if (res
->sdev
&& new_path
)
1333 sdev_printk(KERN_INFO
, res
->sdev
, "Resource path: %s\n",
1334 ipr_format_res_path(res
->ioa_cfg
,
1335 res
->res_path
, buffer
, sizeof(buffer
)));
1337 res
->flags
= cfgtew
->u
.cfgte
->flags
;
1338 if (res
->flags
& IPR_IS_IOA_RESOURCE
)
1339 res
->type
= IPR_RES_TYPE_IOAFP
;
1341 res
->type
= cfgtew
->u
.cfgte
->rsvd_subtype
& 0x0f;
1343 memcpy(&res
->std_inq_data
, &cfgtew
->u
.cfgte
->std_inq_data
,
1344 sizeof(struct ipr_std_inq_data
));
1346 res
->qmodel
= IPR_QUEUEING_MODEL(res
);
1347 proto
= cfgtew
->u
.cfgte
->proto
;
1348 res
->res_handle
= cfgtew
->u
.cfgte
->res_handle
;
1351 ipr_update_ata_class(res
, proto
);
1355 * ipr_clear_res_target - Clear the bit in the bit map representing the target
1357 * @res: resource entry struct
1358 * @cfgtew: config table entry wrapper struct
1363 static void ipr_clear_res_target(struct ipr_resource_entry
*res
)
1365 struct ipr_resource_entry
*gscsi_res
= NULL
;
1366 struct ipr_ioa_cfg
*ioa_cfg
= res
->ioa_cfg
;
1368 if (!ioa_cfg
->sis64
)
1371 if (res
->bus
== IPR_ARRAY_VIRTUAL_BUS
)
1372 clear_bit(res
->target
, ioa_cfg
->array_ids
);
1373 else if (res
->bus
== IPR_VSET_VIRTUAL_BUS
)
1374 clear_bit(res
->target
, ioa_cfg
->vset_ids
);
1375 else if (res
->bus
== 0 && res
->type
== IPR_RES_TYPE_GENERIC_SCSI
) {
1376 list_for_each_entry(gscsi_res
, &ioa_cfg
->used_res_q
, queue
)
1377 if (gscsi_res
->dev_id
== res
->dev_id
&& gscsi_res
!= res
)
1379 clear_bit(res
->target
, ioa_cfg
->target_ids
);
1381 } else if (res
->bus
== 0)
1382 clear_bit(res
->target
, ioa_cfg
->target_ids
);
1386 * ipr_handle_config_change - Handle a config change from the adapter
1387 * @ioa_cfg: ioa config struct
1393 static void ipr_handle_config_change(struct ipr_ioa_cfg
*ioa_cfg
,
1394 struct ipr_hostrcb
*hostrcb
)
1396 struct ipr_resource_entry
*res
= NULL
;
1397 struct ipr_config_table_entry_wrapper cfgtew
;
1398 __be32 cc_res_handle
;
1402 if (ioa_cfg
->sis64
) {
1403 cfgtew
.u
.cfgte64
= &hostrcb
->hcam
.u
.ccn
.u
.cfgte64
;
1404 cc_res_handle
= cfgtew
.u
.cfgte64
->res_handle
;
1406 cfgtew
.u
.cfgte
= &hostrcb
->hcam
.u
.ccn
.u
.cfgte
;
1407 cc_res_handle
= cfgtew
.u
.cfgte
->res_handle
;
1410 list_for_each_entry(res
, &ioa_cfg
->used_res_q
, queue
) {
1411 if (res
->res_handle
== cc_res_handle
) {
1418 if (list_empty(&ioa_cfg
->free_res_q
)) {
1419 ipr_send_hcam(ioa_cfg
,
1420 IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE
,
1425 res
= list_entry(ioa_cfg
->free_res_q
.next
,
1426 struct ipr_resource_entry
, queue
);
1428 list_del(&res
->queue
);
1429 ipr_init_res_entry(res
, &cfgtew
);
1430 list_add_tail(&res
->queue
, &ioa_cfg
->used_res_q
);
1433 ipr_update_res_entry(res
, &cfgtew
);
1435 if (hostrcb
->hcam
.notify_type
== IPR_HOST_RCB_NOTIF_TYPE_REM_ENTRY
) {
1437 res
->del_from_ml
= 1;
1438 res
->res_handle
= IPR_INVALID_RES_HANDLE
;
1439 schedule_work(&ioa_cfg
->work_q
);
1441 ipr_clear_res_target(res
);
1442 list_move_tail(&res
->queue
, &ioa_cfg
->free_res_q
);
1444 } else if (!res
->sdev
|| res
->del_from_ml
) {
1446 schedule_work(&ioa_cfg
->work_q
);
1449 ipr_send_hcam(ioa_cfg
, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE
, hostrcb
);
1453 * ipr_process_ccn - Op done function for a CCN.
1454 * @ipr_cmd: ipr command struct
1456 * This function is the op done function for a configuration
1457 * change notification host controlled async from the adapter.
1462 static void ipr_process_ccn(struct ipr_cmnd
*ipr_cmd
)
1464 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
1465 struct ipr_hostrcb
*hostrcb
= ipr_cmd
->u
.hostrcb
;
1466 u32 ioasc
= be32_to_cpu(ipr_cmd
->s
.ioasa
.hdr
.ioasc
);
1468 list_del(&hostrcb
->queue
);
1469 list_add_tail(&ipr_cmd
->queue
, &ipr_cmd
->hrrq
->hrrq_free_q
);
1472 if (ioasc
!= IPR_IOASC_IOA_WAS_RESET
&&
1473 ioasc
!= IPR_IOASC_ABORTED_CMD_TERM_BY_HOST
)
1474 dev_err(&ioa_cfg
->pdev
->dev
,
1475 "Host RCB failed with IOASC: 0x%08X\n", ioasc
);
1477 ipr_send_hcam(ioa_cfg
, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE
, hostrcb
);
1479 ipr_handle_config_change(ioa_cfg
, hostrcb
);
1484 * strip_and_pad_whitespace - Strip and pad trailing whitespace.
1485 * @i: index into buffer
1486 * @buf: string to modify
1488 * This function will strip all trailing whitespace, pad the end
1489 * of the string with a single space, and NULL terminate the string.
1492 * new length of string
1494 static int strip_and_pad_whitespace(int i
, char *buf
)
1496 while (i
&& buf
[i
] == ' ')
1504 * ipr_log_vpd_compact - Log the passed extended VPD compactly.
1505 * @prefix: string to print at start of printk
1506 * @hostrcb: hostrcb pointer
1507 * @vpd: vendor/product id/sn struct
1512 static void ipr_log_vpd_compact(char *prefix
, struct ipr_hostrcb
*hostrcb
,
1513 struct ipr_vpd
*vpd
)
1515 char buffer
[IPR_VENDOR_ID_LEN
+ IPR_PROD_ID_LEN
+ IPR_SERIAL_NUM_LEN
+ 3];
1518 memcpy(buffer
, vpd
->vpids
.vendor_id
, IPR_VENDOR_ID_LEN
);
1519 i
= strip_and_pad_whitespace(IPR_VENDOR_ID_LEN
- 1, buffer
);
1521 memcpy(&buffer
[i
], vpd
->vpids
.product_id
, IPR_PROD_ID_LEN
);
1522 i
= strip_and_pad_whitespace(i
+ IPR_PROD_ID_LEN
- 1, buffer
);
1524 memcpy(&buffer
[i
], vpd
->sn
, IPR_SERIAL_NUM_LEN
);
1525 buffer
[IPR_SERIAL_NUM_LEN
+ i
] = '\0';
1527 ipr_hcam_err(hostrcb
, "%s VPID/SN: %s\n", prefix
, buffer
);
1531 * ipr_log_vpd - Log the passed VPD to the error log.
1532 * @vpd: vendor/product id/sn struct
1537 static void ipr_log_vpd(struct ipr_vpd
*vpd
)
1539 char buffer
[IPR_VENDOR_ID_LEN
+ IPR_PROD_ID_LEN
1540 + IPR_SERIAL_NUM_LEN
];
1542 memcpy(buffer
, vpd
->vpids
.vendor_id
, IPR_VENDOR_ID_LEN
);
1543 memcpy(buffer
+ IPR_VENDOR_ID_LEN
, vpd
->vpids
.product_id
,
1545 buffer
[IPR_VENDOR_ID_LEN
+ IPR_PROD_ID_LEN
] = '\0';
1546 ipr_err("Vendor/Product ID: %s\n", buffer
);
1548 memcpy(buffer
, vpd
->sn
, IPR_SERIAL_NUM_LEN
);
1549 buffer
[IPR_SERIAL_NUM_LEN
] = '\0';
1550 ipr_err(" Serial Number: %s\n", buffer
);
1554 * ipr_log_ext_vpd_compact - Log the passed extended VPD compactly.
1555 * @prefix: string to print at start of printk
1556 * @hostrcb: hostrcb pointer
1557 * @vpd: vendor/product id/sn/wwn struct
1562 static void ipr_log_ext_vpd_compact(char *prefix
, struct ipr_hostrcb
*hostrcb
,
1563 struct ipr_ext_vpd
*vpd
)
1565 ipr_log_vpd_compact(prefix
, hostrcb
, &vpd
->vpd
);
1566 ipr_hcam_err(hostrcb
, "%s WWN: %08X%08X\n", prefix
,
1567 be32_to_cpu(vpd
->wwid
[0]), be32_to_cpu(vpd
->wwid
[1]));
1571 * ipr_log_ext_vpd - Log the passed extended VPD to the error log.
1572 * @vpd: vendor/product id/sn/wwn struct
1577 static void ipr_log_ext_vpd(struct ipr_ext_vpd
*vpd
)
1579 ipr_log_vpd(&vpd
->vpd
);
1580 ipr_err(" WWN: %08X%08X\n", be32_to_cpu(vpd
->wwid
[0]),
1581 be32_to_cpu(vpd
->wwid
[1]));
1585 * ipr_log_enhanced_cache_error - Log a cache error.
1586 * @ioa_cfg: ioa config struct
1587 * @hostrcb: hostrcb struct
1592 static void ipr_log_enhanced_cache_error(struct ipr_ioa_cfg
*ioa_cfg
,
1593 struct ipr_hostrcb
*hostrcb
)
1595 struct ipr_hostrcb_type_12_error
*error
;
1598 error
= &hostrcb
->hcam
.u
.error64
.u
.type_12_error
;
1600 error
= &hostrcb
->hcam
.u
.error
.u
.type_12_error
;
1602 ipr_err("-----Current Configuration-----\n");
1603 ipr_err("Cache Directory Card Information:\n");
1604 ipr_log_ext_vpd(&error
->ioa_vpd
);
1605 ipr_err("Adapter Card Information:\n");
1606 ipr_log_ext_vpd(&error
->cfc_vpd
);
1608 ipr_err("-----Expected Configuration-----\n");
1609 ipr_err("Cache Directory Card Information:\n");
1610 ipr_log_ext_vpd(&error
->ioa_last_attached_to_cfc_vpd
);
1611 ipr_err("Adapter Card Information:\n");
1612 ipr_log_ext_vpd(&error
->cfc_last_attached_to_ioa_vpd
);
1614 ipr_err("Additional IOA Data: %08X %08X %08X\n",
1615 be32_to_cpu(error
->ioa_data
[0]),
1616 be32_to_cpu(error
->ioa_data
[1]),
1617 be32_to_cpu(error
->ioa_data
[2]));
1621 * ipr_log_cache_error - Log a cache error.
1622 * @ioa_cfg: ioa config struct
1623 * @hostrcb: hostrcb struct
1628 static void ipr_log_cache_error(struct ipr_ioa_cfg
*ioa_cfg
,
1629 struct ipr_hostrcb
*hostrcb
)
1631 struct ipr_hostrcb_type_02_error
*error
=
1632 &hostrcb
->hcam
.u
.error
.u
.type_02_error
;
1634 ipr_err("-----Current Configuration-----\n");
1635 ipr_err("Cache Directory Card Information:\n");
1636 ipr_log_vpd(&error
->ioa_vpd
);
1637 ipr_err("Adapter Card Information:\n");
1638 ipr_log_vpd(&error
->cfc_vpd
);
1640 ipr_err("-----Expected Configuration-----\n");
1641 ipr_err("Cache Directory Card Information:\n");
1642 ipr_log_vpd(&error
->ioa_last_attached_to_cfc_vpd
);
1643 ipr_err("Adapter Card Information:\n");
1644 ipr_log_vpd(&error
->cfc_last_attached_to_ioa_vpd
);
1646 ipr_err("Additional IOA Data: %08X %08X %08X\n",
1647 be32_to_cpu(error
->ioa_data
[0]),
1648 be32_to_cpu(error
->ioa_data
[1]),
1649 be32_to_cpu(error
->ioa_data
[2]));
1653 * ipr_log_enhanced_config_error - Log a configuration error.
1654 * @ioa_cfg: ioa config struct
1655 * @hostrcb: hostrcb struct
1660 static void ipr_log_enhanced_config_error(struct ipr_ioa_cfg
*ioa_cfg
,
1661 struct ipr_hostrcb
*hostrcb
)
1663 int errors_logged
, i
;
1664 struct ipr_hostrcb_device_data_entry_enhanced
*dev_entry
;
1665 struct ipr_hostrcb_type_13_error
*error
;
1667 error
= &hostrcb
->hcam
.u
.error
.u
.type_13_error
;
1668 errors_logged
= be32_to_cpu(error
->errors_logged
);
1670 ipr_err("Device Errors Detected/Logged: %d/%d\n",
1671 be32_to_cpu(error
->errors_detected
), errors_logged
);
1673 dev_entry
= error
->dev
;
1675 for (i
= 0; i
< errors_logged
; i
++, dev_entry
++) {
1678 ipr_phys_res_err(ioa_cfg
, dev_entry
->dev_res_addr
, "Device %d", i
+ 1);
1679 ipr_log_ext_vpd(&dev_entry
->vpd
);
1681 ipr_err("-----New Device Information-----\n");
1682 ipr_log_ext_vpd(&dev_entry
->new_vpd
);
1684 ipr_err("Cache Directory Card Information:\n");
1685 ipr_log_ext_vpd(&dev_entry
->ioa_last_with_dev_vpd
);
1687 ipr_err("Adapter Card Information:\n");
1688 ipr_log_ext_vpd(&dev_entry
->cfc_last_with_dev_vpd
);
1693 * ipr_log_sis64_config_error - Log a device error.
1694 * @ioa_cfg: ioa config struct
1695 * @hostrcb: hostrcb struct
1700 static void ipr_log_sis64_config_error(struct ipr_ioa_cfg
*ioa_cfg
,
1701 struct ipr_hostrcb
*hostrcb
)
1703 int errors_logged
, i
;
1704 struct ipr_hostrcb64_device_data_entry_enhanced
*dev_entry
;
1705 struct ipr_hostrcb_type_23_error
*error
;
1706 char buffer
[IPR_MAX_RES_PATH_LENGTH
];
1708 error
= &hostrcb
->hcam
.u
.error64
.u
.type_23_error
;
1709 errors_logged
= be32_to_cpu(error
->errors_logged
);
1711 ipr_err("Device Errors Detected/Logged: %d/%d\n",
1712 be32_to_cpu(error
->errors_detected
), errors_logged
);
1714 dev_entry
= error
->dev
;
1716 for (i
= 0; i
< errors_logged
; i
++, dev_entry
++) {
1719 ipr_err("Device %d : %s", i
+ 1,
1720 __ipr_format_res_path(dev_entry
->res_path
,
1721 buffer
, sizeof(buffer
)));
1722 ipr_log_ext_vpd(&dev_entry
->vpd
);
1724 ipr_err("-----New Device Information-----\n");
1725 ipr_log_ext_vpd(&dev_entry
->new_vpd
);
1727 ipr_err("Cache Directory Card Information:\n");
1728 ipr_log_ext_vpd(&dev_entry
->ioa_last_with_dev_vpd
);
1730 ipr_err("Adapter Card Information:\n");
1731 ipr_log_ext_vpd(&dev_entry
->cfc_last_with_dev_vpd
);
1736 * ipr_log_config_error - Log a configuration error.
1737 * @ioa_cfg: ioa config struct
1738 * @hostrcb: hostrcb struct
1743 static void ipr_log_config_error(struct ipr_ioa_cfg
*ioa_cfg
,
1744 struct ipr_hostrcb
*hostrcb
)
1746 int errors_logged
, i
;
1747 struct ipr_hostrcb_device_data_entry
*dev_entry
;
1748 struct ipr_hostrcb_type_03_error
*error
;
1750 error
= &hostrcb
->hcam
.u
.error
.u
.type_03_error
;
1751 errors_logged
= be32_to_cpu(error
->errors_logged
);
1753 ipr_err("Device Errors Detected/Logged: %d/%d\n",
1754 be32_to_cpu(error
->errors_detected
), errors_logged
);
1756 dev_entry
= error
->dev
;
1758 for (i
= 0; i
< errors_logged
; i
++, dev_entry
++) {
1761 ipr_phys_res_err(ioa_cfg
, dev_entry
->dev_res_addr
, "Device %d", i
+ 1);
1762 ipr_log_vpd(&dev_entry
->vpd
);
1764 ipr_err("-----New Device Information-----\n");
1765 ipr_log_vpd(&dev_entry
->new_vpd
);
1767 ipr_err("Cache Directory Card Information:\n");
1768 ipr_log_vpd(&dev_entry
->ioa_last_with_dev_vpd
);
1770 ipr_err("Adapter Card Information:\n");
1771 ipr_log_vpd(&dev_entry
->cfc_last_with_dev_vpd
);
1773 ipr_err("Additional IOA Data: %08X %08X %08X %08X %08X\n",
1774 be32_to_cpu(dev_entry
->ioa_data
[0]),
1775 be32_to_cpu(dev_entry
->ioa_data
[1]),
1776 be32_to_cpu(dev_entry
->ioa_data
[2]),
1777 be32_to_cpu(dev_entry
->ioa_data
[3]),
1778 be32_to_cpu(dev_entry
->ioa_data
[4]));
1783 * ipr_log_enhanced_array_error - Log an array configuration error.
1784 * @ioa_cfg: ioa config struct
1785 * @hostrcb: hostrcb struct
1790 static void ipr_log_enhanced_array_error(struct ipr_ioa_cfg
*ioa_cfg
,
1791 struct ipr_hostrcb
*hostrcb
)
1794 struct ipr_hostrcb_type_14_error
*error
;
1795 struct ipr_hostrcb_array_data_entry_enhanced
*array_entry
;
1796 const u8 zero_sn
[IPR_SERIAL_NUM_LEN
] = { [0 ... IPR_SERIAL_NUM_LEN
-1] = '0' };
1798 error
= &hostrcb
->hcam
.u
.error
.u
.type_14_error
;
1802 ipr_err("RAID %s Array Configuration: %d:%d:%d:%d\n",
1803 error
->protection_level
,
1804 ioa_cfg
->host
->host_no
,
1805 error
->last_func_vset_res_addr
.bus
,
1806 error
->last_func_vset_res_addr
.target
,
1807 error
->last_func_vset_res_addr
.lun
);
1811 array_entry
= error
->array_member
;
1812 num_entries
= min_t(u32
, be32_to_cpu(error
->num_entries
),
1813 ARRAY_SIZE(error
->array_member
));
1815 for (i
= 0; i
< num_entries
; i
++, array_entry
++) {
1816 if (!memcmp(array_entry
->vpd
.vpd
.sn
, zero_sn
, IPR_SERIAL_NUM_LEN
))
1819 if (be32_to_cpu(error
->exposed_mode_adn
) == i
)
1820 ipr_err("Exposed Array Member %d:\n", i
);
1822 ipr_err("Array Member %d:\n", i
);
1824 ipr_log_ext_vpd(&array_entry
->vpd
);
1825 ipr_phys_res_err(ioa_cfg
, array_entry
->dev_res_addr
, "Current Location");
1826 ipr_phys_res_err(ioa_cfg
, array_entry
->expected_dev_res_addr
,
1827 "Expected Location");
1834 * ipr_log_array_error - Log an array configuration error.
1835 * @ioa_cfg: ioa config struct
1836 * @hostrcb: hostrcb struct
1841 static void ipr_log_array_error(struct ipr_ioa_cfg
*ioa_cfg
,
1842 struct ipr_hostrcb
*hostrcb
)
1845 struct ipr_hostrcb_type_04_error
*error
;
1846 struct ipr_hostrcb_array_data_entry
*array_entry
;
1847 const u8 zero_sn
[IPR_SERIAL_NUM_LEN
] = { [0 ... IPR_SERIAL_NUM_LEN
-1] = '0' };
1849 error
= &hostrcb
->hcam
.u
.error
.u
.type_04_error
;
1853 ipr_err("RAID %s Array Configuration: %d:%d:%d:%d\n",
1854 error
->protection_level
,
1855 ioa_cfg
->host
->host_no
,
1856 error
->last_func_vset_res_addr
.bus
,
1857 error
->last_func_vset_res_addr
.target
,
1858 error
->last_func_vset_res_addr
.lun
);
1862 array_entry
= error
->array_member
;
1864 for (i
= 0; i
< 18; i
++) {
1865 if (!memcmp(array_entry
->vpd
.sn
, zero_sn
, IPR_SERIAL_NUM_LEN
))
1868 if (be32_to_cpu(error
->exposed_mode_adn
) == i
)
1869 ipr_err("Exposed Array Member %d:\n", i
);
1871 ipr_err("Array Member %d:\n", i
);
1873 ipr_log_vpd(&array_entry
->vpd
);
1875 ipr_phys_res_err(ioa_cfg
, array_entry
->dev_res_addr
, "Current Location");
1876 ipr_phys_res_err(ioa_cfg
, array_entry
->expected_dev_res_addr
,
1877 "Expected Location");
1882 array_entry
= error
->array_member2
;
1889 * ipr_log_hex_data - Log additional hex IOA error data.
1890 * @ioa_cfg: ioa config struct
1891 * @data: IOA error data
1897 static void ipr_log_hex_data(struct ipr_ioa_cfg
*ioa_cfg
, u32
*data
, int len
)
1904 if (ioa_cfg
->log_level
<= IPR_DEFAULT_LOG_LEVEL
)
1905 len
= min_t(int, len
, IPR_DEFAULT_MAX_ERROR_DUMP
);
1907 for (i
= 0; i
< len
/ 4; i
+= 4) {
1908 ipr_err("%08X: %08X %08X %08X %08X\n", i
*4,
1909 be32_to_cpu(data
[i
]),
1910 be32_to_cpu(data
[i
+1]),
1911 be32_to_cpu(data
[i
+2]),
1912 be32_to_cpu(data
[i
+3]));
1917 * ipr_log_enhanced_dual_ioa_error - Log an enhanced dual adapter error.
1918 * @ioa_cfg: ioa config struct
1919 * @hostrcb: hostrcb struct
1924 static void ipr_log_enhanced_dual_ioa_error(struct ipr_ioa_cfg
*ioa_cfg
,
1925 struct ipr_hostrcb
*hostrcb
)
1927 struct ipr_hostrcb_type_17_error
*error
;
1930 error
= &hostrcb
->hcam
.u
.error64
.u
.type_17_error
;
1932 error
= &hostrcb
->hcam
.u
.error
.u
.type_17_error
;
1934 error
->failure_reason
[sizeof(error
->failure_reason
) - 1] = '\0';
1935 strim(error
->failure_reason
);
1937 ipr_hcam_err(hostrcb
, "%s [PRC: %08X]\n", error
->failure_reason
,
1938 be32_to_cpu(hostrcb
->hcam
.u
.error
.prc
));
1939 ipr_log_ext_vpd_compact("Remote IOA", hostrcb
, &error
->vpd
);
1940 ipr_log_hex_data(ioa_cfg
, error
->data
,
1941 be32_to_cpu(hostrcb
->hcam
.length
) -
1942 (offsetof(struct ipr_hostrcb_error
, u
) +
1943 offsetof(struct ipr_hostrcb_type_17_error
, data
)));
1947 * ipr_log_dual_ioa_error - Log a dual adapter error.
1948 * @ioa_cfg: ioa config struct
1949 * @hostrcb: hostrcb struct
1954 static void ipr_log_dual_ioa_error(struct ipr_ioa_cfg
*ioa_cfg
,
1955 struct ipr_hostrcb
*hostrcb
)
1957 struct ipr_hostrcb_type_07_error
*error
;
1959 error
= &hostrcb
->hcam
.u
.error
.u
.type_07_error
;
1960 error
->failure_reason
[sizeof(error
->failure_reason
) - 1] = '\0';
1961 strim(error
->failure_reason
);
1963 ipr_hcam_err(hostrcb
, "%s [PRC: %08X]\n", error
->failure_reason
,
1964 be32_to_cpu(hostrcb
->hcam
.u
.error
.prc
));
1965 ipr_log_vpd_compact("Remote IOA", hostrcb
, &error
->vpd
);
1966 ipr_log_hex_data(ioa_cfg
, error
->data
,
1967 be32_to_cpu(hostrcb
->hcam
.length
) -
1968 (offsetof(struct ipr_hostrcb_error
, u
) +
1969 offsetof(struct ipr_hostrcb_type_07_error
, data
)));
1972 static const struct {
1975 } path_active_desc
[] = {
1976 { IPR_PATH_NO_INFO
, "Path" },
1977 { IPR_PATH_ACTIVE
, "Active path" },
1978 { IPR_PATH_NOT_ACTIVE
, "Inactive path" }
1981 static const struct {
1984 } path_state_desc
[] = {
1985 { IPR_PATH_STATE_NO_INFO
, "has no path state information available" },
1986 { IPR_PATH_HEALTHY
, "is healthy" },
1987 { IPR_PATH_DEGRADED
, "is degraded" },
1988 { IPR_PATH_FAILED
, "is failed" }
1992 * ipr_log_fabric_path - Log a fabric path error
1993 * @hostrcb: hostrcb struct
1994 * @fabric: fabric descriptor
1999 static void ipr_log_fabric_path(struct ipr_hostrcb
*hostrcb
,
2000 struct ipr_hostrcb_fabric_desc
*fabric
)
2003 u8 path_state
= fabric
->path_state
;
2004 u8 active
= path_state
& IPR_PATH_ACTIVE_MASK
;
2005 u8 state
= path_state
& IPR_PATH_STATE_MASK
;
2007 for (i
= 0; i
< ARRAY_SIZE(path_active_desc
); i
++) {
2008 if (path_active_desc
[i
].active
!= active
)
2011 for (j
= 0; j
< ARRAY_SIZE(path_state_desc
); j
++) {
2012 if (path_state_desc
[j
].state
!= state
)
2015 if (fabric
->cascaded_expander
== 0xff && fabric
->phy
== 0xff) {
2016 ipr_hcam_err(hostrcb
, "%s %s: IOA Port=%d\n",
2017 path_active_desc
[i
].desc
, path_state_desc
[j
].desc
,
2019 } else if (fabric
->cascaded_expander
== 0xff) {
2020 ipr_hcam_err(hostrcb
, "%s %s: IOA Port=%d, Phy=%d\n",
2021 path_active_desc
[i
].desc
, path_state_desc
[j
].desc
,
2022 fabric
->ioa_port
, fabric
->phy
);
2023 } else if (fabric
->phy
== 0xff) {
2024 ipr_hcam_err(hostrcb
, "%s %s: IOA Port=%d, Cascade=%d\n",
2025 path_active_desc
[i
].desc
, path_state_desc
[j
].desc
,
2026 fabric
->ioa_port
, fabric
->cascaded_expander
);
2028 ipr_hcam_err(hostrcb
, "%s %s: IOA Port=%d, Cascade=%d, Phy=%d\n",
2029 path_active_desc
[i
].desc
, path_state_desc
[j
].desc
,
2030 fabric
->ioa_port
, fabric
->cascaded_expander
, fabric
->phy
);
2036 ipr_err("Path state=%02X IOA Port=%d Cascade=%d Phy=%d\n", path_state
,
2037 fabric
->ioa_port
, fabric
->cascaded_expander
, fabric
->phy
);
2041 * ipr_log64_fabric_path - Log a fabric path error
2042 * @hostrcb: hostrcb struct
2043 * @fabric: fabric descriptor
2048 static void ipr_log64_fabric_path(struct ipr_hostrcb
*hostrcb
,
2049 struct ipr_hostrcb64_fabric_desc
*fabric
)
2052 u8 path_state
= fabric
->path_state
;
2053 u8 active
= path_state
& IPR_PATH_ACTIVE_MASK
;
2054 u8 state
= path_state
& IPR_PATH_STATE_MASK
;
2055 char buffer
[IPR_MAX_RES_PATH_LENGTH
];
2057 for (i
= 0; i
< ARRAY_SIZE(path_active_desc
); i
++) {
2058 if (path_active_desc
[i
].active
!= active
)
2061 for (j
= 0; j
< ARRAY_SIZE(path_state_desc
); j
++) {
2062 if (path_state_desc
[j
].state
!= state
)
2065 ipr_hcam_err(hostrcb
, "%s %s: Resource Path=%s\n",
2066 path_active_desc
[i
].desc
, path_state_desc
[j
].desc
,
2067 ipr_format_res_path(hostrcb
->ioa_cfg
,
2069 buffer
, sizeof(buffer
)));
2074 ipr_err("Path state=%02X Resource Path=%s\n", path_state
,
2075 ipr_format_res_path(hostrcb
->ioa_cfg
, fabric
->res_path
,
2076 buffer
, sizeof(buffer
)));
2079 static const struct {
2082 } path_type_desc
[] = {
2083 { IPR_PATH_CFG_IOA_PORT
, "IOA port" },
2084 { IPR_PATH_CFG_EXP_PORT
, "Expander port" },
2085 { IPR_PATH_CFG_DEVICE_PORT
, "Device port" },
2086 { IPR_PATH_CFG_DEVICE_LUN
, "Device LUN" }
2089 static const struct {
2092 } path_status_desc
[] = {
2093 { IPR_PATH_CFG_NO_PROB
, "Functional" },
2094 { IPR_PATH_CFG_DEGRADED
, "Degraded" },
2095 { IPR_PATH_CFG_FAILED
, "Failed" },
2096 { IPR_PATH_CFG_SUSPECT
, "Suspect" },
2097 { IPR_PATH_NOT_DETECTED
, "Missing" },
2098 { IPR_PATH_INCORRECT_CONN
, "Incorrectly connected" }
2101 static const char *link_rate
[] = {
2104 "phy reset problem",
2121 * ipr_log_path_elem - Log a fabric path element.
2122 * @hostrcb: hostrcb struct
2123 * @cfg: fabric path element struct
2128 static void ipr_log_path_elem(struct ipr_hostrcb
*hostrcb
,
2129 struct ipr_hostrcb_config_element
*cfg
)
2132 u8 type
= cfg
->type_status
& IPR_PATH_CFG_TYPE_MASK
;
2133 u8 status
= cfg
->type_status
& IPR_PATH_CFG_STATUS_MASK
;
2135 if (type
== IPR_PATH_CFG_NOT_EXIST
)
2138 for (i
= 0; i
< ARRAY_SIZE(path_type_desc
); i
++) {
2139 if (path_type_desc
[i
].type
!= type
)
2142 for (j
= 0; j
< ARRAY_SIZE(path_status_desc
); j
++) {
2143 if (path_status_desc
[j
].status
!= status
)
2146 if (type
== IPR_PATH_CFG_IOA_PORT
) {
2147 ipr_hcam_err(hostrcb
, "%s %s: Phy=%d, Link rate=%s, WWN=%08X%08X\n",
2148 path_status_desc
[j
].desc
, path_type_desc
[i
].desc
,
2149 cfg
->phy
, link_rate
[cfg
->link_rate
& IPR_PHY_LINK_RATE_MASK
],
2150 be32_to_cpu(cfg
->wwid
[0]), be32_to_cpu(cfg
->wwid
[1]));
2152 if (cfg
->cascaded_expander
== 0xff && cfg
->phy
== 0xff) {
2153 ipr_hcam_err(hostrcb
, "%s %s: Link rate=%s, WWN=%08X%08X\n",
2154 path_status_desc
[j
].desc
, path_type_desc
[i
].desc
,
2155 link_rate
[cfg
->link_rate
& IPR_PHY_LINK_RATE_MASK
],
2156 be32_to_cpu(cfg
->wwid
[0]), be32_to_cpu(cfg
->wwid
[1]));
2157 } else if (cfg
->cascaded_expander
== 0xff) {
2158 ipr_hcam_err(hostrcb
, "%s %s: Phy=%d, Link rate=%s, "
2159 "WWN=%08X%08X\n", path_status_desc
[j
].desc
,
2160 path_type_desc
[i
].desc
, cfg
->phy
,
2161 link_rate
[cfg
->link_rate
& IPR_PHY_LINK_RATE_MASK
],
2162 be32_to_cpu(cfg
->wwid
[0]), be32_to_cpu(cfg
->wwid
[1]));
2163 } else if (cfg
->phy
== 0xff) {
2164 ipr_hcam_err(hostrcb
, "%s %s: Cascade=%d, Link rate=%s, "
2165 "WWN=%08X%08X\n", path_status_desc
[j
].desc
,
2166 path_type_desc
[i
].desc
, cfg
->cascaded_expander
,
2167 link_rate
[cfg
->link_rate
& IPR_PHY_LINK_RATE_MASK
],
2168 be32_to_cpu(cfg
->wwid
[0]), be32_to_cpu(cfg
->wwid
[1]));
2170 ipr_hcam_err(hostrcb
, "%s %s: Cascade=%d, Phy=%d, Link rate=%s "
2171 "WWN=%08X%08X\n", path_status_desc
[j
].desc
,
2172 path_type_desc
[i
].desc
, 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]));
2181 ipr_hcam_err(hostrcb
, "Path element=%02X: Cascade=%d Phy=%d Link rate=%s "
2182 "WWN=%08X%08X\n", cfg
->type_status
, cfg
->cascaded_expander
, cfg
->phy
,
2183 link_rate
[cfg
->link_rate
& IPR_PHY_LINK_RATE_MASK
],
2184 be32_to_cpu(cfg
->wwid
[0]), be32_to_cpu(cfg
->wwid
[1]));
2188 * ipr_log64_path_elem - Log a fabric path element.
2189 * @hostrcb: hostrcb struct
2190 * @cfg: fabric path element struct
2195 static void ipr_log64_path_elem(struct ipr_hostrcb
*hostrcb
,
2196 struct ipr_hostrcb64_config_element
*cfg
)
2199 u8 desc_id
= cfg
->descriptor_id
& IPR_DESCRIPTOR_MASK
;
2200 u8 type
= cfg
->type_status
& IPR_PATH_CFG_TYPE_MASK
;
2201 u8 status
= cfg
->type_status
& IPR_PATH_CFG_STATUS_MASK
;
2202 char buffer
[IPR_MAX_RES_PATH_LENGTH
];
2204 if (type
== IPR_PATH_CFG_NOT_EXIST
|| desc_id
!= IPR_DESCRIPTOR_SIS64
)
2207 for (i
= 0; i
< ARRAY_SIZE(path_type_desc
); i
++) {
2208 if (path_type_desc
[i
].type
!= type
)
2211 for (j
= 0; j
< ARRAY_SIZE(path_status_desc
); j
++) {
2212 if (path_status_desc
[j
].status
!= status
)
2215 ipr_hcam_err(hostrcb
, "%s %s: Resource Path=%s, Link rate=%s, WWN=%08X%08X\n",
2216 path_status_desc
[j
].desc
, path_type_desc
[i
].desc
,
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]),
2221 be32_to_cpu(cfg
->wwid
[1]));
2225 ipr_hcam_err(hostrcb
, "Path element=%02X: Resource Path=%s, Link rate=%s "
2226 "WWN=%08X%08X\n", cfg
->type_status
,
2227 ipr_format_res_path(hostrcb
->ioa_cfg
,
2228 cfg
->res_path
, buffer
, sizeof(buffer
)),
2229 link_rate
[cfg
->link_rate
& IPR_PHY_LINK_RATE_MASK
],
2230 be32_to_cpu(cfg
->wwid
[0]), be32_to_cpu(cfg
->wwid
[1]));
2234 * ipr_log_fabric_error - Log a fabric error.
2235 * @ioa_cfg: ioa config struct
2236 * @hostrcb: hostrcb struct
2241 static void ipr_log_fabric_error(struct ipr_ioa_cfg
*ioa_cfg
,
2242 struct ipr_hostrcb
*hostrcb
)
2244 struct ipr_hostrcb_type_20_error
*error
;
2245 struct ipr_hostrcb_fabric_desc
*fabric
;
2246 struct ipr_hostrcb_config_element
*cfg
;
2249 error
= &hostrcb
->hcam
.u
.error
.u
.type_20_error
;
2250 error
->failure_reason
[sizeof(error
->failure_reason
) - 1] = '\0';
2251 ipr_hcam_err(hostrcb
, "%s\n", error
->failure_reason
);
2253 add_len
= be32_to_cpu(hostrcb
->hcam
.length
) -
2254 (offsetof(struct ipr_hostrcb_error
, u
) +
2255 offsetof(struct ipr_hostrcb_type_20_error
, desc
));
2257 for (i
= 0, fabric
= error
->desc
; i
< error
->num_entries
; i
++) {
2258 ipr_log_fabric_path(hostrcb
, fabric
);
2259 for_each_fabric_cfg(fabric
, cfg
)
2260 ipr_log_path_elem(hostrcb
, cfg
);
2262 add_len
-= be16_to_cpu(fabric
->length
);
2263 fabric
= (struct ipr_hostrcb_fabric_desc
*)
2264 ((unsigned long)fabric
+ be16_to_cpu(fabric
->length
));
2267 ipr_log_hex_data(ioa_cfg
, (u32
*)fabric
, add_len
);
2271 * ipr_log_sis64_array_error - Log a sis64 array error.
2272 * @ioa_cfg: ioa config struct
2273 * @hostrcb: hostrcb struct
2278 static void ipr_log_sis64_array_error(struct ipr_ioa_cfg
*ioa_cfg
,
2279 struct ipr_hostrcb
*hostrcb
)
2282 struct ipr_hostrcb_type_24_error
*error
;
2283 struct ipr_hostrcb64_array_data_entry
*array_entry
;
2284 char buffer
[IPR_MAX_RES_PATH_LENGTH
];
2285 const u8 zero_sn
[IPR_SERIAL_NUM_LEN
] = { [0 ... IPR_SERIAL_NUM_LEN
-1] = '0' };
2287 error
= &hostrcb
->hcam
.u
.error64
.u
.type_24_error
;
2291 ipr_err("RAID %s Array Configuration: %s\n",
2292 error
->protection_level
,
2293 ipr_format_res_path(ioa_cfg
, error
->last_res_path
,
2294 buffer
, sizeof(buffer
)));
2298 array_entry
= error
->array_member
;
2299 num_entries
= min_t(u32
, error
->num_entries
,
2300 ARRAY_SIZE(error
->array_member
));
2302 for (i
= 0; i
< num_entries
; i
++, array_entry
++) {
2304 if (!memcmp(array_entry
->vpd
.vpd
.sn
, zero_sn
, IPR_SERIAL_NUM_LEN
))
2307 if (error
->exposed_mode_adn
== i
)
2308 ipr_err("Exposed Array Member %d:\n", i
);
2310 ipr_err("Array Member %d:\n", i
);
2312 ipr_err("Array Member %d:\n", i
);
2313 ipr_log_ext_vpd(&array_entry
->vpd
);
2314 ipr_err("Current Location: %s\n",
2315 ipr_format_res_path(ioa_cfg
, array_entry
->res_path
,
2316 buffer
, sizeof(buffer
)));
2317 ipr_err("Expected Location: %s\n",
2318 ipr_format_res_path(ioa_cfg
,
2319 array_entry
->expected_res_path
,
2320 buffer
, sizeof(buffer
)));
2327 * ipr_log_sis64_fabric_error - Log a sis64 fabric error.
2328 * @ioa_cfg: ioa config struct
2329 * @hostrcb: hostrcb struct
2334 static void ipr_log_sis64_fabric_error(struct ipr_ioa_cfg
*ioa_cfg
,
2335 struct ipr_hostrcb
*hostrcb
)
2337 struct ipr_hostrcb_type_30_error
*error
;
2338 struct ipr_hostrcb64_fabric_desc
*fabric
;
2339 struct ipr_hostrcb64_config_element
*cfg
;
2342 error
= &hostrcb
->hcam
.u
.error64
.u
.type_30_error
;
2344 error
->failure_reason
[sizeof(error
->failure_reason
) - 1] = '\0';
2345 ipr_hcam_err(hostrcb
, "%s\n", error
->failure_reason
);
2347 add_len
= be32_to_cpu(hostrcb
->hcam
.length
) -
2348 (offsetof(struct ipr_hostrcb64_error
, u
) +
2349 offsetof(struct ipr_hostrcb_type_30_error
, desc
));
2351 for (i
= 0, fabric
= error
->desc
; i
< error
->num_entries
; i
++) {
2352 ipr_log64_fabric_path(hostrcb
, fabric
);
2353 for_each_fabric_cfg(fabric
, cfg
)
2354 ipr_log64_path_elem(hostrcb
, cfg
);
2356 add_len
-= be16_to_cpu(fabric
->length
);
2357 fabric
= (struct ipr_hostrcb64_fabric_desc
*)
2358 ((unsigned long)fabric
+ be16_to_cpu(fabric
->length
));
2361 ipr_log_hex_data(ioa_cfg
, (u32
*)fabric
, add_len
);
2365 * ipr_log_generic_error - Log an adapter error.
2366 * @ioa_cfg: ioa config struct
2367 * @hostrcb: hostrcb struct
2372 static void ipr_log_generic_error(struct ipr_ioa_cfg
*ioa_cfg
,
2373 struct ipr_hostrcb
*hostrcb
)
2375 ipr_log_hex_data(ioa_cfg
, hostrcb
->hcam
.u
.raw
.data
,
2376 be32_to_cpu(hostrcb
->hcam
.length
));
2380 * ipr_log_sis64_device_error - Log a cache error.
2381 * @ioa_cfg: ioa config struct
2382 * @hostrcb: hostrcb struct
2387 static void ipr_log_sis64_device_error(struct ipr_ioa_cfg
*ioa_cfg
,
2388 struct ipr_hostrcb
*hostrcb
)
2390 struct ipr_hostrcb_type_21_error
*error
;
2391 char buffer
[IPR_MAX_RES_PATH_LENGTH
];
2393 error
= &hostrcb
->hcam
.u
.error64
.u
.type_21_error
;
2395 ipr_err("-----Failing Device Information-----\n");
2396 ipr_err("World Wide Unique ID: %08X%08X%08X%08X\n",
2397 be32_to_cpu(error
->wwn
[0]), be32_to_cpu(error
->wwn
[1]),
2398 be32_to_cpu(error
->wwn
[2]), be32_to_cpu(error
->wwn
[3]));
2399 ipr_err("Device Resource Path: %s\n",
2400 __ipr_format_res_path(error
->res_path
,
2401 buffer
, sizeof(buffer
)));
2402 error
->primary_problem_desc
[sizeof(error
->primary_problem_desc
) - 1] = '\0';
2403 error
->second_problem_desc
[sizeof(error
->second_problem_desc
) - 1] = '\0';
2404 ipr_err("Primary Problem Description: %s\n", error
->primary_problem_desc
);
2405 ipr_err("Secondary Problem Description: %s\n", error
->second_problem_desc
);
2406 ipr_err("SCSI Sense Data:\n");
2407 ipr_log_hex_data(ioa_cfg
, error
->sense_data
, sizeof(error
->sense_data
));
2408 ipr_err("SCSI Command Descriptor Block: \n");
2409 ipr_log_hex_data(ioa_cfg
, error
->cdb
, sizeof(error
->cdb
));
2411 ipr_err("Additional IOA Data:\n");
2412 ipr_log_hex_data(ioa_cfg
, error
->ioa_data
, be32_to_cpu(error
->length_of_error
));
2416 * ipr_get_error - Find the specfied IOASC in the ipr_error_table.
2419 * This function will return the index of into the ipr_error_table
2420 * for the specified IOASC. If the IOASC is not in the table,
2421 * 0 will be returned, which points to the entry used for unknown errors.
2424 * index into the ipr_error_table
2426 static u32
ipr_get_error(u32 ioasc
)
2430 for (i
= 0; i
< ARRAY_SIZE(ipr_error_table
); i
++)
2431 if (ipr_error_table
[i
].ioasc
== (ioasc
& IPR_IOASC_IOASC_MASK
))
2438 * ipr_handle_log_data - Log an adapter error.
2439 * @ioa_cfg: ioa config struct
2440 * @hostrcb: hostrcb struct
2442 * This function logs an adapter error to the system.
2447 static void ipr_handle_log_data(struct ipr_ioa_cfg
*ioa_cfg
,
2448 struct ipr_hostrcb
*hostrcb
)
2452 struct ipr_hostrcb_type_21_error
*error
;
2454 if (hostrcb
->hcam
.notify_type
!= IPR_HOST_RCB_NOTIF_TYPE_ERROR_LOG_ENTRY
)
2457 if (hostrcb
->hcam
.notifications_lost
== IPR_HOST_RCB_NOTIFICATIONS_LOST
)
2458 dev_err(&ioa_cfg
->pdev
->dev
, "Error notifications lost\n");
2461 ioasc
= be32_to_cpu(hostrcb
->hcam
.u
.error64
.fd_ioasc
);
2463 ioasc
= be32_to_cpu(hostrcb
->hcam
.u
.error
.fd_ioasc
);
2465 if (!ioa_cfg
->sis64
&& (ioasc
== IPR_IOASC_BUS_WAS_RESET
||
2466 ioasc
== IPR_IOASC_BUS_WAS_RESET_BY_OTHER
)) {
2467 /* Tell the midlayer we had a bus reset so it will handle the UA properly */
2468 scsi_report_bus_reset(ioa_cfg
->host
,
2469 hostrcb
->hcam
.u
.error
.fd_res_addr
.bus
);
2472 error_index
= ipr_get_error(ioasc
);
2474 if (!ipr_error_table
[error_index
].log_hcam
)
2477 if (ioasc
== IPR_IOASC_HW_CMD_FAILED
&&
2478 hostrcb
->hcam
.overlay_id
== IPR_HOST_RCB_OVERLAY_ID_21
) {
2479 error
= &hostrcb
->hcam
.u
.error64
.u
.type_21_error
;
2481 if (((be32_to_cpu(error
->sense_data
[0]) & 0x0000ff00) >> 8) == ILLEGAL_REQUEST
&&
2482 ioa_cfg
->log_level
<= IPR_DEFAULT_LOG_LEVEL
)
2486 ipr_hcam_err(hostrcb
, "%s\n", ipr_error_table
[error_index
].error
);
2488 /* Set indication we have logged an error */
2489 ioa_cfg
->errors_logged
++;
2491 if (ioa_cfg
->log_level
< ipr_error_table
[error_index
].log_hcam
)
2493 if (be32_to_cpu(hostrcb
->hcam
.length
) > sizeof(hostrcb
->hcam
.u
.raw
))
2494 hostrcb
->hcam
.length
= cpu_to_be32(sizeof(hostrcb
->hcam
.u
.raw
));
2496 switch (hostrcb
->hcam
.overlay_id
) {
2497 case IPR_HOST_RCB_OVERLAY_ID_2
:
2498 ipr_log_cache_error(ioa_cfg
, hostrcb
);
2500 case IPR_HOST_RCB_OVERLAY_ID_3
:
2501 ipr_log_config_error(ioa_cfg
, hostrcb
);
2503 case IPR_HOST_RCB_OVERLAY_ID_4
:
2504 case IPR_HOST_RCB_OVERLAY_ID_6
:
2505 ipr_log_array_error(ioa_cfg
, hostrcb
);
2507 case IPR_HOST_RCB_OVERLAY_ID_7
:
2508 ipr_log_dual_ioa_error(ioa_cfg
, hostrcb
);
2510 case IPR_HOST_RCB_OVERLAY_ID_12
:
2511 ipr_log_enhanced_cache_error(ioa_cfg
, hostrcb
);
2513 case IPR_HOST_RCB_OVERLAY_ID_13
:
2514 ipr_log_enhanced_config_error(ioa_cfg
, hostrcb
);
2516 case IPR_HOST_RCB_OVERLAY_ID_14
:
2517 case IPR_HOST_RCB_OVERLAY_ID_16
:
2518 ipr_log_enhanced_array_error(ioa_cfg
, hostrcb
);
2520 case IPR_HOST_RCB_OVERLAY_ID_17
:
2521 ipr_log_enhanced_dual_ioa_error(ioa_cfg
, hostrcb
);
2523 case IPR_HOST_RCB_OVERLAY_ID_20
:
2524 ipr_log_fabric_error(ioa_cfg
, hostrcb
);
2526 case IPR_HOST_RCB_OVERLAY_ID_21
:
2527 ipr_log_sis64_device_error(ioa_cfg
, hostrcb
);
2529 case IPR_HOST_RCB_OVERLAY_ID_23
:
2530 ipr_log_sis64_config_error(ioa_cfg
, hostrcb
);
2532 case IPR_HOST_RCB_OVERLAY_ID_24
:
2533 case IPR_HOST_RCB_OVERLAY_ID_26
:
2534 ipr_log_sis64_array_error(ioa_cfg
, hostrcb
);
2536 case IPR_HOST_RCB_OVERLAY_ID_30
:
2537 ipr_log_sis64_fabric_error(ioa_cfg
, hostrcb
);
2539 case IPR_HOST_RCB_OVERLAY_ID_1
:
2540 case IPR_HOST_RCB_OVERLAY_ID_DEFAULT
:
2542 ipr_log_generic_error(ioa_cfg
, hostrcb
);
2548 * ipr_process_error - Op done function for an adapter error log.
2549 * @ipr_cmd: ipr command struct
2551 * This function is the op done function for an error log host
2552 * controlled async from the adapter. It will log the error and
2553 * send the HCAM back to the adapter.
2558 static void ipr_process_error(struct ipr_cmnd
*ipr_cmd
)
2560 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
2561 struct ipr_hostrcb
*hostrcb
= ipr_cmd
->u
.hostrcb
;
2562 u32 ioasc
= be32_to_cpu(ipr_cmd
->s
.ioasa
.hdr
.ioasc
);
2566 fd_ioasc
= be32_to_cpu(hostrcb
->hcam
.u
.error64
.fd_ioasc
);
2568 fd_ioasc
= be32_to_cpu(hostrcb
->hcam
.u
.error
.fd_ioasc
);
2570 list_del(&hostrcb
->queue
);
2571 list_add_tail(&ipr_cmd
->queue
, &ipr_cmd
->hrrq
->hrrq_free_q
);
2574 ipr_handle_log_data(ioa_cfg
, hostrcb
);
2575 if (fd_ioasc
== IPR_IOASC_NR_IOA_RESET_REQUIRED
)
2576 ipr_initiate_ioa_reset(ioa_cfg
, IPR_SHUTDOWN_ABBREV
);
2577 } else if (ioasc
!= IPR_IOASC_IOA_WAS_RESET
&&
2578 ioasc
!= IPR_IOASC_ABORTED_CMD_TERM_BY_HOST
) {
2579 dev_err(&ioa_cfg
->pdev
->dev
,
2580 "Host RCB failed with IOASC: 0x%08X\n", ioasc
);
2583 ipr_send_hcam(ioa_cfg
, IPR_HCAM_CDB_OP_CODE_LOG_DATA
, hostrcb
);
2587 * ipr_timeout - An internally generated op has timed out.
2588 * @ipr_cmd: ipr command struct
2590 * This function blocks host requests and initiates an
2596 static void ipr_timeout(struct ipr_cmnd
*ipr_cmd
)
2598 unsigned long lock_flags
= 0;
2599 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
2602 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
2604 ioa_cfg
->errors_logged
++;
2605 dev_err(&ioa_cfg
->pdev
->dev
,
2606 "Adapter being reset due to command timeout.\n");
2608 if (WAIT_FOR_DUMP
== ioa_cfg
->sdt_state
)
2609 ioa_cfg
->sdt_state
= GET_DUMP
;
2611 if (!ioa_cfg
->in_reset_reload
|| ioa_cfg
->reset_cmd
== ipr_cmd
)
2612 ipr_initiate_ioa_reset(ioa_cfg
, IPR_SHUTDOWN_NONE
);
2614 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
2619 * ipr_oper_timeout - Adapter timed out transitioning to operational
2620 * @ipr_cmd: ipr command struct
2622 * This function blocks host requests and initiates an
2628 static void ipr_oper_timeout(struct ipr_cmnd
*ipr_cmd
)
2630 unsigned long lock_flags
= 0;
2631 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
2634 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
2636 ioa_cfg
->errors_logged
++;
2637 dev_err(&ioa_cfg
->pdev
->dev
,
2638 "Adapter timed out transitioning to operational.\n");
2640 if (WAIT_FOR_DUMP
== ioa_cfg
->sdt_state
)
2641 ioa_cfg
->sdt_state
= GET_DUMP
;
2643 if (!ioa_cfg
->in_reset_reload
|| ioa_cfg
->reset_cmd
== ipr_cmd
) {
2645 ioa_cfg
->reset_retries
+= IPR_NUM_RESET_RELOAD_RETRIES
;
2646 ipr_initiate_ioa_reset(ioa_cfg
, IPR_SHUTDOWN_NONE
);
2649 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
2654 * ipr_find_ses_entry - Find matching SES in SES table
2655 * @res: resource entry struct of SES
2658 * pointer to SES table entry / NULL on failure
2660 static const struct ipr_ses_table_entry
*
2661 ipr_find_ses_entry(struct ipr_resource_entry
*res
)
2664 struct ipr_std_inq_vpids
*vpids
;
2665 const struct ipr_ses_table_entry
*ste
= ipr_ses_table
;
2667 for (i
= 0; i
< ARRAY_SIZE(ipr_ses_table
); i
++, ste
++) {
2668 for (j
= 0, matches
= 0; j
< IPR_PROD_ID_LEN
; j
++) {
2669 if (ste
->compare_product_id_byte
[j
] == 'X') {
2670 vpids
= &res
->std_inq_data
.vpids
;
2671 if (vpids
->product_id
[j
] == ste
->product_id
[j
])
2679 if (matches
== IPR_PROD_ID_LEN
)
2687 * ipr_get_max_scsi_speed - Determine max SCSI speed for a given bus
2688 * @ioa_cfg: ioa config struct
2690 * @bus_width: bus width
2693 * SCSI bus speed in units of 100KHz, 1600 is 160 MHz
2694 * For a 2-byte wide SCSI bus, the maximum transfer speed is
2695 * twice the maximum transfer rate (e.g. for a wide enabled bus,
2696 * max 160MHz = max 320MB/sec).
2698 static u32
ipr_get_max_scsi_speed(struct ipr_ioa_cfg
*ioa_cfg
, u8 bus
, u8 bus_width
)
2700 struct ipr_resource_entry
*res
;
2701 const struct ipr_ses_table_entry
*ste
;
2702 u32 max_xfer_rate
= IPR_MAX_SCSI_RATE(bus_width
);
2704 /* Loop through each config table entry in the config table buffer */
2705 list_for_each_entry(res
, &ioa_cfg
->used_res_q
, queue
) {
2706 if (!(IPR_IS_SES_DEVICE(res
->std_inq_data
)))
2709 if (bus
!= res
->bus
)
2712 if (!(ste
= ipr_find_ses_entry(res
)))
2715 max_xfer_rate
= (ste
->max_bus_speed_limit
* 10) / (bus_width
/ 8);
2718 return max_xfer_rate
;
2722 * ipr_wait_iodbg_ack - Wait for an IODEBUG ACK from the IOA
2723 * @ioa_cfg: ioa config struct
2724 * @max_delay: max delay in micro-seconds to wait
2726 * Waits for an IODEBUG ACK from the IOA, doing busy looping.
2729 * 0 on success / other on failure
2731 static int ipr_wait_iodbg_ack(struct ipr_ioa_cfg
*ioa_cfg
, int max_delay
)
2733 volatile u32 pcii_reg
;
2736 /* Read interrupt reg until IOA signals IO Debug Acknowledge */
2737 while (delay
< max_delay
) {
2738 pcii_reg
= readl(ioa_cfg
->regs
.sense_interrupt_reg
);
2740 if (pcii_reg
& IPR_PCII_IO_DEBUG_ACKNOWLEDGE
)
2743 /* udelay cannot be used if delay is more than a few milliseconds */
2744 if ((delay
/ 1000) > MAX_UDELAY_MS
)
2745 mdelay(delay
/ 1000);
2755 * ipr_get_sis64_dump_data_section - Dump IOA memory
2756 * @ioa_cfg: ioa config struct
2757 * @start_addr: adapter address to dump
2758 * @dest: destination kernel buffer
2759 * @length_in_words: length to dump in 4 byte words
2764 static int ipr_get_sis64_dump_data_section(struct ipr_ioa_cfg
*ioa_cfg
,
2766 __be32
*dest
, u32 length_in_words
)
2770 for (i
= 0; i
< length_in_words
; i
++) {
2771 writel(start_addr
+(i
*4), ioa_cfg
->regs
.dump_addr_reg
);
2772 *dest
= cpu_to_be32(readl(ioa_cfg
->regs
.dump_data_reg
));
2780 * ipr_get_ldump_data_section - Dump IOA memory
2781 * @ioa_cfg: ioa config struct
2782 * @start_addr: adapter address to dump
2783 * @dest: destination kernel buffer
2784 * @length_in_words: length to dump in 4 byte words
2787 * 0 on success / -EIO on failure
2789 static int ipr_get_ldump_data_section(struct ipr_ioa_cfg
*ioa_cfg
,
2791 __be32
*dest
, u32 length_in_words
)
2793 volatile u32 temp_pcii_reg
;
2797 return ipr_get_sis64_dump_data_section(ioa_cfg
, start_addr
,
2798 dest
, length_in_words
);
2800 /* Write IOA interrupt reg starting LDUMP state */
2801 writel((IPR_UPROCI_RESET_ALERT
| IPR_UPROCI_IO_DEBUG_ALERT
),
2802 ioa_cfg
->regs
.set_uproc_interrupt_reg32
);
2804 /* Wait for IO debug acknowledge */
2805 if (ipr_wait_iodbg_ack(ioa_cfg
,
2806 IPR_LDUMP_MAX_LONG_ACK_DELAY_IN_USEC
)) {
2807 dev_err(&ioa_cfg
->pdev
->dev
,
2808 "IOA dump long data transfer timeout\n");
2812 /* Signal LDUMP interlocked - clear IO debug ack */
2813 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE
,
2814 ioa_cfg
->regs
.clr_interrupt_reg
);
2816 /* Write Mailbox with starting address */
2817 writel(start_addr
, ioa_cfg
->ioa_mailbox
);
2819 /* Signal address valid - clear IOA Reset alert */
2820 writel(IPR_UPROCI_RESET_ALERT
,
2821 ioa_cfg
->regs
.clr_uproc_interrupt_reg32
);
2823 for (i
= 0; i
< length_in_words
; i
++) {
2824 /* Wait for IO debug acknowledge */
2825 if (ipr_wait_iodbg_ack(ioa_cfg
,
2826 IPR_LDUMP_MAX_SHORT_ACK_DELAY_IN_USEC
)) {
2827 dev_err(&ioa_cfg
->pdev
->dev
,
2828 "IOA dump short data transfer timeout\n");
2832 /* Read data from mailbox and increment destination pointer */
2833 *dest
= cpu_to_be32(readl(ioa_cfg
->ioa_mailbox
));
2836 /* For all but the last word of data, signal data received */
2837 if (i
< (length_in_words
- 1)) {
2838 /* Signal dump data received - Clear IO debug Ack */
2839 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE
,
2840 ioa_cfg
->regs
.clr_interrupt_reg
);
2844 /* Signal end of block transfer. Set reset alert then clear IO debug ack */
2845 writel(IPR_UPROCI_RESET_ALERT
,
2846 ioa_cfg
->regs
.set_uproc_interrupt_reg32
);
2848 writel(IPR_UPROCI_IO_DEBUG_ALERT
,
2849 ioa_cfg
->regs
.clr_uproc_interrupt_reg32
);
2851 /* Signal dump data received - Clear IO debug Ack */
2852 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE
,
2853 ioa_cfg
->regs
.clr_interrupt_reg
);
2855 /* Wait for IOA to signal LDUMP exit - IOA reset alert will be cleared */
2856 while (delay
< IPR_LDUMP_MAX_SHORT_ACK_DELAY_IN_USEC
) {
2858 readl(ioa_cfg
->regs
.sense_uproc_interrupt_reg32
);
2860 if (!(temp_pcii_reg
& IPR_UPROCI_RESET_ALERT
))
2870 #ifdef CONFIG_SCSI_IPR_DUMP
2872 * ipr_sdt_copy - Copy Smart Dump Table to kernel buffer
2873 * @ioa_cfg: ioa config struct
2874 * @pci_address: adapter address
2875 * @length: length of data to copy
2877 * Copy data from PCI adapter to kernel buffer.
2878 * Note: length MUST be a 4 byte multiple
2880 * 0 on success / other on failure
2882 static int ipr_sdt_copy(struct ipr_ioa_cfg
*ioa_cfg
,
2883 unsigned long pci_address
, u32 length
)
2885 int bytes_copied
= 0;
2886 int cur_len
, rc
, rem_len
, rem_page_len
, max_dump_size
;
2888 unsigned long lock_flags
= 0;
2889 struct ipr_ioa_dump
*ioa_dump
= &ioa_cfg
->dump
->ioa_dump
;
2892 max_dump_size
= IPR_FMT3_MAX_IOA_DUMP_SIZE
;
2894 max_dump_size
= IPR_FMT2_MAX_IOA_DUMP_SIZE
;
2896 while (bytes_copied
< length
&&
2897 (ioa_dump
->hdr
.len
+ bytes_copied
) < max_dump_size
) {
2898 if (ioa_dump
->page_offset
>= PAGE_SIZE
||
2899 ioa_dump
->page_offset
== 0) {
2900 page
= (__be32
*)__get_free_page(GFP_ATOMIC
);
2904 return bytes_copied
;
2907 ioa_dump
->page_offset
= 0;
2908 ioa_dump
->ioa_data
[ioa_dump
->next_page_index
] = page
;
2909 ioa_dump
->next_page_index
++;
2911 page
= ioa_dump
->ioa_data
[ioa_dump
->next_page_index
- 1];
2913 rem_len
= length
- bytes_copied
;
2914 rem_page_len
= PAGE_SIZE
- ioa_dump
->page_offset
;
2915 cur_len
= min(rem_len
, rem_page_len
);
2917 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
2918 if (ioa_cfg
->sdt_state
== ABORT_DUMP
) {
2921 rc
= ipr_get_ldump_data_section(ioa_cfg
,
2922 pci_address
+ bytes_copied
,
2923 &page
[ioa_dump
->page_offset
/ 4],
2924 (cur_len
/ sizeof(u32
)));
2926 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
2929 ioa_dump
->page_offset
+= cur_len
;
2930 bytes_copied
+= cur_len
;
2938 return bytes_copied
;
2942 * ipr_init_dump_entry_hdr - Initialize a dump entry header.
2943 * @hdr: dump entry header struct
2948 static void ipr_init_dump_entry_hdr(struct ipr_dump_entry_header
*hdr
)
2950 hdr
->eye_catcher
= IPR_DUMP_EYE_CATCHER
;
2952 hdr
->offset
= sizeof(*hdr
);
2953 hdr
->status
= IPR_DUMP_STATUS_SUCCESS
;
2957 * ipr_dump_ioa_type_data - Fill in the adapter type in the dump.
2958 * @ioa_cfg: ioa config struct
2959 * @driver_dump: driver dump struct
2964 static void ipr_dump_ioa_type_data(struct ipr_ioa_cfg
*ioa_cfg
,
2965 struct ipr_driver_dump
*driver_dump
)
2967 struct ipr_inquiry_page3
*ucode_vpd
= &ioa_cfg
->vpd_cbs
->page3_data
;
2969 ipr_init_dump_entry_hdr(&driver_dump
->ioa_type_entry
.hdr
);
2970 driver_dump
->ioa_type_entry
.hdr
.len
=
2971 sizeof(struct ipr_dump_ioa_type_entry
) -
2972 sizeof(struct ipr_dump_entry_header
);
2973 driver_dump
->ioa_type_entry
.hdr
.data_type
= IPR_DUMP_DATA_TYPE_BINARY
;
2974 driver_dump
->ioa_type_entry
.hdr
.id
= IPR_DUMP_DRIVER_TYPE_ID
;
2975 driver_dump
->ioa_type_entry
.type
= ioa_cfg
->type
;
2976 driver_dump
->ioa_type_entry
.fw_version
= (ucode_vpd
->major_release
<< 24) |
2977 (ucode_vpd
->card_type
<< 16) | (ucode_vpd
->minor_release
[0] << 8) |
2978 ucode_vpd
->minor_release
[1];
2979 driver_dump
->hdr
.num_entries
++;
2983 * ipr_dump_version_data - Fill in the driver version in the dump.
2984 * @ioa_cfg: ioa config struct
2985 * @driver_dump: driver dump struct
2990 static void ipr_dump_version_data(struct ipr_ioa_cfg
*ioa_cfg
,
2991 struct ipr_driver_dump
*driver_dump
)
2993 ipr_init_dump_entry_hdr(&driver_dump
->version_entry
.hdr
);
2994 driver_dump
->version_entry
.hdr
.len
=
2995 sizeof(struct ipr_dump_version_entry
) -
2996 sizeof(struct ipr_dump_entry_header
);
2997 driver_dump
->version_entry
.hdr
.data_type
= IPR_DUMP_DATA_TYPE_ASCII
;
2998 driver_dump
->version_entry
.hdr
.id
= IPR_DUMP_DRIVER_VERSION_ID
;
2999 strcpy(driver_dump
->version_entry
.version
, IPR_DRIVER_VERSION
);
3000 driver_dump
->hdr
.num_entries
++;
3004 * ipr_dump_trace_data - Fill in the IOA trace in the dump.
3005 * @ioa_cfg: ioa config struct
3006 * @driver_dump: driver dump struct
3011 static void ipr_dump_trace_data(struct ipr_ioa_cfg
*ioa_cfg
,
3012 struct ipr_driver_dump
*driver_dump
)
3014 ipr_init_dump_entry_hdr(&driver_dump
->trace_entry
.hdr
);
3015 driver_dump
->trace_entry
.hdr
.len
=
3016 sizeof(struct ipr_dump_trace_entry
) -
3017 sizeof(struct ipr_dump_entry_header
);
3018 driver_dump
->trace_entry
.hdr
.data_type
= IPR_DUMP_DATA_TYPE_BINARY
;
3019 driver_dump
->trace_entry
.hdr
.id
= IPR_DUMP_TRACE_ID
;
3020 memcpy(driver_dump
->trace_entry
.trace
, ioa_cfg
->trace
, IPR_TRACE_SIZE
);
3021 driver_dump
->hdr
.num_entries
++;
3025 * ipr_dump_location_data - Fill in the IOA location in the dump.
3026 * @ioa_cfg: ioa config struct
3027 * @driver_dump: driver dump struct
3032 static void ipr_dump_location_data(struct ipr_ioa_cfg
*ioa_cfg
,
3033 struct ipr_driver_dump
*driver_dump
)
3035 ipr_init_dump_entry_hdr(&driver_dump
->location_entry
.hdr
);
3036 driver_dump
->location_entry
.hdr
.len
=
3037 sizeof(struct ipr_dump_location_entry
) -
3038 sizeof(struct ipr_dump_entry_header
);
3039 driver_dump
->location_entry
.hdr
.data_type
= IPR_DUMP_DATA_TYPE_ASCII
;
3040 driver_dump
->location_entry
.hdr
.id
= IPR_DUMP_LOCATION_ID
;
3041 strcpy(driver_dump
->location_entry
.location
, dev_name(&ioa_cfg
->pdev
->dev
));
3042 driver_dump
->hdr
.num_entries
++;
3046 * ipr_get_ioa_dump - Perform a dump of the driver and adapter.
3047 * @ioa_cfg: ioa config struct
3048 * @dump: dump struct
3053 static void ipr_get_ioa_dump(struct ipr_ioa_cfg
*ioa_cfg
, struct ipr_dump
*dump
)
3055 unsigned long start_addr
, sdt_word
;
3056 unsigned long lock_flags
= 0;
3057 struct ipr_driver_dump
*driver_dump
= &dump
->driver_dump
;
3058 struct ipr_ioa_dump
*ioa_dump
= &dump
->ioa_dump
;
3059 u32 num_entries
, max_num_entries
, start_off
, end_off
;
3060 u32 max_dump_size
, bytes_to_copy
, bytes_copied
, rc
;
3061 struct ipr_sdt
*sdt
;
3067 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
3069 if (ioa_cfg
->sdt_state
!= READ_DUMP
) {
3070 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3074 if (ioa_cfg
->sis64
) {
3075 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3076 ssleep(IPR_DUMP_DELAY_SECONDS
);
3077 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
3080 start_addr
= readl(ioa_cfg
->ioa_mailbox
);
3082 if (!ioa_cfg
->sis64
&& !ipr_sdt_is_fmt2(start_addr
)) {
3083 dev_err(&ioa_cfg
->pdev
->dev
,
3084 "Invalid dump table format: %lx\n", start_addr
);
3085 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3089 dev_err(&ioa_cfg
->pdev
->dev
, "Dump of IOA initiated\n");
3091 driver_dump
->hdr
.eye_catcher
= IPR_DUMP_EYE_CATCHER
;
3093 /* Initialize the overall dump header */
3094 driver_dump
->hdr
.len
= sizeof(struct ipr_driver_dump
);
3095 driver_dump
->hdr
.num_entries
= 1;
3096 driver_dump
->hdr
.first_entry_offset
= sizeof(struct ipr_dump_header
);
3097 driver_dump
->hdr
.status
= IPR_DUMP_STATUS_SUCCESS
;
3098 driver_dump
->hdr
.os
= IPR_DUMP_OS_LINUX
;
3099 driver_dump
->hdr
.driver_name
= IPR_DUMP_DRIVER_NAME
;
3101 ipr_dump_version_data(ioa_cfg
, driver_dump
);
3102 ipr_dump_location_data(ioa_cfg
, driver_dump
);
3103 ipr_dump_ioa_type_data(ioa_cfg
, driver_dump
);
3104 ipr_dump_trace_data(ioa_cfg
, driver_dump
);
3106 /* Update dump_header */
3107 driver_dump
->hdr
.len
+= sizeof(struct ipr_dump_entry_header
);
3109 /* IOA Dump entry */
3110 ipr_init_dump_entry_hdr(&ioa_dump
->hdr
);
3111 ioa_dump
->hdr
.len
= 0;
3112 ioa_dump
->hdr
.data_type
= IPR_DUMP_DATA_TYPE_BINARY
;
3113 ioa_dump
->hdr
.id
= IPR_DUMP_IOA_DUMP_ID
;
3115 /* First entries in sdt are actually a list of dump addresses and
3116 lengths to gather the real dump data. sdt represents the pointer
3117 to the ioa generated dump table. Dump data will be extracted based
3118 on entries in this table */
3119 sdt
= &ioa_dump
->sdt
;
3121 if (ioa_cfg
->sis64
) {
3122 max_num_entries
= IPR_FMT3_NUM_SDT_ENTRIES
;
3123 max_dump_size
= IPR_FMT3_MAX_IOA_DUMP_SIZE
;
3125 max_num_entries
= IPR_FMT2_NUM_SDT_ENTRIES
;
3126 max_dump_size
= IPR_FMT2_MAX_IOA_DUMP_SIZE
;
3129 bytes_to_copy
= offsetof(struct ipr_sdt
, entry
) +
3130 (max_num_entries
* sizeof(struct ipr_sdt_entry
));
3131 rc
= ipr_get_ldump_data_section(ioa_cfg
, start_addr
, (__be32
*)sdt
,
3132 bytes_to_copy
/ sizeof(__be32
));
3134 /* Smart Dump table is ready to use and the first entry is valid */
3135 if (rc
|| ((be32_to_cpu(sdt
->hdr
.state
) != IPR_FMT3_SDT_READY_TO_USE
) &&
3136 (be32_to_cpu(sdt
->hdr
.state
) != IPR_FMT2_SDT_READY_TO_USE
))) {
3137 dev_err(&ioa_cfg
->pdev
->dev
,
3138 "Dump of IOA failed. Dump table not valid: %d, %X.\n",
3139 rc
, be32_to_cpu(sdt
->hdr
.state
));
3140 driver_dump
->hdr
.status
= IPR_DUMP_STATUS_FAILED
;
3141 ioa_cfg
->sdt_state
= DUMP_OBTAINED
;
3142 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3146 num_entries
= be32_to_cpu(sdt
->hdr
.num_entries_used
);
3148 if (num_entries
> max_num_entries
)
3149 num_entries
= max_num_entries
;
3151 /* Update dump length to the actual data to be copied */
3152 dump
->driver_dump
.hdr
.len
+= sizeof(struct ipr_sdt_header
);
3154 dump
->driver_dump
.hdr
.len
+= num_entries
* sizeof(struct ipr_sdt_entry
);
3156 dump
->driver_dump
.hdr
.len
+= max_num_entries
* sizeof(struct ipr_sdt_entry
);
3158 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3160 for (i
= 0; i
< num_entries
; i
++) {
3161 if (ioa_dump
->hdr
.len
> max_dump_size
) {
3162 driver_dump
->hdr
.status
= IPR_DUMP_STATUS_QUAL_SUCCESS
;
3166 if (sdt
->entry
[i
].flags
& IPR_SDT_VALID_ENTRY
) {
3167 sdt_word
= be32_to_cpu(sdt
->entry
[i
].start_token
);
3169 bytes_to_copy
= be32_to_cpu(sdt
->entry
[i
].end_token
);
3171 start_off
= sdt_word
& IPR_FMT2_MBX_ADDR_MASK
;
3172 end_off
= be32_to_cpu(sdt
->entry
[i
].end_token
);
3174 if (ipr_sdt_is_fmt2(sdt_word
) && sdt_word
)
3175 bytes_to_copy
= end_off
- start_off
;
3180 if (bytes_to_copy
> max_dump_size
) {
3181 sdt
->entry
[i
].flags
&= ~IPR_SDT_VALID_ENTRY
;
3185 /* Copy data from adapter to driver buffers */
3186 bytes_copied
= ipr_sdt_copy(ioa_cfg
, sdt_word
,
3189 ioa_dump
->hdr
.len
+= bytes_copied
;
3191 if (bytes_copied
!= bytes_to_copy
) {
3192 driver_dump
->hdr
.status
= IPR_DUMP_STATUS_QUAL_SUCCESS
;
3199 dev_err(&ioa_cfg
->pdev
->dev
, "Dump of IOA completed.\n");
3201 /* Update dump_header */
3202 driver_dump
->hdr
.len
+= ioa_dump
->hdr
.len
;
3204 ioa_cfg
->sdt_state
= DUMP_OBTAINED
;
3209 #define ipr_get_ioa_dump(ioa_cfg, dump) do { } while (0)
3213 * ipr_release_dump - Free adapter dump memory
3214 * @kref: kref struct
3219 static void ipr_release_dump(struct kref
*kref
)
3221 struct ipr_dump
*dump
= container_of(kref
, struct ipr_dump
, kref
);
3222 struct ipr_ioa_cfg
*ioa_cfg
= dump
->ioa_cfg
;
3223 unsigned long lock_flags
= 0;
3227 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
3228 ioa_cfg
->dump
= NULL
;
3229 ioa_cfg
->sdt_state
= INACTIVE
;
3230 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3232 for (i
= 0; i
< dump
->ioa_dump
.next_page_index
; i
++)
3233 free_page((unsigned long) dump
->ioa_dump
.ioa_data
[i
]);
3235 vfree(dump
->ioa_dump
.ioa_data
);
3241 * ipr_worker_thread - Worker thread
3242 * @work: ioa config struct
3244 * Called at task level from a work thread. This function takes care
3245 * of adding and removing device from the mid-layer as configuration
3246 * changes are detected by the adapter.
3251 static void ipr_worker_thread(struct work_struct
*work
)
3253 unsigned long lock_flags
;
3254 struct ipr_resource_entry
*res
;
3255 struct scsi_device
*sdev
;
3256 struct ipr_dump
*dump
;
3257 struct ipr_ioa_cfg
*ioa_cfg
=
3258 container_of(work
, struct ipr_ioa_cfg
, work_q
);
3259 u8 bus
, target
, lun
;
3263 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
3265 if (ioa_cfg
->sdt_state
== READ_DUMP
) {
3266 dump
= ioa_cfg
->dump
;
3268 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3271 kref_get(&dump
->kref
);
3272 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3273 ipr_get_ioa_dump(ioa_cfg
, dump
);
3274 kref_put(&dump
->kref
, ipr_release_dump
);
3276 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
3277 if (ioa_cfg
->sdt_state
== DUMP_OBTAINED
&& !ioa_cfg
->dump_timeout
)
3278 ipr_initiate_ioa_reset(ioa_cfg
, IPR_SHUTDOWN_NONE
);
3279 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3286 if (!ioa_cfg
->hrrq
[IPR_INIT_HRRQ
].allow_cmds
) {
3287 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3291 list_for_each_entry(res
, &ioa_cfg
->used_res_q
, queue
) {
3292 if (res
->del_from_ml
&& res
->sdev
) {
3295 if (!scsi_device_get(sdev
)) {
3296 if (!res
->add_to_ml
)
3297 list_move_tail(&res
->queue
, &ioa_cfg
->free_res_q
);
3299 res
->del_from_ml
= 0;
3300 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3301 scsi_remove_device(sdev
);
3302 scsi_device_put(sdev
);
3303 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
3310 list_for_each_entry(res
, &ioa_cfg
->used_res_q
, queue
) {
3311 if (res
->add_to_ml
) {
3313 target
= res
->target
;
3316 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3317 scsi_add_device(ioa_cfg
->host
, bus
, target
, lun
);
3318 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
3323 ioa_cfg
->scan_done
= 1;
3324 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3325 kobject_uevent(&ioa_cfg
->host
->shost_dev
.kobj
, KOBJ_CHANGE
);
3329 #ifdef CONFIG_SCSI_IPR_TRACE
3331 * ipr_read_trace - Dump the adapter trace
3332 * @filp: open sysfs file
3333 * @kobj: kobject struct
3334 * @bin_attr: bin_attribute struct
3337 * @count: buffer size
3340 * number of bytes printed to buffer
3342 static ssize_t
ipr_read_trace(struct file
*filp
, struct kobject
*kobj
,
3343 struct bin_attribute
*bin_attr
,
3344 char *buf
, loff_t off
, size_t count
)
3346 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3347 struct Scsi_Host
*shost
= class_to_shost(dev
);
3348 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*)shost
->hostdata
;
3349 unsigned long lock_flags
= 0;
3352 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
3353 ret
= memory_read_from_buffer(buf
, count
, &off
, ioa_cfg
->trace
,
3355 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3360 static struct bin_attribute ipr_trace_attr
= {
3366 .read
= ipr_read_trace
,
3371 * ipr_show_fw_version - Show the firmware version
3372 * @dev: class device struct
3376 * number of bytes printed to buffer
3378 static ssize_t
ipr_show_fw_version(struct device
*dev
,
3379 struct device_attribute
*attr
, char *buf
)
3381 struct Scsi_Host
*shost
= class_to_shost(dev
);
3382 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*)shost
->hostdata
;
3383 struct ipr_inquiry_page3
*ucode_vpd
= &ioa_cfg
->vpd_cbs
->page3_data
;
3384 unsigned long lock_flags
= 0;
3387 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
3388 len
= snprintf(buf
, PAGE_SIZE
, "%02X%02X%02X%02X\n",
3389 ucode_vpd
->major_release
, ucode_vpd
->card_type
,
3390 ucode_vpd
->minor_release
[0],
3391 ucode_vpd
->minor_release
[1]);
3392 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3396 static struct device_attribute ipr_fw_version_attr
= {
3398 .name
= "fw_version",
3401 .show
= ipr_show_fw_version
,
3405 * ipr_show_log_level - Show the adapter's error logging level
3406 * @dev: class device struct
3410 * number of bytes printed to buffer
3412 static ssize_t
ipr_show_log_level(struct device
*dev
,
3413 struct device_attribute
*attr
, char *buf
)
3415 struct Scsi_Host
*shost
= class_to_shost(dev
);
3416 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*)shost
->hostdata
;
3417 unsigned long lock_flags
= 0;
3420 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
3421 len
= snprintf(buf
, PAGE_SIZE
, "%d\n", ioa_cfg
->log_level
);
3422 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3427 * ipr_store_log_level - Change the adapter's error logging level
3428 * @dev: class device struct
3432 * number of bytes printed to buffer
3434 static ssize_t
ipr_store_log_level(struct device
*dev
,
3435 struct device_attribute
*attr
,
3436 const char *buf
, size_t count
)
3438 struct Scsi_Host
*shost
= class_to_shost(dev
);
3439 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*)shost
->hostdata
;
3440 unsigned long lock_flags
= 0;
3442 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
3443 ioa_cfg
->log_level
= simple_strtoul(buf
, NULL
, 10);
3444 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3448 static struct device_attribute ipr_log_level_attr
= {
3450 .name
= "log_level",
3451 .mode
= S_IRUGO
| S_IWUSR
,
3453 .show
= ipr_show_log_level
,
3454 .store
= ipr_store_log_level
3458 * ipr_store_diagnostics - IOA Diagnostics interface
3459 * @dev: device struct
3461 * @count: buffer size
3463 * This function will reset the adapter and wait a reasonable
3464 * amount of time for any errors that the adapter might log.
3467 * count on success / other on failure
3469 static ssize_t
ipr_store_diagnostics(struct device
*dev
,
3470 struct device_attribute
*attr
,
3471 const char *buf
, size_t count
)
3473 struct Scsi_Host
*shost
= class_to_shost(dev
);
3474 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*)shost
->hostdata
;
3475 unsigned long lock_flags
= 0;
3478 if (!capable(CAP_SYS_ADMIN
))
3481 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
3482 while (ioa_cfg
->in_reset_reload
) {
3483 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3484 wait_event(ioa_cfg
->reset_wait_q
, !ioa_cfg
->in_reset_reload
);
3485 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
3488 ioa_cfg
->errors_logged
= 0;
3489 ipr_initiate_ioa_reset(ioa_cfg
, IPR_SHUTDOWN_NORMAL
);
3491 if (ioa_cfg
->in_reset_reload
) {
3492 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3493 wait_event(ioa_cfg
->reset_wait_q
, !ioa_cfg
->in_reset_reload
);
3495 /* Wait for a second for any errors to be logged */
3498 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3502 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
3503 if (ioa_cfg
->in_reset_reload
|| ioa_cfg
->errors_logged
)
3505 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3510 static struct device_attribute ipr_diagnostics_attr
= {
3512 .name
= "run_diagnostics",
3515 .store
= ipr_store_diagnostics
3519 * ipr_show_adapter_state - Show the adapter's state
3520 * @class_dev: device struct
3524 * number of bytes printed to buffer
3526 static ssize_t
ipr_show_adapter_state(struct device
*dev
,
3527 struct device_attribute
*attr
, char *buf
)
3529 struct Scsi_Host
*shost
= class_to_shost(dev
);
3530 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*)shost
->hostdata
;
3531 unsigned long lock_flags
= 0;
3534 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
3535 if (ioa_cfg
->hrrq
[IPR_INIT_HRRQ
].ioa_is_dead
)
3536 len
= snprintf(buf
, PAGE_SIZE
, "offline\n");
3538 len
= snprintf(buf
, PAGE_SIZE
, "online\n");
3539 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3544 * ipr_store_adapter_state - Change adapter state
3545 * @dev: device struct
3547 * @count: buffer size
3549 * This function will change the adapter's state.
3552 * count on success / other on failure
3554 static ssize_t
ipr_store_adapter_state(struct device
*dev
,
3555 struct device_attribute
*attr
,
3556 const char *buf
, size_t count
)
3558 struct Scsi_Host
*shost
= class_to_shost(dev
);
3559 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*)shost
->hostdata
;
3560 unsigned long lock_flags
;
3561 int result
= count
, i
;
3563 if (!capable(CAP_SYS_ADMIN
))
3566 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
3567 if (ioa_cfg
->hrrq
[IPR_INIT_HRRQ
].ioa_is_dead
&&
3568 !strncmp(buf
, "online", 6)) {
3569 for (i
= 0; i
< ioa_cfg
->hrrq_num
; i
++) {
3570 spin_lock(&ioa_cfg
->hrrq
[i
]._lock
);
3571 ioa_cfg
->hrrq
[i
].ioa_is_dead
= 0;
3572 spin_unlock(&ioa_cfg
->hrrq
[i
]._lock
);
3575 ioa_cfg
->reset_retries
= 0;
3576 ioa_cfg
->in_ioa_bringdown
= 0;
3577 ipr_initiate_ioa_reset(ioa_cfg
, IPR_SHUTDOWN_NONE
);
3579 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3580 wait_event(ioa_cfg
->reset_wait_q
, !ioa_cfg
->in_reset_reload
);
3585 static struct device_attribute ipr_ioa_state_attr
= {
3587 .name
= "online_state",
3588 .mode
= S_IRUGO
| S_IWUSR
,
3590 .show
= ipr_show_adapter_state
,
3591 .store
= ipr_store_adapter_state
3595 * ipr_store_reset_adapter - Reset the adapter
3596 * @dev: device struct
3598 * @count: buffer size
3600 * This function will reset the adapter.
3603 * count on success / other on failure
3605 static ssize_t
ipr_store_reset_adapter(struct device
*dev
,
3606 struct device_attribute
*attr
,
3607 const char *buf
, size_t count
)
3609 struct Scsi_Host
*shost
= class_to_shost(dev
);
3610 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*)shost
->hostdata
;
3611 unsigned long lock_flags
;
3614 if (!capable(CAP_SYS_ADMIN
))
3617 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
3618 if (!ioa_cfg
->in_reset_reload
)
3619 ipr_initiate_ioa_reset(ioa_cfg
, IPR_SHUTDOWN_NORMAL
);
3620 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3621 wait_event(ioa_cfg
->reset_wait_q
, !ioa_cfg
->in_reset_reload
);
3626 static struct device_attribute ipr_ioa_reset_attr
= {
3628 .name
= "reset_host",
3631 .store
= ipr_store_reset_adapter
3634 static int ipr_iopoll(struct blk_iopoll
*iop
, int budget
);
3636 * ipr_show_iopoll_weight - Show ipr polling mode
3637 * @dev: class device struct
3641 * number of bytes printed to buffer
3643 static ssize_t
ipr_show_iopoll_weight(struct device
*dev
,
3644 struct device_attribute
*attr
, char *buf
)
3646 struct Scsi_Host
*shost
= class_to_shost(dev
);
3647 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*)shost
->hostdata
;
3648 unsigned long lock_flags
= 0;
3651 spin_lock_irqsave(shost
->host_lock
, lock_flags
);
3652 len
= snprintf(buf
, PAGE_SIZE
, "%d\n", ioa_cfg
->iopoll_weight
);
3653 spin_unlock_irqrestore(shost
->host_lock
, lock_flags
);
3659 * ipr_store_iopoll_weight - Change the adapter's polling mode
3660 * @dev: class device struct
3664 * number of bytes printed to buffer
3666 static ssize_t
ipr_store_iopoll_weight(struct device
*dev
,
3667 struct device_attribute
*attr
,
3668 const char *buf
, size_t count
)
3670 struct Scsi_Host
*shost
= class_to_shost(dev
);
3671 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*)shost
->hostdata
;
3672 unsigned long user_iopoll_weight
;
3673 unsigned long lock_flags
= 0;
3676 if (!ioa_cfg
->sis64
) {
3677 dev_info(&ioa_cfg
->pdev
->dev
, "blk-iopoll not supported on this adapter\n");
3680 if (kstrtoul(buf
, 10, &user_iopoll_weight
))
3683 if (user_iopoll_weight
> 256) {
3684 dev_info(&ioa_cfg
->pdev
->dev
, "Invalid blk-iopoll weight. It must be less than 256\n");
3688 if (user_iopoll_weight
== ioa_cfg
->iopoll_weight
) {
3689 dev_info(&ioa_cfg
->pdev
->dev
, "Current blk-iopoll weight has the same weight\n");
3693 if (ioa_cfg
->iopoll_weight
&& ioa_cfg
->sis64
&& ioa_cfg
->nvectors
> 1) {
3694 for (i
= 1; i
< ioa_cfg
->hrrq_num
; i
++)
3695 blk_iopoll_disable(&ioa_cfg
->hrrq
[i
].iopoll
);
3698 spin_lock_irqsave(shost
->host_lock
, lock_flags
);
3699 ioa_cfg
->iopoll_weight
= user_iopoll_weight
;
3700 if (ioa_cfg
->iopoll_weight
&& ioa_cfg
->sis64
&& ioa_cfg
->nvectors
> 1) {
3701 for (i
= 1; i
< ioa_cfg
->hrrq_num
; i
++) {
3702 blk_iopoll_init(&ioa_cfg
->hrrq
[i
].iopoll
,
3703 ioa_cfg
->iopoll_weight
, ipr_iopoll
);
3704 blk_iopoll_enable(&ioa_cfg
->hrrq
[i
].iopoll
);
3707 spin_unlock_irqrestore(shost
->host_lock
, lock_flags
);
3712 static struct device_attribute ipr_iopoll_weight_attr
= {
3714 .name
= "iopoll_weight",
3715 .mode
= S_IRUGO
| S_IWUSR
,
3717 .show
= ipr_show_iopoll_weight
,
3718 .store
= ipr_store_iopoll_weight
3722 * ipr_alloc_ucode_buffer - Allocates a microcode download buffer
3723 * @buf_len: buffer length
3725 * Allocates a DMA'able buffer in chunks and assembles a scatter/gather
3726 * list to use for microcode download
3729 * pointer to sglist / NULL on failure
3731 static struct ipr_sglist
*ipr_alloc_ucode_buffer(int buf_len
)
3733 int sg_size
, order
, bsize_elem
, num_elem
, i
, j
;
3734 struct ipr_sglist
*sglist
;
3735 struct scatterlist
*scatterlist
;
3738 /* Get the minimum size per scatter/gather element */
3739 sg_size
= buf_len
/ (IPR_MAX_SGLIST
- 1);
3741 /* Get the actual size per element */
3742 order
= get_order(sg_size
);
3744 /* Determine the actual number of bytes per element */
3745 bsize_elem
= PAGE_SIZE
* (1 << order
);
3747 /* Determine the actual number of sg entries needed */
3748 if (buf_len
% bsize_elem
)
3749 num_elem
= (buf_len
/ bsize_elem
) + 1;
3751 num_elem
= buf_len
/ bsize_elem
;
3753 /* Allocate a scatter/gather list for the DMA */
3754 sglist
= kzalloc(sizeof(struct ipr_sglist
) +
3755 (sizeof(struct scatterlist
) * (num_elem
- 1)),
3758 if (sglist
== NULL
) {
3763 scatterlist
= sglist
->scatterlist
;
3764 sg_init_table(scatterlist
, num_elem
);
3766 sglist
->order
= order
;
3767 sglist
->num_sg
= num_elem
;
3769 /* Allocate a bunch of sg elements */
3770 for (i
= 0; i
< num_elem
; i
++) {
3771 page
= alloc_pages(GFP_KERNEL
, order
);
3775 /* Free up what we already allocated */
3776 for (j
= i
- 1; j
>= 0; j
--)
3777 __free_pages(sg_page(&scatterlist
[j
]), order
);
3782 sg_set_page(&scatterlist
[i
], page
, 0, 0);
3789 * ipr_free_ucode_buffer - Frees a microcode download buffer
3790 * @p_dnld: scatter/gather list pointer
3792 * Free a DMA'able ucode download buffer previously allocated with
3793 * ipr_alloc_ucode_buffer
3798 static void ipr_free_ucode_buffer(struct ipr_sglist
*sglist
)
3802 for (i
= 0; i
< sglist
->num_sg
; i
++)
3803 __free_pages(sg_page(&sglist
->scatterlist
[i
]), sglist
->order
);
3809 * ipr_copy_ucode_buffer - Copy user buffer to kernel buffer
3810 * @sglist: scatter/gather list pointer
3811 * @buffer: buffer pointer
3812 * @len: buffer length
3814 * Copy a microcode image from a user buffer into a buffer allocated by
3815 * ipr_alloc_ucode_buffer
3818 * 0 on success / other on failure
3820 static int ipr_copy_ucode_buffer(struct ipr_sglist
*sglist
,
3821 u8
*buffer
, u32 len
)
3823 int bsize_elem
, i
, result
= 0;
3824 struct scatterlist
*scatterlist
;
3827 /* Determine the actual number of bytes per element */
3828 bsize_elem
= PAGE_SIZE
* (1 << sglist
->order
);
3830 scatterlist
= sglist
->scatterlist
;
3832 for (i
= 0; i
< (len
/ bsize_elem
); i
++, buffer
+= bsize_elem
) {
3833 struct page
*page
= sg_page(&scatterlist
[i
]);
3836 memcpy(kaddr
, buffer
, bsize_elem
);
3839 scatterlist
[i
].length
= bsize_elem
;
3847 if (len
% bsize_elem
) {
3848 struct page
*page
= sg_page(&scatterlist
[i
]);
3851 memcpy(kaddr
, buffer
, len
% bsize_elem
);
3854 scatterlist
[i
].length
= len
% bsize_elem
;
3857 sglist
->buffer_len
= len
;
3862 * ipr_build_ucode_ioadl64 - Build a microcode download IOADL
3863 * @ipr_cmd: ipr command struct
3864 * @sglist: scatter/gather list
3866 * Builds a microcode download IOA data list (IOADL).
3869 static void ipr_build_ucode_ioadl64(struct ipr_cmnd
*ipr_cmd
,
3870 struct ipr_sglist
*sglist
)
3872 struct ipr_ioarcb
*ioarcb
= &ipr_cmd
->ioarcb
;
3873 struct ipr_ioadl64_desc
*ioadl64
= ipr_cmd
->i
.ioadl64
;
3874 struct scatterlist
*scatterlist
= sglist
->scatterlist
;
3877 ipr_cmd
->dma_use_sg
= sglist
->num_dma_sg
;
3878 ioarcb
->cmd_pkt
.flags_hi
|= IPR_FLAGS_HI_WRITE_NOT_READ
;
3879 ioarcb
->data_transfer_length
= cpu_to_be32(sglist
->buffer_len
);
3882 cpu_to_be32(sizeof(struct ipr_ioadl64_desc
) * ipr_cmd
->dma_use_sg
);
3883 for (i
= 0; i
< ipr_cmd
->dma_use_sg
; i
++) {
3884 ioadl64
[i
].flags
= cpu_to_be32(IPR_IOADL_FLAGS_WRITE
);
3885 ioadl64
[i
].data_len
= cpu_to_be32(sg_dma_len(&scatterlist
[i
]));
3886 ioadl64
[i
].address
= cpu_to_be64(sg_dma_address(&scatterlist
[i
]));
3889 ioadl64
[i
-1].flags
|= cpu_to_be32(IPR_IOADL_FLAGS_LAST
);
3893 * ipr_build_ucode_ioadl - Build a microcode download IOADL
3894 * @ipr_cmd: ipr command struct
3895 * @sglist: scatter/gather list
3897 * Builds a microcode download IOA data list (IOADL).
3900 static void ipr_build_ucode_ioadl(struct ipr_cmnd
*ipr_cmd
,
3901 struct ipr_sglist
*sglist
)
3903 struct ipr_ioarcb
*ioarcb
= &ipr_cmd
->ioarcb
;
3904 struct ipr_ioadl_desc
*ioadl
= ipr_cmd
->i
.ioadl
;
3905 struct scatterlist
*scatterlist
= sglist
->scatterlist
;
3908 ipr_cmd
->dma_use_sg
= sglist
->num_dma_sg
;
3909 ioarcb
->cmd_pkt
.flags_hi
|= IPR_FLAGS_HI_WRITE_NOT_READ
;
3910 ioarcb
->data_transfer_length
= cpu_to_be32(sglist
->buffer_len
);
3913 cpu_to_be32(sizeof(struct ipr_ioadl_desc
) * ipr_cmd
->dma_use_sg
);
3915 for (i
= 0; i
< ipr_cmd
->dma_use_sg
; i
++) {
3916 ioadl
[i
].flags_and_data_len
=
3917 cpu_to_be32(IPR_IOADL_FLAGS_WRITE
| sg_dma_len(&scatterlist
[i
]));
3919 cpu_to_be32(sg_dma_address(&scatterlist
[i
]));
3922 ioadl
[i
-1].flags_and_data_len
|=
3923 cpu_to_be32(IPR_IOADL_FLAGS_LAST
);
3927 * ipr_update_ioa_ucode - Update IOA's microcode
3928 * @ioa_cfg: ioa config struct
3929 * @sglist: scatter/gather list
3931 * Initiate an adapter reset to update the IOA's microcode
3934 * 0 on success / -EIO on failure
3936 static int ipr_update_ioa_ucode(struct ipr_ioa_cfg
*ioa_cfg
,
3937 struct ipr_sglist
*sglist
)
3939 unsigned long lock_flags
;
3941 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
3942 while (ioa_cfg
->in_reset_reload
) {
3943 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3944 wait_event(ioa_cfg
->reset_wait_q
, !ioa_cfg
->in_reset_reload
);
3945 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
3948 if (ioa_cfg
->ucode_sglist
) {
3949 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3950 dev_err(&ioa_cfg
->pdev
->dev
,
3951 "Microcode download already in progress\n");
3955 sglist
->num_dma_sg
= dma_map_sg(&ioa_cfg
->pdev
->dev
,
3956 sglist
->scatterlist
, sglist
->num_sg
,
3959 if (!sglist
->num_dma_sg
) {
3960 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3961 dev_err(&ioa_cfg
->pdev
->dev
,
3962 "Failed to map microcode download buffer!\n");
3966 ioa_cfg
->ucode_sglist
= sglist
;
3967 ipr_initiate_ioa_reset(ioa_cfg
, IPR_SHUTDOWN_NORMAL
);
3968 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3969 wait_event(ioa_cfg
->reset_wait_q
, !ioa_cfg
->in_reset_reload
);
3971 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
3972 ioa_cfg
->ucode_sglist
= NULL
;
3973 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3978 * ipr_store_update_fw - Update the firmware on the adapter
3979 * @class_dev: device struct
3981 * @count: buffer size
3983 * This function will update the firmware on the adapter.
3986 * count on success / other on failure
3988 static ssize_t
ipr_store_update_fw(struct device
*dev
,
3989 struct device_attribute
*attr
,
3990 const char *buf
, size_t count
)
3992 struct Scsi_Host
*shost
= class_to_shost(dev
);
3993 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*)shost
->hostdata
;
3994 struct ipr_ucode_image_header
*image_hdr
;
3995 const struct firmware
*fw_entry
;
3996 struct ipr_sglist
*sglist
;
3999 int len
, result
, dnld_size
;
4001 if (!capable(CAP_SYS_ADMIN
))
4004 len
= snprintf(fname
, 99, "%s", buf
);
4005 fname
[len
-1] = '\0';
4007 if (request_firmware(&fw_entry
, fname
, &ioa_cfg
->pdev
->dev
)) {
4008 dev_err(&ioa_cfg
->pdev
->dev
, "Firmware file %s not found\n", fname
);
4012 image_hdr
= (struct ipr_ucode_image_header
*)fw_entry
->data
;
4014 src
= (u8
*)image_hdr
+ be32_to_cpu(image_hdr
->header_length
);
4015 dnld_size
= fw_entry
->size
- be32_to_cpu(image_hdr
->header_length
);
4016 sglist
= ipr_alloc_ucode_buffer(dnld_size
);
4019 dev_err(&ioa_cfg
->pdev
->dev
, "Microcode buffer allocation failed\n");
4020 release_firmware(fw_entry
);
4024 result
= ipr_copy_ucode_buffer(sglist
, src
, dnld_size
);
4027 dev_err(&ioa_cfg
->pdev
->dev
,
4028 "Microcode buffer copy to DMA buffer failed\n");
4032 ipr_info("Updating microcode, please be patient. This may take up to 30 minutes.\n");
4034 result
= ipr_update_ioa_ucode(ioa_cfg
, sglist
);
4039 ipr_free_ucode_buffer(sglist
);
4040 release_firmware(fw_entry
);
4044 static struct device_attribute ipr_update_fw_attr
= {
4046 .name
= "update_fw",
4049 .store
= ipr_store_update_fw
4053 * ipr_show_fw_type - Show the adapter's firmware type.
4054 * @dev: class device struct
4058 * number of bytes printed to buffer
4060 static ssize_t
ipr_show_fw_type(struct device
*dev
,
4061 struct device_attribute
*attr
, char *buf
)
4063 struct Scsi_Host
*shost
= class_to_shost(dev
);
4064 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*)shost
->hostdata
;
4065 unsigned long lock_flags
= 0;
4068 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
4069 len
= snprintf(buf
, PAGE_SIZE
, "%d\n", ioa_cfg
->sis64
);
4070 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
4074 static struct device_attribute ipr_ioa_fw_type_attr
= {
4079 .show
= ipr_show_fw_type
4082 static struct device_attribute
*ipr_ioa_attrs
[] = {
4083 &ipr_fw_version_attr
,
4084 &ipr_log_level_attr
,
4085 &ipr_diagnostics_attr
,
4086 &ipr_ioa_state_attr
,
4087 &ipr_ioa_reset_attr
,
4088 &ipr_update_fw_attr
,
4089 &ipr_ioa_fw_type_attr
,
4090 &ipr_iopoll_weight_attr
,
4094 #ifdef CONFIG_SCSI_IPR_DUMP
4096 * ipr_read_dump - Dump the adapter
4097 * @filp: open sysfs file
4098 * @kobj: kobject struct
4099 * @bin_attr: bin_attribute struct
4102 * @count: buffer size
4105 * number of bytes printed to buffer
4107 static ssize_t
ipr_read_dump(struct file
*filp
, struct kobject
*kobj
,
4108 struct bin_attribute
*bin_attr
,
4109 char *buf
, loff_t off
, size_t count
)
4111 struct device
*cdev
= container_of(kobj
, struct device
, kobj
);
4112 struct Scsi_Host
*shost
= class_to_shost(cdev
);
4113 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*)shost
->hostdata
;
4114 struct ipr_dump
*dump
;
4115 unsigned long lock_flags
= 0;
4120 if (!capable(CAP_SYS_ADMIN
))
4123 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
4124 dump
= ioa_cfg
->dump
;
4126 if (ioa_cfg
->sdt_state
!= DUMP_OBTAINED
|| !dump
) {
4127 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
4130 kref_get(&dump
->kref
);
4131 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
4133 if (off
> dump
->driver_dump
.hdr
.len
) {
4134 kref_put(&dump
->kref
, ipr_release_dump
);
4138 if (off
+ count
> dump
->driver_dump
.hdr
.len
) {
4139 count
= dump
->driver_dump
.hdr
.len
- off
;
4143 if (count
&& off
< sizeof(dump
->driver_dump
)) {
4144 if (off
+ count
> sizeof(dump
->driver_dump
))
4145 len
= sizeof(dump
->driver_dump
) - off
;
4148 src
= (u8
*)&dump
->driver_dump
+ off
;
4149 memcpy(buf
, src
, len
);
4155 off
-= sizeof(dump
->driver_dump
);
4158 sdt_end
= offsetof(struct ipr_ioa_dump
, sdt
.entry
) +
4159 (be32_to_cpu(dump
->ioa_dump
.sdt
.hdr
.num_entries_used
) *
4160 sizeof(struct ipr_sdt_entry
));
4162 sdt_end
= offsetof(struct ipr_ioa_dump
, sdt
.entry
) +
4163 (IPR_FMT2_NUM_SDT_ENTRIES
* sizeof(struct ipr_sdt_entry
));
4165 if (count
&& off
< sdt_end
) {
4166 if (off
+ count
> sdt_end
)
4167 len
= sdt_end
- off
;
4170 src
= (u8
*)&dump
->ioa_dump
+ off
;
4171 memcpy(buf
, src
, len
);
4180 if ((off
& PAGE_MASK
) != ((off
+ count
) & PAGE_MASK
))
4181 len
= PAGE_ALIGN(off
) - off
;
4184 src
= (u8
*)dump
->ioa_dump
.ioa_data
[(off
& PAGE_MASK
) >> PAGE_SHIFT
];
4185 src
+= off
& ~PAGE_MASK
;
4186 memcpy(buf
, src
, len
);
4192 kref_put(&dump
->kref
, ipr_release_dump
);
4197 * ipr_alloc_dump - Prepare for adapter dump
4198 * @ioa_cfg: ioa config struct
4201 * 0 on success / other on failure
4203 static int ipr_alloc_dump(struct ipr_ioa_cfg
*ioa_cfg
)
4205 struct ipr_dump
*dump
;
4207 unsigned long lock_flags
= 0;
4209 dump
= kzalloc(sizeof(struct ipr_dump
), GFP_KERNEL
);
4212 ipr_err("Dump memory allocation failed\n");
4217 ioa_data
= vmalloc(IPR_FMT3_MAX_NUM_DUMP_PAGES
* sizeof(__be32
*));
4219 ioa_data
= vmalloc(IPR_FMT2_MAX_NUM_DUMP_PAGES
* sizeof(__be32
*));
4222 ipr_err("Dump memory allocation failed\n");
4227 dump
->ioa_dump
.ioa_data
= ioa_data
;
4229 kref_init(&dump
->kref
);
4230 dump
->ioa_cfg
= ioa_cfg
;
4232 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
4234 if (INACTIVE
!= ioa_cfg
->sdt_state
) {
4235 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
4236 vfree(dump
->ioa_dump
.ioa_data
);
4241 ioa_cfg
->dump
= dump
;
4242 ioa_cfg
->sdt_state
= WAIT_FOR_DUMP
;
4243 if (ioa_cfg
->hrrq
[IPR_INIT_HRRQ
].ioa_is_dead
&& !ioa_cfg
->dump_taken
) {
4244 ioa_cfg
->dump_taken
= 1;
4245 schedule_work(&ioa_cfg
->work_q
);
4247 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
4253 * ipr_free_dump - Free adapter dump memory
4254 * @ioa_cfg: ioa config struct
4257 * 0 on success / other on failure
4259 static int ipr_free_dump(struct ipr_ioa_cfg
*ioa_cfg
)
4261 struct ipr_dump
*dump
;
4262 unsigned long lock_flags
= 0;
4266 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
4267 dump
= ioa_cfg
->dump
;
4269 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
4273 ioa_cfg
->dump
= NULL
;
4274 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
4276 kref_put(&dump
->kref
, ipr_release_dump
);
4283 * ipr_write_dump - Setup dump state of adapter
4284 * @filp: open sysfs file
4285 * @kobj: kobject struct
4286 * @bin_attr: bin_attribute struct
4289 * @count: buffer size
4292 * number of bytes printed to buffer
4294 static ssize_t
ipr_write_dump(struct file
*filp
, struct kobject
*kobj
,
4295 struct bin_attribute
*bin_attr
,
4296 char *buf
, loff_t off
, size_t count
)
4298 struct device
*cdev
= container_of(kobj
, struct device
, kobj
);
4299 struct Scsi_Host
*shost
= class_to_shost(cdev
);
4300 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*)shost
->hostdata
;
4303 if (!capable(CAP_SYS_ADMIN
))
4307 rc
= ipr_alloc_dump(ioa_cfg
);
4308 else if (buf
[0] == '0')
4309 rc
= ipr_free_dump(ioa_cfg
);
4319 static struct bin_attribute ipr_dump_attr
= {
4322 .mode
= S_IRUSR
| S_IWUSR
,
4325 .read
= ipr_read_dump
,
4326 .write
= ipr_write_dump
4329 static int ipr_free_dump(struct ipr_ioa_cfg
*ioa_cfg
) { return 0; };
4333 * ipr_change_queue_depth - Change the device's queue depth
4334 * @sdev: scsi device struct
4335 * @qdepth: depth to set
4336 * @reason: calling context
4341 static int ipr_change_queue_depth(struct scsi_device
*sdev
, int qdepth
)
4343 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*)sdev
->host
->hostdata
;
4344 struct ipr_resource_entry
*res
;
4345 unsigned long lock_flags
= 0;
4347 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
4348 res
= (struct ipr_resource_entry
*)sdev
->hostdata
;
4350 if (res
&& ipr_is_gata(res
) && qdepth
> IPR_MAX_CMD_PER_ATA_LUN
)
4351 qdepth
= IPR_MAX_CMD_PER_ATA_LUN
;
4352 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
4354 scsi_change_queue_depth(sdev
, qdepth
);
4355 return sdev
->queue_depth
;
4359 * ipr_show_adapter_handle - Show the adapter's resource handle for this device
4360 * @dev: device struct
4361 * @attr: device attribute structure
4365 * number of bytes printed to buffer
4367 static ssize_t
ipr_show_adapter_handle(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
4369 struct scsi_device
*sdev
= to_scsi_device(dev
);
4370 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*)sdev
->host
->hostdata
;
4371 struct ipr_resource_entry
*res
;
4372 unsigned long lock_flags
= 0;
4373 ssize_t len
= -ENXIO
;
4375 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
4376 res
= (struct ipr_resource_entry
*)sdev
->hostdata
;
4378 len
= snprintf(buf
, PAGE_SIZE
, "%08X\n", res
->res_handle
);
4379 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
4383 static struct device_attribute ipr_adapter_handle_attr
= {
4385 .name
= "adapter_handle",
4388 .show
= ipr_show_adapter_handle
4392 * ipr_show_resource_path - Show the resource path or the resource address for
4394 * @dev: device struct
4395 * @attr: device attribute structure
4399 * number of bytes printed to buffer
4401 static ssize_t
ipr_show_resource_path(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
4403 struct scsi_device
*sdev
= to_scsi_device(dev
);
4404 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*)sdev
->host
->hostdata
;
4405 struct ipr_resource_entry
*res
;
4406 unsigned long lock_flags
= 0;
4407 ssize_t len
= -ENXIO
;
4408 char buffer
[IPR_MAX_RES_PATH_LENGTH
];
4410 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
4411 res
= (struct ipr_resource_entry
*)sdev
->hostdata
;
4412 if (res
&& ioa_cfg
->sis64
)
4413 len
= snprintf(buf
, PAGE_SIZE
, "%s\n",
4414 __ipr_format_res_path(res
->res_path
, buffer
,
4417 len
= snprintf(buf
, PAGE_SIZE
, "%d:%d:%d:%d\n", ioa_cfg
->host
->host_no
,
4418 res
->bus
, res
->target
, res
->lun
);
4420 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
4424 static struct device_attribute ipr_resource_path_attr
= {
4426 .name
= "resource_path",
4429 .show
= ipr_show_resource_path
4433 * ipr_show_device_id - Show the device_id for this device.
4434 * @dev: device struct
4435 * @attr: device attribute structure
4439 * number of bytes printed to buffer
4441 static ssize_t
ipr_show_device_id(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
4443 struct scsi_device
*sdev
= to_scsi_device(dev
);
4444 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*)sdev
->host
->hostdata
;
4445 struct ipr_resource_entry
*res
;
4446 unsigned long lock_flags
= 0;
4447 ssize_t len
= -ENXIO
;
4449 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
4450 res
= (struct ipr_resource_entry
*)sdev
->hostdata
;
4451 if (res
&& ioa_cfg
->sis64
)
4452 len
= snprintf(buf
, PAGE_SIZE
, "0x%llx\n", res
->dev_id
);
4454 len
= snprintf(buf
, PAGE_SIZE
, "0x%llx\n", res
->lun_wwn
);
4456 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
4460 static struct device_attribute ipr_device_id_attr
= {
4462 .name
= "device_id",
4465 .show
= ipr_show_device_id
4469 * ipr_show_resource_type - Show the resource type for this device.
4470 * @dev: device struct
4471 * @attr: device attribute structure
4475 * number of bytes printed to buffer
4477 static ssize_t
ipr_show_resource_type(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
4479 struct scsi_device
*sdev
= to_scsi_device(dev
);
4480 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*)sdev
->host
->hostdata
;
4481 struct ipr_resource_entry
*res
;
4482 unsigned long lock_flags
= 0;
4483 ssize_t len
= -ENXIO
;
4485 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
4486 res
= (struct ipr_resource_entry
*)sdev
->hostdata
;
4489 len
= snprintf(buf
, PAGE_SIZE
, "%x\n", res
->type
);
4491 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
4495 static struct device_attribute ipr_resource_type_attr
= {
4497 .name
= "resource_type",
4500 .show
= ipr_show_resource_type
4504 * ipr_show_raw_mode - Show the adapter's raw mode
4505 * @dev: class device struct
4509 * number of bytes printed to buffer
4511 static ssize_t
ipr_show_raw_mode(struct device
*dev
,
4512 struct device_attribute
*attr
, char *buf
)
4514 struct scsi_device
*sdev
= to_scsi_device(dev
);
4515 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*)sdev
->host
->hostdata
;
4516 struct ipr_resource_entry
*res
;
4517 unsigned long lock_flags
= 0;
4520 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
4521 res
= (struct ipr_resource_entry
*)sdev
->hostdata
;
4523 len
= snprintf(buf
, PAGE_SIZE
, "%d\n", res
->raw_mode
);
4526 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
4531 * ipr_store_raw_mode - Change the adapter's raw mode
4532 * @dev: class device struct
4536 * number of bytes printed to buffer
4538 static ssize_t
ipr_store_raw_mode(struct device
*dev
,
4539 struct device_attribute
*attr
,
4540 const char *buf
, size_t count
)
4542 struct scsi_device
*sdev
= to_scsi_device(dev
);
4543 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*)sdev
->host
->hostdata
;
4544 struct ipr_resource_entry
*res
;
4545 unsigned long lock_flags
= 0;
4548 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
4549 res
= (struct ipr_resource_entry
*)sdev
->hostdata
;
4551 if (ioa_cfg
->sis64
&& ipr_is_af_dasd_device(res
)) {
4552 res
->raw_mode
= simple_strtoul(buf
, NULL
, 10);
4555 sdev_printk(KERN_INFO
, res
->sdev
, "raw mode is %s\n",
4556 res
->raw_mode
? "enabled" : "disabled");
4561 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
4565 static struct device_attribute ipr_raw_mode_attr
= {
4568 .mode
= S_IRUGO
| S_IWUSR
,
4570 .show
= ipr_show_raw_mode
,
4571 .store
= ipr_store_raw_mode
4574 static struct device_attribute
*ipr_dev_attrs
[] = {
4575 &ipr_adapter_handle_attr
,
4576 &ipr_resource_path_attr
,
4577 &ipr_device_id_attr
,
4578 &ipr_resource_type_attr
,
4584 * ipr_biosparam - Return the HSC mapping
4585 * @sdev: scsi device struct
4586 * @block_device: block device pointer
4587 * @capacity: capacity of the device
4588 * @parm: Array containing returned HSC values.
4590 * This function generates the HSC parms that fdisk uses.
4591 * We want to make sure we return something that places partitions
4592 * on 4k boundaries for best performance with the IOA.
4597 static int ipr_biosparam(struct scsi_device
*sdev
,
4598 struct block_device
*block_device
,
4599 sector_t capacity
, int *parm
)
4607 cylinders
= capacity
;
4608 sector_div(cylinders
, (128 * 32));
4613 parm
[2] = cylinders
;
4619 * ipr_find_starget - Find target based on bus/target.
4620 * @starget: scsi target struct
4623 * resource entry pointer if found / NULL if not found
4625 static struct ipr_resource_entry
*ipr_find_starget(struct scsi_target
*starget
)
4627 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
4628 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*) shost
->hostdata
;
4629 struct ipr_resource_entry
*res
;
4631 list_for_each_entry(res
, &ioa_cfg
->used_res_q
, queue
) {
4632 if ((res
->bus
== starget
->channel
) &&
4633 (res
->target
== starget
->id
)) {
4641 static struct ata_port_info sata_port_info
;
4644 * ipr_target_alloc - Prepare for commands to a SCSI target
4645 * @starget: scsi target struct
4647 * If the device is a SATA device, this function allocates an
4648 * ATA port with libata, else it does nothing.
4651 * 0 on success / non-0 on failure
4653 static int ipr_target_alloc(struct scsi_target
*starget
)
4655 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
4656 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*) shost
->hostdata
;
4657 struct ipr_sata_port
*sata_port
;
4658 struct ata_port
*ap
;
4659 struct ipr_resource_entry
*res
;
4660 unsigned long lock_flags
;
4662 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
4663 res
= ipr_find_starget(starget
);
4664 starget
->hostdata
= NULL
;
4666 if (res
&& ipr_is_gata(res
)) {
4667 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
4668 sata_port
= kzalloc(sizeof(*sata_port
), GFP_KERNEL
);
4672 ap
= ata_sas_port_alloc(&ioa_cfg
->ata_host
, &sata_port_info
, shost
);
4674 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
4675 sata_port
->ioa_cfg
= ioa_cfg
;
4677 sata_port
->res
= res
;
4679 res
->sata_port
= sata_port
;
4680 ap
->private_data
= sata_port
;
4681 starget
->hostdata
= sata_port
;
4687 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
4693 * ipr_target_destroy - Destroy a SCSI target
4694 * @starget: scsi target struct
4696 * If the device was a SATA device, this function frees the libata
4697 * ATA port, else it does nothing.
4700 static void ipr_target_destroy(struct scsi_target
*starget
)
4702 struct ipr_sata_port
*sata_port
= starget
->hostdata
;
4703 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
4704 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*) shost
->hostdata
;
4706 if (ioa_cfg
->sis64
) {
4707 if (!ipr_find_starget(starget
)) {
4708 if (starget
->channel
== IPR_ARRAY_VIRTUAL_BUS
)
4709 clear_bit(starget
->id
, ioa_cfg
->array_ids
);
4710 else if (starget
->channel
== IPR_VSET_VIRTUAL_BUS
)
4711 clear_bit(starget
->id
, ioa_cfg
->vset_ids
);
4712 else if (starget
->channel
== 0)
4713 clear_bit(starget
->id
, ioa_cfg
->target_ids
);
4718 starget
->hostdata
= NULL
;
4719 ata_sas_port_destroy(sata_port
->ap
);
4725 * ipr_find_sdev - Find device based on bus/target/lun.
4726 * @sdev: scsi device struct
4729 * resource entry pointer if found / NULL if not found
4731 static struct ipr_resource_entry
*ipr_find_sdev(struct scsi_device
*sdev
)
4733 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*) sdev
->host
->hostdata
;
4734 struct ipr_resource_entry
*res
;
4736 list_for_each_entry(res
, &ioa_cfg
->used_res_q
, queue
) {
4737 if ((res
->bus
== sdev
->channel
) &&
4738 (res
->target
== sdev
->id
) &&
4739 (res
->lun
== sdev
->lun
))
4747 * ipr_slave_destroy - Unconfigure a SCSI device
4748 * @sdev: scsi device struct
4753 static void ipr_slave_destroy(struct scsi_device
*sdev
)
4755 struct ipr_resource_entry
*res
;
4756 struct ipr_ioa_cfg
*ioa_cfg
;
4757 unsigned long lock_flags
= 0;
4759 ioa_cfg
= (struct ipr_ioa_cfg
*) sdev
->host
->hostdata
;
4761 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
4762 res
= (struct ipr_resource_entry
*) sdev
->hostdata
;
4765 res
->sata_port
->ap
->link
.device
[0].class = ATA_DEV_NONE
;
4766 sdev
->hostdata
= NULL
;
4768 res
->sata_port
= NULL
;
4770 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
4774 * ipr_slave_configure - Configure a SCSI device
4775 * @sdev: scsi device struct
4777 * This function configures the specified scsi device.
4782 static int ipr_slave_configure(struct scsi_device
*sdev
)
4784 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*) sdev
->host
->hostdata
;
4785 struct ipr_resource_entry
*res
;
4786 struct ata_port
*ap
= NULL
;
4787 unsigned long lock_flags
= 0;
4788 char buffer
[IPR_MAX_RES_PATH_LENGTH
];
4790 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
4791 res
= sdev
->hostdata
;
4793 if (ipr_is_af_dasd_device(res
))
4794 sdev
->type
= TYPE_RAID
;
4795 if (ipr_is_af_dasd_device(res
) || ipr_is_ioa_resource(res
)) {
4796 sdev
->scsi_level
= 4;
4797 sdev
->no_uld_attach
= 1;
4799 if (ipr_is_vset_device(res
)) {
4800 sdev
->scsi_level
= SCSI_SPC_3
;
4801 blk_queue_rq_timeout(sdev
->request_queue
,
4802 IPR_VSET_RW_TIMEOUT
);
4803 blk_queue_max_hw_sectors(sdev
->request_queue
, IPR_VSET_MAX_SECTORS
);
4805 if (ipr_is_gata(res
) && res
->sata_port
)
4806 ap
= res
->sata_port
->ap
;
4807 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
4810 scsi_change_queue_depth(sdev
, IPR_MAX_CMD_PER_ATA_LUN
);
4811 ata_sas_slave_configure(sdev
, ap
);
4815 sdev_printk(KERN_INFO
, sdev
, "Resource path: %s\n",
4816 ipr_format_res_path(ioa_cfg
,
4817 res
->res_path
, buffer
, sizeof(buffer
)));
4820 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
4825 * ipr_ata_slave_alloc - Prepare for commands to a SATA device
4826 * @sdev: scsi device struct
4828 * This function initializes an ATA port so that future commands
4829 * sent through queuecommand will work.
4834 static int ipr_ata_slave_alloc(struct scsi_device
*sdev
)
4836 struct ipr_sata_port
*sata_port
= NULL
;
4840 if (sdev
->sdev_target
)
4841 sata_port
= sdev
->sdev_target
->hostdata
;
4843 rc
= ata_sas_port_init(sata_port
->ap
);
4845 rc
= ata_sas_sync_probe(sata_port
->ap
);
4849 ipr_slave_destroy(sdev
);
4856 * ipr_slave_alloc - Prepare for commands to a device.
4857 * @sdev: scsi device struct
4859 * This function saves a pointer to the resource entry
4860 * in the scsi device struct if the device exists. We
4861 * can then use this pointer in ipr_queuecommand when
4862 * handling new commands.
4865 * 0 on success / -ENXIO if device does not exist
4867 static int ipr_slave_alloc(struct scsi_device
*sdev
)
4869 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*) sdev
->host
->hostdata
;
4870 struct ipr_resource_entry
*res
;
4871 unsigned long lock_flags
;
4874 sdev
->hostdata
= NULL
;
4876 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
4878 res
= ipr_find_sdev(sdev
);
4883 sdev
->hostdata
= res
;
4884 if (!ipr_is_naca_model(res
))
4885 res
->needs_sync_complete
= 1;
4887 if (ipr_is_gata(res
)) {
4888 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
4889 return ipr_ata_slave_alloc(sdev
);
4893 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
4899 * ipr_match_lun - Match function for specified LUN
4900 * @ipr_cmd: ipr command struct
4901 * @device: device to match (sdev)
4904 * 1 if command matches sdev / 0 if command does not match sdev
4906 static int ipr_match_lun(struct ipr_cmnd
*ipr_cmd
, void *device
)
4908 if (ipr_cmd
->scsi_cmd
&& ipr_cmd
->scsi_cmd
->device
== device
)
4914 * ipr_wait_for_ops - Wait for matching commands to complete
4915 * @ipr_cmd: ipr command struct
4916 * @device: device to match (sdev)
4917 * @match: match function to use
4922 static int ipr_wait_for_ops(struct ipr_ioa_cfg
*ioa_cfg
, void *device
,
4923 int (*match
)(struct ipr_cmnd
*, void *))
4925 struct ipr_cmnd
*ipr_cmd
;
4927 unsigned long flags
;
4928 struct ipr_hrr_queue
*hrrq
;
4929 signed long timeout
= IPR_ABORT_TASK_TIMEOUT
;
4930 DECLARE_COMPLETION_ONSTACK(comp
);
4936 for_each_hrrq(hrrq
, ioa_cfg
) {
4937 spin_lock_irqsave(hrrq
->lock
, flags
);
4938 list_for_each_entry(ipr_cmd
, &hrrq
->hrrq_pending_q
, queue
) {
4939 if (match(ipr_cmd
, device
)) {
4940 ipr_cmd
->eh_comp
= &comp
;
4944 spin_unlock_irqrestore(hrrq
->lock
, flags
);
4948 timeout
= wait_for_completion_timeout(&comp
, timeout
);
4953 for_each_hrrq(hrrq
, ioa_cfg
) {
4954 spin_lock_irqsave(hrrq
->lock
, flags
);
4955 list_for_each_entry(ipr_cmd
, &hrrq
->hrrq_pending_q
, queue
) {
4956 if (match(ipr_cmd
, device
)) {
4957 ipr_cmd
->eh_comp
= NULL
;
4961 spin_unlock_irqrestore(hrrq
->lock
, flags
);
4965 dev_err(&ioa_cfg
->pdev
->dev
, "Timed out waiting for aborted commands\n");
4967 return wait
? FAILED
: SUCCESS
;
4976 static int ipr_eh_host_reset(struct scsi_cmnd
*cmd
)
4978 struct ipr_ioa_cfg
*ioa_cfg
;
4979 unsigned long lock_flags
= 0;
4983 ioa_cfg
= (struct ipr_ioa_cfg
*) cmd
->device
->host
->hostdata
;
4984 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
4986 if (!ioa_cfg
->in_reset_reload
&& !ioa_cfg
->hrrq
[IPR_INIT_HRRQ
].ioa_is_dead
) {
4987 ipr_initiate_ioa_reset(ioa_cfg
, IPR_SHUTDOWN_ABBREV
);
4988 dev_err(&ioa_cfg
->pdev
->dev
,
4989 "Adapter being reset as a result of error recovery.\n");
4991 if (WAIT_FOR_DUMP
== ioa_cfg
->sdt_state
)
4992 ioa_cfg
->sdt_state
= GET_DUMP
;
4995 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
4996 wait_event(ioa_cfg
->reset_wait_q
, !ioa_cfg
->in_reset_reload
);
4997 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
4999 /* If we got hit with a host reset while we were already resetting
5000 the adapter for some reason, and the reset failed. */
5001 if (ioa_cfg
->hrrq
[IPR_INIT_HRRQ
].ioa_is_dead
) {
5006 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
5012 * ipr_device_reset - Reset the device
5013 * @ioa_cfg: ioa config struct
5014 * @res: resource entry struct
5016 * This function issues a device reset to the affected device.
5017 * If the device is a SCSI device, a LUN reset will be sent
5018 * to the device first. If that does not work, a target reset
5019 * will be sent. If the device is a SATA device, a PHY reset will
5023 * 0 on success / non-zero on failure
5025 static int ipr_device_reset(struct ipr_ioa_cfg
*ioa_cfg
,
5026 struct ipr_resource_entry
*res
)
5028 struct ipr_cmnd
*ipr_cmd
;
5029 struct ipr_ioarcb
*ioarcb
;
5030 struct ipr_cmd_pkt
*cmd_pkt
;
5031 struct ipr_ioarcb_ata_regs
*regs
;
5035 ipr_cmd
= ipr_get_free_ipr_cmnd(ioa_cfg
);
5036 ioarcb
= &ipr_cmd
->ioarcb
;
5037 cmd_pkt
= &ioarcb
->cmd_pkt
;
5039 if (ipr_cmd
->ioa_cfg
->sis64
) {
5040 regs
= &ipr_cmd
->i
.ata_ioadl
.regs
;
5041 ioarcb
->add_cmd_parms_offset
= cpu_to_be16(sizeof(*ioarcb
));
5043 regs
= &ioarcb
->u
.add_data
.u
.regs
;
5045 ioarcb
->res_handle
= res
->res_handle
;
5046 cmd_pkt
->request_type
= IPR_RQTYPE_IOACMD
;
5047 cmd_pkt
->cdb
[0] = IPR_RESET_DEVICE
;
5048 if (ipr_is_gata(res
)) {
5049 cmd_pkt
->cdb
[2] = IPR_ATA_PHY_RESET
;
5050 ioarcb
->add_cmd_parms_len
= cpu_to_be16(sizeof(regs
->flags
));
5051 regs
->flags
|= IPR_ATA_FLAG_STATUS_ON_GOOD_COMPLETION
;
5054 ipr_send_blocking_cmd(ipr_cmd
, ipr_timeout
, IPR_DEVICE_RESET_TIMEOUT
);
5055 ioasc
= be32_to_cpu(ipr_cmd
->s
.ioasa
.hdr
.ioasc
);
5056 list_add_tail(&ipr_cmd
->queue
, &ipr_cmd
->hrrq
->hrrq_free_q
);
5057 if (ipr_is_gata(res
) && res
->sata_port
&& ioasc
!= IPR_IOASC_IOA_WAS_RESET
) {
5058 if (ipr_cmd
->ioa_cfg
->sis64
)
5059 memcpy(&res
->sata_port
->ioasa
, &ipr_cmd
->s
.ioasa64
.u
.gata
,
5060 sizeof(struct ipr_ioasa_gata
));
5062 memcpy(&res
->sata_port
->ioasa
, &ipr_cmd
->s
.ioasa
.u
.gata
,
5063 sizeof(struct ipr_ioasa_gata
));
5067 return IPR_IOASC_SENSE_KEY(ioasc
) ? -EIO
: 0;
5071 * ipr_sata_reset - Reset the SATA port
5072 * @link: SATA link to reset
5073 * @classes: class of the attached device
5075 * This function issues a SATA phy reset to the affected ATA link.
5078 * 0 on success / non-zero on failure
5080 static int ipr_sata_reset(struct ata_link
*link
, unsigned int *classes
,
5081 unsigned long deadline
)
5083 struct ipr_sata_port
*sata_port
= link
->ap
->private_data
;
5084 struct ipr_ioa_cfg
*ioa_cfg
= sata_port
->ioa_cfg
;
5085 struct ipr_resource_entry
*res
;
5086 unsigned long lock_flags
= 0;
5090 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
5091 while (ioa_cfg
->in_reset_reload
) {
5092 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
5093 wait_event(ioa_cfg
->reset_wait_q
, !ioa_cfg
->in_reset_reload
);
5094 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
5097 res
= sata_port
->res
;
5099 rc
= ipr_device_reset(ioa_cfg
, res
);
5100 *classes
= res
->ata_class
;
5103 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
5109 * ipr_eh_dev_reset - Reset the device
5110 * @scsi_cmd: scsi command struct
5112 * This function issues a device reset to the affected device.
5113 * A LUN reset will be sent to the device first. If that does
5114 * not work, a target reset will be sent.
5119 static int __ipr_eh_dev_reset(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 ata_port
*ap
;
5126 struct ipr_hrr_queue
*hrrq
;
5129 ioa_cfg
= (struct ipr_ioa_cfg
*) scsi_cmd
->device
->host
->hostdata
;
5130 res
= scsi_cmd
->device
->hostdata
;
5136 * If we are currently going through reset/reload, return failed. This will force the
5137 * mid-layer to call ipr_eh_host_reset, which will then go to sleep and wait for the
5140 if (ioa_cfg
->in_reset_reload
)
5142 if (ioa_cfg
->hrrq
[IPR_INIT_HRRQ
].ioa_is_dead
)
5145 for_each_hrrq(hrrq
, ioa_cfg
) {
5146 spin_lock(&hrrq
->_lock
);
5147 list_for_each_entry(ipr_cmd
, &hrrq
->hrrq_pending_q
, queue
) {
5148 if (ipr_cmd
->ioarcb
.res_handle
== res
->res_handle
) {
5149 if (ipr_cmd
->scsi_cmd
)
5150 ipr_cmd
->done
= ipr_scsi_eh_done
;
5152 ipr_cmd
->done
= ipr_sata_eh_done
;
5154 !(ipr_cmd
->qc
->flags
& ATA_QCFLAG_FAILED
)) {
5155 ipr_cmd
->qc
->err_mask
|= AC_ERR_TIMEOUT
;
5156 ipr_cmd
->qc
->flags
|= ATA_QCFLAG_FAILED
;
5160 spin_unlock(&hrrq
->_lock
);
5162 res
->resetting_device
= 1;
5163 scmd_printk(KERN_ERR
, scsi_cmd
, "Resetting device\n");
5165 if (ipr_is_gata(res
) && res
->sata_port
) {
5166 ap
= res
->sata_port
->ap
;
5167 spin_unlock_irq(scsi_cmd
->device
->host
->host_lock
);
5168 ata_std_error_handler(ap
);
5169 spin_lock_irq(scsi_cmd
->device
->host
->host_lock
);
5171 for_each_hrrq(hrrq
, ioa_cfg
) {
5172 spin_lock(&hrrq
->_lock
);
5173 list_for_each_entry(ipr_cmd
,
5174 &hrrq
->hrrq_pending_q
, queue
) {
5175 if (ipr_cmd
->ioarcb
.res_handle
==
5181 spin_unlock(&hrrq
->_lock
);
5184 rc
= ipr_device_reset(ioa_cfg
, res
);
5185 res
->resetting_device
= 0;
5186 res
->reset_occurred
= 1;
5189 return rc
? FAILED
: SUCCESS
;
5192 static int ipr_eh_dev_reset(struct scsi_cmnd
*cmd
)
5195 struct ipr_ioa_cfg
*ioa_cfg
;
5197 ioa_cfg
= (struct ipr_ioa_cfg
*) cmd
->device
->host
->hostdata
;
5199 spin_lock_irq(cmd
->device
->host
->host_lock
);
5200 rc
= __ipr_eh_dev_reset(cmd
);
5201 spin_unlock_irq(cmd
->device
->host
->host_lock
);
5204 rc
= ipr_wait_for_ops(ioa_cfg
, cmd
->device
, ipr_match_lun
);
5210 * ipr_bus_reset_done - Op done function for bus reset.
5211 * @ipr_cmd: ipr command struct
5213 * This function is the op done function for a bus reset
5218 static void ipr_bus_reset_done(struct ipr_cmnd
*ipr_cmd
)
5220 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
5221 struct ipr_resource_entry
*res
;
5224 if (!ioa_cfg
->sis64
)
5225 list_for_each_entry(res
, &ioa_cfg
->used_res_q
, queue
) {
5226 if (res
->res_handle
== ipr_cmd
->ioarcb
.res_handle
) {
5227 scsi_report_bus_reset(ioa_cfg
->host
, res
->bus
);
5233 * If abort has not completed, indicate the reset has, else call the
5234 * abort's done function to wake the sleeping eh thread
5236 if (ipr_cmd
->sibling
->sibling
)
5237 ipr_cmd
->sibling
->sibling
= NULL
;
5239 ipr_cmd
->sibling
->done(ipr_cmd
->sibling
);
5241 list_add_tail(&ipr_cmd
->queue
, &ipr_cmd
->hrrq
->hrrq_free_q
);
5246 * ipr_abort_timeout - An abort task has timed out
5247 * @ipr_cmd: ipr command struct
5249 * This function handles when an abort task times out. If this
5250 * happens we issue a bus reset since we have resources tied
5251 * up that must be freed before returning to the midlayer.
5256 static void ipr_abort_timeout(struct ipr_cmnd
*ipr_cmd
)
5258 struct ipr_cmnd
*reset_cmd
;
5259 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
5260 struct ipr_cmd_pkt
*cmd_pkt
;
5261 unsigned long lock_flags
= 0;
5264 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
5265 if (ipr_cmd
->completion
.done
|| ioa_cfg
->in_reset_reload
) {
5266 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
5270 sdev_printk(KERN_ERR
, ipr_cmd
->u
.sdev
, "Abort timed out. Resetting bus.\n");
5271 reset_cmd
= ipr_get_free_ipr_cmnd(ioa_cfg
);
5272 ipr_cmd
->sibling
= reset_cmd
;
5273 reset_cmd
->sibling
= ipr_cmd
;
5274 reset_cmd
->ioarcb
.res_handle
= ipr_cmd
->ioarcb
.res_handle
;
5275 cmd_pkt
= &reset_cmd
->ioarcb
.cmd_pkt
;
5276 cmd_pkt
->request_type
= IPR_RQTYPE_IOACMD
;
5277 cmd_pkt
->cdb
[0] = IPR_RESET_DEVICE
;
5278 cmd_pkt
->cdb
[2] = IPR_RESET_TYPE_SELECT
| IPR_BUS_RESET
;
5280 ipr_do_req(reset_cmd
, ipr_bus_reset_done
, ipr_timeout
, IPR_DEVICE_RESET_TIMEOUT
);
5281 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
5286 * ipr_cancel_op - Cancel specified op
5287 * @scsi_cmd: scsi command struct
5289 * This function cancels specified op.
5294 static int ipr_cancel_op(struct scsi_cmnd
*scsi_cmd
)
5296 struct ipr_cmnd
*ipr_cmd
;
5297 struct ipr_ioa_cfg
*ioa_cfg
;
5298 struct ipr_resource_entry
*res
;
5299 struct ipr_cmd_pkt
*cmd_pkt
;
5302 struct ipr_hrr_queue
*hrrq
;
5305 ioa_cfg
= (struct ipr_ioa_cfg
*)scsi_cmd
->device
->host
->hostdata
;
5306 res
= scsi_cmd
->device
->hostdata
;
5308 /* If we are currently going through reset/reload, return failed.
5309 * This will force the mid-layer to call ipr_eh_host_reset,
5310 * which will then go to sleep and wait for the reset to complete
5312 if (ioa_cfg
->in_reset_reload
||
5313 ioa_cfg
->hrrq
[IPR_INIT_HRRQ
].ioa_is_dead
)
5319 * If we are aborting a timed out op, chances are that the timeout was caused
5320 * by a still not detected EEH error. In such cases, reading a register will
5321 * trigger the EEH recovery infrastructure.
5323 int_reg
= readl(ioa_cfg
->regs
.sense_interrupt_reg
);
5325 if (!ipr_is_gscsi(res
))
5328 for_each_hrrq(hrrq
, ioa_cfg
) {
5329 spin_lock(&hrrq
->_lock
);
5330 list_for_each_entry(ipr_cmd
, &hrrq
->hrrq_pending_q
, queue
) {
5331 if (ipr_cmd
->scsi_cmd
== scsi_cmd
) {
5332 ipr_cmd
->done
= ipr_scsi_eh_done
;
5337 spin_unlock(&hrrq
->_lock
);
5343 ipr_cmd
= ipr_get_free_ipr_cmnd(ioa_cfg
);
5344 ipr_cmd
->ioarcb
.res_handle
= res
->res_handle
;
5345 cmd_pkt
= &ipr_cmd
->ioarcb
.cmd_pkt
;
5346 cmd_pkt
->request_type
= IPR_RQTYPE_IOACMD
;
5347 cmd_pkt
->cdb
[0] = IPR_CANCEL_ALL_REQUESTS
;
5348 ipr_cmd
->u
.sdev
= scsi_cmd
->device
;
5350 scmd_printk(KERN_ERR
, scsi_cmd
, "Aborting command: %02X\n",
5352 ipr_send_blocking_cmd(ipr_cmd
, ipr_abort_timeout
, IPR_CANCEL_ALL_TIMEOUT
);
5353 ioasc
= be32_to_cpu(ipr_cmd
->s
.ioasa
.hdr
.ioasc
);
5356 * If the abort task timed out and we sent a bus reset, we will get
5357 * one the following responses to the abort
5359 if (ioasc
== IPR_IOASC_BUS_WAS_RESET
|| ioasc
== IPR_IOASC_SYNC_REQUIRED
) {
5364 list_add_tail(&ipr_cmd
->queue
, &ipr_cmd
->hrrq
->hrrq_free_q
);
5365 if (!ipr_is_naca_model(res
))
5366 res
->needs_sync_complete
= 1;
5369 return IPR_IOASC_SENSE_KEY(ioasc
) ? FAILED
: SUCCESS
;
5373 * ipr_eh_abort - Abort a single op
5374 * @scsi_cmd: scsi command struct
5377 * 0 if scan in progress / 1 if scan is complete
5379 static int ipr_scan_finished(struct Scsi_Host
*shost
, unsigned long elapsed_time
)
5381 unsigned long lock_flags
;
5382 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*) shost
->hostdata
;
5385 spin_lock_irqsave(shost
->host_lock
, lock_flags
);
5386 if (ioa_cfg
->hrrq
[IPR_INIT_HRRQ
].ioa_is_dead
|| ioa_cfg
->scan_done
)
5388 if ((elapsed_time
/HZ
) > (ioa_cfg
->transop_timeout
* 2))
5390 spin_unlock_irqrestore(shost
->host_lock
, lock_flags
);
5395 * ipr_eh_host_reset - Reset the host adapter
5396 * @scsi_cmd: scsi command struct
5401 static int ipr_eh_abort(struct scsi_cmnd
*scsi_cmd
)
5403 unsigned long flags
;
5405 struct ipr_ioa_cfg
*ioa_cfg
;
5409 ioa_cfg
= (struct ipr_ioa_cfg
*) scsi_cmd
->device
->host
->hostdata
;
5411 spin_lock_irqsave(scsi_cmd
->device
->host
->host_lock
, flags
);
5412 rc
= ipr_cancel_op(scsi_cmd
);
5413 spin_unlock_irqrestore(scsi_cmd
->device
->host
->host_lock
, flags
);
5416 rc
= ipr_wait_for_ops(ioa_cfg
, scsi_cmd
->device
, ipr_match_lun
);
5422 * ipr_handle_other_interrupt - Handle "other" interrupts
5423 * @ioa_cfg: ioa config struct
5424 * @int_reg: interrupt register
5427 * IRQ_NONE / IRQ_HANDLED
5429 static irqreturn_t
ipr_handle_other_interrupt(struct ipr_ioa_cfg
*ioa_cfg
,
5432 irqreturn_t rc
= IRQ_HANDLED
;
5435 int_mask_reg
= readl(ioa_cfg
->regs
.sense_interrupt_mask_reg32
);
5436 int_reg
&= ~int_mask_reg
;
5438 /* If an interrupt on the adapter did not occur, ignore it.
5439 * Or in the case of SIS 64, check for a stage change interrupt.
5441 if ((int_reg
& IPR_PCII_OPER_INTERRUPTS
) == 0) {
5442 if (ioa_cfg
->sis64
) {
5443 int_mask_reg
= readl(ioa_cfg
->regs
.sense_interrupt_mask_reg
);
5444 int_reg
= readl(ioa_cfg
->regs
.sense_interrupt_reg
) & ~int_mask_reg
;
5445 if (int_reg
& IPR_PCII_IPL_STAGE_CHANGE
) {
5447 /* clear stage change */
5448 writel(IPR_PCII_IPL_STAGE_CHANGE
, ioa_cfg
->regs
.clr_interrupt_reg
);
5449 int_reg
= readl(ioa_cfg
->regs
.sense_interrupt_reg
) & ~int_mask_reg
;
5450 list_del(&ioa_cfg
->reset_cmd
->queue
);
5451 del_timer(&ioa_cfg
->reset_cmd
->timer
);
5452 ipr_reset_ioa_job(ioa_cfg
->reset_cmd
);
5460 if (int_reg
& IPR_PCII_IOA_TRANS_TO_OPER
) {
5461 /* Mask the interrupt */
5462 writel(IPR_PCII_IOA_TRANS_TO_OPER
, ioa_cfg
->regs
.set_interrupt_mask_reg
);
5463 int_reg
= readl(ioa_cfg
->regs
.sense_interrupt_reg
);
5465 list_del(&ioa_cfg
->reset_cmd
->queue
);
5466 del_timer(&ioa_cfg
->reset_cmd
->timer
);
5467 ipr_reset_ioa_job(ioa_cfg
->reset_cmd
);
5468 } else if ((int_reg
& IPR_PCII_HRRQ_UPDATED
) == int_reg
) {
5469 if (ioa_cfg
->clear_isr
) {
5470 if (ipr_debug
&& printk_ratelimit())
5471 dev_err(&ioa_cfg
->pdev
->dev
,
5472 "Spurious interrupt detected. 0x%08X\n", int_reg
);
5473 writel(IPR_PCII_HRRQ_UPDATED
, ioa_cfg
->regs
.clr_interrupt_reg32
);
5474 int_reg
= readl(ioa_cfg
->regs
.sense_interrupt_reg32
);
5478 if (int_reg
& IPR_PCII_IOA_UNIT_CHECKED
)
5479 ioa_cfg
->ioa_unit_checked
= 1;
5480 else if (int_reg
& IPR_PCII_NO_HOST_RRQ
)
5481 dev_err(&ioa_cfg
->pdev
->dev
,
5482 "No Host RRQ. 0x%08X\n", int_reg
);
5484 dev_err(&ioa_cfg
->pdev
->dev
,
5485 "Permanent IOA failure. 0x%08X\n", int_reg
);
5487 if (WAIT_FOR_DUMP
== ioa_cfg
->sdt_state
)
5488 ioa_cfg
->sdt_state
= GET_DUMP
;
5490 ipr_mask_and_clear_interrupts(ioa_cfg
, ~0);
5491 ipr_initiate_ioa_reset(ioa_cfg
, IPR_SHUTDOWN_NONE
);
5498 * ipr_isr_eh - Interrupt service routine error handler
5499 * @ioa_cfg: ioa config struct
5500 * @msg: message to log
5505 static void ipr_isr_eh(struct ipr_ioa_cfg
*ioa_cfg
, char *msg
, u16 number
)
5507 ioa_cfg
->errors_logged
++;
5508 dev_err(&ioa_cfg
->pdev
->dev
, "%s %d\n", msg
, number
);
5510 if (WAIT_FOR_DUMP
== ioa_cfg
->sdt_state
)
5511 ioa_cfg
->sdt_state
= GET_DUMP
;
5513 ipr_initiate_ioa_reset(ioa_cfg
, IPR_SHUTDOWN_NONE
);
5516 static int ipr_process_hrrq(struct ipr_hrr_queue
*hrr_queue
, int budget
,
5517 struct list_head
*doneq
)
5521 struct ipr_cmnd
*ipr_cmd
;
5522 struct ipr_ioa_cfg
*ioa_cfg
= hrr_queue
->ioa_cfg
;
5525 /* If interrupts are disabled, ignore the interrupt */
5526 if (!hrr_queue
->allow_interrupts
)
5529 while ((be32_to_cpu(*hrr_queue
->hrrq_curr
) & IPR_HRRQ_TOGGLE_BIT
) ==
5530 hrr_queue
->toggle_bit
) {
5532 cmd_index
= (be32_to_cpu(*hrr_queue
->hrrq_curr
) &
5533 IPR_HRRQ_REQ_RESP_HANDLE_MASK
) >>
5534 IPR_HRRQ_REQ_RESP_HANDLE_SHIFT
;
5536 if (unlikely(cmd_index
> hrr_queue
->max_cmd_id
||
5537 cmd_index
< hrr_queue
->min_cmd_id
)) {
5539 "Invalid response handle from IOA: ",
5544 ipr_cmd
= ioa_cfg
->ipr_cmnd_list
[cmd_index
];
5545 ioasc
= be32_to_cpu(ipr_cmd
->s
.ioasa
.hdr
.ioasc
);
5547 ipr_trc_hook(ipr_cmd
, IPR_TRACE_FINISH
, ioasc
);
5549 list_move_tail(&ipr_cmd
->queue
, doneq
);
5551 if (hrr_queue
->hrrq_curr
< hrr_queue
->hrrq_end
) {
5552 hrr_queue
->hrrq_curr
++;
5554 hrr_queue
->hrrq_curr
= hrr_queue
->hrrq_start
;
5555 hrr_queue
->toggle_bit
^= 1u;
5558 if (budget
> 0 && num_hrrq
>= budget
)
5565 static int ipr_iopoll(struct blk_iopoll
*iop
, int budget
)
5567 struct ipr_ioa_cfg
*ioa_cfg
;
5568 struct ipr_hrr_queue
*hrrq
;
5569 struct ipr_cmnd
*ipr_cmd
, *temp
;
5570 unsigned long hrrq_flags
;
5574 hrrq
= container_of(iop
, struct ipr_hrr_queue
, iopoll
);
5575 ioa_cfg
= hrrq
->ioa_cfg
;
5577 spin_lock_irqsave(hrrq
->lock
, hrrq_flags
);
5578 completed_ops
= ipr_process_hrrq(hrrq
, budget
, &doneq
);
5580 if (completed_ops
< budget
)
5581 blk_iopoll_complete(iop
);
5582 spin_unlock_irqrestore(hrrq
->lock
, hrrq_flags
);
5584 list_for_each_entry_safe(ipr_cmd
, temp
, &doneq
, queue
) {
5585 list_del(&ipr_cmd
->queue
);
5586 del_timer(&ipr_cmd
->timer
);
5587 ipr_cmd
->fast_done(ipr_cmd
);
5590 return completed_ops
;
5594 * ipr_isr - Interrupt service routine
5596 * @devp: pointer to ioa config struct
5599 * IRQ_NONE / IRQ_HANDLED
5601 static irqreturn_t
ipr_isr(int irq
, void *devp
)
5603 struct ipr_hrr_queue
*hrrq
= (struct ipr_hrr_queue
*)devp
;
5604 struct ipr_ioa_cfg
*ioa_cfg
= hrrq
->ioa_cfg
;
5605 unsigned long hrrq_flags
= 0;
5609 struct ipr_cmnd
*ipr_cmd
, *temp
;
5610 irqreturn_t rc
= IRQ_NONE
;
5613 spin_lock_irqsave(hrrq
->lock
, hrrq_flags
);
5614 /* If interrupts are disabled, ignore the interrupt */
5615 if (!hrrq
->allow_interrupts
) {
5616 spin_unlock_irqrestore(hrrq
->lock
, hrrq_flags
);
5621 if (ipr_process_hrrq(hrrq
, -1, &doneq
)) {
5624 if (!ioa_cfg
->clear_isr
)
5627 /* Clear the PCI interrupt */
5630 writel(IPR_PCII_HRRQ_UPDATED
,
5631 ioa_cfg
->regs
.clr_interrupt_reg32
);
5632 int_reg
= readl(ioa_cfg
->regs
.sense_interrupt_reg32
);
5633 } while (int_reg
& IPR_PCII_HRRQ_UPDATED
&&
5634 num_hrrq
++ < IPR_MAX_HRRQ_RETRIES
);
5636 } else if (rc
== IRQ_NONE
&& irq_none
== 0) {
5637 int_reg
= readl(ioa_cfg
->regs
.sense_interrupt_reg32
);
5639 } else if (num_hrrq
== IPR_MAX_HRRQ_RETRIES
&&
5640 int_reg
& IPR_PCII_HRRQ_UPDATED
) {
5642 "Error clearing HRRQ: ", num_hrrq
);
5649 if (unlikely(rc
== IRQ_NONE
))
5650 rc
= ipr_handle_other_interrupt(ioa_cfg
, int_reg
);
5652 spin_unlock_irqrestore(hrrq
->lock
, hrrq_flags
);
5653 list_for_each_entry_safe(ipr_cmd
, temp
, &doneq
, queue
) {
5654 list_del(&ipr_cmd
->queue
);
5655 del_timer(&ipr_cmd
->timer
);
5656 ipr_cmd
->fast_done(ipr_cmd
);
5662 * ipr_isr_mhrrq - Interrupt service routine
5664 * @devp: pointer to ioa config struct
5667 * IRQ_NONE / IRQ_HANDLED
5669 static irqreturn_t
ipr_isr_mhrrq(int irq
, void *devp
)
5671 struct ipr_hrr_queue
*hrrq
= (struct ipr_hrr_queue
*)devp
;
5672 struct ipr_ioa_cfg
*ioa_cfg
= hrrq
->ioa_cfg
;
5673 unsigned long hrrq_flags
= 0;
5674 struct ipr_cmnd
*ipr_cmd
, *temp
;
5675 irqreturn_t rc
= IRQ_NONE
;
5678 spin_lock_irqsave(hrrq
->lock
, hrrq_flags
);
5680 /* If interrupts are disabled, ignore the interrupt */
5681 if (!hrrq
->allow_interrupts
) {
5682 spin_unlock_irqrestore(hrrq
->lock
, hrrq_flags
);
5686 if (ioa_cfg
->iopoll_weight
&& ioa_cfg
->sis64
&& ioa_cfg
->nvectors
> 1) {
5687 if ((be32_to_cpu(*hrrq
->hrrq_curr
) & IPR_HRRQ_TOGGLE_BIT
) ==
5689 if (!blk_iopoll_sched_prep(&hrrq
->iopoll
))
5690 blk_iopoll_sched(&hrrq
->iopoll
);
5691 spin_unlock_irqrestore(hrrq
->lock
, hrrq_flags
);
5695 if ((be32_to_cpu(*hrrq
->hrrq_curr
) & IPR_HRRQ_TOGGLE_BIT
) ==
5698 if (ipr_process_hrrq(hrrq
, -1, &doneq
))
5702 spin_unlock_irqrestore(hrrq
->lock
, hrrq_flags
);
5704 list_for_each_entry_safe(ipr_cmd
, temp
, &doneq
, queue
) {
5705 list_del(&ipr_cmd
->queue
);
5706 del_timer(&ipr_cmd
->timer
);
5707 ipr_cmd
->fast_done(ipr_cmd
);
5713 * ipr_build_ioadl64 - Build a scatter/gather list and map the buffer
5714 * @ioa_cfg: ioa config struct
5715 * @ipr_cmd: ipr command struct
5718 * 0 on success / -1 on failure
5720 static int ipr_build_ioadl64(struct ipr_ioa_cfg
*ioa_cfg
,
5721 struct ipr_cmnd
*ipr_cmd
)
5724 struct scatterlist
*sg
;
5726 u32 ioadl_flags
= 0;
5727 struct scsi_cmnd
*scsi_cmd
= ipr_cmd
->scsi_cmd
;
5728 struct ipr_ioarcb
*ioarcb
= &ipr_cmd
->ioarcb
;
5729 struct ipr_ioadl64_desc
*ioadl64
= ipr_cmd
->i
.ioadl64
;
5731 length
= scsi_bufflen(scsi_cmd
);
5735 nseg
= scsi_dma_map(scsi_cmd
);
5737 if (printk_ratelimit())
5738 dev_err(&ioa_cfg
->pdev
->dev
, "scsi_dma_map failed!\n");
5742 ipr_cmd
->dma_use_sg
= nseg
;
5744 ioarcb
->data_transfer_length
= cpu_to_be32(length
);
5746 cpu_to_be32(sizeof(struct ipr_ioadl64_desc
) * ipr_cmd
->dma_use_sg
);
5748 if (scsi_cmd
->sc_data_direction
== DMA_TO_DEVICE
) {
5749 ioadl_flags
= IPR_IOADL_FLAGS_WRITE
;
5750 ioarcb
->cmd_pkt
.flags_hi
|= IPR_FLAGS_HI_WRITE_NOT_READ
;
5751 } else if (scsi_cmd
->sc_data_direction
== DMA_FROM_DEVICE
)
5752 ioadl_flags
= IPR_IOADL_FLAGS_READ
;
5754 scsi_for_each_sg(scsi_cmd
, sg
, ipr_cmd
->dma_use_sg
, i
) {
5755 ioadl64
[i
].flags
= cpu_to_be32(ioadl_flags
);
5756 ioadl64
[i
].data_len
= cpu_to_be32(sg_dma_len(sg
));
5757 ioadl64
[i
].address
= cpu_to_be64(sg_dma_address(sg
));
5760 ioadl64
[i
-1].flags
|= cpu_to_be32(IPR_IOADL_FLAGS_LAST
);
5765 * ipr_build_ioadl - Build a scatter/gather list and map the buffer
5766 * @ioa_cfg: ioa config struct
5767 * @ipr_cmd: ipr command struct
5770 * 0 on success / -1 on failure
5772 static int ipr_build_ioadl(struct ipr_ioa_cfg
*ioa_cfg
,
5773 struct ipr_cmnd
*ipr_cmd
)
5776 struct scatterlist
*sg
;
5778 u32 ioadl_flags
= 0;
5779 struct scsi_cmnd
*scsi_cmd
= ipr_cmd
->scsi_cmd
;
5780 struct ipr_ioarcb
*ioarcb
= &ipr_cmd
->ioarcb
;
5781 struct ipr_ioadl_desc
*ioadl
= ipr_cmd
->i
.ioadl
;
5783 length
= scsi_bufflen(scsi_cmd
);
5787 nseg
= scsi_dma_map(scsi_cmd
);
5789 dev_err(&ioa_cfg
->pdev
->dev
, "scsi_dma_map failed!\n");
5793 ipr_cmd
->dma_use_sg
= nseg
;
5795 if (scsi_cmd
->sc_data_direction
== DMA_TO_DEVICE
) {
5796 ioadl_flags
= IPR_IOADL_FLAGS_WRITE
;
5797 ioarcb
->cmd_pkt
.flags_hi
|= IPR_FLAGS_HI_WRITE_NOT_READ
;
5798 ioarcb
->data_transfer_length
= cpu_to_be32(length
);
5800 cpu_to_be32(sizeof(struct ipr_ioadl_desc
) * ipr_cmd
->dma_use_sg
);
5801 } else if (scsi_cmd
->sc_data_direction
== DMA_FROM_DEVICE
) {
5802 ioadl_flags
= IPR_IOADL_FLAGS_READ
;
5803 ioarcb
->read_data_transfer_length
= cpu_to_be32(length
);
5804 ioarcb
->read_ioadl_len
=
5805 cpu_to_be32(sizeof(struct ipr_ioadl_desc
) * ipr_cmd
->dma_use_sg
);
5808 if (ipr_cmd
->dma_use_sg
<= ARRAY_SIZE(ioarcb
->u
.add_data
.u
.ioadl
)) {
5809 ioadl
= ioarcb
->u
.add_data
.u
.ioadl
;
5810 ioarcb
->write_ioadl_addr
= cpu_to_be32((ipr_cmd
->dma_addr
) +
5811 offsetof(struct ipr_ioarcb
, u
.add_data
));
5812 ioarcb
->read_ioadl_addr
= ioarcb
->write_ioadl_addr
;
5815 scsi_for_each_sg(scsi_cmd
, sg
, ipr_cmd
->dma_use_sg
, i
) {
5816 ioadl
[i
].flags_and_data_len
=
5817 cpu_to_be32(ioadl_flags
| sg_dma_len(sg
));
5818 ioadl
[i
].address
= cpu_to_be32(sg_dma_address(sg
));
5821 ioadl
[i
-1].flags_and_data_len
|= cpu_to_be32(IPR_IOADL_FLAGS_LAST
);
5826 * ipr_erp_done - Process completion of ERP for a device
5827 * @ipr_cmd: ipr command struct
5829 * This function copies the sense buffer into the scsi_cmd
5830 * struct and pushes the scsi_done function.
5835 static void ipr_erp_done(struct ipr_cmnd
*ipr_cmd
)
5837 struct scsi_cmnd
*scsi_cmd
= ipr_cmd
->scsi_cmd
;
5838 struct ipr_resource_entry
*res
= scsi_cmd
->device
->hostdata
;
5839 u32 ioasc
= be32_to_cpu(ipr_cmd
->s
.ioasa
.hdr
.ioasc
);
5841 if (IPR_IOASC_SENSE_KEY(ioasc
) > 0) {
5842 scsi_cmd
->result
|= (DID_ERROR
<< 16);
5843 scmd_printk(KERN_ERR
, scsi_cmd
,
5844 "Request Sense failed with IOASC: 0x%08X\n", ioasc
);
5846 memcpy(scsi_cmd
->sense_buffer
, ipr_cmd
->sense_buffer
,
5847 SCSI_SENSE_BUFFERSIZE
);
5851 if (!ipr_is_naca_model(res
))
5852 res
->needs_sync_complete
= 1;
5855 scsi_dma_unmap(ipr_cmd
->scsi_cmd
);
5856 list_add_tail(&ipr_cmd
->queue
, &ipr_cmd
->hrrq
->hrrq_free_q
);
5857 scsi_cmd
->scsi_done(scsi_cmd
);
5861 * ipr_reinit_ipr_cmnd_for_erp - Re-initialize a cmnd block to be used for ERP
5862 * @ipr_cmd: ipr command struct
5867 static void ipr_reinit_ipr_cmnd_for_erp(struct ipr_cmnd
*ipr_cmd
)
5869 struct ipr_ioarcb
*ioarcb
= &ipr_cmd
->ioarcb
;
5870 struct ipr_ioasa
*ioasa
= &ipr_cmd
->s
.ioasa
;
5871 dma_addr_t dma_addr
= ipr_cmd
->dma_addr
;
5873 memset(&ioarcb
->cmd_pkt
, 0, sizeof(struct ipr_cmd_pkt
));
5874 ioarcb
->data_transfer_length
= 0;
5875 ioarcb
->read_data_transfer_length
= 0;
5876 ioarcb
->ioadl_len
= 0;
5877 ioarcb
->read_ioadl_len
= 0;
5878 ioasa
->hdr
.ioasc
= 0;
5879 ioasa
->hdr
.residual_data_len
= 0;
5881 if (ipr_cmd
->ioa_cfg
->sis64
)
5882 ioarcb
->u
.sis64_addr_data
.data_ioadl_addr
=
5883 cpu_to_be64(dma_addr
+ offsetof(struct ipr_cmnd
, i
.ioadl64
));
5885 ioarcb
->write_ioadl_addr
=
5886 cpu_to_be32(dma_addr
+ offsetof(struct ipr_cmnd
, i
.ioadl
));
5887 ioarcb
->read_ioadl_addr
= ioarcb
->write_ioadl_addr
;
5892 * ipr_erp_request_sense - Send request sense to a device
5893 * @ipr_cmd: ipr command struct
5895 * This function sends a request sense to a device as a result
5896 * of a check condition.
5901 static void ipr_erp_request_sense(struct ipr_cmnd
*ipr_cmd
)
5903 struct ipr_cmd_pkt
*cmd_pkt
= &ipr_cmd
->ioarcb
.cmd_pkt
;
5904 u32 ioasc
= be32_to_cpu(ipr_cmd
->s
.ioasa
.hdr
.ioasc
);
5906 if (IPR_IOASC_SENSE_KEY(ioasc
) > 0) {
5907 ipr_erp_done(ipr_cmd
);
5911 ipr_reinit_ipr_cmnd_for_erp(ipr_cmd
);
5913 cmd_pkt
->request_type
= IPR_RQTYPE_SCSICDB
;
5914 cmd_pkt
->cdb
[0] = REQUEST_SENSE
;
5915 cmd_pkt
->cdb
[4] = SCSI_SENSE_BUFFERSIZE
;
5916 cmd_pkt
->flags_hi
|= IPR_FLAGS_HI_SYNC_OVERRIDE
;
5917 cmd_pkt
->flags_hi
|= IPR_FLAGS_HI_NO_ULEN_CHK
;
5918 cmd_pkt
->timeout
= cpu_to_be16(IPR_REQUEST_SENSE_TIMEOUT
/ HZ
);
5920 ipr_init_ioadl(ipr_cmd
, ipr_cmd
->sense_buffer_dma
,
5921 SCSI_SENSE_BUFFERSIZE
, IPR_IOADL_FLAGS_READ_LAST
);
5923 ipr_do_req(ipr_cmd
, ipr_erp_done
, ipr_timeout
,
5924 IPR_REQUEST_SENSE_TIMEOUT
* 2);
5928 * ipr_erp_cancel_all - Send cancel all to a device
5929 * @ipr_cmd: ipr command struct
5931 * This function sends a cancel all to a device to clear the
5932 * queue. If we are running TCQ on the device, QERR is set to 1,
5933 * which means all outstanding ops have been dropped on the floor.
5934 * Cancel all will return them to us.
5939 static void ipr_erp_cancel_all(struct ipr_cmnd
*ipr_cmd
)
5941 struct scsi_cmnd
*scsi_cmd
= ipr_cmd
->scsi_cmd
;
5942 struct ipr_resource_entry
*res
= scsi_cmd
->device
->hostdata
;
5943 struct ipr_cmd_pkt
*cmd_pkt
;
5947 ipr_reinit_ipr_cmnd_for_erp(ipr_cmd
);
5949 if (!scsi_cmd
->device
->simple_tags
) {
5950 ipr_erp_request_sense(ipr_cmd
);
5954 cmd_pkt
= &ipr_cmd
->ioarcb
.cmd_pkt
;
5955 cmd_pkt
->request_type
= IPR_RQTYPE_IOACMD
;
5956 cmd_pkt
->cdb
[0] = IPR_CANCEL_ALL_REQUESTS
;
5958 ipr_do_req(ipr_cmd
, ipr_erp_request_sense
, ipr_timeout
,
5959 IPR_CANCEL_ALL_TIMEOUT
);
5963 * ipr_dump_ioasa - Dump contents of IOASA
5964 * @ioa_cfg: ioa config struct
5965 * @ipr_cmd: ipr command struct
5966 * @res: resource entry struct
5968 * This function is invoked by the interrupt handler when ops
5969 * fail. It will log the IOASA if appropriate. Only called
5975 static void ipr_dump_ioasa(struct ipr_ioa_cfg
*ioa_cfg
,
5976 struct ipr_cmnd
*ipr_cmd
, struct ipr_resource_entry
*res
)
5980 u32 ioasc
, fd_ioasc
;
5981 struct ipr_ioasa
*ioasa
= &ipr_cmd
->s
.ioasa
;
5982 __be32
*ioasa_data
= (__be32
*)ioasa
;
5985 ioasc
= be32_to_cpu(ioasa
->hdr
.ioasc
) & IPR_IOASC_IOASC_MASK
;
5986 fd_ioasc
= be32_to_cpu(ioasa
->hdr
.fd_ioasc
) & IPR_IOASC_IOASC_MASK
;
5991 if (ioa_cfg
->log_level
< IPR_DEFAULT_LOG_LEVEL
)
5994 if (ioasc
== IPR_IOASC_BUS_WAS_RESET
&& fd_ioasc
)
5995 error_index
= ipr_get_error(fd_ioasc
);
5997 error_index
= ipr_get_error(ioasc
);
5999 if (ioa_cfg
->log_level
< IPR_MAX_LOG_LEVEL
) {
6000 /* Don't log an error if the IOA already logged one */
6001 if (ioasa
->hdr
.ilid
!= 0)
6004 if (!ipr_is_gscsi(res
))
6007 if (ipr_error_table
[error_index
].log_ioasa
== 0)
6011 ipr_res_err(ioa_cfg
, res
, "%s\n", ipr_error_table
[error_index
].error
);
6013 data_len
= be16_to_cpu(ioasa
->hdr
.ret_stat_len
);
6014 if (ioa_cfg
->sis64
&& sizeof(struct ipr_ioasa64
) < data_len
)
6015 data_len
= sizeof(struct ipr_ioasa64
);
6016 else if (!ioa_cfg
->sis64
&& sizeof(struct ipr_ioasa
) < data_len
)
6017 data_len
= sizeof(struct ipr_ioasa
);
6019 ipr_err("IOASA Dump:\n");
6021 for (i
= 0; i
< data_len
/ 4; i
+= 4) {
6022 ipr_err("%08X: %08X %08X %08X %08X\n", i
*4,
6023 be32_to_cpu(ioasa_data
[i
]),
6024 be32_to_cpu(ioasa_data
[i
+1]),
6025 be32_to_cpu(ioasa_data
[i
+2]),
6026 be32_to_cpu(ioasa_data
[i
+3]));
6031 * ipr_gen_sense - Generate SCSI sense data from an IOASA
6033 * @sense_buf: sense data buffer
6038 static void ipr_gen_sense(struct ipr_cmnd
*ipr_cmd
)
6041 u8
*sense_buf
= ipr_cmd
->scsi_cmd
->sense_buffer
;
6042 struct ipr_resource_entry
*res
= ipr_cmd
->scsi_cmd
->device
->hostdata
;
6043 struct ipr_ioasa
*ioasa
= &ipr_cmd
->s
.ioasa
;
6044 u32 ioasc
= be32_to_cpu(ioasa
->hdr
.ioasc
);
6046 memset(sense_buf
, 0, SCSI_SENSE_BUFFERSIZE
);
6048 if (ioasc
>= IPR_FIRST_DRIVER_IOASC
)
6051 ipr_cmd
->scsi_cmd
->result
= SAM_STAT_CHECK_CONDITION
;
6053 if (ipr_is_vset_device(res
) &&
6054 ioasc
== IPR_IOASC_MED_DO_NOT_REALLOC
&&
6055 ioasa
->u
.vset
.failing_lba_hi
!= 0) {
6056 sense_buf
[0] = 0x72;
6057 sense_buf
[1] = IPR_IOASC_SENSE_KEY(ioasc
);
6058 sense_buf
[2] = IPR_IOASC_SENSE_CODE(ioasc
);
6059 sense_buf
[3] = IPR_IOASC_SENSE_QUAL(ioasc
);
6063 sense_buf
[9] = 0x0A;
6064 sense_buf
[10] = 0x80;
6066 failing_lba
= be32_to_cpu(ioasa
->u
.vset
.failing_lba_hi
);
6068 sense_buf
[12] = (failing_lba
& 0xff000000) >> 24;
6069 sense_buf
[13] = (failing_lba
& 0x00ff0000) >> 16;
6070 sense_buf
[14] = (failing_lba
& 0x0000ff00) >> 8;
6071 sense_buf
[15] = failing_lba
& 0x000000ff;
6073 failing_lba
= be32_to_cpu(ioasa
->u
.vset
.failing_lba_lo
);
6075 sense_buf
[16] = (failing_lba
& 0xff000000) >> 24;
6076 sense_buf
[17] = (failing_lba
& 0x00ff0000) >> 16;
6077 sense_buf
[18] = (failing_lba
& 0x0000ff00) >> 8;
6078 sense_buf
[19] = failing_lba
& 0x000000ff;
6080 sense_buf
[0] = 0x70;
6081 sense_buf
[2] = IPR_IOASC_SENSE_KEY(ioasc
);
6082 sense_buf
[12] = IPR_IOASC_SENSE_CODE(ioasc
);
6083 sense_buf
[13] = IPR_IOASC_SENSE_QUAL(ioasc
);
6085 /* Illegal request */
6086 if ((IPR_IOASC_SENSE_KEY(ioasc
) == 0x05) &&
6087 (be32_to_cpu(ioasa
->hdr
.ioasc_specific
) & IPR_FIELD_POINTER_VALID
)) {
6088 sense_buf
[7] = 10; /* additional length */
6090 /* IOARCB was in error */
6091 if (IPR_IOASC_SENSE_CODE(ioasc
) == 0x24)
6092 sense_buf
[15] = 0xC0;
6093 else /* Parameter data was invalid */
6094 sense_buf
[15] = 0x80;
6097 ((IPR_FIELD_POINTER_MASK
&
6098 be32_to_cpu(ioasa
->hdr
.ioasc_specific
)) >> 8) & 0xff;
6100 (IPR_FIELD_POINTER_MASK
&
6101 be32_to_cpu(ioasa
->hdr
.ioasc_specific
)) & 0xff;
6103 if (ioasc
== IPR_IOASC_MED_DO_NOT_REALLOC
) {
6104 if (ipr_is_vset_device(res
))
6105 failing_lba
= be32_to_cpu(ioasa
->u
.vset
.failing_lba_lo
);
6107 failing_lba
= be32_to_cpu(ioasa
->u
.dasd
.failing_lba
);
6109 sense_buf
[0] |= 0x80; /* Or in the Valid bit */
6110 sense_buf
[3] = (failing_lba
& 0xff000000) >> 24;
6111 sense_buf
[4] = (failing_lba
& 0x00ff0000) >> 16;
6112 sense_buf
[5] = (failing_lba
& 0x0000ff00) >> 8;
6113 sense_buf
[6] = failing_lba
& 0x000000ff;
6116 sense_buf
[7] = 6; /* additional length */
6122 * ipr_get_autosense - Copy autosense data to sense buffer
6123 * @ipr_cmd: ipr command struct
6125 * This function copies the autosense buffer to the buffer
6126 * in the scsi_cmd, if there is autosense available.
6129 * 1 if autosense was available / 0 if not
6131 static int ipr_get_autosense(struct ipr_cmnd
*ipr_cmd
)
6133 struct ipr_ioasa
*ioasa
= &ipr_cmd
->s
.ioasa
;
6134 struct ipr_ioasa64
*ioasa64
= &ipr_cmd
->s
.ioasa64
;
6136 if ((be32_to_cpu(ioasa
->hdr
.ioasc_specific
) & IPR_AUTOSENSE_VALID
) == 0)
6139 if (ipr_cmd
->ioa_cfg
->sis64
)
6140 memcpy(ipr_cmd
->scsi_cmd
->sense_buffer
, ioasa64
->auto_sense
.data
,
6141 min_t(u16
, be16_to_cpu(ioasa64
->auto_sense
.auto_sense_len
),
6142 SCSI_SENSE_BUFFERSIZE
));
6144 memcpy(ipr_cmd
->scsi_cmd
->sense_buffer
, ioasa
->auto_sense
.data
,
6145 min_t(u16
, be16_to_cpu(ioasa
->auto_sense
.auto_sense_len
),
6146 SCSI_SENSE_BUFFERSIZE
));
6151 * ipr_erp_start - Process an error response for a SCSI op
6152 * @ioa_cfg: ioa config struct
6153 * @ipr_cmd: ipr command struct
6155 * This function determines whether or not to initiate ERP
6156 * on the affected device.
6161 static void ipr_erp_start(struct ipr_ioa_cfg
*ioa_cfg
,
6162 struct ipr_cmnd
*ipr_cmd
)
6164 struct scsi_cmnd
*scsi_cmd
= ipr_cmd
->scsi_cmd
;
6165 struct ipr_resource_entry
*res
= scsi_cmd
->device
->hostdata
;
6166 u32 ioasc
= be32_to_cpu(ipr_cmd
->s
.ioasa
.hdr
.ioasc
);
6167 u32 masked_ioasc
= ioasc
& IPR_IOASC_IOASC_MASK
;
6170 ipr_scsi_eh_done(ipr_cmd
);
6174 if (!ipr_is_gscsi(res
) && masked_ioasc
!= IPR_IOASC_HW_DEV_BUS_STATUS
)
6175 ipr_gen_sense(ipr_cmd
);
6177 ipr_dump_ioasa(ioa_cfg
, ipr_cmd
, res
);
6179 switch (masked_ioasc
) {
6180 case IPR_IOASC_ABORTED_CMD_TERM_BY_HOST
:
6181 if (ipr_is_naca_model(res
))
6182 scsi_cmd
->result
|= (DID_ABORT
<< 16);
6184 scsi_cmd
->result
|= (DID_IMM_RETRY
<< 16);
6186 case IPR_IOASC_IR_RESOURCE_HANDLE
:
6187 case IPR_IOASC_IR_NO_CMDS_TO_2ND_IOA
:
6188 scsi_cmd
->result
|= (DID_NO_CONNECT
<< 16);
6190 case IPR_IOASC_HW_SEL_TIMEOUT
:
6191 scsi_cmd
->result
|= (DID_NO_CONNECT
<< 16);
6192 if (!ipr_is_naca_model(res
))
6193 res
->needs_sync_complete
= 1;
6195 case IPR_IOASC_SYNC_REQUIRED
:
6197 res
->needs_sync_complete
= 1;
6198 scsi_cmd
->result
|= (DID_IMM_RETRY
<< 16);
6200 case IPR_IOASC_MED_DO_NOT_REALLOC
: /* prevent retries */
6201 case IPR_IOASA_IR_DUAL_IOA_DISABLED
:
6202 scsi_cmd
->result
|= (DID_PASSTHROUGH
<< 16);
6204 case IPR_IOASC_BUS_WAS_RESET
:
6205 case IPR_IOASC_BUS_WAS_RESET_BY_OTHER
:
6207 * Report the bus reset and ask for a retry. The device
6208 * will give CC/UA the next command.
6210 if (!res
->resetting_device
)
6211 scsi_report_bus_reset(ioa_cfg
->host
, scsi_cmd
->device
->channel
);
6212 scsi_cmd
->result
|= (DID_ERROR
<< 16);
6213 if (!ipr_is_naca_model(res
))
6214 res
->needs_sync_complete
= 1;
6216 case IPR_IOASC_HW_DEV_BUS_STATUS
:
6217 scsi_cmd
->result
|= IPR_IOASC_SENSE_STATUS(ioasc
);
6218 if (IPR_IOASC_SENSE_STATUS(ioasc
) == SAM_STAT_CHECK_CONDITION
) {
6219 if (!ipr_get_autosense(ipr_cmd
)) {
6220 if (!ipr_is_naca_model(res
)) {
6221 ipr_erp_cancel_all(ipr_cmd
);
6226 if (!ipr_is_naca_model(res
))
6227 res
->needs_sync_complete
= 1;
6229 case IPR_IOASC_NR_INIT_CMD_REQUIRED
:
6231 case IPR_IOASC_IR_NON_OPTIMIZED
:
6232 if (res
->raw_mode
) {
6234 scsi_cmd
->result
|= (DID_IMM_RETRY
<< 16);
6236 scsi_cmd
->result
|= (DID_ERROR
<< 16);
6239 if (IPR_IOASC_SENSE_KEY(ioasc
) > RECOVERED_ERROR
)
6240 scsi_cmd
->result
|= (DID_ERROR
<< 16);
6241 if (!ipr_is_vset_device(res
) && !ipr_is_naca_model(res
))
6242 res
->needs_sync_complete
= 1;
6246 scsi_dma_unmap(ipr_cmd
->scsi_cmd
);
6247 list_add_tail(&ipr_cmd
->queue
, &ipr_cmd
->hrrq
->hrrq_free_q
);
6248 scsi_cmd
->scsi_done(scsi_cmd
);
6252 * ipr_scsi_done - mid-layer done function
6253 * @ipr_cmd: ipr command struct
6255 * This function is invoked by the interrupt handler for
6256 * ops generated by the SCSI mid-layer
6261 static void ipr_scsi_done(struct ipr_cmnd
*ipr_cmd
)
6263 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
6264 struct scsi_cmnd
*scsi_cmd
= ipr_cmd
->scsi_cmd
;
6265 u32 ioasc
= be32_to_cpu(ipr_cmd
->s
.ioasa
.hdr
.ioasc
);
6266 unsigned long hrrq_flags
;
6268 scsi_set_resid(scsi_cmd
, be32_to_cpu(ipr_cmd
->s
.ioasa
.hdr
.residual_data_len
));
6270 if (likely(IPR_IOASC_SENSE_KEY(ioasc
) == 0)) {
6271 scsi_dma_unmap(scsi_cmd
);
6273 spin_lock_irqsave(ipr_cmd
->hrrq
->lock
, hrrq_flags
);
6274 list_add_tail(&ipr_cmd
->queue
, &ipr_cmd
->hrrq
->hrrq_free_q
);
6275 scsi_cmd
->scsi_done(scsi_cmd
);
6276 spin_unlock_irqrestore(ipr_cmd
->hrrq
->lock
, hrrq_flags
);
6278 spin_lock_irqsave(ipr_cmd
->hrrq
->lock
, hrrq_flags
);
6279 ipr_erp_start(ioa_cfg
, ipr_cmd
);
6280 spin_unlock_irqrestore(ipr_cmd
->hrrq
->lock
, hrrq_flags
);
6285 * ipr_queuecommand - Queue a mid-layer request
6286 * @shost: scsi host struct
6287 * @scsi_cmd: scsi command struct
6289 * This function queues a request generated by the mid-layer.
6293 * SCSI_MLQUEUE_DEVICE_BUSY if device is busy
6294 * SCSI_MLQUEUE_HOST_BUSY if host is busy
6296 static int ipr_queuecommand(struct Scsi_Host
*shost
,
6297 struct scsi_cmnd
*scsi_cmd
)
6299 struct ipr_ioa_cfg
*ioa_cfg
;
6300 struct ipr_resource_entry
*res
;
6301 struct ipr_ioarcb
*ioarcb
;
6302 struct ipr_cmnd
*ipr_cmd
;
6303 unsigned long hrrq_flags
, lock_flags
;
6305 struct ipr_hrr_queue
*hrrq
;
6308 ioa_cfg
= (struct ipr_ioa_cfg
*)shost
->hostdata
;
6310 scsi_cmd
->result
= (DID_OK
<< 16);
6311 res
= scsi_cmd
->device
->hostdata
;
6313 if (ipr_is_gata(res
) && res
->sata_port
) {
6314 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
6315 rc
= ata_sas_queuecmd(scsi_cmd
, res
->sata_port
->ap
);
6316 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
6320 hrrq_id
= ipr_get_hrrq_index(ioa_cfg
);
6321 hrrq
= &ioa_cfg
->hrrq
[hrrq_id
];
6323 spin_lock_irqsave(hrrq
->lock
, hrrq_flags
);
6325 * We are currently blocking all devices due to a host reset
6326 * We have told the host to stop giving us new requests, but
6327 * ERP ops don't count. FIXME
6329 if (unlikely(!hrrq
->allow_cmds
&& !hrrq
->ioa_is_dead
&& !hrrq
->removing_ioa
)) {
6330 spin_unlock_irqrestore(hrrq
->lock
, hrrq_flags
);
6331 return SCSI_MLQUEUE_HOST_BUSY
;
6335 * FIXME - Create scsi_set_host_offline interface
6336 * and the ioa_is_dead check can be removed
6338 if (unlikely(hrrq
->ioa_is_dead
|| hrrq
->removing_ioa
|| !res
)) {
6339 spin_unlock_irqrestore(hrrq
->lock
, hrrq_flags
);
6343 ipr_cmd
= __ipr_get_free_ipr_cmnd(hrrq
);
6344 if (ipr_cmd
== NULL
) {
6345 spin_unlock_irqrestore(hrrq
->lock
, hrrq_flags
);
6346 return SCSI_MLQUEUE_HOST_BUSY
;
6348 spin_unlock_irqrestore(hrrq
->lock
, hrrq_flags
);
6350 ipr_init_ipr_cmnd(ipr_cmd
, ipr_scsi_done
);
6351 ioarcb
= &ipr_cmd
->ioarcb
;
6353 memcpy(ioarcb
->cmd_pkt
.cdb
, scsi_cmd
->cmnd
, scsi_cmd
->cmd_len
);
6354 ipr_cmd
->scsi_cmd
= scsi_cmd
;
6355 ipr_cmd
->done
= ipr_scsi_eh_done
;
6357 if (ipr_is_gscsi(res
) || ipr_is_vset_device(res
)) {
6358 if (scsi_cmd
->underflow
== 0)
6359 ioarcb
->cmd_pkt
.flags_hi
|= IPR_FLAGS_HI_NO_ULEN_CHK
;
6361 ioarcb
->cmd_pkt
.flags_hi
|= IPR_FLAGS_HI_NO_LINK_DESC
;
6362 if (ipr_is_gscsi(res
) && res
->reset_occurred
) {
6363 res
->reset_occurred
= 0;
6364 ioarcb
->cmd_pkt
.flags_lo
|= IPR_FLAGS_LO_DELAY_AFTER_RST
;
6366 ioarcb
->cmd_pkt
.flags_lo
|= IPR_FLAGS_LO_ALIGNED_BFR
;
6367 if (scsi_cmd
->flags
& SCMD_TAGGED
)
6368 ioarcb
->cmd_pkt
.flags_lo
|= IPR_FLAGS_LO_SIMPLE_TASK
;
6370 ioarcb
->cmd_pkt
.flags_lo
|= IPR_FLAGS_LO_UNTAGGED_TASK
;
6373 if (scsi_cmd
->cmnd
[0] >= 0xC0 &&
6374 (!ipr_is_gscsi(res
) || scsi_cmd
->cmnd
[0] == IPR_QUERY_RSRC_STATE
)) {
6375 ioarcb
->cmd_pkt
.request_type
= IPR_RQTYPE_IOACMD
;
6377 if (res
->raw_mode
&& ipr_is_af_dasd_device(res
))
6378 ioarcb
->cmd_pkt
.request_type
= IPR_RQTYPE_PIPE
;
6381 rc
= ipr_build_ioadl64(ioa_cfg
, ipr_cmd
);
6383 rc
= ipr_build_ioadl(ioa_cfg
, ipr_cmd
);
6385 spin_lock_irqsave(hrrq
->lock
, hrrq_flags
);
6386 if (unlikely(rc
|| (!hrrq
->allow_cmds
&& !hrrq
->ioa_is_dead
))) {
6387 list_add_tail(&ipr_cmd
->queue
, &hrrq
->hrrq_free_q
);
6388 spin_unlock_irqrestore(hrrq
->lock
, hrrq_flags
);
6390 scsi_dma_unmap(scsi_cmd
);
6391 return SCSI_MLQUEUE_HOST_BUSY
;
6394 if (unlikely(hrrq
->ioa_is_dead
)) {
6395 list_add_tail(&ipr_cmd
->queue
, &hrrq
->hrrq_free_q
);
6396 spin_unlock_irqrestore(hrrq
->lock
, hrrq_flags
);
6397 scsi_dma_unmap(scsi_cmd
);
6401 ioarcb
->res_handle
= res
->res_handle
;
6402 if (res
->needs_sync_complete
) {
6403 ioarcb
->cmd_pkt
.flags_hi
|= IPR_FLAGS_HI_SYNC_COMPLETE
;
6404 res
->needs_sync_complete
= 0;
6406 list_add_tail(&ipr_cmd
->queue
, &hrrq
->hrrq_pending_q
);
6407 ipr_trc_hook(ipr_cmd
, IPR_TRACE_START
, IPR_GET_RES_PHYS_LOC(res
));
6408 ipr_send_command(ipr_cmd
);
6409 spin_unlock_irqrestore(hrrq
->lock
, hrrq_flags
);
6413 spin_lock_irqsave(hrrq
->lock
, hrrq_flags
);
6414 memset(scsi_cmd
->sense_buffer
, 0, SCSI_SENSE_BUFFERSIZE
);
6415 scsi_cmd
->result
= (DID_NO_CONNECT
<< 16);
6416 scsi_cmd
->scsi_done(scsi_cmd
);
6417 spin_unlock_irqrestore(hrrq
->lock
, hrrq_flags
);
6422 * ipr_ioctl - IOCTL handler
6423 * @sdev: scsi device struct
6428 * 0 on success / other on failure
6430 static int ipr_ioctl(struct scsi_device
*sdev
, int cmd
, void __user
*arg
)
6432 struct ipr_resource_entry
*res
;
6434 res
= (struct ipr_resource_entry
*)sdev
->hostdata
;
6435 if (res
&& ipr_is_gata(res
)) {
6436 if (cmd
== HDIO_GET_IDENTITY
)
6438 return ata_sas_scsi_ioctl(res
->sata_port
->ap
, sdev
, cmd
, arg
);
6445 * ipr_info - Get information about the card/driver
6446 * @scsi_host: scsi host struct
6449 * pointer to buffer with description string
6451 static const char *ipr_ioa_info(struct Scsi_Host
*host
)
6453 static char buffer
[512];
6454 struct ipr_ioa_cfg
*ioa_cfg
;
6455 unsigned long lock_flags
= 0;
6457 ioa_cfg
= (struct ipr_ioa_cfg
*) host
->hostdata
;
6459 spin_lock_irqsave(host
->host_lock
, lock_flags
);
6460 sprintf(buffer
, "IBM %X Storage Adapter", ioa_cfg
->type
);
6461 spin_unlock_irqrestore(host
->host_lock
, lock_flags
);
6466 static struct scsi_host_template driver_template
= {
6467 .module
= THIS_MODULE
,
6469 .info
= ipr_ioa_info
,
6471 .queuecommand
= ipr_queuecommand
,
6472 .eh_abort_handler
= ipr_eh_abort
,
6473 .eh_device_reset_handler
= ipr_eh_dev_reset
,
6474 .eh_host_reset_handler
= ipr_eh_host_reset
,
6475 .slave_alloc
= ipr_slave_alloc
,
6476 .slave_configure
= ipr_slave_configure
,
6477 .slave_destroy
= ipr_slave_destroy
,
6478 .scan_finished
= ipr_scan_finished
,
6479 .target_alloc
= ipr_target_alloc
,
6480 .target_destroy
= ipr_target_destroy
,
6481 .change_queue_depth
= ipr_change_queue_depth
,
6482 .bios_param
= ipr_biosparam
,
6483 .can_queue
= IPR_MAX_COMMANDS
,
6485 .sg_tablesize
= IPR_MAX_SGLIST
,
6486 .max_sectors
= IPR_IOA_MAX_SECTORS
,
6487 .cmd_per_lun
= IPR_MAX_CMD_PER_LUN
,
6488 .use_clustering
= ENABLE_CLUSTERING
,
6489 .shost_attrs
= ipr_ioa_attrs
,
6490 .sdev_attrs
= ipr_dev_attrs
,
6491 .proc_name
= IPR_NAME
,
6496 * ipr_ata_phy_reset - libata phy_reset handler
6497 * @ap: ata port to reset
6500 static void ipr_ata_phy_reset(struct ata_port
*ap
)
6502 unsigned long flags
;
6503 struct ipr_sata_port
*sata_port
= ap
->private_data
;
6504 struct ipr_resource_entry
*res
= sata_port
->res
;
6505 struct ipr_ioa_cfg
*ioa_cfg
= sata_port
->ioa_cfg
;
6509 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, flags
);
6510 while (ioa_cfg
->in_reset_reload
) {
6511 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, flags
);
6512 wait_event(ioa_cfg
->reset_wait_q
, !ioa_cfg
->in_reset_reload
);
6513 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, flags
);
6516 if (!ioa_cfg
->hrrq
[IPR_INIT_HRRQ
].allow_cmds
)
6519 rc
= ipr_device_reset(ioa_cfg
, res
);
6522 ap
->link
.device
[0].class = ATA_DEV_NONE
;
6526 ap
->link
.device
[0].class = res
->ata_class
;
6527 if (ap
->link
.device
[0].class == ATA_DEV_UNKNOWN
)
6528 ap
->link
.device
[0].class = ATA_DEV_NONE
;
6531 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, flags
);
6536 * ipr_ata_post_internal - Cleanup after an internal command
6537 * @qc: ATA queued command
6542 static void ipr_ata_post_internal(struct ata_queued_cmd
*qc
)
6544 struct ipr_sata_port
*sata_port
= qc
->ap
->private_data
;
6545 struct ipr_ioa_cfg
*ioa_cfg
= sata_port
->ioa_cfg
;
6546 struct ipr_cmnd
*ipr_cmd
;
6547 struct ipr_hrr_queue
*hrrq
;
6548 unsigned long flags
;
6550 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, flags
);
6551 while (ioa_cfg
->in_reset_reload
) {
6552 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, flags
);
6553 wait_event(ioa_cfg
->reset_wait_q
, !ioa_cfg
->in_reset_reload
);
6554 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, flags
);
6557 for_each_hrrq(hrrq
, ioa_cfg
) {
6558 spin_lock(&hrrq
->_lock
);
6559 list_for_each_entry(ipr_cmd
, &hrrq
->hrrq_pending_q
, queue
) {
6560 if (ipr_cmd
->qc
== qc
) {
6561 ipr_device_reset(ioa_cfg
, sata_port
->res
);
6565 spin_unlock(&hrrq
->_lock
);
6567 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, flags
);
6571 * ipr_copy_sata_tf - Copy a SATA taskfile to an IOA data structure
6572 * @regs: destination
6573 * @tf: source ATA taskfile
6578 static void ipr_copy_sata_tf(struct ipr_ioarcb_ata_regs
*regs
,
6579 struct ata_taskfile
*tf
)
6581 regs
->feature
= tf
->feature
;
6582 regs
->nsect
= tf
->nsect
;
6583 regs
->lbal
= tf
->lbal
;
6584 regs
->lbam
= tf
->lbam
;
6585 regs
->lbah
= tf
->lbah
;
6586 regs
->device
= tf
->device
;
6587 regs
->command
= tf
->command
;
6588 regs
->hob_feature
= tf
->hob_feature
;
6589 regs
->hob_nsect
= tf
->hob_nsect
;
6590 regs
->hob_lbal
= tf
->hob_lbal
;
6591 regs
->hob_lbam
= tf
->hob_lbam
;
6592 regs
->hob_lbah
= tf
->hob_lbah
;
6593 regs
->ctl
= tf
->ctl
;
6597 * ipr_sata_done - done function for SATA commands
6598 * @ipr_cmd: ipr command struct
6600 * This function is invoked by the interrupt handler for
6601 * ops generated by the SCSI mid-layer to SATA devices
6606 static void ipr_sata_done(struct ipr_cmnd
*ipr_cmd
)
6608 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
6609 struct ata_queued_cmd
*qc
= ipr_cmd
->qc
;
6610 struct ipr_sata_port
*sata_port
= qc
->ap
->private_data
;
6611 struct ipr_resource_entry
*res
= sata_port
->res
;
6612 u32 ioasc
= be32_to_cpu(ipr_cmd
->s
.ioasa
.hdr
.ioasc
);
6614 spin_lock(&ipr_cmd
->hrrq
->_lock
);
6615 if (ipr_cmd
->ioa_cfg
->sis64
)
6616 memcpy(&sata_port
->ioasa
, &ipr_cmd
->s
.ioasa64
.u
.gata
,
6617 sizeof(struct ipr_ioasa_gata
));
6619 memcpy(&sata_port
->ioasa
, &ipr_cmd
->s
.ioasa
.u
.gata
,
6620 sizeof(struct ipr_ioasa_gata
));
6621 ipr_dump_ioasa(ioa_cfg
, ipr_cmd
, res
);
6623 if (be32_to_cpu(ipr_cmd
->s
.ioasa
.hdr
.ioasc_specific
) & IPR_ATA_DEVICE_WAS_RESET
)
6624 scsi_report_device_reset(ioa_cfg
->host
, res
->bus
, res
->target
);
6626 if (IPR_IOASC_SENSE_KEY(ioasc
) > RECOVERED_ERROR
)
6627 qc
->err_mask
|= __ac_err_mask(sata_port
->ioasa
.status
);
6629 qc
->err_mask
|= ac_err_mask(sata_port
->ioasa
.status
);
6630 list_add_tail(&ipr_cmd
->queue
, &ipr_cmd
->hrrq
->hrrq_free_q
);
6631 spin_unlock(&ipr_cmd
->hrrq
->_lock
);
6632 ata_qc_complete(qc
);
6636 * ipr_build_ata_ioadl64 - Build an ATA scatter/gather list
6637 * @ipr_cmd: ipr command struct
6638 * @qc: ATA queued command
6641 static void ipr_build_ata_ioadl64(struct ipr_cmnd
*ipr_cmd
,
6642 struct ata_queued_cmd
*qc
)
6644 u32 ioadl_flags
= 0;
6645 struct ipr_ioarcb
*ioarcb
= &ipr_cmd
->ioarcb
;
6646 struct ipr_ioadl64_desc
*ioadl64
= ipr_cmd
->i
.ata_ioadl
.ioadl64
;
6647 struct ipr_ioadl64_desc
*last_ioadl64
= NULL
;
6648 int len
= qc
->nbytes
;
6649 struct scatterlist
*sg
;
6651 dma_addr_t dma_addr
= ipr_cmd
->dma_addr
;
6656 if (qc
->dma_dir
== DMA_TO_DEVICE
) {
6657 ioadl_flags
= IPR_IOADL_FLAGS_WRITE
;
6658 ioarcb
->cmd_pkt
.flags_hi
|= IPR_FLAGS_HI_WRITE_NOT_READ
;
6659 } else if (qc
->dma_dir
== DMA_FROM_DEVICE
)
6660 ioadl_flags
= IPR_IOADL_FLAGS_READ
;
6662 ioarcb
->data_transfer_length
= cpu_to_be32(len
);
6664 cpu_to_be32(sizeof(struct ipr_ioadl64_desc
) * ipr_cmd
->dma_use_sg
);
6665 ioarcb
->u
.sis64_addr_data
.data_ioadl_addr
=
6666 cpu_to_be64(dma_addr
+ offsetof(struct ipr_cmnd
, i
.ata_ioadl
.ioadl64
));
6668 for_each_sg(qc
->sg
, sg
, qc
->n_elem
, si
) {
6669 ioadl64
->flags
= cpu_to_be32(ioadl_flags
);
6670 ioadl64
->data_len
= cpu_to_be32(sg_dma_len(sg
));
6671 ioadl64
->address
= cpu_to_be64(sg_dma_address(sg
));
6673 last_ioadl64
= ioadl64
;
6677 if (likely(last_ioadl64
))
6678 last_ioadl64
->flags
|= cpu_to_be32(IPR_IOADL_FLAGS_LAST
);
6682 * ipr_build_ata_ioadl - Build an ATA scatter/gather list
6683 * @ipr_cmd: ipr command struct
6684 * @qc: ATA queued command
6687 static void ipr_build_ata_ioadl(struct ipr_cmnd
*ipr_cmd
,
6688 struct ata_queued_cmd
*qc
)
6690 u32 ioadl_flags
= 0;
6691 struct ipr_ioarcb
*ioarcb
= &ipr_cmd
->ioarcb
;
6692 struct ipr_ioadl_desc
*ioadl
= ipr_cmd
->i
.ioadl
;
6693 struct ipr_ioadl_desc
*last_ioadl
= NULL
;
6694 int len
= qc
->nbytes
;
6695 struct scatterlist
*sg
;
6701 if (qc
->dma_dir
== DMA_TO_DEVICE
) {
6702 ioadl_flags
= IPR_IOADL_FLAGS_WRITE
;
6703 ioarcb
->cmd_pkt
.flags_hi
|= IPR_FLAGS_HI_WRITE_NOT_READ
;
6704 ioarcb
->data_transfer_length
= cpu_to_be32(len
);
6706 cpu_to_be32(sizeof(struct ipr_ioadl_desc
) * ipr_cmd
->dma_use_sg
);
6707 } else if (qc
->dma_dir
== DMA_FROM_DEVICE
) {
6708 ioadl_flags
= IPR_IOADL_FLAGS_READ
;
6709 ioarcb
->read_data_transfer_length
= cpu_to_be32(len
);
6710 ioarcb
->read_ioadl_len
=
6711 cpu_to_be32(sizeof(struct ipr_ioadl_desc
) * ipr_cmd
->dma_use_sg
);
6714 for_each_sg(qc
->sg
, sg
, qc
->n_elem
, si
) {
6715 ioadl
->flags_and_data_len
= cpu_to_be32(ioadl_flags
| sg_dma_len(sg
));
6716 ioadl
->address
= cpu_to_be32(sg_dma_address(sg
));
6722 if (likely(last_ioadl
))
6723 last_ioadl
->flags_and_data_len
|= cpu_to_be32(IPR_IOADL_FLAGS_LAST
);
6727 * ipr_qc_defer - Get a free ipr_cmd
6728 * @qc: queued command
6733 static int ipr_qc_defer(struct ata_queued_cmd
*qc
)
6735 struct ata_port
*ap
= qc
->ap
;
6736 struct ipr_sata_port
*sata_port
= ap
->private_data
;
6737 struct ipr_ioa_cfg
*ioa_cfg
= sata_port
->ioa_cfg
;
6738 struct ipr_cmnd
*ipr_cmd
;
6739 struct ipr_hrr_queue
*hrrq
;
6742 hrrq_id
= ipr_get_hrrq_index(ioa_cfg
);
6743 hrrq
= &ioa_cfg
->hrrq
[hrrq_id
];
6745 qc
->lldd_task
= NULL
;
6746 spin_lock(&hrrq
->_lock
);
6747 if (unlikely(hrrq
->ioa_is_dead
)) {
6748 spin_unlock(&hrrq
->_lock
);
6752 if (unlikely(!hrrq
->allow_cmds
)) {
6753 spin_unlock(&hrrq
->_lock
);
6754 return ATA_DEFER_LINK
;
6757 ipr_cmd
= __ipr_get_free_ipr_cmnd(hrrq
);
6758 if (ipr_cmd
== NULL
) {
6759 spin_unlock(&hrrq
->_lock
);
6760 return ATA_DEFER_LINK
;
6763 qc
->lldd_task
= ipr_cmd
;
6764 spin_unlock(&hrrq
->_lock
);
6769 * ipr_qc_issue - Issue a SATA qc to a device
6770 * @qc: queued command
6775 static unsigned int ipr_qc_issue(struct ata_queued_cmd
*qc
)
6777 struct ata_port
*ap
= qc
->ap
;
6778 struct ipr_sata_port
*sata_port
= ap
->private_data
;
6779 struct ipr_resource_entry
*res
= sata_port
->res
;
6780 struct ipr_ioa_cfg
*ioa_cfg
= sata_port
->ioa_cfg
;
6781 struct ipr_cmnd
*ipr_cmd
;
6782 struct ipr_ioarcb
*ioarcb
;
6783 struct ipr_ioarcb_ata_regs
*regs
;
6785 if (qc
->lldd_task
== NULL
)
6788 ipr_cmd
= qc
->lldd_task
;
6789 if (ipr_cmd
== NULL
)
6790 return AC_ERR_SYSTEM
;
6792 qc
->lldd_task
= NULL
;
6793 spin_lock(&ipr_cmd
->hrrq
->_lock
);
6794 if (unlikely(!ipr_cmd
->hrrq
->allow_cmds
||
6795 ipr_cmd
->hrrq
->ioa_is_dead
)) {
6796 list_add_tail(&ipr_cmd
->queue
, &ipr_cmd
->hrrq
->hrrq_free_q
);
6797 spin_unlock(&ipr_cmd
->hrrq
->_lock
);
6798 return AC_ERR_SYSTEM
;
6801 ipr_init_ipr_cmnd(ipr_cmd
, ipr_lock_and_done
);
6802 ioarcb
= &ipr_cmd
->ioarcb
;
6804 if (ioa_cfg
->sis64
) {
6805 regs
= &ipr_cmd
->i
.ata_ioadl
.regs
;
6806 ioarcb
->add_cmd_parms_offset
= cpu_to_be16(sizeof(*ioarcb
));
6808 regs
= &ioarcb
->u
.add_data
.u
.regs
;
6810 memset(regs
, 0, sizeof(*regs
));
6811 ioarcb
->add_cmd_parms_len
= cpu_to_be16(sizeof(*regs
));
6813 list_add_tail(&ipr_cmd
->queue
, &ipr_cmd
->hrrq
->hrrq_pending_q
);
6815 ipr_cmd
->done
= ipr_sata_done
;
6816 ipr_cmd
->ioarcb
.res_handle
= res
->res_handle
;
6817 ioarcb
->cmd_pkt
.request_type
= IPR_RQTYPE_ATA_PASSTHRU
;
6818 ioarcb
->cmd_pkt
.flags_hi
|= IPR_FLAGS_HI_NO_LINK_DESC
;
6819 ioarcb
->cmd_pkt
.flags_hi
|= IPR_FLAGS_HI_NO_ULEN_CHK
;
6820 ipr_cmd
->dma_use_sg
= qc
->n_elem
;
6823 ipr_build_ata_ioadl64(ipr_cmd
, qc
);
6825 ipr_build_ata_ioadl(ipr_cmd
, qc
);
6827 regs
->flags
|= IPR_ATA_FLAG_STATUS_ON_GOOD_COMPLETION
;
6828 ipr_copy_sata_tf(regs
, &qc
->tf
);
6829 memcpy(ioarcb
->cmd_pkt
.cdb
, qc
->cdb
, IPR_MAX_CDB_LEN
);
6830 ipr_trc_hook(ipr_cmd
, IPR_TRACE_START
, IPR_GET_RES_PHYS_LOC(res
));
6832 switch (qc
->tf
.protocol
) {
6833 case ATA_PROT_NODATA
:
6838 regs
->flags
|= IPR_ATA_FLAG_XFER_TYPE_DMA
;
6841 case ATAPI_PROT_PIO
:
6842 case ATAPI_PROT_NODATA
:
6843 regs
->flags
|= IPR_ATA_FLAG_PACKET_CMD
;
6846 case ATAPI_PROT_DMA
:
6847 regs
->flags
|= IPR_ATA_FLAG_PACKET_CMD
;
6848 regs
->flags
|= IPR_ATA_FLAG_XFER_TYPE_DMA
;
6853 spin_unlock(&ipr_cmd
->hrrq
->_lock
);
6854 return AC_ERR_INVALID
;
6857 ipr_send_command(ipr_cmd
);
6858 spin_unlock(&ipr_cmd
->hrrq
->_lock
);
6864 * ipr_qc_fill_rtf - Read result TF
6865 * @qc: ATA queued command
6870 static bool ipr_qc_fill_rtf(struct ata_queued_cmd
*qc
)
6872 struct ipr_sata_port
*sata_port
= qc
->ap
->private_data
;
6873 struct ipr_ioasa_gata
*g
= &sata_port
->ioasa
;
6874 struct ata_taskfile
*tf
= &qc
->result_tf
;
6876 tf
->feature
= g
->error
;
6877 tf
->nsect
= g
->nsect
;
6881 tf
->device
= g
->device
;
6882 tf
->command
= g
->status
;
6883 tf
->hob_nsect
= g
->hob_nsect
;
6884 tf
->hob_lbal
= g
->hob_lbal
;
6885 tf
->hob_lbam
= g
->hob_lbam
;
6886 tf
->hob_lbah
= g
->hob_lbah
;
6891 static struct ata_port_operations ipr_sata_ops
= {
6892 .phy_reset
= ipr_ata_phy_reset
,
6893 .hardreset
= ipr_sata_reset
,
6894 .post_internal_cmd
= ipr_ata_post_internal
,
6895 .qc_prep
= ata_noop_qc_prep
,
6896 .qc_defer
= ipr_qc_defer
,
6897 .qc_issue
= ipr_qc_issue
,
6898 .qc_fill_rtf
= ipr_qc_fill_rtf
,
6899 .port_start
= ata_sas_port_start
,
6900 .port_stop
= ata_sas_port_stop
6903 static struct ata_port_info sata_port_info
= {
6904 .flags
= ATA_FLAG_SATA
| ATA_FLAG_PIO_DMA
|
6906 .pio_mask
= ATA_PIO4_ONLY
,
6907 .mwdma_mask
= ATA_MWDMA2
,
6908 .udma_mask
= ATA_UDMA6
,
6909 .port_ops
= &ipr_sata_ops
6912 #ifdef CONFIG_PPC_PSERIES
6913 static const u16 ipr_blocked_processors
[] = {
6925 * ipr_invalid_adapter - Determine if this adapter is supported on this hardware
6926 * @ioa_cfg: ioa cfg struct
6928 * Adapters that use Gemstone revision < 3.1 do not work reliably on
6929 * certain pSeries hardware. This function determines if the given
6930 * adapter is in one of these confgurations or not.
6933 * 1 if adapter is not supported / 0 if adapter is supported
6935 static int ipr_invalid_adapter(struct ipr_ioa_cfg
*ioa_cfg
)
6939 if ((ioa_cfg
->type
== 0x5702) && (ioa_cfg
->pdev
->revision
< 4)) {
6940 for (i
= 0; i
< ARRAY_SIZE(ipr_blocked_processors
); i
++) {
6941 if (pvr_version_is(ipr_blocked_processors
[i
]))
6948 #define ipr_invalid_adapter(ioa_cfg) 0
6952 * ipr_ioa_bringdown_done - IOA bring down completion.
6953 * @ipr_cmd: ipr command struct
6955 * This function processes the completion of an adapter bring down.
6956 * It wakes any reset sleepers.
6961 static int ipr_ioa_bringdown_done(struct ipr_cmnd
*ipr_cmd
)
6963 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
6967 if (!ioa_cfg
->hrrq
[IPR_INIT_HRRQ
].removing_ioa
) {
6969 spin_unlock_irq(ioa_cfg
->host
->host_lock
);
6970 scsi_unblock_requests(ioa_cfg
->host
);
6971 spin_lock_irq(ioa_cfg
->host
->host_lock
);
6974 ioa_cfg
->in_reset_reload
= 0;
6975 ioa_cfg
->reset_retries
= 0;
6976 for (i
= 0; i
< ioa_cfg
->hrrq_num
; i
++) {
6977 spin_lock(&ioa_cfg
->hrrq
[i
]._lock
);
6978 ioa_cfg
->hrrq
[i
].ioa_is_dead
= 1;
6979 spin_unlock(&ioa_cfg
->hrrq
[i
]._lock
);
6983 list_add_tail(&ipr_cmd
->queue
, &ipr_cmd
->hrrq
->hrrq_free_q
);
6984 wake_up_all(&ioa_cfg
->reset_wait_q
);
6987 return IPR_RC_JOB_RETURN
;
6991 * ipr_ioa_reset_done - IOA reset completion.
6992 * @ipr_cmd: ipr command struct
6994 * This function processes the completion of an adapter reset.
6995 * It schedules any necessary mid-layer add/removes and
6996 * wakes any reset sleepers.
7001 static int ipr_ioa_reset_done(struct ipr_cmnd
*ipr_cmd
)
7003 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
7004 struct ipr_resource_entry
*res
;
7005 struct ipr_hostrcb
*hostrcb
, *temp
;
7009 ioa_cfg
->in_reset_reload
= 0;
7010 for (j
= 0; j
< ioa_cfg
->hrrq_num
; j
++) {
7011 spin_lock(&ioa_cfg
->hrrq
[j
]._lock
);
7012 ioa_cfg
->hrrq
[j
].allow_cmds
= 1;
7013 spin_unlock(&ioa_cfg
->hrrq
[j
]._lock
);
7016 ioa_cfg
->reset_cmd
= NULL
;
7017 ioa_cfg
->doorbell
|= IPR_RUNTIME_RESET
;
7019 list_for_each_entry(res
, &ioa_cfg
->used_res_q
, queue
) {
7020 if (res
->add_to_ml
|| res
->del_from_ml
) {
7025 schedule_work(&ioa_cfg
->work_q
);
7027 list_for_each_entry_safe(hostrcb
, temp
, &ioa_cfg
->hostrcb_free_q
, queue
) {
7028 list_del(&hostrcb
->queue
);
7029 if (i
++ < IPR_NUM_LOG_HCAMS
)
7030 ipr_send_hcam(ioa_cfg
, IPR_HCAM_CDB_OP_CODE_LOG_DATA
, hostrcb
);
7032 ipr_send_hcam(ioa_cfg
, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE
, hostrcb
);
7035 scsi_report_bus_reset(ioa_cfg
->host
, IPR_VSET_BUS
);
7036 dev_info(&ioa_cfg
->pdev
->dev
, "IOA initialized.\n");
7038 ioa_cfg
->reset_retries
= 0;
7039 list_add_tail(&ipr_cmd
->queue
, &ipr_cmd
->hrrq
->hrrq_free_q
);
7040 wake_up_all(&ioa_cfg
->reset_wait_q
);
7042 spin_unlock(ioa_cfg
->host
->host_lock
);
7043 scsi_unblock_requests(ioa_cfg
->host
);
7044 spin_lock(ioa_cfg
->host
->host_lock
);
7046 if (!ioa_cfg
->hrrq
[IPR_INIT_HRRQ
].allow_cmds
)
7047 scsi_block_requests(ioa_cfg
->host
);
7049 schedule_work(&ioa_cfg
->work_q
);
7051 return IPR_RC_JOB_RETURN
;
7055 * ipr_set_sup_dev_dflt - Initialize a Set Supported Device buffer
7056 * @supported_dev: supported device struct
7057 * @vpids: vendor product id struct
7062 static void ipr_set_sup_dev_dflt(struct ipr_supported_device
*supported_dev
,
7063 struct ipr_std_inq_vpids
*vpids
)
7065 memset(supported_dev
, 0, sizeof(struct ipr_supported_device
));
7066 memcpy(&supported_dev
->vpids
, vpids
, sizeof(struct ipr_std_inq_vpids
));
7067 supported_dev
->num_records
= 1;
7068 supported_dev
->data_length
=
7069 cpu_to_be16(sizeof(struct ipr_supported_device
));
7070 supported_dev
->reserved
= 0;
7074 * ipr_set_supported_devs - Send Set Supported Devices for a device
7075 * @ipr_cmd: ipr command struct
7077 * This function sends a Set Supported Devices to the adapter
7080 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7082 static int ipr_set_supported_devs(struct ipr_cmnd
*ipr_cmd
)
7084 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
7085 struct ipr_supported_device
*supp_dev
= &ioa_cfg
->vpd_cbs
->supp_dev
;
7086 struct ipr_ioarcb
*ioarcb
= &ipr_cmd
->ioarcb
;
7087 struct ipr_resource_entry
*res
= ipr_cmd
->u
.res
;
7089 ipr_cmd
->job_step
= ipr_ioa_reset_done
;
7091 list_for_each_entry_continue(res
, &ioa_cfg
->used_res_q
, queue
) {
7092 if (!ipr_is_scsi_disk(res
))
7095 ipr_cmd
->u
.res
= res
;
7096 ipr_set_sup_dev_dflt(supp_dev
, &res
->std_inq_data
.vpids
);
7098 ioarcb
->res_handle
= cpu_to_be32(IPR_IOA_RES_HANDLE
);
7099 ioarcb
->cmd_pkt
.flags_hi
|= IPR_FLAGS_HI_WRITE_NOT_READ
;
7100 ioarcb
->cmd_pkt
.request_type
= IPR_RQTYPE_IOACMD
;
7102 ioarcb
->cmd_pkt
.cdb
[0] = IPR_SET_SUPPORTED_DEVICES
;
7103 ioarcb
->cmd_pkt
.cdb
[1] = IPR_SET_ALL_SUPPORTED_DEVICES
;
7104 ioarcb
->cmd_pkt
.cdb
[7] = (sizeof(struct ipr_supported_device
) >> 8) & 0xff;
7105 ioarcb
->cmd_pkt
.cdb
[8] = sizeof(struct ipr_supported_device
) & 0xff;
7107 ipr_init_ioadl(ipr_cmd
,
7108 ioa_cfg
->vpd_cbs_dma
+
7109 offsetof(struct ipr_misc_cbs
, supp_dev
),
7110 sizeof(struct ipr_supported_device
),
7111 IPR_IOADL_FLAGS_WRITE_LAST
);
7113 ipr_do_req(ipr_cmd
, ipr_reset_ioa_job
, ipr_timeout
,
7114 IPR_SET_SUP_DEVICE_TIMEOUT
);
7116 if (!ioa_cfg
->sis64
)
7117 ipr_cmd
->job_step
= ipr_set_supported_devs
;
7119 return IPR_RC_JOB_RETURN
;
7123 return IPR_RC_JOB_CONTINUE
;
7127 * ipr_get_mode_page - Locate specified mode page
7128 * @mode_pages: mode page buffer
7129 * @page_code: page code to find
7130 * @len: minimum required length for mode page
7133 * pointer to mode page / NULL on failure
7135 static void *ipr_get_mode_page(struct ipr_mode_pages
*mode_pages
,
7136 u32 page_code
, u32 len
)
7138 struct ipr_mode_page_hdr
*mode_hdr
;
7142 if (!mode_pages
|| (mode_pages
->hdr
.length
== 0))
7145 length
= (mode_pages
->hdr
.length
+ 1) - 4 - mode_pages
->hdr
.block_desc_len
;
7146 mode_hdr
= (struct ipr_mode_page_hdr
*)
7147 (mode_pages
->data
+ mode_pages
->hdr
.block_desc_len
);
7150 if (IPR_GET_MODE_PAGE_CODE(mode_hdr
) == page_code
) {
7151 if (mode_hdr
->page_length
>= (len
- sizeof(struct ipr_mode_page_hdr
)))
7155 page_length
= (sizeof(struct ipr_mode_page_hdr
) +
7156 mode_hdr
->page_length
);
7157 length
-= page_length
;
7158 mode_hdr
= (struct ipr_mode_page_hdr
*)
7159 ((unsigned long)mode_hdr
+ page_length
);
7166 * ipr_check_term_power - Check for term power errors
7167 * @ioa_cfg: ioa config struct
7168 * @mode_pages: IOAFP mode pages buffer
7170 * Check the IOAFP's mode page 28 for term power errors
7175 static void ipr_check_term_power(struct ipr_ioa_cfg
*ioa_cfg
,
7176 struct ipr_mode_pages
*mode_pages
)
7180 struct ipr_dev_bus_entry
*bus
;
7181 struct ipr_mode_page28
*mode_page
;
7183 mode_page
= ipr_get_mode_page(mode_pages
, 0x28,
7184 sizeof(struct ipr_mode_page28
));
7186 entry_length
= mode_page
->entry_length
;
7188 bus
= mode_page
->bus
;
7190 for (i
= 0; i
< mode_page
->num_entries
; i
++) {
7191 if (bus
->flags
& IPR_SCSI_ATTR_NO_TERM_PWR
) {
7192 dev_err(&ioa_cfg
->pdev
->dev
,
7193 "Term power is absent on scsi bus %d\n",
7197 bus
= (struct ipr_dev_bus_entry
*)((char *)bus
+ entry_length
);
7202 * ipr_scsi_bus_speed_limit - Limit the SCSI speed based on SES table
7203 * @ioa_cfg: ioa config struct
7205 * Looks through the config table checking for SES devices. If
7206 * the SES device is in the SES table indicating a maximum SCSI
7207 * bus speed, the speed is limited for the bus.
7212 static void ipr_scsi_bus_speed_limit(struct ipr_ioa_cfg
*ioa_cfg
)
7217 for (i
= 0; i
< IPR_MAX_NUM_BUSES
; i
++) {
7218 max_xfer_rate
= ipr_get_max_scsi_speed(ioa_cfg
, i
,
7219 ioa_cfg
->bus_attr
[i
].bus_width
);
7221 if (max_xfer_rate
< ioa_cfg
->bus_attr
[i
].max_xfer_rate
)
7222 ioa_cfg
->bus_attr
[i
].max_xfer_rate
= max_xfer_rate
;
7227 * ipr_modify_ioafp_mode_page_28 - Modify IOAFP Mode Page 28
7228 * @ioa_cfg: ioa config struct
7229 * @mode_pages: mode page 28 buffer
7231 * Updates mode page 28 based on driver configuration
7236 static void ipr_modify_ioafp_mode_page_28(struct ipr_ioa_cfg
*ioa_cfg
,
7237 struct ipr_mode_pages
*mode_pages
)
7239 int i
, entry_length
;
7240 struct ipr_dev_bus_entry
*bus
;
7241 struct ipr_bus_attributes
*bus_attr
;
7242 struct ipr_mode_page28
*mode_page
;
7244 mode_page
= ipr_get_mode_page(mode_pages
, 0x28,
7245 sizeof(struct ipr_mode_page28
));
7247 entry_length
= mode_page
->entry_length
;
7249 /* Loop for each device bus entry */
7250 for (i
= 0, bus
= mode_page
->bus
;
7251 i
< mode_page
->num_entries
;
7252 i
++, bus
= (struct ipr_dev_bus_entry
*)((u8
*)bus
+ entry_length
)) {
7253 if (bus
->res_addr
.bus
> IPR_MAX_NUM_BUSES
) {
7254 dev_err(&ioa_cfg
->pdev
->dev
,
7255 "Invalid resource address reported: 0x%08X\n",
7256 IPR_GET_PHYS_LOC(bus
->res_addr
));
7260 bus_attr
= &ioa_cfg
->bus_attr
[i
];
7261 bus
->extended_reset_delay
= IPR_EXTENDED_RESET_DELAY
;
7262 bus
->bus_width
= bus_attr
->bus_width
;
7263 bus
->max_xfer_rate
= cpu_to_be32(bus_attr
->max_xfer_rate
);
7264 bus
->flags
&= ~IPR_SCSI_ATTR_QAS_MASK
;
7265 if (bus_attr
->qas_enabled
)
7266 bus
->flags
|= IPR_SCSI_ATTR_ENABLE_QAS
;
7268 bus
->flags
|= IPR_SCSI_ATTR_DISABLE_QAS
;
7273 * ipr_build_mode_select - Build a mode select command
7274 * @ipr_cmd: ipr command struct
7275 * @res_handle: resource handle to send command to
7276 * @parm: Byte 2 of Mode Sense command
7277 * @dma_addr: DMA buffer address
7278 * @xfer_len: data transfer length
7283 static void ipr_build_mode_select(struct ipr_cmnd
*ipr_cmd
,
7284 __be32 res_handle
, u8 parm
,
7285 dma_addr_t dma_addr
, u8 xfer_len
)
7287 struct ipr_ioarcb
*ioarcb
= &ipr_cmd
->ioarcb
;
7289 ioarcb
->res_handle
= res_handle
;
7290 ioarcb
->cmd_pkt
.request_type
= IPR_RQTYPE_SCSICDB
;
7291 ioarcb
->cmd_pkt
.flags_hi
|= IPR_FLAGS_HI_WRITE_NOT_READ
;
7292 ioarcb
->cmd_pkt
.cdb
[0] = MODE_SELECT
;
7293 ioarcb
->cmd_pkt
.cdb
[1] = parm
;
7294 ioarcb
->cmd_pkt
.cdb
[4] = xfer_len
;
7296 ipr_init_ioadl(ipr_cmd
, dma_addr
, xfer_len
, IPR_IOADL_FLAGS_WRITE_LAST
);
7300 * ipr_ioafp_mode_select_page28 - Issue Mode Select Page 28 to IOA
7301 * @ipr_cmd: ipr command struct
7303 * This function sets up the SCSI bus attributes and sends
7304 * a Mode Select for Page 28 to activate them.
7309 static int ipr_ioafp_mode_select_page28(struct ipr_cmnd
*ipr_cmd
)
7311 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
7312 struct ipr_mode_pages
*mode_pages
= &ioa_cfg
->vpd_cbs
->mode_pages
;
7316 ipr_scsi_bus_speed_limit(ioa_cfg
);
7317 ipr_check_term_power(ioa_cfg
, mode_pages
);
7318 ipr_modify_ioafp_mode_page_28(ioa_cfg
, mode_pages
);
7319 length
= mode_pages
->hdr
.length
+ 1;
7320 mode_pages
->hdr
.length
= 0;
7322 ipr_build_mode_select(ipr_cmd
, cpu_to_be32(IPR_IOA_RES_HANDLE
), 0x11,
7323 ioa_cfg
->vpd_cbs_dma
+ offsetof(struct ipr_misc_cbs
, mode_pages
),
7326 ipr_cmd
->job_step
= ipr_set_supported_devs
;
7327 ipr_cmd
->u
.res
= list_entry(ioa_cfg
->used_res_q
.next
,
7328 struct ipr_resource_entry
, queue
);
7329 ipr_do_req(ipr_cmd
, ipr_reset_ioa_job
, ipr_timeout
, IPR_INTERNAL_TIMEOUT
);
7332 return IPR_RC_JOB_RETURN
;
7336 * ipr_build_mode_sense - Builds a mode sense command
7337 * @ipr_cmd: ipr command struct
7338 * @res: resource entry struct
7339 * @parm: Byte 2 of mode sense command
7340 * @dma_addr: DMA address of mode sense buffer
7341 * @xfer_len: Size of DMA buffer
7346 static void ipr_build_mode_sense(struct ipr_cmnd
*ipr_cmd
,
7348 u8 parm
, dma_addr_t dma_addr
, u8 xfer_len
)
7350 struct ipr_ioarcb
*ioarcb
= &ipr_cmd
->ioarcb
;
7352 ioarcb
->res_handle
= res_handle
;
7353 ioarcb
->cmd_pkt
.cdb
[0] = MODE_SENSE
;
7354 ioarcb
->cmd_pkt
.cdb
[2] = parm
;
7355 ioarcb
->cmd_pkt
.cdb
[4] = xfer_len
;
7356 ioarcb
->cmd_pkt
.request_type
= IPR_RQTYPE_SCSICDB
;
7358 ipr_init_ioadl(ipr_cmd
, dma_addr
, xfer_len
, IPR_IOADL_FLAGS_READ_LAST
);
7362 * ipr_reset_cmd_failed - Handle failure of IOA reset command
7363 * @ipr_cmd: ipr command struct
7365 * This function handles the failure of an IOA bringup command.
7370 static int ipr_reset_cmd_failed(struct ipr_cmnd
*ipr_cmd
)
7372 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
7373 u32 ioasc
= be32_to_cpu(ipr_cmd
->s
.ioasa
.hdr
.ioasc
);
7375 dev_err(&ioa_cfg
->pdev
->dev
,
7376 "0x%02X failed with IOASC: 0x%08X\n",
7377 ipr_cmd
->ioarcb
.cmd_pkt
.cdb
[0], ioasc
);
7379 ipr_initiate_ioa_reset(ioa_cfg
, IPR_SHUTDOWN_NONE
);
7380 list_add_tail(&ipr_cmd
->queue
, &ipr_cmd
->hrrq
->hrrq_free_q
);
7381 return IPR_RC_JOB_RETURN
;
7385 * ipr_reset_mode_sense_failed - Handle failure of IOAFP mode sense
7386 * @ipr_cmd: ipr command struct
7388 * This function handles the failure of a Mode Sense to the IOAFP.
7389 * Some adapters do not handle all mode pages.
7392 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7394 static int ipr_reset_mode_sense_failed(struct ipr_cmnd
*ipr_cmd
)
7396 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
7397 u32 ioasc
= be32_to_cpu(ipr_cmd
->s
.ioasa
.hdr
.ioasc
);
7399 if (ioasc
== IPR_IOASC_IR_INVALID_REQ_TYPE_OR_PKT
) {
7400 ipr_cmd
->job_step
= ipr_set_supported_devs
;
7401 ipr_cmd
->u
.res
= list_entry(ioa_cfg
->used_res_q
.next
,
7402 struct ipr_resource_entry
, queue
);
7403 return IPR_RC_JOB_CONTINUE
;
7406 return ipr_reset_cmd_failed(ipr_cmd
);
7410 * ipr_ioafp_mode_sense_page28 - Issue Mode Sense Page 28 to IOA
7411 * @ipr_cmd: ipr command struct
7413 * This function send a Page 28 mode sense to the IOA to
7414 * retrieve SCSI bus attributes.
7419 static int ipr_ioafp_mode_sense_page28(struct ipr_cmnd
*ipr_cmd
)
7421 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
7424 ipr_build_mode_sense(ipr_cmd
, cpu_to_be32(IPR_IOA_RES_HANDLE
),
7425 0x28, ioa_cfg
->vpd_cbs_dma
+
7426 offsetof(struct ipr_misc_cbs
, mode_pages
),
7427 sizeof(struct ipr_mode_pages
));
7429 ipr_cmd
->job_step
= ipr_ioafp_mode_select_page28
;
7430 ipr_cmd
->job_step_failed
= ipr_reset_mode_sense_failed
;
7432 ipr_do_req(ipr_cmd
, ipr_reset_ioa_job
, ipr_timeout
, IPR_INTERNAL_TIMEOUT
);
7435 return IPR_RC_JOB_RETURN
;
7439 * ipr_ioafp_mode_select_page24 - Issue Mode Select to IOA
7440 * @ipr_cmd: ipr command struct
7442 * This function enables dual IOA RAID support if possible.
7447 static int ipr_ioafp_mode_select_page24(struct ipr_cmnd
*ipr_cmd
)
7449 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
7450 struct ipr_mode_pages
*mode_pages
= &ioa_cfg
->vpd_cbs
->mode_pages
;
7451 struct ipr_mode_page24
*mode_page
;
7455 mode_page
= ipr_get_mode_page(mode_pages
, 0x24,
7456 sizeof(struct ipr_mode_page24
));
7459 mode_page
->flags
|= IPR_ENABLE_DUAL_IOA_AF
;
7461 length
= mode_pages
->hdr
.length
+ 1;
7462 mode_pages
->hdr
.length
= 0;
7464 ipr_build_mode_select(ipr_cmd
, cpu_to_be32(IPR_IOA_RES_HANDLE
), 0x11,
7465 ioa_cfg
->vpd_cbs_dma
+ offsetof(struct ipr_misc_cbs
, mode_pages
),
7468 ipr_cmd
->job_step
= ipr_ioafp_mode_sense_page28
;
7469 ipr_do_req(ipr_cmd
, ipr_reset_ioa_job
, ipr_timeout
, IPR_INTERNAL_TIMEOUT
);
7472 return IPR_RC_JOB_RETURN
;
7476 * ipr_reset_mode_sense_page24_failed - Handle failure of IOAFP mode sense
7477 * @ipr_cmd: ipr command struct
7479 * This function handles the failure of a Mode Sense to the IOAFP.
7480 * Some adapters do not handle all mode pages.
7483 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7485 static int ipr_reset_mode_sense_page24_failed(struct ipr_cmnd
*ipr_cmd
)
7487 u32 ioasc
= be32_to_cpu(ipr_cmd
->s
.ioasa
.hdr
.ioasc
);
7489 if (ioasc
== IPR_IOASC_IR_INVALID_REQ_TYPE_OR_PKT
) {
7490 ipr_cmd
->job_step
= ipr_ioafp_mode_sense_page28
;
7491 return IPR_RC_JOB_CONTINUE
;
7494 return ipr_reset_cmd_failed(ipr_cmd
);
7498 * ipr_ioafp_mode_sense_page24 - Issue Page 24 Mode Sense to IOA
7499 * @ipr_cmd: ipr command struct
7501 * This function send a mode sense to the IOA to retrieve
7502 * the IOA Advanced Function Control mode page.
7507 static int ipr_ioafp_mode_sense_page24(struct ipr_cmnd
*ipr_cmd
)
7509 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
7512 ipr_build_mode_sense(ipr_cmd
, cpu_to_be32(IPR_IOA_RES_HANDLE
),
7513 0x24, ioa_cfg
->vpd_cbs_dma
+
7514 offsetof(struct ipr_misc_cbs
, mode_pages
),
7515 sizeof(struct ipr_mode_pages
));
7517 ipr_cmd
->job_step
= ipr_ioafp_mode_select_page24
;
7518 ipr_cmd
->job_step_failed
= ipr_reset_mode_sense_page24_failed
;
7520 ipr_do_req(ipr_cmd
, ipr_reset_ioa_job
, ipr_timeout
, IPR_INTERNAL_TIMEOUT
);
7523 return IPR_RC_JOB_RETURN
;
7527 * ipr_init_res_table - Initialize the resource table
7528 * @ipr_cmd: ipr command struct
7530 * This function looks through the existing resource table, comparing
7531 * it with the config table. This function will take care of old/new
7532 * devices and schedule adding/removing them from the mid-layer
7536 * IPR_RC_JOB_CONTINUE
7538 static int ipr_init_res_table(struct ipr_cmnd
*ipr_cmd
)
7540 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
7541 struct ipr_resource_entry
*res
, *temp
;
7542 struct ipr_config_table_entry_wrapper cfgtew
;
7543 int entries
, found
, flag
, i
;
7548 flag
= ioa_cfg
->u
.cfg_table64
->hdr64
.flags
;
7550 flag
= ioa_cfg
->u
.cfg_table
->hdr
.flags
;
7552 if (flag
& IPR_UCODE_DOWNLOAD_REQ
)
7553 dev_err(&ioa_cfg
->pdev
->dev
, "Microcode download required\n");
7555 list_for_each_entry_safe(res
, temp
, &ioa_cfg
->used_res_q
, queue
)
7556 list_move_tail(&res
->queue
, &old_res
);
7559 entries
= be16_to_cpu(ioa_cfg
->u
.cfg_table64
->hdr64
.num_entries
);
7561 entries
= ioa_cfg
->u
.cfg_table
->hdr
.num_entries
;
7563 for (i
= 0; i
< entries
; i
++) {
7565 cfgtew
.u
.cfgte64
= &ioa_cfg
->u
.cfg_table64
->dev
[i
];
7567 cfgtew
.u
.cfgte
= &ioa_cfg
->u
.cfg_table
->dev
[i
];
7570 list_for_each_entry_safe(res
, temp
, &old_res
, queue
) {
7571 if (ipr_is_same_device(res
, &cfgtew
)) {
7572 list_move_tail(&res
->queue
, &ioa_cfg
->used_res_q
);
7579 if (list_empty(&ioa_cfg
->free_res_q
)) {
7580 dev_err(&ioa_cfg
->pdev
->dev
, "Too many devices attached\n");
7585 res
= list_entry(ioa_cfg
->free_res_q
.next
,
7586 struct ipr_resource_entry
, queue
);
7587 list_move_tail(&res
->queue
, &ioa_cfg
->used_res_q
);
7588 ipr_init_res_entry(res
, &cfgtew
);
7590 } else if (res
->sdev
&& (ipr_is_vset_device(res
) || ipr_is_scsi_disk(res
)))
7591 res
->sdev
->allow_restart
= 1;
7594 ipr_update_res_entry(res
, &cfgtew
);
7597 list_for_each_entry_safe(res
, temp
, &old_res
, queue
) {
7599 res
->del_from_ml
= 1;
7600 res
->res_handle
= IPR_INVALID_RES_HANDLE
;
7601 list_move_tail(&res
->queue
, &ioa_cfg
->used_res_q
);
7605 list_for_each_entry_safe(res
, temp
, &old_res
, queue
) {
7606 ipr_clear_res_target(res
);
7607 list_move_tail(&res
->queue
, &ioa_cfg
->free_res_q
);
7610 if (ioa_cfg
->dual_raid
&& ipr_dual_ioa_raid
)
7611 ipr_cmd
->job_step
= ipr_ioafp_mode_sense_page24
;
7613 ipr_cmd
->job_step
= ipr_ioafp_mode_sense_page28
;
7616 return IPR_RC_JOB_CONTINUE
;
7620 * ipr_ioafp_query_ioa_cfg - Send a Query IOA Config to the adapter.
7621 * @ipr_cmd: ipr command struct
7623 * This function sends a Query IOA Configuration command
7624 * to the adapter to retrieve the IOA configuration table.
7629 static int ipr_ioafp_query_ioa_cfg(struct ipr_cmnd
*ipr_cmd
)
7631 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
7632 struct ipr_ioarcb
*ioarcb
= &ipr_cmd
->ioarcb
;
7633 struct ipr_inquiry_page3
*ucode_vpd
= &ioa_cfg
->vpd_cbs
->page3_data
;
7634 struct ipr_inquiry_cap
*cap
= &ioa_cfg
->vpd_cbs
->cap
;
7637 if (cap
->cap
& IPR_CAP_DUAL_IOA_RAID
)
7638 ioa_cfg
->dual_raid
= 1;
7639 dev_info(&ioa_cfg
->pdev
->dev
, "Adapter firmware version: %02X%02X%02X%02X\n",
7640 ucode_vpd
->major_release
, ucode_vpd
->card_type
,
7641 ucode_vpd
->minor_release
[0], ucode_vpd
->minor_release
[1]);
7642 ioarcb
->cmd_pkt
.request_type
= IPR_RQTYPE_IOACMD
;
7643 ioarcb
->res_handle
= cpu_to_be32(IPR_IOA_RES_HANDLE
);
7645 ioarcb
->cmd_pkt
.cdb
[0] = IPR_QUERY_IOA_CONFIG
;
7646 ioarcb
->cmd_pkt
.cdb
[6] = (ioa_cfg
->cfg_table_size
>> 16) & 0xff;
7647 ioarcb
->cmd_pkt
.cdb
[7] = (ioa_cfg
->cfg_table_size
>> 8) & 0xff;
7648 ioarcb
->cmd_pkt
.cdb
[8] = ioa_cfg
->cfg_table_size
& 0xff;
7650 ipr_init_ioadl(ipr_cmd
, ioa_cfg
->cfg_table_dma
, ioa_cfg
->cfg_table_size
,
7651 IPR_IOADL_FLAGS_READ_LAST
);
7653 ipr_cmd
->job_step
= ipr_init_res_table
;
7655 ipr_do_req(ipr_cmd
, ipr_reset_ioa_job
, ipr_timeout
, IPR_INTERNAL_TIMEOUT
);
7658 return IPR_RC_JOB_RETURN
;
7662 * ipr_ioafp_inquiry - Send an Inquiry to the adapter.
7663 * @ipr_cmd: ipr command struct
7665 * This utility function sends an inquiry to the adapter.
7670 static void ipr_ioafp_inquiry(struct ipr_cmnd
*ipr_cmd
, u8 flags
, u8 page
,
7671 dma_addr_t dma_addr
, u8 xfer_len
)
7673 struct ipr_ioarcb
*ioarcb
= &ipr_cmd
->ioarcb
;
7676 ioarcb
->cmd_pkt
.request_type
= IPR_RQTYPE_SCSICDB
;
7677 ioarcb
->res_handle
= cpu_to_be32(IPR_IOA_RES_HANDLE
);
7679 ioarcb
->cmd_pkt
.cdb
[0] = INQUIRY
;
7680 ioarcb
->cmd_pkt
.cdb
[1] = flags
;
7681 ioarcb
->cmd_pkt
.cdb
[2] = page
;
7682 ioarcb
->cmd_pkt
.cdb
[4] = xfer_len
;
7684 ipr_init_ioadl(ipr_cmd
, dma_addr
, xfer_len
, IPR_IOADL_FLAGS_READ_LAST
);
7686 ipr_do_req(ipr_cmd
, ipr_reset_ioa_job
, ipr_timeout
, IPR_INTERNAL_TIMEOUT
);
7691 * ipr_inquiry_page_supported - Is the given inquiry page supported
7692 * @page0: inquiry page 0 buffer
7695 * This function determines if the specified inquiry page is supported.
7698 * 1 if page is supported / 0 if not
7700 static int ipr_inquiry_page_supported(struct ipr_inquiry_page0
*page0
, u8 page
)
7704 for (i
= 0; i
< min_t(u8
, page0
->len
, IPR_INQUIRY_PAGE0_ENTRIES
); i
++)
7705 if (page0
->page
[i
] == page
)
7712 * ipr_ioafp_cap_inquiry - Send a Page 0xD0 Inquiry to the adapter.
7713 * @ipr_cmd: ipr command struct
7715 * This function sends a Page 0xD0 inquiry to the adapter
7716 * to retrieve adapter capabilities.
7719 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7721 static int ipr_ioafp_cap_inquiry(struct ipr_cmnd
*ipr_cmd
)
7723 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
7724 struct ipr_inquiry_page0
*page0
= &ioa_cfg
->vpd_cbs
->page0_data
;
7725 struct ipr_inquiry_cap
*cap
= &ioa_cfg
->vpd_cbs
->cap
;
7728 ipr_cmd
->job_step
= ipr_ioafp_query_ioa_cfg
;
7729 memset(cap
, 0, sizeof(*cap
));
7731 if (ipr_inquiry_page_supported(page0
, 0xD0)) {
7732 ipr_ioafp_inquiry(ipr_cmd
, 1, 0xD0,
7733 ioa_cfg
->vpd_cbs_dma
+ offsetof(struct ipr_misc_cbs
, cap
),
7734 sizeof(struct ipr_inquiry_cap
));
7735 return IPR_RC_JOB_RETURN
;
7739 return IPR_RC_JOB_CONTINUE
;
7743 * ipr_ioafp_page3_inquiry - Send a Page 3 Inquiry to the adapter.
7744 * @ipr_cmd: ipr command struct
7746 * This function sends a Page 3 inquiry to the adapter
7747 * to retrieve software VPD information.
7750 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7752 static int ipr_ioafp_page3_inquiry(struct ipr_cmnd
*ipr_cmd
)
7754 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
7758 ipr_cmd
->job_step
= ipr_ioafp_cap_inquiry
;
7760 ipr_ioafp_inquiry(ipr_cmd
, 1, 3,
7761 ioa_cfg
->vpd_cbs_dma
+ offsetof(struct ipr_misc_cbs
, page3_data
),
7762 sizeof(struct ipr_inquiry_page3
));
7765 return IPR_RC_JOB_RETURN
;
7769 * ipr_ioafp_page0_inquiry - Send a Page 0 Inquiry to the adapter.
7770 * @ipr_cmd: ipr command struct
7772 * This function sends a Page 0 inquiry to the adapter
7773 * to retrieve supported inquiry pages.
7776 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7778 static int ipr_ioafp_page0_inquiry(struct ipr_cmnd
*ipr_cmd
)
7780 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
7785 /* Grab the type out of the VPD and store it away */
7786 memcpy(type
, ioa_cfg
->vpd_cbs
->ioa_vpd
.std_inq_data
.vpids
.product_id
, 4);
7788 ioa_cfg
->type
= simple_strtoul((char *)type
, NULL
, 16);
7790 if (ipr_invalid_adapter(ioa_cfg
)) {
7791 dev_err(&ioa_cfg
->pdev
->dev
,
7792 "Adapter not supported in this hardware configuration.\n");
7794 if (!ipr_testmode
) {
7795 ioa_cfg
->reset_retries
+= IPR_NUM_RESET_RELOAD_RETRIES
;
7796 ipr_initiate_ioa_reset(ioa_cfg
, IPR_SHUTDOWN_NONE
);
7797 list_add_tail(&ipr_cmd
->queue
,
7798 &ioa_cfg
->hrrq
->hrrq_free_q
);
7799 return IPR_RC_JOB_RETURN
;
7803 ipr_cmd
->job_step
= ipr_ioafp_page3_inquiry
;
7805 ipr_ioafp_inquiry(ipr_cmd
, 1, 0,
7806 ioa_cfg
->vpd_cbs_dma
+ offsetof(struct ipr_misc_cbs
, page0_data
),
7807 sizeof(struct ipr_inquiry_page0
));
7810 return IPR_RC_JOB_RETURN
;
7814 * ipr_ioafp_std_inquiry - Send a Standard Inquiry to the adapter.
7815 * @ipr_cmd: ipr command struct
7817 * This function sends a standard inquiry to the adapter.
7822 static int ipr_ioafp_std_inquiry(struct ipr_cmnd
*ipr_cmd
)
7824 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
7827 ipr_cmd
->job_step
= ipr_ioafp_page0_inquiry
;
7829 ipr_ioafp_inquiry(ipr_cmd
, 0, 0,
7830 ioa_cfg
->vpd_cbs_dma
+ offsetof(struct ipr_misc_cbs
, ioa_vpd
),
7831 sizeof(struct ipr_ioa_vpd
));
7834 return IPR_RC_JOB_RETURN
;
7838 * ipr_ioafp_identify_hrrq - Send Identify Host RRQ.
7839 * @ipr_cmd: ipr command struct
7841 * This function send an Identify Host Request Response Queue
7842 * command to establish the HRRQ with the adapter.
7847 static int ipr_ioafp_identify_hrrq(struct ipr_cmnd
*ipr_cmd
)
7849 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
7850 struct ipr_ioarcb
*ioarcb
= &ipr_cmd
->ioarcb
;
7851 struct ipr_hrr_queue
*hrrq
;
7854 ipr_cmd
->job_step
= ipr_ioafp_std_inquiry
;
7855 dev_info(&ioa_cfg
->pdev
->dev
, "Starting IOA initialization sequence.\n");
7857 if (ioa_cfg
->identify_hrrq_index
< ioa_cfg
->hrrq_num
) {
7858 hrrq
= &ioa_cfg
->hrrq
[ioa_cfg
->identify_hrrq_index
];
7860 ioarcb
->cmd_pkt
.cdb
[0] = IPR_ID_HOST_RR_Q
;
7861 ioarcb
->res_handle
= cpu_to_be32(IPR_IOA_RES_HANDLE
);
7863 ioarcb
->cmd_pkt
.request_type
= IPR_RQTYPE_IOACMD
;
7865 ioarcb
->cmd_pkt
.cdb
[1] = 0x1;
7867 if (ioa_cfg
->nvectors
== 1)
7868 ioarcb
->cmd_pkt
.cdb
[1] &= ~IPR_ID_HRRQ_SELE_ENABLE
;
7870 ioarcb
->cmd_pkt
.cdb
[1] |= IPR_ID_HRRQ_SELE_ENABLE
;
7872 ioarcb
->cmd_pkt
.cdb
[2] =
7873 ((u64
) hrrq
->host_rrq_dma
>> 24) & 0xff;
7874 ioarcb
->cmd_pkt
.cdb
[3] =
7875 ((u64
) hrrq
->host_rrq_dma
>> 16) & 0xff;
7876 ioarcb
->cmd_pkt
.cdb
[4] =
7877 ((u64
) hrrq
->host_rrq_dma
>> 8) & 0xff;
7878 ioarcb
->cmd_pkt
.cdb
[5] =
7879 ((u64
) hrrq
->host_rrq_dma
) & 0xff;
7880 ioarcb
->cmd_pkt
.cdb
[7] =
7881 ((sizeof(u32
) * hrrq
->size
) >> 8) & 0xff;
7882 ioarcb
->cmd_pkt
.cdb
[8] =
7883 (sizeof(u32
) * hrrq
->size
) & 0xff;
7885 if (ioarcb
->cmd_pkt
.cdb
[1] & IPR_ID_HRRQ_SELE_ENABLE
)
7886 ioarcb
->cmd_pkt
.cdb
[9] =
7887 ioa_cfg
->identify_hrrq_index
;
7889 if (ioa_cfg
->sis64
) {
7890 ioarcb
->cmd_pkt
.cdb
[10] =
7891 ((u64
) hrrq
->host_rrq_dma
>> 56) & 0xff;
7892 ioarcb
->cmd_pkt
.cdb
[11] =
7893 ((u64
) hrrq
->host_rrq_dma
>> 48) & 0xff;
7894 ioarcb
->cmd_pkt
.cdb
[12] =
7895 ((u64
) hrrq
->host_rrq_dma
>> 40) & 0xff;
7896 ioarcb
->cmd_pkt
.cdb
[13] =
7897 ((u64
) hrrq
->host_rrq_dma
>> 32) & 0xff;
7900 if (ioarcb
->cmd_pkt
.cdb
[1] & IPR_ID_HRRQ_SELE_ENABLE
)
7901 ioarcb
->cmd_pkt
.cdb
[14] =
7902 ioa_cfg
->identify_hrrq_index
;
7904 ipr_do_req(ipr_cmd
, ipr_reset_ioa_job
, ipr_timeout
,
7905 IPR_INTERNAL_TIMEOUT
);
7907 if (++ioa_cfg
->identify_hrrq_index
< ioa_cfg
->hrrq_num
)
7908 ipr_cmd
->job_step
= ipr_ioafp_identify_hrrq
;
7911 return IPR_RC_JOB_RETURN
;
7915 return IPR_RC_JOB_CONTINUE
;
7919 * ipr_reset_timer_done - Adapter reset timer function
7920 * @ipr_cmd: ipr command struct
7922 * Description: This function is used in adapter reset processing
7923 * for timing events. If the reset_cmd pointer in the IOA
7924 * config struct is not this adapter's we are doing nested
7925 * resets and fail_all_ops will take care of freeing the
7931 static void ipr_reset_timer_done(struct ipr_cmnd
*ipr_cmd
)
7933 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
7934 unsigned long lock_flags
= 0;
7936 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
7938 if (ioa_cfg
->reset_cmd
== ipr_cmd
) {
7939 list_del(&ipr_cmd
->queue
);
7940 ipr_cmd
->done(ipr_cmd
);
7943 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
7947 * ipr_reset_start_timer - Start a timer for adapter reset job
7948 * @ipr_cmd: ipr command struct
7949 * @timeout: timeout value
7951 * Description: This function is used in adapter reset processing
7952 * for timing events. If the reset_cmd pointer in the IOA
7953 * config struct is not this adapter's we are doing nested
7954 * resets and fail_all_ops will take care of freeing the
7960 static void ipr_reset_start_timer(struct ipr_cmnd
*ipr_cmd
,
7961 unsigned long timeout
)
7965 list_add_tail(&ipr_cmd
->queue
, &ipr_cmd
->hrrq
->hrrq_pending_q
);
7966 ipr_cmd
->done
= ipr_reset_ioa_job
;
7968 ipr_cmd
->timer
.data
= (unsigned long) ipr_cmd
;
7969 ipr_cmd
->timer
.expires
= jiffies
+ timeout
;
7970 ipr_cmd
->timer
.function
= (void (*)(unsigned long))ipr_reset_timer_done
;
7971 add_timer(&ipr_cmd
->timer
);
7975 * ipr_init_ioa_mem - Initialize ioa_cfg control block
7976 * @ioa_cfg: ioa cfg struct
7981 static void ipr_init_ioa_mem(struct ipr_ioa_cfg
*ioa_cfg
)
7983 struct ipr_hrr_queue
*hrrq
;
7985 for_each_hrrq(hrrq
, ioa_cfg
) {
7986 spin_lock(&hrrq
->_lock
);
7987 memset(hrrq
->host_rrq
, 0, sizeof(u32
) * hrrq
->size
);
7989 /* Initialize Host RRQ pointers */
7990 hrrq
->hrrq_start
= hrrq
->host_rrq
;
7991 hrrq
->hrrq_end
= &hrrq
->host_rrq
[hrrq
->size
- 1];
7992 hrrq
->hrrq_curr
= hrrq
->hrrq_start
;
7993 hrrq
->toggle_bit
= 1;
7994 spin_unlock(&hrrq
->_lock
);
7998 ioa_cfg
->identify_hrrq_index
= 0;
7999 if (ioa_cfg
->hrrq_num
== 1)
8000 atomic_set(&ioa_cfg
->hrrq_index
, 0);
8002 atomic_set(&ioa_cfg
->hrrq_index
, 1);
8004 /* Zero out config table */
8005 memset(ioa_cfg
->u
.cfg_table
, 0, ioa_cfg
->cfg_table_size
);
8009 * ipr_reset_next_stage - Process IPL stage change based on feedback register.
8010 * @ipr_cmd: ipr command struct
8013 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
8015 static int ipr_reset_next_stage(struct ipr_cmnd
*ipr_cmd
)
8017 unsigned long stage
, stage_time
;
8019 volatile u32 int_reg
;
8020 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
8023 feedback
= readl(ioa_cfg
->regs
.init_feedback_reg
);
8024 stage
= feedback
& IPR_IPL_INIT_STAGE_MASK
;
8025 stage_time
= feedback
& IPR_IPL_INIT_STAGE_TIME_MASK
;
8027 ipr_dbg("IPL stage = 0x%lx, IPL stage time = %ld\n", stage
, stage_time
);
8029 /* sanity check the stage_time value */
8030 if (stage_time
== 0)
8031 stage_time
= IPR_IPL_INIT_DEFAULT_STAGE_TIME
;
8032 else if (stage_time
< IPR_IPL_INIT_MIN_STAGE_TIME
)
8033 stage_time
= IPR_IPL_INIT_MIN_STAGE_TIME
;
8034 else if (stage_time
> IPR_LONG_OPERATIONAL_TIMEOUT
)
8035 stage_time
= IPR_LONG_OPERATIONAL_TIMEOUT
;
8037 if (stage
== IPR_IPL_INIT_STAGE_UNKNOWN
) {
8038 writel(IPR_PCII_IPL_STAGE_CHANGE
, ioa_cfg
->regs
.set_interrupt_mask_reg
);
8039 int_reg
= readl(ioa_cfg
->regs
.sense_interrupt_mask_reg
);
8040 stage_time
= ioa_cfg
->transop_timeout
;
8041 ipr_cmd
->job_step
= ipr_ioafp_identify_hrrq
;
8042 } else if (stage
== IPR_IPL_INIT_STAGE_TRANSOP
) {
8043 int_reg
= readl(ioa_cfg
->regs
.sense_interrupt_reg32
);
8044 if (int_reg
& IPR_PCII_IOA_TRANS_TO_OPER
) {
8045 ipr_cmd
->job_step
= ipr_ioafp_identify_hrrq
;
8046 maskval
= IPR_PCII_IPL_STAGE_CHANGE
;
8047 maskval
= (maskval
<< 32) | IPR_PCII_IOA_TRANS_TO_OPER
;
8048 writeq(maskval
, ioa_cfg
->regs
.set_interrupt_mask_reg
);
8049 int_reg
= readl(ioa_cfg
->regs
.sense_interrupt_mask_reg
);
8050 return IPR_RC_JOB_CONTINUE
;
8054 ipr_cmd
->timer
.data
= (unsigned long) ipr_cmd
;
8055 ipr_cmd
->timer
.expires
= jiffies
+ stage_time
* HZ
;
8056 ipr_cmd
->timer
.function
= (void (*)(unsigned long))ipr_oper_timeout
;
8057 ipr_cmd
->done
= ipr_reset_ioa_job
;
8058 add_timer(&ipr_cmd
->timer
);
8060 list_add_tail(&ipr_cmd
->queue
, &ipr_cmd
->hrrq
->hrrq_pending_q
);
8062 return IPR_RC_JOB_RETURN
;
8066 * ipr_reset_enable_ioa - Enable the IOA following a reset.
8067 * @ipr_cmd: ipr command struct
8069 * This function reinitializes some control blocks and
8070 * enables destructive diagnostics on the adapter.
8075 static int ipr_reset_enable_ioa(struct ipr_cmnd
*ipr_cmd
)
8077 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
8078 volatile u32 int_reg
;
8079 volatile u64 maskval
;
8083 ipr_cmd
->job_step
= ipr_ioafp_identify_hrrq
;
8084 ipr_init_ioa_mem(ioa_cfg
);
8086 for (i
= 0; i
< ioa_cfg
->hrrq_num
; i
++) {
8087 spin_lock(&ioa_cfg
->hrrq
[i
]._lock
);
8088 ioa_cfg
->hrrq
[i
].allow_interrupts
= 1;
8089 spin_unlock(&ioa_cfg
->hrrq
[i
]._lock
);
8092 if (ioa_cfg
->sis64
) {
8093 /* Set the adapter to the correct endian mode. */
8094 writel(IPR_ENDIAN_SWAP_KEY
, ioa_cfg
->regs
.endian_swap_reg
);
8095 int_reg
= readl(ioa_cfg
->regs
.endian_swap_reg
);
8098 int_reg
= readl(ioa_cfg
->regs
.sense_interrupt_reg32
);
8100 if (int_reg
& IPR_PCII_IOA_TRANS_TO_OPER
) {
8101 writel((IPR_PCII_ERROR_INTERRUPTS
| IPR_PCII_HRRQ_UPDATED
),
8102 ioa_cfg
->regs
.clr_interrupt_mask_reg32
);
8103 int_reg
= readl(ioa_cfg
->regs
.sense_interrupt_mask_reg
);
8104 return IPR_RC_JOB_CONTINUE
;
8107 /* Enable destructive diagnostics on IOA */
8108 writel(ioa_cfg
->doorbell
, ioa_cfg
->regs
.set_uproc_interrupt_reg32
);
8110 if (ioa_cfg
->sis64
) {
8111 maskval
= IPR_PCII_IPL_STAGE_CHANGE
;
8112 maskval
= (maskval
<< 32) | IPR_PCII_OPER_INTERRUPTS
;
8113 writeq(maskval
, ioa_cfg
->regs
.clr_interrupt_mask_reg
);
8115 writel(IPR_PCII_OPER_INTERRUPTS
, ioa_cfg
->regs
.clr_interrupt_mask_reg32
);
8117 int_reg
= readl(ioa_cfg
->regs
.sense_interrupt_mask_reg
);
8119 dev_info(&ioa_cfg
->pdev
->dev
, "Initializing IOA.\n");
8121 if (ioa_cfg
->sis64
) {
8122 ipr_cmd
->job_step
= ipr_reset_next_stage
;
8123 return IPR_RC_JOB_CONTINUE
;
8126 ipr_cmd
->timer
.data
= (unsigned long) ipr_cmd
;
8127 ipr_cmd
->timer
.expires
= jiffies
+ (ioa_cfg
->transop_timeout
* HZ
);
8128 ipr_cmd
->timer
.function
= (void (*)(unsigned long))ipr_oper_timeout
;
8129 ipr_cmd
->done
= ipr_reset_ioa_job
;
8130 add_timer(&ipr_cmd
->timer
);
8131 list_add_tail(&ipr_cmd
->queue
, &ipr_cmd
->hrrq
->hrrq_pending_q
);
8134 return IPR_RC_JOB_RETURN
;
8138 * ipr_reset_wait_for_dump - Wait for a dump to timeout.
8139 * @ipr_cmd: ipr command struct
8141 * This function is invoked when an adapter dump has run out
8142 * of processing time.
8145 * IPR_RC_JOB_CONTINUE
8147 static int ipr_reset_wait_for_dump(struct ipr_cmnd
*ipr_cmd
)
8149 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
8151 if (ioa_cfg
->sdt_state
== GET_DUMP
)
8152 ioa_cfg
->sdt_state
= WAIT_FOR_DUMP
;
8153 else if (ioa_cfg
->sdt_state
== READ_DUMP
)
8154 ioa_cfg
->sdt_state
= ABORT_DUMP
;
8156 ioa_cfg
->dump_timeout
= 1;
8157 ipr_cmd
->job_step
= ipr_reset_alert
;
8159 return IPR_RC_JOB_CONTINUE
;
8163 * ipr_unit_check_no_data - Log a unit check/no data error log
8164 * @ioa_cfg: ioa config struct
8166 * Logs an error indicating the adapter unit checked, but for some
8167 * reason, we were unable to fetch the unit check buffer.
8172 static void ipr_unit_check_no_data(struct ipr_ioa_cfg
*ioa_cfg
)
8174 ioa_cfg
->errors_logged
++;
8175 dev_err(&ioa_cfg
->pdev
->dev
, "IOA unit check with no data\n");
8179 * ipr_get_unit_check_buffer - Get the unit check buffer from the IOA
8180 * @ioa_cfg: ioa config struct
8182 * Fetches the unit check buffer from the adapter by clocking the data
8183 * through the mailbox register.
8188 static void ipr_get_unit_check_buffer(struct ipr_ioa_cfg
*ioa_cfg
)
8190 unsigned long mailbox
;
8191 struct ipr_hostrcb
*hostrcb
;
8192 struct ipr_uc_sdt sdt
;
8196 mailbox
= readl(ioa_cfg
->ioa_mailbox
);
8198 if (!ioa_cfg
->sis64
&& !ipr_sdt_is_fmt2(mailbox
)) {
8199 ipr_unit_check_no_data(ioa_cfg
);
8203 memset(&sdt
, 0, sizeof(struct ipr_uc_sdt
));
8204 rc
= ipr_get_ldump_data_section(ioa_cfg
, mailbox
, (__be32
*) &sdt
,
8205 (sizeof(struct ipr_uc_sdt
)) / sizeof(__be32
));
8207 if (rc
|| !(sdt
.entry
[0].flags
& IPR_SDT_VALID_ENTRY
) ||
8208 ((be32_to_cpu(sdt
.hdr
.state
) != IPR_FMT3_SDT_READY_TO_USE
) &&
8209 (be32_to_cpu(sdt
.hdr
.state
) != IPR_FMT2_SDT_READY_TO_USE
))) {
8210 ipr_unit_check_no_data(ioa_cfg
);
8214 /* Find length of the first sdt entry (UC buffer) */
8215 if (be32_to_cpu(sdt
.hdr
.state
) == IPR_FMT3_SDT_READY_TO_USE
)
8216 length
= be32_to_cpu(sdt
.entry
[0].end_token
);
8218 length
= (be32_to_cpu(sdt
.entry
[0].end_token
) -
8219 be32_to_cpu(sdt
.entry
[0].start_token
)) &
8220 IPR_FMT2_MBX_ADDR_MASK
;
8222 hostrcb
= list_entry(ioa_cfg
->hostrcb_free_q
.next
,
8223 struct ipr_hostrcb
, queue
);
8224 list_del(&hostrcb
->queue
);
8225 memset(&hostrcb
->hcam
, 0, sizeof(hostrcb
->hcam
));
8227 rc
= ipr_get_ldump_data_section(ioa_cfg
,
8228 be32_to_cpu(sdt
.entry
[0].start_token
),
8229 (__be32
*)&hostrcb
->hcam
,
8230 min(length
, (int)sizeof(hostrcb
->hcam
)) / sizeof(__be32
));
8233 ipr_handle_log_data(ioa_cfg
, hostrcb
);
8234 ioasc
= be32_to_cpu(hostrcb
->hcam
.u
.error
.fd_ioasc
);
8235 if (ioasc
== IPR_IOASC_NR_IOA_RESET_REQUIRED
&&
8236 ioa_cfg
->sdt_state
== GET_DUMP
)
8237 ioa_cfg
->sdt_state
= WAIT_FOR_DUMP
;
8239 ipr_unit_check_no_data(ioa_cfg
);
8241 list_add_tail(&hostrcb
->queue
, &ioa_cfg
->hostrcb_free_q
);
8245 * ipr_reset_get_unit_check_job - Call to get the unit check buffer.
8246 * @ipr_cmd: ipr command struct
8248 * Description: This function will call to get the unit check buffer.
8253 static int ipr_reset_get_unit_check_job(struct ipr_cmnd
*ipr_cmd
)
8255 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
8258 ioa_cfg
->ioa_unit_checked
= 0;
8259 ipr_get_unit_check_buffer(ioa_cfg
);
8260 ipr_cmd
->job_step
= ipr_reset_alert
;
8261 ipr_reset_start_timer(ipr_cmd
, 0);
8264 return IPR_RC_JOB_RETURN
;
8268 * ipr_reset_restore_cfg_space - Restore PCI config space.
8269 * @ipr_cmd: ipr command struct
8271 * Description: This function restores the saved PCI config space of
8272 * the adapter, fails all outstanding ops back to the callers, and
8273 * fetches the dump/unit check if applicable to this reset.
8276 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
8278 static int ipr_reset_restore_cfg_space(struct ipr_cmnd
*ipr_cmd
)
8280 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
8284 ioa_cfg
->pdev
->state_saved
= true;
8285 pci_restore_state(ioa_cfg
->pdev
);
8287 if (ipr_set_pcix_cmd_reg(ioa_cfg
)) {
8288 ipr_cmd
->s
.ioasa
.hdr
.ioasc
= cpu_to_be32(IPR_IOASC_PCI_ACCESS_ERROR
);
8289 return IPR_RC_JOB_CONTINUE
;
8292 ipr_fail_all_ops(ioa_cfg
);
8294 if (ioa_cfg
->sis64
) {
8295 /* Set the adapter to the correct endian mode. */
8296 writel(IPR_ENDIAN_SWAP_KEY
, ioa_cfg
->regs
.endian_swap_reg
);
8297 int_reg
= readl(ioa_cfg
->regs
.endian_swap_reg
);
8300 if (ioa_cfg
->ioa_unit_checked
) {
8301 if (ioa_cfg
->sis64
) {
8302 ipr_cmd
->job_step
= ipr_reset_get_unit_check_job
;
8303 ipr_reset_start_timer(ipr_cmd
, IPR_DUMP_DELAY_TIMEOUT
);
8304 return IPR_RC_JOB_RETURN
;
8306 ioa_cfg
->ioa_unit_checked
= 0;
8307 ipr_get_unit_check_buffer(ioa_cfg
);
8308 ipr_cmd
->job_step
= ipr_reset_alert
;
8309 ipr_reset_start_timer(ipr_cmd
, 0);
8310 return IPR_RC_JOB_RETURN
;
8314 if (ioa_cfg
->in_ioa_bringdown
) {
8315 ipr_cmd
->job_step
= ipr_ioa_bringdown_done
;
8317 ipr_cmd
->job_step
= ipr_reset_enable_ioa
;
8319 if (GET_DUMP
== ioa_cfg
->sdt_state
) {
8320 ioa_cfg
->sdt_state
= READ_DUMP
;
8321 ioa_cfg
->dump_timeout
= 0;
8323 ipr_reset_start_timer(ipr_cmd
, IPR_SIS64_DUMP_TIMEOUT
);
8325 ipr_reset_start_timer(ipr_cmd
, IPR_SIS32_DUMP_TIMEOUT
);
8326 ipr_cmd
->job_step
= ipr_reset_wait_for_dump
;
8327 schedule_work(&ioa_cfg
->work_q
);
8328 return IPR_RC_JOB_RETURN
;
8333 return IPR_RC_JOB_CONTINUE
;
8337 * ipr_reset_bist_done - BIST has completed on the adapter.
8338 * @ipr_cmd: ipr command struct
8340 * Description: Unblock config space and resume the reset process.
8343 * IPR_RC_JOB_CONTINUE
8345 static int ipr_reset_bist_done(struct ipr_cmnd
*ipr_cmd
)
8347 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
8350 if (ioa_cfg
->cfg_locked
)
8351 pci_cfg_access_unlock(ioa_cfg
->pdev
);
8352 ioa_cfg
->cfg_locked
= 0;
8353 ipr_cmd
->job_step
= ipr_reset_restore_cfg_space
;
8355 return IPR_RC_JOB_CONTINUE
;
8359 * ipr_reset_start_bist - Run BIST on the adapter.
8360 * @ipr_cmd: ipr command struct
8362 * Description: This function runs BIST on the adapter, then delays 2 seconds.
8365 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
8367 static int ipr_reset_start_bist(struct ipr_cmnd
*ipr_cmd
)
8369 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
8370 int rc
= PCIBIOS_SUCCESSFUL
;
8373 if (ioa_cfg
->ipr_chip
->bist_method
== IPR_MMIO
)
8374 writel(IPR_UPROCI_SIS64_START_BIST
,
8375 ioa_cfg
->regs
.set_uproc_interrupt_reg32
);
8377 rc
= pci_write_config_byte(ioa_cfg
->pdev
, PCI_BIST
, PCI_BIST_START
);
8379 if (rc
== PCIBIOS_SUCCESSFUL
) {
8380 ipr_cmd
->job_step
= ipr_reset_bist_done
;
8381 ipr_reset_start_timer(ipr_cmd
, IPR_WAIT_FOR_BIST_TIMEOUT
);
8382 rc
= IPR_RC_JOB_RETURN
;
8384 if (ioa_cfg
->cfg_locked
)
8385 pci_cfg_access_unlock(ipr_cmd
->ioa_cfg
->pdev
);
8386 ioa_cfg
->cfg_locked
= 0;
8387 ipr_cmd
->s
.ioasa
.hdr
.ioasc
= cpu_to_be32(IPR_IOASC_PCI_ACCESS_ERROR
);
8388 rc
= IPR_RC_JOB_CONTINUE
;
8396 * ipr_reset_slot_reset_done - Clear PCI reset to the adapter
8397 * @ipr_cmd: ipr command struct
8399 * Description: This clears PCI reset to the adapter and delays two seconds.
8404 static int ipr_reset_slot_reset_done(struct ipr_cmnd
*ipr_cmd
)
8407 ipr_cmd
->job_step
= ipr_reset_bist_done
;
8408 ipr_reset_start_timer(ipr_cmd
, IPR_WAIT_FOR_BIST_TIMEOUT
);
8410 return IPR_RC_JOB_RETURN
;
8414 * ipr_reset_reset_work - Pulse a PCIe fundamental reset
8415 * @work: work struct
8417 * Description: This pulses warm reset to a slot.
8420 static void ipr_reset_reset_work(struct work_struct
*work
)
8422 struct ipr_cmnd
*ipr_cmd
= container_of(work
, struct ipr_cmnd
, work
);
8423 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
8424 struct pci_dev
*pdev
= ioa_cfg
->pdev
;
8425 unsigned long lock_flags
= 0;
8428 pci_set_pcie_reset_state(pdev
, pcie_warm_reset
);
8429 msleep(jiffies_to_msecs(IPR_PCI_RESET_TIMEOUT
));
8430 pci_set_pcie_reset_state(pdev
, pcie_deassert_reset
);
8432 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
8433 if (ioa_cfg
->reset_cmd
== ipr_cmd
)
8434 ipr_reset_ioa_job(ipr_cmd
);
8435 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
8440 * ipr_reset_slot_reset - Reset the PCI slot of the adapter.
8441 * @ipr_cmd: ipr command struct
8443 * Description: This asserts PCI reset to the adapter.
8448 static int ipr_reset_slot_reset(struct ipr_cmnd
*ipr_cmd
)
8450 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
8453 INIT_WORK(&ipr_cmd
->work
, ipr_reset_reset_work
);
8454 queue_work(ioa_cfg
->reset_work_q
, &ipr_cmd
->work
);
8455 ipr_cmd
->job_step
= ipr_reset_slot_reset_done
;
8457 return IPR_RC_JOB_RETURN
;
8461 * ipr_reset_block_config_access_wait - Wait for permission to block config access
8462 * @ipr_cmd: ipr command struct
8464 * Description: This attempts to block config access to the IOA.
8467 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
8469 static int ipr_reset_block_config_access_wait(struct ipr_cmnd
*ipr_cmd
)
8471 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
8472 int rc
= IPR_RC_JOB_CONTINUE
;
8474 if (pci_cfg_access_trylock(ioa_cfg
->pdev
)) {
8475 ioa_cfg
->cfg_locked
= 1;
8476 ipr_cmd
->job_step
= ioa_cfg
->reset
;
8478 if (ipr_cmd
->u
.time_left
) {
8479 rc
= IPR_RC_JOB_RETURN
;
8480 ipr_cmd
->u
.time_left
-= IPR_CHECK_FOR_RESET_TIMEOUT
;
8481 ipr_reset_start_timer(ipr_cmd
,
8482 IPR_CHECK_FOR_RESET_TIMEOUT
);
8484 ipr_cmd
->job_step
= ioa_cfg
->reset
;
8485 dev_err(&ioa_cfg
->pdev
->dev
,
8486 "Timed out waiting to lock config access. Resetting anyway.\n");
8494 * ipr_reset_block_config_access - Block config access to the IOA
8495 * @ipr_cmd: ipr command struct
8497 * Description: This attempts to block config access to the IOA
8500 * IPR_RC_JOB_CONTINUE
8502 static int ipr_reset_block_config_access(struct ipr_cmnd
*ipr_cmd
)
8504 ipr_cmd
->ioa_cfg
->cfg_locked
= 0;
8505 ipr_cmd
->job_step
= ipr_reset_block_config_access_wait
;
8506 ipr_cmd
->u
.time_left
= IPR_WAIT_FOR_RESET_TIMEOUT
;
8507 return IPR_RC_JOB_CONTINUE
;
8511 * ipr_reset_allowed - Query whether or not IOA can be reset
8512 * @ioa_cfg: ioa config struct
8515 * 0 if reset not allowed / non-zero if reset is allowed
8517 static int ipr_reset_allowed(struct ipr_ioa_cfg
*ioa_cfg
)
8519 volatile u32 temp_reg
;
8521 temp_reg
= readl(ioa_cfg
->regs
.sense_interrupt_reg
);
8522 return ((temp_reg
& IPR_PCII_CRITICAL_OPERATION
) == 0);
8526 * ipr_reset_wait_to_start_bist - Wait for permission to reset IOA.
8527 * @ipr_cmd: ipr command struct
8529 * Description: This function waits for adapter permission to run BIST,
8530 * then runs BIST. If the adapter does not give permission after a
8531 * reasonable time, we will reset the adapter anyway. The impact of
8532 * resetting the adapter without warning the adapter is the risk of
8533 * losing the persistent error log on the adapter. If the adapter is
8534 * reset while it is writing to the flash on the adapter, the flash
8535 * segment will have bad ECC and be zeroed.
8538 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
8540 static int ipr_reset_wait_to_start_bist(struct ipr_cmnd
*ipr_cmd
)
8542 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
8543 int rc
= IPR_RC_JOB_RETURN
;
8545 if (!ipr_reset_allowed(ioa_cfg
) && ipr_cmd
->u
.time_left
) {
8546 ipr_cmd
->u
.time_left
-= IPR_CHECK_FOR_RESET_TIMEOUT
;
8547 ipr_reset_start_timer(ipr_cmd
, IPR_CHECK_FOR_RESET_TIMEOUT
);
8549 ipr_cmd
->job_step
= ipr_reset_block_config_access
;
8550 rc
= IPR_RC_JOB_CONTINUE
;
8557 * ipr_reset_alert - Alert the adapter of a pending reset
8558 * @ipr_cmd: ipr command struct
8560 * Description: This function alerts the adapter that it will be reset.
8561 * If memory space is not currently enabled, proceed directly
8562 * to running BIST on the adapter. The timer must always be started
8563 * so we guarantee we do not run BIST from ipr_isr.
8568 static int ipr_reset_alert(struct ipr_cmnd
*ipr_cmd
)
8570 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
8575 rc
= pci_read_config_word(ioa_cfg
->pdev
, PCI_COMMAND
, &cmd_reg
);
8577 if ((rc
== PCIBIOS_SUCCESSFUL
) && (cmd_reg
& PCI_COMMAND_MEMORY
)) {
8578 ipr_mask_and_clear_interrupts(ioa_cfg
, ~0);
8579 writel(IPR_UPROCI_RESET_ALERT
, ioa_cfg
->regs
.set_uproc_interrupt_reg32
);
8580 ipr_cmd
->job_step
= ipr_reset_wait_to_start_bist
;
8582 ipr_cmd
->job_step
= ipr_reset_block_config_access
;
8585 ipr_cmd
->u
.time_left
= IPR_WAIT_FOR_RESET_TIMEOUT
;
8586 ipr_reset_start_timer(ipr_cmd
, IPR_CHECK_FOR_RESET_TIMEOUT
);
8589 return IPR_RC_JOB_RETURN
;
8593 * ipr_reset_quiesce_done - Complete IOA disconnect
8594 * @ipr_cmd: ipr command struct
8596 * Description: Freeze the adapter to complete quiesce processing
8599 * IPR_RC_JOB_CONTINUE
8601 static int ipr_reset_quiesce_done(struct ipr_cmnd
*ipr_cmd
)
8603 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
8606 ipr_cmd
->job_step
= ipr_ioa_bringdown_done
;
8607 ipr_mask_and_clear_interrupts(ioa_cfg
, ~IPR_PCII_IOA_TRANS_TO_OPER
);
8609 return IPR_RC_JOB_CONTINUE
;
8613 * ipr_reset_cancel_hcam_done - Check for outstanding commands
8614 * @ipr_cmd: ipr command struct
8616 * Description: Ensure nothing is outstanding to the IOA and
8617 * proceed with IOA disconnect. Otherwise reset the IOA.
8620 * IPR_RC_JOB_RETURN / IPR_RC_JOB_CONTINUE
8622 static int ipr_reset_cancel_hcam_done(struct ipr_cmnd
*ipr_cmd
)
8624 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
8625 struct ipr_cmnd
*loop_cmd
;
8626 struct ipr_hrr_queue
*hrrq
;
8627 int rc
= IPR_RC_JOB_CONTINUE
;
8631 ipr_cmd
->job_step
= ipr_reset_quiesce_done
;
8633 for_each_hrrq(hrrq
, ioa_cfg
) {
8634 spin_lock(&hrrq
->_lock
);
8635 list_for_each_entry(loop_cmd
, &hrrq
->hrrq_pending_q
, queue
) {
8637 ipr_initiate_ioa_reset(ioa_cfg
, IPR_SHUTDOWN_NONE
);
8638 list_add_tail(&ipr_cmd
->queue
, &ipr_cmd
->hrrq
->hrrq_free_q
);
8639 rc
= IPR_RC_JOB_RETURN
;
8642 spin_unlock(&hrrq
->_lock
);
8653 * ipr_reset_cancel_hcam - Cancel outstanding HCAMs
8654 * @ipr_cmd: ipr command struct
8656 * Description: Cancel any oustanding HCAMs to the IOA.
8659 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
8661 static int ipr_reset_cancel_hcam(struct ipr_cmnd
*ipr_cmd
)
8663 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
8664 int rc
= IPR_RC_JOB_CONTINUE
;
8665 struct ipr_cmd_pkt
*cmd_pkt
;
8666 struct ipr_cmnd
*hcam_cmd
;
8667 struct ipr_hrr_queue
*hrrq
= &ioa_cfg
->hrrq
[IPR_INIT_HRRQ
];
8670 ipr_cmd
->job_step
= ipr_reset_cancel_hcam_done
;
8672 if (!hrrq
->ioa_is_dead
) {
8673 if (!list_empty(&ioa_cfg
->hostrcb_pending_q
)) {
8674 list_for_each_entry(hcam_cmd
, &hrrq
->hrrq_pending_q
, queue
) {
8675 if (hcam_cmd
->ioarcb
.cmd_pkt
.cdb
[0] != IPR_HOST_CONTROLLED_ASYNC
)
8678 ipr_cmd
->ioarcb
.res_handle
= cpu_to_be32(IPR_IOA_RES_HANDLE
);
8679 ipr_cmd
->ioarcb
.cmd_pkt
.request_type
= IPR_RQTYPE_IOACMD
;
8680 cmd_pkt
= &ipr_cmd
->ioarcb
.cmd_pkt
;
8681 cmd_pkt
->request_type
= IPR_RQTYPE_IOACMD
;
8682 cmd_pkt
->cdb
[0] = IPR_CANCEL_REQUEST
;
8683 cmd_pkt
->cdb
[1] = IPR_CANCEL_64BIT_IOARCB
;
8684 cmd_pkt
->cdb
[10] = ((u64
) hcam_cmd
->dma_addr
>> 56) & 0xff;
8685 cmd_pkt
->cdb
[11] = ((u64
) hcam_cmd
->dma_addr
>> 48) & 0xff;
8686 cmd_pkt
->cdb
[12] = ((u64
) hcam_cmd
->dma_addr
>> 40) & 0xff;
8687 cmd_pkt
->cdb
[13] = ((u64
) hcam_cmd
->dma_addr
>> 32) & 0xff;
8688 cmd_pkt
->cdb
[2] = ((u64
) hcam_cmd
->dma_addr
>> 24) & 0xff;
8689 cmd_pkt
->cdb
[3] = ((u64
) hcam_cmd
->dma_addr
>> 16) & 0xff;
8690 cmd_pkt
->cdb
[4] = ((u64
) hcam_cmd
->dma_addr
>> 8) & 0xff;
8691 cmd_pkt
->cdb
[5] = ((u64
) hcam_cmd
->dma_addr
) & 0xff;
8693 ipr_do_req(ipr_cmd
, ipr_reset_ioa_job
, ipr_timeout
,
8694 IPR_CANCEL_TIMEOUT
);
8696 rc
= IPR_RC_JOB_RETURN
;
8697 ipr_cmd
->job_step
= ipr_reset_cancel_hcam
;
8702 ipr_cmd
->job_step
= ipr_reset_alert
;
8709 * ipr_reset_ucode_download_done - Microcode download completion
8710 * @ipr_cmd: ipr command struct
8712 * Description: This function unmaps the microcode download buffer.
8715 * IPR_RC_JOB_CONTINUE
8717 static int ipr_reset_ucode_download_done(struct ipr_cmnd
*ipr_cmd
)
8719 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
8720 struct ipr_sglist
*sglist
= ioa_cfg
->ucode_sglist
;
8722 dma_unmap_sg(&ioa_cfg
->pdev
->dev
, sglist
->scatterlist
,
8723 sglist
->num_sg
, DMA_TO_DEVICE
);
8725 ipr_cmd
->job_step
= ipr_reset_alert
;
8726 return IPR_RC_JOB_CONTINUE
;
8730 * ipr_reset_ucode_download - Download microcode to the adapter
8731 * @ipr_cmd: ipr command struct
8733 * Description: This function checks to see if it there is microcode
8734 * to download to the adapter. If there is, a download is performed.
8737 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
8739 static int ipr_reset_ucode_download(struct ipr_cmnd
*ipr_cmd
)
8741 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
8742 struct ipr_sglist
*sglist
= ioa_cfg
->ucode_sglist
;
8745 ipr_cmd
->job_step
= ipr_reset_alert
;
8748 return IPR_RC_JOB_CONTINUE
;
8750 ipr_cmd
->ioarcb
.res_handle
= cpu_to_be32(IPR_IOA_RES_HANDLE
);
8751 ipr_cmd
->ioarcb
.cmd_pkt
.request_type
= IPR_RQTYPE_SCSICDB
;
8752 ipr_cmd
->ioarcb
.cmd_pkt
.cdb
[0] = WRITE_BUFFER
;
8753 ipr_cmd
->ioarcb
.cmd_pkt
.cdb
[1] = IPR_WR_BUF_DOWNLOAD_AND_SAVE
;
8754 ipr_cmd
->ioarcb
.cmd_pkt
.cdb
[6] = (sglist
->buffer_len
& 0xff0000) >> 16;
8755 ipr_cmd
->ioarcb
.cmd_pkt
.cdb
[7] = (sglist
->buffer_len
& 0x00ff00) >> 8;
8756 ipr_cmd
->ioarcb
.cmd_pkt
.cdb
[8] = sglist
->buffer_len
& 0x0000ff;
8759 ipr_build_ucode_ioadl64(ipr_cmd
, sglist
);
8761 ipr_build_ucode_ioadl(ipr_cmd
, sglist
);
8762 ipr_cmd
->job_step
= ipr_reset_ucode_download_done
;
8764 ipr_do_req(ipr_cmd
, ipr_reset_ioa_job
, ipr_timeout
,
8765 IPR_WRITE_BUFFER_TIMEOUT
);
8768 return IPR_RC_JOB_RETURN
;
8772 * ipr_reset_shutdown_ioa - Shutdown the adapter
8773 * @ipr_cmd: ipr command struct
8775 * Description: This function issues an adapter shutdown of the
8776 * specified type to the specified adapter as part of the
8777 * adapter reset job.
8780 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
8782 static int ipr_reset_shutdown_ioa(struct ipr_cmnd
*ipr_cmd
)
8784 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
8785 enum ipr_shutdown_type shutdown_type
= ipr_cmd
->u
.shutdown_type
;
8786 unsigned long timeout
;
8787 int rc
= IPR_RC_JOB_CONTINUE
;
8790 if (shutdown_type
== IPR_SHUTDOWN_QUIESCE
)
8791 ipr_cmd
->job_step
= ipr_reset_cancel_hcam
;
8792 else if (shutdown_type
!= IPR_SHUTDOWN_NONE
&&
8793 !ioa_cfg
->hrrq
[IPR_INIT_HRRQ
].ioa_is_dead
) {
8794 ipr_cmd
->ioarcb
.res_handle
= cpu_to_be32(IPR_IOA_RES_HANDLE
);
8795 ipr_cmd
->ioarcb
.cmd_pkt
.request_type
= IPR_RQTYPE_IOACMD
;
8796 ipr_cmd
->ioarcb
.cmd_pkt
.cdb
[0] = IPR_IOA_SHUTDOWN
;
8797 ipr_cmd
->ioarcb
.cmd_pkt
.cdb
[1] = shutdown_type
;
8799 if (shutdown_type
== IPR_SHUTDOWN_NORMAL
)
8800 timeout
= IPR_SHUTDOWN_TIMEOUT
;
8801 else if (shutdown_type
== IPR_SHUTDOWN_PREPARE_FOR_NORMAL
)
8802 timeout
= IPR_INTERNAL_TIMEOUT
;
8803 else if (ioa_cfg
->dual_raid
&& ipr_dual_ioa_raid
)
8804 timeout
= IPR_DUAL_IOA_ABBR_SHUTDOWN_TO
;
8806 timeout
= IPR_ABBREV_SHUTDOWN_TIMEOUT
;
8808 ipr_do_req(ipr_cmd
, ipr_reset_ioa_job
, ipr_timeout
, timeout
);
8810 rc
= IPR_RC_JOB_RETURN
;
8811 ipr_cmd
->job_step
= ipr_reset_ucode_download
;
8813 ipr_cmd
->job_step
= ipr_reset_alert
;
8820 * ipr_reset_ioa_job - Adapter reset job
8821 * @ipr_cmd: ipr command struct
8823 * Description: This function is the job router for the adapter reset job.
8828 static void ipr_reset_ioa_job(struct ipr_cmnd
*ipr_cmd
)
8831 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
8834 ioasc
= be32_to_cpu(ipr_cmd
->s
.ioasa
.hdr
.ioasc
);
8836 if (ioa_cfg
->reset_cmd
!= ipr_cmd
) {
8838 * We are doing nested adapter resets and this is
8839 * not the current reset job.
8841 list_add_tail(&ipr_cmd
->queue
,
8842 &ipr_cmd
->hrrq
->hrrq_free_q
);
8846 if (IPR_IOASC_SENSE_KEY(ioasc
)) {
8847 rc
= ipr_cmd
->job_step_failed(ipr_cmd
);
8848 if (rc
== IPR_RC_JOB_RETURN
)
8852 ipr_reinit_ipr_cmnd(ipr_cmd
);
8853 ipr_cmd
->job_step_failed
= ipr_reset_cmd_failed
;
8854 rc
= ipr_cmd
->job_step(ipr_cmd
);
8855 } while (rc
== IPR_RC_JOB_CONTINUE
);
8859 * _ipr_initiate_ioa_reset - Initiate an adapter reset
8860 * @ioa_cfg: ioa config struct
8861 * @job_step: first job step of reset job
8862 * @shutdown_type: shutdown type
8864 * Description: This function will initiate the reset of the given adapter
8865 * starting at the selected job step.
8866 * If the caller needs to wait on the completion of the reset,
8867 * the caller must sleep on the reset_wait_q.
8872 static void _ipr_initiate_ioa_reset(struct ipr_ioa_cfg
*ioa_cfg
,
8873 int (*job_step
) (struct ipr_cmnd
*),
8874 enum ipr_shutdown_type shutdown_type
)
8876 struct ipr_cmnd
*ipr_cmd
;
8879 ioa_cfg
->in_reset_reload
= 1;
8880 for (i
= 0; i
< ioa_cfg
->hrrq_num
; i
++) {
8881 spin_lock(&ioa_cfg
->hrrq
[i
]._lock
);
8882 ioa_cfg
->hrrq
[i
].allow_cmds
= 0;
8883 spin_unlock(&ioa_cfg
->hrrq
[i
]._lock
);
8886 if (!ioa_cfg
->hrrq
[IPR_INIT_HRRQ
].removing_ioa
)
8887 scsi_block_requests(ioa_cfg
->host
);
8889 ipr_cmd
= ipr_get_free_ipr_cmnd(ioa_cfg
);
8890 ioa_cfg
->reset_cmd
= ipr_cmd
;
8891 ipr_cmd
->job_step
= job_step
;
8892 ipr_cmd
->u
.shutdown_type
= shutdown_type
;
8894 ipr_reset_ioa_job(ipr_cmd
);
8898 * ipr_initiate_ioa_reset - Initiate an adapter reset
8899 * @ioa_cfg: ioa config struct
8900 * @shutdown_type: shutdown type
8902 * Description: This function will initiate the reset of the given adapter.
8903 * If the caller needs to wait on the completion of the reset,
8904 * the caller must sleep on the reset_wait_q.
8909 static void ipr_initiate_ioa_reset(struct ipr_ioa_cfg
*ioa_cfg
,
8910 enum ipr_shutdown_type shutdown_type
)
8914 if (ioa_cfg
->hrrq
[IPR_INIT_HRRQ
].ioa_is_dead
)
8917 if (ioa_cfg
->in_reset_reload
) {
8918 if (ioa_cfg
->sdt_state
== GET_DUMP
)
8919 ioa_cfg
->sdt_state
= WAIT_FOR_DUMP
;
8920 else if (ioa_cfg
->sdt_state
== READ_DUMP
)
8921 ioa_cfg
->sdt_state
= ABORT_DUMP
;
8924 if (ioa_cfg
->reset_retries
++ >= IPR_NUM_RESET_RELOAD_RETRIES
) {
8925 dev_err(&ioa_cfg
->pdev
->dev
,
8926 "IOA taken offline - error recovery failed\n");
8928 ioa_cfg
->reset_retries
= 0;
8929 for (i
= 0; i
< ioa_cfg
->hrrq_num
; i
++) {
8930 spin_lock(&ioa_cfg
->hrrq
[i
]._lock
);
8931 ioa_cfg
->hrrq
[i
].ioa_is_dead
= 1;
8932 spin_unlock(&ioa_cfg
->hrrq
[i
]._lock
);
8936 if (ioa_cfg
->in_ioa_bringdown
) {
8937 ioa_cfg
->reset_cmd
= NULL
;
8938 ioa_cfg
->in_reset_reload
= 0;
8939 ipr_fail_all_ops(ioa_cfg
);
8940 wake_up_all(&ioa_cfg
->reset_wait_q
);
8942 if (!ioa_cfg
->hrrq
[IPR_INIT_HRRQ
].removing_ioa
) {
8943 spin_unlock_irq(ioa_cfg
->host
->host_lock
);
8944 scsi_unblock_requests(ioa_cfg
->host
);
8945 spin_lock_irq(ioa_cfg
->host
->host_lock
);
8949 ioa_cfg
->in_ioa_bringdown
= 1;
8950 shutdown_type
= IPR_SHUTDOWN_NONE
;
8954 _ipr_initiate_ioa_reset(ioa_cfg
, ipr_reset_shutdown_ioa
,
8959 * ipr_reset_freeze - Hold off all I/O activity
8960 * @ipr_cmd: ipr command struct
8962 * Description: If the PCI slot is frozen, hold off all I/O
8963 * activity; then, as soon as the slot is available again,
8964 * initiate an adapter reset.
8966 static int ipr_reset_freeze(struct ipr_cmnd
*ipr_cmd
)
8968 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
8971 /* Disallow new interrupts, avoid loop */
8972 for (i
= 0; i
< ioa_cfg
->hrrq_num
; i
++) {
8973 spin_lock(&ioa_cfg
->hrrq
[i
]._lock
);
8974 ioa_cfg
->hrrq
[i
].allow_interrupts
= 0;
8975 spin_unlock(&ioa_cfg
->hrrq
[i
]._lock
);
8978 list_add_tail(&ipr_cmd
->queue
, &ipr_cmd
->hrrq
->hrrq_pending_q
);
8979 ipr_cmd
->done
= ipr_reset_ioa_job
;
8980 return IPR_RC_JOB_RETURN
;
8984 * ipr_pci_mmio_enabled - Called when MMIO has been re-enabled
8985 * @pdev: PCI device struct
8987 * Description: This routine is called to tell us that the MMIO
8988 * access to the IOA has been restored
8990 static pci_ers_result_t
ipr_pci_mmio_enabled(struct pci_dev
*pdev
)
8992 unsigned long flags
= 0;
8993 struct ipr_ioa_cfg
*ioa_cfg
= pci_get_drvdata(pdev
);
8995 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, flags
);
8996 if (!ioa_cfg
->probe_done
)
8997 pci_save_state(pdev
);
8998 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, flags
);
8999 return PCI_ERS_RESULT_NEED_RESET
;
9003 * ipr_pci_frozen - Called when slot has experienced a PCI bus error.
9004 * @pdev: PCI device struct
9006 * Description: This routine is called to tell us that the PCI bus
9007 * is down. Can't do anything here, except put the device driver
9008 * into a holding pattern, waiting for the PCI bus to come back.
9010 static void ipr_pci_frozen(struct pci_dev
*pdev
)
9012 unsigned long flags
= 0;
9013 struct ipr_ioa_cfg
*ioa_cfg
= pci_get_drvdata(pdev
);
9015 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, flags
);
9016 if (ioa_cfg
->probe_done
)
9017 _ipr_initiate_ioa_reset(ioa_cfg
, ipr_reset_freeze
, IPR_SHUTDOWN_NONE
);
9018 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, flags
);
9022 * ipr_pci_slot_reset - Called when PCI slot has been reset.
9023 * @pdev: PCI device struct
9025 * Description: This routine is called by the pci error recovery
9026 * code after the PCI slot has been reset, just before we
9027 * should resume normal operations.
9029 static pci_ers_result_t
ipr_pci_slot_reset(struct pci_dev
*pdev
)
9031 unsigned long flags
= 0;
9032 struct ipr_ioa_cfg
*ioa_cfg
= pci_get_drvdata(pdev
);
9034 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, flags
);
9035 if (ioa_cfg
->probe_done
) {
9036 if (ioa_cfg
->needs_warm_reset
)
9037 ipr_initiate_ioa_reset(ioa_cfg
, IPR_SHUTDOWN_NONE
);
9039 _ipr_initiate_ioa_reset(ioa_cfg
, ipr_reset_restore_cfg_space
,
9042 wake_up_all(&ioa_cfg
->eeh_wait_q
);
9043 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, flags
);
9044 return PCI_ERS_RESULT_RECOVERED
;
9048 * ipr_pci_perm_failure - Called when PCI slot is dead for good.
9049 * @pdev: PCI device struct
9051 * Description: This routine is called when the PCI bus has
9052 * permanently failed.
9054 static void ipr_pci_perm_failure(struct pci_dev
*pdev
)
9056 unsigned long flags
= 0;
9057 struct ipr_ioa_cfg
*ioa_cfg
= pci_get_drvdata(pdev
);
9060 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, flags
);
9061 if (ioa_cfg
->probe_done
) {
9062 if (ioa_cfg
->sdt_state
== WAIT_FOR_DUMP
)
9063 ioa_cfg
->sdt_state
= ABORT_DUMP
;
9064 ioa_cfg
->reset_retries
= IPR_NUM_RESET_RELOAD_RETRIES
- 1;
9065 ioa_cfg
->in_ioa_bringdown
= 1;
9066 for (i
= 0; i
< ioa_cfg
->hrrq_num
; i
++) {
9067 spin_lock(&ioa_cfg
->hrrq
[i
]._lock
);
9068 ioa_cfg
->hrrq
[i
].allow_cmds
= 0;
9069 spin_unlock(&ioa_cfg
->hrrq
[i
]._lock
);
9072 ipr_initiate_ioa_reset(ioa_cfg
, IPR_SHUTDOWN_NONE
);
9074 wake_up_all(&ioa_cfg
->eeh_wait_q
);
9075 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, flags
);
9079 * ipr_pci_error_detected - Called when a PCI error is detected.
9080 * @pdev: PCI device struct
9081 * @state: PCI channel state
9083 * Description: Called when a PCI error is detected.
9086 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
9088 static pci_ers_result_t
ipr_pci_error_detected(struct pci_dev
*pdev
,
9089 pci_channel_state_t state
)
9092 case pci_channel_io_frozen
:
9093 ipr_pci_frozen(pdev
);
9094 return PCI_ERS_RESULT_CAN_RECOVER
;
9095 case pci_channel_io_perm_failure
:
9096 ipr_pci_perm_failure(pdev
);
9097 return PCI_ERS_RESULT_DISCONNECT
;
9102 return PCI_ERS_RESULT_NEED_RESET
;
9106 * ipr_probe_ioa_part2 - Initializes IOAs found in ipr_probe_ioa(..)
9107 * @ioa_cfg: ioa cfg struct
9109 * Description: This is the second phase of adapter intialization
9110 * This function takes care of initilizing the adapter to the point
9111 * where it can accept new commands.
9114 * 0 on success / -EIO on failure
9116 static int ipr_probe_ioa_part2(struct ipr_ioa_cfg
*ioa_cfg
)
9119 unsigned long host_lock_flags
= 0;
9122 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, host_lock_flags
);
9123 dev_dbg(&ioa_cfg
->pdev
->dev
, "ioa_cfg adx: 0x%p\n", ioa_cfg
);
9124 ioa_cfg
->probe_done
= 1;
9125 if (ioa_cfg
->needs_hard_reset
) {
9126 ioa_cfg
->needs_hard_reset
= 0;
9127 ipr_initiate_ioa_reset(ioa_cfg
, IPR_SHUTDOWN_NONE
);
9129 _ipr_initiate_ioa_reset(ioa_cfg
, ipr_reset_enable_ioa
,
9131 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, host_lock_flags
);
9138 * ipr_free_cmd_blks - Frees command blocks allocated for an adapter
9139 * @ioa_cfg: ioa config struct
9144 static void ipr_free_cmd_blks(struct ipr_ioa_cfg
*ioa_cfg
)
9148 if (ioa_cfg
->ipr_cmnd_list
) {
9149 for (i
= 0; i
< IPR_NUM_CMD_BLKS
; i
++) {
9150 if (ioa_cfg
->ipr_cmnd_list
[i
])
9151 dma_pool_free(ioa_cfg
->ipr_cmd_pool
,
9152 ioa_cfg
->ipr_cmnd_list
[i
],
9153 ioa_cfg
->ipr_cmnd_list_dma
[i
]);
9155 ioa_cfg
->ipr_cmnd_list
[i
] = NULL
;
9159 if (ioa_cfg
->ipr_cmd_pool
)
9160 dma_pool_destroy(ioa_cfg
->ipr_cmd_pool
);
9162 kfree(ioa_cfg
->ipr_cmnd_list
);
9163 kfree(ioa_cfg
->ipr_cmnd_list_dma
);
9164 ioa_cfg
->ipr_cmnd_list
= NULL
;
9165 ioa_cfg
->ipr_cmnd_list_dma
= NULL
;
9166 ioa_cfg
->ipr_cmd_pool
= NULL
;
9170 * ipr_free_mem - Frees memory allocated for an adapter
9171 * @ioa_cfg: ioa cfg struct
9176 static void ipr_free_mem(struct ipr_ioa_cfg
*ioa_cfg
)
9180 kfree(ioa_cfg
->res_entries
);
9181 dma_free_coherent(&ioa_cfg
->pdev
->dev
, sizeof(struct ipr_misc_cbs
),
9182 ioa_cfg
->vpd_cbs
, ioa_cfg
->vpd_cbs_dma
);
9183 ipr_free_cmd_blks(ioa_cfg
);
9185 for (i
= 0; i
< ioa_cfg
->hrrq_num
; i
++)
9186 dma_free_coherent(&ioa_cfg
->pdev
->dev
,
9187 sizeof(u32
) * ioa_cfg
->hrrq
[i
].size
,
9188 ioa_cfg
->hrrq
[i
].host_rrq
,
9189 ioa_cfg
->hrrq
[i
].host_rrq_dma
);
9191 dma_free_coherent(&ioa_cfg
->pdev
->dev
, ioa_cfg
->cfg_table_size
,
9192 ioa_cfg
->u
.cfg_table
, ioa_cfg
->cfg_table_dma
);
9194 for (i
= 0; i
< IPR_NUM_HCAMS
; i
++) {
9195 dma_free_coherent(&ioa_cfg
->pdev
->dev
,
9196 sizeof(struct ipr_hostrcb
),
9197 ioa_cfg
->hostrcb
[i
],
9198 ioa_cfg
->hostrcb_dma
[i
]);
9201 ipr_free_dump(ioa_cfg
);
9202 kfree(ioa_cfg
->trace
);
9206 * ipr_free_irqs - Free all allocated IRQs for the adapter.
9207 * @ioa_cfg: ipr cfg struct
9209 * This function frees all allocated IRQs for the
9210 * specified adapter.
9215 static void ipr_free_irqs(struct ipr_ioa_cfg
*ioa_cfg
)
9217 struct pci_dev
*pdev
= ioa_cfg
->pdev
;
9219 if (ioa_cfg
->intr_flag
== IPR_USE_MSI
||
9220 ioa_cfg
->intr_flag
== IPR_USE_MSIX
) {
9222 for (i
= 0; i
< ioa_cfg
->nvectors
; i
++)
9223 free_irq(ioa_cfg
->vectors_info
[i
].vec
,
9226 free_irq(pdev
->irq
, &ioa_cfg
->hrrq
[0]);
9228 if (ioa_cfg
->intr_flag
== IPR_USE_MSI
) {
9229 pci_disable_msi(pdev
);
9230 ioa_cfg
->intr_flag
&= ~IPR_USE_MSI
;
9231 } else if (ioa_cfg
->intr_flag
== IPR_USE_MSIX
) {
9232 pci_disable_msix(pdev
);
9233 ioa_cfg
->intr_flag
&= ~IPR_USE_MSIX
;
9238 * ipr_free_all_resources - Free all allocated resources for an adapter.
9239 * @ipr_cmd: ipr command struct
9241 * This function frees all allocated resources for the
9242 * specified adapter.
9247 static void ipr_free_all_resources(struct ipr_ioa_cfg
*ioa_cfg
)
9249 struct pci_dev
*pdev
= ioa_cfg
->pdev
;
9252 ipr_free_irqs(ioa_cfg
);
9253 if (ioa_cfg
->reset_work_q
)
9254 destroy_workqueue(ioa_cfg
->reset_work_q
);
9255 iounmap(ioa_cfg
->hdw_dma_regs
);
9256 pci_release_regions(pdev
);
9257 ipr_free_mem(ioa_cfg
);
9258 scsi_host_put(ioa_cfg
->host
);
9259 pci_disable_device(pdev
);
9264 * ipr_alloc_cmd_blks - Allocate command blocks for an adapter
9265 * @ioa_cfg: ioa config struct
9268 * 0 on success / -ENOMEM on allocation failure
9270 static int ipr_alloc_cmd_blks(struct ipr_ioa_cfg
*ioa_cfg
)
9272 struct ipr_cmnd
*ipr_cmd
;
9273 struct ipr_ioarcb
*ioarcb
;
9274 dma_addr_t dma_addr
;
9275 int i
, entries_each_hrrq
, hrrq_id
= 0;
9277 ioa_cfg
->ipr_cmd_pool
= dma_pool_create(IPR_NAME
, &ioa_cfg
->pdev
->dev
,
9278 sizeof(struct ipr_cmnd
), 512, 0);
9280 if (!ioa_cfg
->ipr_cmd_pool
)
9283 ioa_cfg
->ipr_cmnd_list
= kcalloc(IPR_NUM_CMD_BLKS
, sizeof(struct ipr_cmnd
*), GFP_KERNEL
);
9284 ioa_cfg
->ipr_cmnd_list_dma
= kcalloc(IPR_NUM_CMD_BLKS
, sizeof(dma_addr_t
), GFP_KERNEL
);
9286 if (!ioa_cfg
->ipr_cmnd_list
|| !ioa_cfg
->ipr_cmnd_list_dma
) {
9287 ipr_free_cmd_blks(ioa_cfg
);
9291 for (i
= 0; i
< ioa_cfg
->hrrq_num
; i
++) {
9292 if (ioa_cfg
->hrrq_num
> 1) {
9294 entries_each_hrrq
= IPR_NUM_INTERNAL_CMD_BLKS
;
9295 ioa_cfg
->hrrq
[i
].min_cmd_id
= 0;
9296 ioa_cfg
->hrrq
[i
].max_cmd_id
=
9297 (entries_each_hrrq
- 1);
9300 IPR_NUM_BASE_CMD_BLKS
/
9301 (ioa_cfg
->hrrq_num
- 1);
9302 ioa_cfg
->hrrq
[i
].min_cmd_id
=
9303 IPR_NUM_INTERNAL_CMD_BLKS
+
9304 (i
- 1) * entries_each_hrrq
;
9305 ioa_cfg
->hrrq
[i
].max_cmd_id
=
9306 (IPR_NUM_INTERNAL_CMD_BLKS
+
9307 i
* entries_each_hrrq
- 1);
9310 entries_each_hrrq
= IPR_NUM_CMD_BLKS
;
9311 ioa_cfg
->hrrq
[i
].min_cmd_id
= 0;
9312 ioa_cfg
->hrrq
[i
].max_cmd_id
= (entries_each_hrrq
- 1);
9314 ioa_cfg
->hrrq
[i
].size
= entries_each_hrrq
;
9317 BUG_ON(ioa_cfg
->hrrq_num
== 0);
9319 i
= IPR_NUM_CMD_BLKS
-
9320 ioa_cfg
->hrrq
[ioa_cfg
->hrrq_num
- 1].max_cmd_id
- 1;
9322 ioa_cfg
->hrrq
[ioa_cfg
->hrrq_num
- 1].size
+= i
;
9323 ioa_cfg
->hrrq
[ioa_cfg
->hrrq_num
- 1].max_cmd_id
+= i
;
9326 for (i
= 0; i
< IPR_NUM_CMD_BLKS
; i
++) {
9327 ipr_cmd
= dma_pool_alloc(ioa_cfg
->ipr_cmd_pool
, GFP_KERNEL
, &dma_addr
);
9330 ipr_free_cmd_blks(ioa_cfg
);
9334 memset(ipr_cmd
, 0, sizeof(*ipr_cmd
));
9335 ioa_cfg
->ipr_cmnd_list
[i
] = ipr_cmd
;
9336 ioa_cfg
->ipr_cmnd_list_dma
[i
] = dma_addr
;
9338 ioarcb
= &ipr_cmd
->ioarcb
;
9339 ipr_cmd
->dma_addr
= dma_addr
;
9341 ioarcb
->a
.ioarcb_host_pci_addr64
= cpu_to_be64(dma_addr
);
9343 ioarcb
->a
.ioarcb_host_pci_addr
= cpu_to_be32(dma_addr
);
9345 ioarcb
->host_response_handle
= cpu_to_be32(i
<< 2);
9346 if (ioa_cfg
->sis64
) {
9347 ioarcb
->u
.sis64_addr_data
.data_ioadl_addr
=
9348 cpu_to_be64(dma_addr
+ offsetof(struct ipr_cmnd
, i
.ioadl64
));
9349 ioarcb
->u
.sis64_addr_data
.ioasa_host_pci_addr
=
9350 cpu_to_be64(dma_addr
+ offsetof(struct ipr_cmnd
, s
.ioasa64
));
9352 ioarcb
->write_ioadl_addr
=
9353 cpu_to_be32(dma_addr
+ offsetof(struct ipr_cmnd
, i
.ioadl
));
9354 ioarcb
->read_ioadl_addr
= ioarcb
->write_ioadl_addr
;
9355 ioarcb
->ioasa_host_pci_addr
=
9356 cpu_to_be32(dma_addr
+ offsetof(struct ipr_cmnd
, s
.ioasa
));
9358 ioarcb
->ioasa_len
= cpu_to_be16(sizeof(struct ipr_ioasa
));
9359 ipr_cmd
->cmd_index
= i
;
9360 ipr_cmd
->ioa_cfg
= ioa_cfg
;
9361 ipr_cmd
->sense_buffer_dma
= dma_addr
+
9362 offsetof(struct ipr_cmnd
, sense_buffer
);
9364 ipr_cmd
->ioarcb
.cmd_pkt
.hrrq_id
= hrrq_id
;
9365 ipr_cmd
->hrrq
= &ioa_cfg
->hrrq
[hrrq_id
];
9366 list_add_tail(&ipr_cmd
->queue
, &ipr_cmd
->hrrq
->hrrq_free_q
);
9367 if (i
>= ioa_cfg
->hrrq
[hrrq_id
].max_cmd_id
)
9375 * ipr_alloc_mem - Allocate memory for an adapter
9376 * @ioa_cfg: ioa config struct
9379 * 0 on success / non-zero for error
9381 static int ipr_alloc_mem(struct ipr_ioa_cfg
*ioa_cfg
)
9383 struct pci_dev
*pdev
= ioa_cfg
->pdev
;
9384 int i
, rc
= -ENOMEM
;
9387 ioa_cfg
->res_entries
= kzalloc(sizeof(struct ipr_resource_entry
) *
9388 ioa_cfg
->max_devs_supported
, GFP_KERNEL
);
9390 if (!ioa_cfg
->res_entries
)
9393 for (i
= 0; i
< ioa_cfg
->max_devs_supported
; i
++) {
9394 list_add_tail(&ioa_cfg
->res_entries
[i
].queue
, &ioa_cfg
->free_res_q
);
9395 ioa_cfg
->res_entries
[i
].ioa_cfg
= ioa_cfg
;
9398 ioa_cfg
->vpd_cbs
= dma_alloc_coherent(&pdev
->dev
,
9399 sizeof(struct ipr_misc_cbs
),
9400 &ioa_cfg
->vpd_cbs_dma
,
9403 if (!ioa_cfg
->vpd_cbs
)
9404 goto out_free_res_entries
;
9406 if (ipr_alloc_cmd_blks(ioa_cfg
))
9407 goto out_free_vpd_cbs
;
9409 for (i
= 0; i
< ioa_cfg
->hrrq_num
; i
++) {
9410 ioa_cfg
->hrrq
[i
].host_rrq
= dma_alloc_coherent(&pdev
->dev
,
9411 sizeof(u32
) * ioa_cfg
->hrrq
[i
].size
,
9412 &ioa_cfg
->hrrq
[i
].host_rrq_dma
,
9415 if (!ioa_cfg
->hrrq
[i
].host_rrq
) {
9417 dma_free_coherent(&pdev
->dev
,
9418 sizeof(u32
) * ioa_cfg
->hrrq
[i
].size
,
9419 ioa_cfg
->hrrq
[i
].host_rrq
,
9420 ioa_cfg
->hrrq
[i
].host_rrq_dma
);
9421 goto out_ipr_free_cmd_blocks
;
9423 ioa_cfg
->hrrq
[i
].ioa_cfg
= ioa_cfg
;
9426 ioa_cfg
->u
.cfg_table
= dma_alloc_coherent(&pdev
->dev
,
9427 ioa_cfg
->cfg_table_size
,
9428 &ioa_cfg
->cfg_table_dma
,
9431 if (!ioa_cfg
->u
.cfg_table
)
9432 goto out_free_host_rrq
;
9434 for (i
= 0; i
< IPR_NUM_HCAMS
; i
++) {
9435 ioa_cfg
->hostrcb
[i
] = dma_alloc_coherent(&pdev
->dev
,
9436 sizeof(struct ipr_hostrcb
),
9437 &ioa_cfg
->hostrcb_dma
[i
],
9440 if (!ioa_cfg
->hostrcb
[i
])
9441 goto out_free_hostrcb_dma
;
9443 ioa_cfg
->hostrcb
[i
]->hostrcb_dma
=
9444 ioa_cfg
->hostrcb_dma
[i
] + offsetof(struct ipr_hostrcb
, hcam
);
9445 ioa_cfg
->hostrcb
[i
]->ioa_cfg
= ioa_cfg
;
9446 list_add_tail(&ioa_cfg
->hostrcb
[i
]->queue
, &ioa_cfg
->hostrcb_free_q
);
9449 ioa_cfg
->trace
= kzalloc(sizeof(struct ipr_trace_entry
) *
9450 IPR_NUM_TRACE_ENTRIES
, GFP_KERNEL
);
9452 if (!ioa_cfg
->trace
)
9453 goto out_free_hostrcb_dma
;
9460 out_free_hostrcb_dma
:
9462 dma_free_coherent(&pdev
->dev
, sizeof(struct ipr_hostrcb
),
9463 ioa_cfg
->hostrcb
[i
],
9464 ioa_cfg
->hostrcb_dma
[i
]);
9466 dma_free_coherent(&pdev
->dev
, ioa_cfg
->cfg_table_size
,
9467 ioa_cfg
->u
.cfg_table
, ioa_cfg
->cfg_table_dma
);
9469 for (i
= 0; i
< ioa_cfg
->hrrq_num
; i
++) {
9470 dma_free_coherent(&pdev
->dev
,
9471 sizeof(u32
) * ioa_cfg
->hrrq
[i
].size
,
9472 ioa_cfg
->hrrq
[i
].host_rrq
,
9473 ioa_cfg
->hrrq
[i
].host_rrq_dma
);
9475 out_ipr_free_cmd_blocks
:
9476 ipr_free_cmd_blks(ioa_cfg
);
9478 dma_free_coherent(&pdev
->dev
, sizeof(struct ipr_misc_cbs
),
9479 ioa_cfg
->vpd_cbs
, ioa_cfg
->vpd_cbs_dma
);
9480 out_free_res_entries
:
9481 kfree(ioa_cfg
->res_entries
);
9486 * ipr_initialize_bus_attr - Initialize SCSI bus attributes to default values
9487 * @ioa_cfg: ioa config struct
9492 static void ipr_initialize_bus_attr(struct ipr_ioa_cfg
*ioa_cfg
)
9496 for (i
= 0; i
< IPR_MAX_NUM_BUSES
; i
++) {
9497 ioa_cfg
->bus_attr
[i
].bus
= i
;
9498 ioa_cfg
->bus_attr
[i
].qas_enabled
= 0;
9499 ioa_cfg
->bus_attr
[i
].bus_width
= IPR_DEFAULT_BUS_WIDTH
;
9500 if (ipr_max_speed
< ARRAY_SIZE(ipr_max_bus_speeds
))
9501 ioa_cfg
->bus_attr
[i
].max_xfer_rate
= ipr_max_bus_speeds
[ipr_max_speed
];
9503 ioa_cfg
->bus_attr
[i
].max_xfer_rate
= IPR_U160_SCSI_RATE
;
9508 * ipr_init_regs - Initialize IOA registers
9509 * @ioa_cfg: ioa config struct
9514 static void ipr_init_regs(struct ipr_ioa_cfg
*ioa_cfg
)
9516 const struct ipr_interrupt_offsets
*p
;
9517 struct ipr_interrupts
*t
;
9520 p
= &ioa_cfg
->chip_cfg
->regs
;
9522 base
= ioa_cfg
->hdw_dma_regs
;
9524 t
->set_interrupt_mask_reg
= base
+ p
->set_interrupt_mask_reg
;
9525 t
->clr_interrupt_mask_reg
= base
+ p
->clr_interrupt_mask_reg
;
9526 t
->clr_interrupt_mask_reg32
= base
+ p
->clr_interrupt_mask_reg32
;
9527 t
->sense_interrupt_mask_reg
= base
+ p
->sense_interrupt_mask_reg
;
9528 t
->sense_interrupt_mask_reg32
= base
+ p
->sense_interrupt_mask_reg32
;
9529 t
->clr_interrupt_reg
= base
+ p
->clr_interrupt_reg
;
9530 t
->clr_interrupt_reg32
= base
+ p
->clr_interrupt_reg32
;
9531 t
->sense_interrupt_reg
= base
+ p
->sense_interrupt_reg
;
9532 t
->sense_interrupt_reg32
= base
+ p
->sense_interrupt_reg32
;
9533 t
->ioarrin_reg
= base
+ p
->ioarrin_reg
;
9534 t
->sense_uproc_interrupt_reg
= base
+ p
->sense_uproc_interrupt_reg
;
9535 t
->sense_uproc_interrupt_reg32
= base
+ p
->sense_uproc_interrupt_reg32
;
9536 t
->set_uproc_interrupt_reg
= base
+ p
->set_uproc_interrupt_reg
;
9537 t
->set_uproc_interrupt_reg32
= base
+ p
->set_uproc_interrupt_reg32
;
9538 t
->clr_uproc_interrupt_reg
= base
+ p
->clr_uproc_interrupt_reg
;
9539 t
->clr_uproc_interrupt_reg32
= base
+ p
->clr_uproc_interrupt_reg32
;
9541 if (ioa_cfg
->sis64
) {
9542 t
->init_feedback_reg
= base
+ p
->init_feedback_reg
;
9543 t
->dump_addr_reg
= base
+ p
->dump_addr_reg
;
9544 t
->dump_data_reg
= base
+ p
->dump_data_reg
;
9545 t
->endian_swap_reg
= base
+ p
->endian_swap_reg
;
9550 * ipr_init_ioa_cfg - Initialize IOA config struct
9551 * @ioa_cfg: ioa config struct
9552 * @host: scsi host struct
9553 * @pdev: PCI dev struct
9558 static void ipr_init_ioa_cfg(struct ipr_ioa_cfg
*ioa_cfg
,
9559 struct Scsi_Host
*host
, struct pci_dev
*pdev
)
9563 ioa_cfg
->host
= host
;
9564 ioa_cfg
->pdev
= pdev
;
9565 ioa_cfg
->log_level
= ipr_log_level
;
9566 ioa_cfg
->doorbell
= IPR_DOORBELL
;
9567 sprintf(ioa_cfg
->eye_catcher
, IPR_EYECATCHER
);
9568 sprintf(ioa_cfg
->trace_start
, IPR_TRACE_START_LABEL
);
9569 sprintf(ioa_cfg
->cfg_table_start
, IPR_CFG_TBL_START
);
9570 sprintf(ioa_cfg
->resource_table_label
, IPR_RES_TABLE_LABEL
);
9571 sprintf(ioa_cfg
->ipr_hcam_label
, IPR_HCAM_LABEL
);
9572 sprintf(ioa_cfg
->ipr_cmd_label
, IPR_CMD_LABEL
);
9574 INIT_LIST_HEAD(&ioa_cfg
->hostrcb_free_q
);
9575 INIT_LIST_HEAD(&ioa_cfg
->hostrcb_pending_q
);
9576 INIT_LIST_HEAD(&ioa_cfg
->free_res_q
);
9577 INIT_LIST_HEAD(&ioa_cfg
->used_res_q
);
9578 INIT_WORK(&ioa_cfg
->work_q
, ipr_worker_thread
);
9579 init_waitqueue_head(&ioa_cfg
->reset_wait_q
);
9580 init_waitqueue_head(&ioa_cfg
->msi_wait_q
);
9581 init_waitqueue_head(&ioa_cfg
->eeh_wait_q
);
9582 ioa_cfg
->sdt_state
= INACTIVE
;
9584 ipr_initialize_bus_attr(ioa_cfg
);
9585 ioa_cfg
->max_devs_supported
= ipr_max_devs
;
9587 if (ioa_cfg
->sis64
) {
9588 host
->max_id
= IPR_MAX_SIS64_TARGETS_PER_BUS
;
9589 host
->max_lun
= IPR_MAX_SIS64_LUNS_PER_TARGET
;
9590 if (ipr_max_devs
> IPR_MAX_SIS64_DEVS
)
9591 ioa_cfg
->max_devs_supported
= IPR_MAX_SIS64_DEVS
;
9592 ioa_cfg
->cfg_table_size
= (sizeof(struct ipr_config_table_hdr64
)
9593 + ((sizeof(struct ipr_config_table_entry64
)
9594 * ioa_cfg
->max_devs_supported
)));
9596 host
->max_id
= IPR_MAX_NUM_TARGETS_PER_BUS
;
9597 host
->max_lun
= IPR_MAX_NUM_LUNS_PER_TARGET
;
9598 if (ipr_max_devs
> IPR_MAX_PHYSICAL_DEVS
)
9599 ioa_cfg
->max_devs_supported
= IPR_MAX_PHYSICAL_DEVS
;
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
)));
9605 host
->max_channel
= IPR_VSET_BUS
;
9606 host
->unique_id
= host
->host_no
;
9607 host
->max_cmd_len
= IPR_MAX_CDB_LEN
;
9608 host
->can_queue
= ioa_cfg
->max_cmds
;
9609 pci_set_drvdata(pdev
, ioa_cfg
);
9611 for (i
= 0; i
< ARRAY_SIZE(ioa_cfg
->hrrq
); i
++) {
9612 INIT_LIST_HEAD(&ioa_cfg
->hrrq
[i
].hrrq_free_q
);
9613 INIT_LIST_HEAD(&ioa_cfg
->hrrq
[i
].hrrq_pending_q
);
9614 spin_lock_init(&ioa_cfg
->hrrq
[i
]._lock
);
9616 ioa_cfg
->hrrq
[i
].lock
= ioa_cfg
->host
->host_lock
;
9618 ioa_cfg
->hrrq
[i
].lock
= &ioa_cfg
->hrrq
[i
]._lock
;
9623 * ipr_get_chip_info - Find adapter chip information
9624 * @dev_id: PCI device id struct
9627 * ptr to chip information on success / NULL on failure
9629 static const struct ipr_chip_t
*
9630 ipr_get_chip_info(const struct pci_device_id
*dev_id
)
9634 for (i
= 0; i
< ARRAY_SIZE(ipr_chip
); i
++)
9635 if (ipr_chip
[i
].vendor
== dev_id
->vendor
&&
9636 ipr_chip
[i
].device
== dev_id
->device
)
9637 return &ipr_chip
[i
];
9642 * ipr_wait_for_pci_err_recovery - Wait for any PCI error recovery to complete
9644 * @ioa_cfg: ioa config struct
9649 static void ipr_wait_for_pci_err_recovery(struct ipr_ioa_cfg
*ioa_cfg
)
9651 struct pci_dev
*pdev
= ioa_cfg
->pdev
;
9653 if (pci_channel_offline(pdev
)) {
9654 wait_event_timeout(ioa_cfg
->eeh_wait_q
,
9655 !pci_channel_offline(pdev
),
9656 IPR_PCI_ERROR_RECOVERY_TIMEOUT
);
9657 pci_restore_state(pdev
);
9661 static int ipr_enable_msix(struct ipr_ioa_cfg
*ioa_cfg
)
9663 struct msix_entry entries
[IPR_MAX_MSIX_VECTORS
];
9666 for (i
= 0; i
< ARRAY_SIZE(entries
); ++i
)
9667 entries
[i
].entry
= i
;
9669 vectors
= pci_enable_msix_range(ioa_cfg
->pdev
,
9670 entries
, 1, ipr_number_of_msix
);
9672 ipr_wait_for_pci_err_recovery(ioa_cfg
);
9676 for (i
= 0; i
< vectors
; i
++)
9677 ioa_cfg
->vectors_info
[i
].vec
= entries
[i
].vector
;
9678 ioa_cfg
->nvectors
= vectors
;
9683 static int ipr_enable_msi(struct ipr_ioa_cfg
*ioa_cfg
)
9687 vectors
= pci_enable_msi_range(ioa_cfg
->pdev
, 1, ipr_number_of_msix
);
9689 ipr_wait_for_pci_err_recovery(ioa_cfg
);
9693 for (i
= 0; i
< vectors
; i
++)
9694 ioa_cfg
->vectors_info
[i
].vec
= ioa_cfg
->pdev
->irq
+ i
;
9695 ioa_cfg
->nvectors
= vectors
;
9700 static void name_msi_vectors(struct ipr_ioa_cfg
*ioa_cfg
)
9702 int vec_idx
, n
= sizeof(ioa_cfg
->vectors_info
[0].desc
) - 1;
9704 for (vec_idx
= 0; vec_idx
< ioa_cfg
->nvectors
; vec_idx
++) {
9705 snprintf(ioa_cfg
->vectors_info
[vec_idx
].desc
, n
,
9706 "host%d-%d", ioa_cfg
->host
->host_no
, vec_idx
);
9707 ioa_cfg
->vectors_info
[vec_idx
].
9708 desc
[strlen(ioa_cfg
->vectors_info
[vec_idx
].desc
)] = 0;
9712 static int ipr_request_other_msi_irqs(struct ipr_ioa_cfg
*ioa_cfg
)
9716 for (i
= 1; i
< ioa_cfg
->nvectors
; i
++) {
9717 rc
= request_irq(ioa_cfg
->vectors_info
[i
].vec
,
9720 ioa_cfg
->vectors_info
[i
].desc
,
9724 free_irq(ioa_cfg
->vectors_info
[i
].vec
,
9733 * ipr_test_intr - Handle the interrupt generated in ipr_test_msi().
9734 * @pdev: PCI device struct
9736 * Description: Simply set the msi_received flag to 1 indicating that
9737 * Message Signaled Interrupts are supported.
9740 * 0 on success / non-zero on failure
9742 static irqreturn_t
ipr_test_intr(int irq
, void *devp
)
9744 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*)devp
;
9745 unsigned long lock_flags
= 0;
9746 irqreturn_t rc
= IRQ_HANDLED
;
9748 dev_info(&ioa_cfg
->pdev
->dev
, "Received IRQ : %d\n", irq
);
9749 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
9751 ioa_cfg
->msi_received
= 1;
9752 wake_up(&ioa_cfg
->msi_wait_q
);
9754 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
9759 * ipr_test_msi - Test for Message Signaled Interrupt (MSI) support.
9760 * @pdev: PCI device struct
9762 * Description: The return value from pci_enable_msi_range() can not always be
9763 * trusted. This routine sets up and initiates a test interrupt to determine
9764 * if the interrupt is received via the ipr_test_intr() service routine.
9765 * If the tests fails, the driver will fall back to LSI.
9768 * 0 on success / non-zero on failure
9770 static int ipr_test_msi(struct ipr_ioa_cfg
*ioa_cfg
, struct pci_dev
*pdev
)
9773 volatile u32 int_reg
;
9774 unsigned long lock_flags
= 0;
9778 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
9779 init_waitqueue_head(&ioa_cfg
->msi_wait_q
);
9780 ioa_cfg
->msi_received
= 0;
9781 ipr_mask_and_clear_interrupts(ioa_cfg
, ~IPR_PCII_IOA_TRANS_TO_OPER
);
9782 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE
, ioa_cfg
->regs
.clr_interrupt_mask_reg32
);
9783 int_reg
= readl(ioa_cfg
->regs
.sense_interrupt_mask_reg
);
9784 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
9786 if (ioa_cfg
->intr_flag
== IPR_USE_MSIX
)
9787 rc
= request_irq(ioa_cfg
->vectors_info
[0].vec
, ipr_test_intr
, 0, IPR_NAME
, ioa_cfg
);
9789 rc
= request_irq(pdev
->irq
, ipr_test_intr
, 0, IPR_NAME
, ioa_cfg
);
9791 dev_err(&pdev
->dev
, "Can not assign irq %d\n", pdev
->irq
);
9793 } else if (ipr_debug
)
9794 dev_info(&pdev
->dev
, "IRQ assigned: %d\n", pdev
->irq
);
9796 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE
, ioa_cfg
->regs
.sense_interrupt_reg32
);
9797 int_reg
= readl(ioa_cfg
->regs
.sense_interrupt_reg
);
9798 wait_event_timeout(ioa_cfg
->msi_wait_q
, ioa_cfg
->msi_received
, HZ
);
9799 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
9800 ipr_mask_and_clear_interrupts(ioa_cfg
, ~IPR_PCII_IOA_TRANS_TO_OPER
);
9802 if (!ioa_cfg
->msi_received
) {
9803 /* MSI test failed */
9804 dev_info(&pdev
->dev
, "MSI test failed. Falling back to LSI.\n");
9806 } else if (ipr_debug
)
9807 dev_info(&pdev
->dev
, "MSI test succeeded.\n");
9809 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
9811 if (ioa_cfg
->intr_flag
== IPR_USE_MSIX
)
9812 free_irq(ioa_cfg
->vectors_info
[0].vec
, ioa_cfg
);
9814 free_irq(pdev
->irq
, ioa_cfg
);
9821 /* ipr_probe_ioa - Allocates memory and does first stage of initialization
9822 * @pdev: PCI device struct
9823 * @dev_id: PCI device id struct
9826 * 0 on success / non-zero on failure
9828 static int ipr_probe_ioa(struct pci_dev
*pdev
,
9829 const struct pci_device_id
*dev_id
)
9831 struct ipr_ioa_cfg
*ioa_cfg
;
9832 struct Scsi_Host
*host
;
9833 unsigned long ipr_regs_pci
;
9834 void __iomem
*ipr_regs
;
9835 int rc
= PCIBIOS_SUCCESSFUL
;
9836 volatile u32 mask
, uproc
, interrupts
;
9837 unsigned long lock_flags
, driver_lock_flags
;
9841 dev_info(&pdev
->dev
, "Found IOA with IRQ: %d\n", pdev
->irq
);
9842 host
= scsi_host_alloc(&driver_template
, sizeof(*ioa_cfg
));
9845 dev_err(&pdev
->dev
, "call to scsi_host_alloc failed!\n");
9850 ioa_cfg
= (struct ipr_ioa_cfg
*)host
->hostdata
;
9851 memset(ioa_cfg
, 0, sizeof(struct ipr_ioa_cfg
));
9852 ata_host_init(&ioa_cfg
->ata_host
, &pdev
->dev
, &ipr_sata_ops
);
9854 ioa_cfg
->ipr_chip
= ipr_get_chip_info(dev_id
);
9856 if (!ioa_cfg
->ipr_chip
) {
9857 dev_err(&pdev
->dev
, "Unknown adapter chipset 0x%04X 0x%04X\n",
9858 dev_id
->vendor
, dev_id
->device
);
9859 goto out_scsi_host_put
;
9862 /* set SIS 32 or SIS 64 */
9863 ioa_cfg
->sis64
= ioa_cfg
->ipr_chip
->sis_type
== IPR_SIS64
? 1 : 0;
9864 ioa_cfg
->chip_cfg
= ioa_cfg
->ipr_chip
->cfg
;
9865 ioa_cfg
->clear_isr
= ioa_cfg
->chip_cfg
->clear_isr
;
9866 ioa_cfg
->max_cmds
= ioa_cfg
->chip_cfg
->max_cmds
;
9868 if (ipr_transop_timeout
)
9869 ioa_cfg
->transop_timeout
= ipr_transop_timeout
;
9870 else if (dev_id
->driver_data
& IPR_USE_LONG_TRANSOP_TIMEOUT
)
9871 ioa_cfg
->transop_timeout
= IPR_LONG_OPERATIONAL_TIMEOUT
;
9873 ioa_cfg
->transop_timeout
= IPR_OPERATIONAL_TIMEOUT
;
9875 ioa_cfg
->revid
= pdev
->revision
;
9877 ipr_init_ioa_cfg(ioa_cfg
, host
, pdev
);
9879 ipr_regs_pci
= pci_resource_start(pdev
, 0);
9881 rc
= pci_request_regions(pdev
, IPR_NAME
);
9884 "Couldn't register memory range of registers\n");
9885 goto out_scsi_host_put
;
9888 rc
= pci_enable_device(pdev
);
9890 if (rc
|| pci_channel_offline(pdev
)) {
9891 if (pci_channel_offline(pdev
)) {
9892 ipr_wait_for_pci_err_recovery(ioa_cfg
);
9893 rc
= pci_enable_device(pdev
);
9897 dev_err(&pdev
->dev
, "Cannot enable adapter\n");
9898 ipr_wait_for_pci_err_recovery(ioa_cfg
);
9899 goto out_release_regions
;
9903 ipr_regs
= pci_ioremap_bar(pdev
, 0);
9907 "Couldn't map memory range of registers\n");
9912 ioa_cfg
->hdw_dma_regs
= ipr_regs
;
9913 ioa_cfg
->hdw_dma_regs_pci
= ipr_regs_pci
;
9914 ioa_cfg
->ioa_mailbox
= ioa_cfg
->chip_cfg
->mailbox
+ ipr_regs
;
9916 ipr_init_regs(ioa_cfg
);
9918 if (ioa_cfg
->sis64
) {
9919 rc
= dma_set_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(64));
9921 dev_dbg(&pdev
->dev
, "Failed to set 64 bit DMA mask\n");
9922 rc
= dma_set_mask_and_coherent(&pdev
->dev
,
9926 rc
= dma_set_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(32));
9929 dev_err(&pdev
->dev
, "Failed to set DMA mask\n");
9933 rc
= pci_write_config_byte(pdev
, PCI_CACHE_LINE_SIZE
,
9934 ioa_cfg
->chip_cfg
->cache_line_size
);
9936 if (rc
!= PCIBIOS_SUCCESSFUL
) {
9937 dev_err(&pdev
->dev
, "Write of cache line size failed\n");
9938 ipr_wait_for_pci_err_recovery(ioa_cfg
);
9943 /* Issue MMIO read to ensure card is not in EEH */
9944 interrupts
= readl(ioa_cfg
->regs
.sense_interrupt_reg
);
9945 ipr_wait_for_pci_err_recovery(ioa_cfg
);
9947 if (ipr_number_of_msix
> IPR_MAX_MSIX_VECTORS
) {
9948 dev_err(&pdev
->dev
, "The max number of MSIX is %d\n",
9949 IPR_MAX_MSIX_VECTORS
);
9950 ipr_number_of_msix
= IPR_MAX_MSIX_VECTORS
;
9953 if (ioa_cfg
->ipr_chip
->intr_type
== IPR_USE_MSI
&&
9954 ipr_enable_msix(ioa_cfg
) == 0)
9955 ioa_cfg
->intr_flag
= IPR_USE_MSIX
;
9956 else if (ioa_cfg
->ipr_chip
->intr_type
== IPR_USE_MSI
&&
9957 ipr_enable_msi(ioa_cfg
) == 0)
9958 ioa_cfg
->intr_flag
= IPR_USE_MSI
;
9960 ioa_cfg
->intr_flag
= IPR_USE_LSI
;
9961 ioa_cfg
->nvectors
= 1;
9962 dev_info(&pdev
->dev
, "Cannot enable MSI.\n");
9965 pci_set_master(pdev
);
9967 if (pci_channel_offline(pdev
)) {
9968 ipr_wait_for_pci_err_recovery(ioa_cfg
);
9969 pci_set_master(pdev
);
9970 if (pci_channel_offline(pdev
)) {
9972 goto out_msi_disable
;
9976 if (ioa_cfg
->intr_flag
== IPR_USE_MSI
||
9977 ioa_cfg
->intr_flag
== IPR_USE_MSIX
) {
9978 rc
= ipr_test_msi(ioa_cfg
, pdev
);
9979 if (rc
== -EOPNOTSUPP
) {
9980 ipr_wait_for_pci_err_recovery(ioa_cfg
);
9981 if (ioa_cfg
->intr_flag
== IPR_USE_MSI
) {
9982 ioa_cfg
->intr_flag
&= ~IPR_USE_MSI
;
9983 pci_disable_msi(pdev
);
9984 } else if (ioa_cfg
->intr_flag
== IPR_USE_MSIX
) {
9985 ioa_cfg
->intr_flag
&= ~IPR_USE_MSIX
;
9986 pci_disable_msix(pdev
);
9989 ioa_cfg
->intr_flag
= IPR_USE_LSI
;
9990 ioa_cfg
->nvectors
= 1;
9993 goto out_msi_disable
;
9995 if (ioa_cfg
->intr_flag
== IPR_USE_MSI
)
9996 dev_info(&pdev
->dev
,
9997 "Request for %d MSIs succeeded with starting IRQ: %d\n",
9998 ioa_cfg
->nvectors
, pdev
->irq
);
9999 else if (ioa_cfg
->intr_flag
== IPR_USE_MSIX
)
10000 dev_info(&pdev
->dev
,
10001 "Request for %d MSIXs succeeded.",
10002 ioa_cfg
->nvectors
);
10006 ioa_cfg
->hrrq_num
= min3(ioa_cfg
->nvectors
,
10007 (unsigned int)num_online_cpus(),
10008 (unsigned int)IPR_MAX_HRRQ_NUM
);
10010 if ((rc
= ipr_save_pcix_cmd_reg(ioa_cfg
)))
10011 goto out_msi_disable
;
10013 if ((rc
= ipr_set_pcix_cmd_reg(ioa_cfg
)))
10014 goto out_msi_disable
;
10016 rc
= ipr_alloc_mem(ioa_cfg
);
10018 dev_err(&pdev
->dev
,
10019 "Couldn't allocate enough memory for device driver!\n");
10020 goto out_msi_disable
;
10023 /* Save away PCI config space for use following IOA reset */
10024 rc
= pci_save_state(pdev
);
10026 if (rc
!= PCIBIOS_SUCCESSFUL
) {
10027 dev_err(&pdev
->dev
, "Failed to save PCI config space\n");
10029 goto cleanup_nolog
;
10033 * If HRRQ updated interrupt is not masked, or reset alert is set,
10034 * the card is in an unknown state and needs a hard reset
10036 mask
= readl(ioa_cfg
->regs
.sense_interrupt_mask_reg32
);
10037 interrupts
= readl(ioa_cfg
->regs
.sense_interrupt_reg32
);
10038 uproc
= readl(ioa_cfg
->regs
.sense_uproc_interrupt_reg32
);
10039 if ((mask
& IPR_PCII_HRRQ_UPDATED
) == 0 || (uproc
& IPR_UPROCI_RESET_ALERT
))
10040 ioa_cfg
->needs_hard_reset
= 1;
10041 if ((interrupts
& IPR_PCII_ERROR_INTERRUPTS
) || reset_devices
)
10042 ioa_cfg
->needs_hard_reset
= 1;
10043 if (interrupts
& IPR_PCII_IOA_UNIT_CHECKED
)
10044 ioa_cfg
->ioa_unit_checked
= 1;
10046 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
10047 ipr_mask_and_clear_interrupts(ioa_cfg
, ~IPR_PCII_IOA_TRANS_TO_OPER
);
10048 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
10050 if (ioa_cfg
->intr_flag
== IPR_USE_MSI
10051 || ioa_cfg
->intr_flag
== IPR_USE_MSIX
) {
10052 name_msi_vectors(ioa_cfg
);
10053 rc
= request_irq(ioa_cfg
->vectors_info
[0].vec
, ipr_isr
,
10055 ioa_cfg
->vectors_info
[0].desc
,
10056 &ioa_cfg
->hrrq
[0]);
10058 rc
= ipr_request_other_msi_irqs(ioa_cfg
);
10060 rc
= request_irq(pdev
->irq
, ipr_isr
,
10062 IPR_NAME
, &ioa_cfg
->hrrq
[0]);
10065 dev_err(&pdev
->dev
, "Couldn't register IRQ %d! rc=%d\n",
10067 goto cleanup_nolog
;
10070 if ((dev_id
->driver_data
& IPR_USE_PCI_WARM_RESET
) ||
10071 (dev_id
->device
== PCI_DEVICE_ID_IBM_OBSIDIAN_E
&& !ioa_cfg
->revid
)) {
10072 ioa_cfg
->needs_warm_reset
= 1;
10073 ioa_cfg
->reset
= ipr_reset_slot_reset
;
10075 ioa_cfg
->reset_work_q
= alloc_ordered_workqueue("ipr_reset_%d",
10076 WQ_MEM_RECLAIM
, host
->host_no
);
10078 if (!ioa_cfg
->reset_work_q
) {
10079 dev_err(&pdev
->dev
, "Couldn't register reset workqueue\n");
10083 ioa_cfg
->reset
= ipr_reset_start_bist
;
10085 spin_lock_irqsave(&ipr_driver_lock
, driver_lock_flags
);
10086 list_add_tail(&ioa_cfg
->queue
, &ipr_ioa_head
);
10087 spin_unlock_irqrestore(&ipr_driver_lock
, driver_lock_flags
);
10094 ipr_free_irqs(ioa_cfg
);
10096 ipr_free_mem(ioa_cfg
);
10098 ipr_wait_for_pci_err_recovery(ioa_cfg
);
10099 if (ioa_cfg
->intr_flag
== IPR_USE_MSI
)
10100 pci_disable_msi(pdev
);
10101 else if (ioa_cfg
->intr_flag
== IPR_USE_MSIX
)
10102 pci_disable_msix(pdev
);
10106 pci_disable_device(pdev
);
10107 out_release_regions
:
10108 pci_release_regions(pdev
);
10110 scsi_host_put(host
);
10115 * ipr_initiate_ioa_bringdown - Bring down an adapter
10116 * @ioa_cfg: ioa config struct
10117 * @shutdown_type: shutdown type
10119 * Description: This function will initiate bringing down the adapter.
10120 * This consists of issuing an IOA shutdown to the adapter
10121 * to flush the cache, and running BIST.
10122 * If the caller needs to wait on the completion of the reset,
10123 * the caller must sleep on the reset_wait_q.
10128 static void ipr_initiate_ioa_bringdown(struct ipr_ioa_cfg
*ioa_cfg
,
10129 enum ipr_shutdown_type shutdown_type
)
10132 if (ioa_cfg
->sdt_state
== WAIT_FOR_DUMP
)
10133 ioa_cfg
->sdt_state
= ABORT_DUMP
;
10134 ioa_cfg
->reset_retries
= 0;
10135 ioa_cfg
->in_ioa_bringdown
= 1;
10136 ipr_initiate_ioa_reset(ioa_cfg
, shutdown_type
);
10141 * __ipr_remove - Remove a single adapter
10142 * @pdev: pci device struct
10144 * Adapter hot plug remove entry point.
10149 static void __ipr_remove(struct pci_dev
*pdev
)
10151 unsigned long host_lock_flags
= 0;
10152 struct ipr_ioa_cfg
*ioa_cfg
= pci_get_drvdata(pdev
);
10154 unsigned long driver_lock_flags
;
10157 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, host_lock_flags
);
10158 while (ioa_cfg
->in_reset_reload
) {
10159 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, host_lock_flags
);
10160 wait_event(ioa_cfg
->reset_wait_q
, !ioa_cfg
->in_reset_reload
);
10161 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, host_lock_flags
);
10164 for (i
= 0; i
< ioa_cfg
->hrrq_num
; i
++) {
10165 spin_lock(&ioa_cfg
->hrrq
[i
]._lock
);
10166 ioa_cfg
->hrrq
[i
].removing_ioa
= 1;
10167 spin_unlock(&ioa_cfg
->hrrq
[i
]._lock
);
10170 ipr_initiate_ioa_bringdown(ioa_cfg
, IPR_SHUTDOWN_NORMAL
);
10172 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, host_lock_flags
);
10173 wait_event(ioa_cfg
->reset_wait_q
, !ioa_cfg
->in_reset_reload
);
10174 flush_work(&ioa_cfg
->work_q
);
10175 if (ioa_cfg
->reset_work_q
)
10176 flush_workqueue(ioa_cfg
->reset_work_q
);
10177 INIT_LIST_HEAD(&ioa_cfg
->used_res_q
);
10178 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, host_lock_flags
);
10180 spin_lock_irqsave(&ipr_driver_lock
, driver_lock_flags
);
10181 list_del(&ioa_cfg
->queue
);
10182 spin_unlock_irqrestore(&ipr_driver_lock
, driver_lock_flags
);
10184 if (ioa_cfg
->sdt_state
== ABORT_DUMP
)
10185 ioa_cfg
->sdt_state
= WAIT_FOR_DUMP
;
10186 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, host_lock_flags
);
10188 ipr_free_all_resources(ioa_cfg
);
10194 * ipr_remove - IOA hot plug remove entry point
10195 * @pdev: pci device struct
10197 * Adapter hot plug remove entry point.
10202 static void ipr_remove(struct pci_dev
*pdev
)
10204 struct ipr_ioa_cfg
*ioa_cfg
= pci_get_drvdata(pdev
);
10208 ipr_remove_trace_file(&ioa_cfg
->host
->shost_dev
.kobj
,
10210 ipr_remove_dump_file(&ioa_cfg
->host
->shost_dev
.kobj
,
10212 scsi_remove_host(ioa_cfg
->host
);
10214 __ipr_remove(pdev
);
10220 * ipr_probe - Adapter hot plug add entry point
10223 * 0 on success / non-zero on failure
10225 static int ipr_probe(struct pci_dev
*pdev
, const struct pci_device_id
*dev_id
)
10227 struct ipr_ioa_cfg
*ioa_cfg
;
10230 rc
= ipr_probe_ioa(pdev
, dev_id
);
10235 ioa_cfg
= pci_get_drvdata(pdev
);
10236 rc
= ipr_probe_ioa_part2(ioa_cfg
);
10239 __ipr_remove(pdev
);
10243 rc
= scsi_add_host(ioa_cfg
->host
, &pdev
->dev
);
10246 __ipr_remove(pdev
);
10250 rc
= ipr_create_trace_file(&ioa_cfg
->host
->shost_dev
.kobj
,
10254 scsi_remove_host(ioa_cfg
->host
);
10255 __ipr_remove(pdev
);
10259 rc
= ipr_create_dump_file(&ioa_cfg
->host
->shost_dev
.kobj
,
10263 ipr_remove_trace_file(&ioa_cfg
->host
->shost_dev
.kobj
,
10265 scsi_remove_host(ioa_cfg
->host
);
10266 __ipr_remove(pdev
);
10270 scsi_scan_host(ioa_cfg
->host
);
10271 ioa_cfg
->iopoll_weight
= ioa_cfg
->chip_cfg
->iopoll_weight
;
10273 if (ioa_cfg
->iopoll_weight
&& ioa_cfg
->sis64
&& ioa_cfg
->nvectors
> 1) {
10274 for (i
= 1; i
< ioa_cfg
->hrrq_num
; i
++) {
10275 blk_iopoll_init(&ioa_cfg
->hrrq
[i
].iopoll
,
10276 ioa_cfg
->iopoll_weight
, ipr_iopoll
);
10277 blk_iopoll_enable(&ioa_cfg
->hrrq
[i
].iopoll
);
10281 schedule_work(&ioa_cfg
->work_q
);
10286 * ipr_shutdown - Shutdown handler.
10287 * @pdev: pci device struct
10289 * This function is invoked upon system shutdown/reboot. It will issue
10290 * an adapter shutdown to the adapter to flush the write cache.
10295 static void ipr_shutdown(struct pci_dev
*pdev
)
10297 struct ipr_ioa_cfg
*ioa_cfg
= pci_get_drvdata(pdev
);
10298 unsigned long lock_flags
= 0;
10299 enum ipr_shutdown_type shutdown_type
= IPR_SHUTDOWN_NORMAL
;
10302 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
10303 if (ioa_cfg
->iopoll_weight
&& ioa_cfg
->sis64
&& ioa_cfg
->nvectors
> 1) {
10304 ioa_cfg
->iopoll_weight
= 0;
10305 for (i
= 1; i
< ioa_cfg
->hrrq_num
; i
++)
10306 blk_iopoll_disable(&ioa_cfg
->hrrq
[i
].iopoll
);
10309 while (ioa_cfg
->in_reset_reload
) {
10310 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
10311 wait_event(ioa_cfg
->reset_wait_q
, !ioa_cfg
->in_reset_reload
);
10312 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
10315 if (ipr_fast_reboot
&& system_state
== SYSTEM_RESTART
&& ioa_cfg
->sis64
)
10316 shutdown_type
= IPR_SHUTDOWN_QUIESCE
;
10318 ipr_initiate_ioa_bringdown(ioa_cfg
, shutdown_type
);
10319 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
10320 wait_event(ioa_cfg
->reset_wait_q
, !ioa_cfg
->in_reset_reload
);
10321 if (ipr_fast_reboot
&& system_state
== SYSTEM_RESTART
&& ioa_cfg
->sis64
) {
10322 ipr_free_irqs(ioa_cfg
);
10323 pci_disable_device(ioa_cfg
->pdev
);
10327 static struct pci_device_id ipr_pci_table
[] = {
10328 { PCI_VENDOR_ID_MYLEX
, PCI_DEVICE_ID_IBM_GEMSTONE
,
10329 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_5702
, 0, 0, 0 },
10330 { PCI_VENDOR_ID_MYLEX
, PCI_DEVICE_ID_IBM_GEMSTONE
,
10331 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_5703
, 0, 0, 0 },
10332 { PCI_VENDOR_ID_MYLEX
, PCI_DEVICE_ID_IBM_GEMSTONE
,
10333 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_573D
, 0, 0, 0 },
10334 { PCI_VENDOR_ID_MYLEX
, PCI_DEVICE_ID_IBM_GEMSTONE
,
10335 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_573E
, 0, 0, 0 },
10336 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_CITRINE
,
10337 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_571B
, 0, 0, 0 },
10338 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_CITRINE
,
10339 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_572E
, 0, 0, 0 },
10340 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_CITRINE
,
10341 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_571A
, 0, 0, 0 },
10342 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_CITRINE
,
10343 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_575B
, 0, 0,
10344 IPR_USE_LONG_TRANSOP_TIMEOUT
},
10345 { PCI_VENDOR_ID_ADAPTEC2
, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN
,
10346 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_572A
, 0, 0, 0 },
10347 { PCI_VENDOR_ID_ADAPTEC2
, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN
,
10348 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_572B
, 0, 0,
10349 IPR_USE_LONG_TRANSOP_TIMEOUT
},
10350 { PCI_VENDOR_ID_ADAPTEC2
, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN
,
10351 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_575C
, 0, 0,
10352 IPR_USE_LONG_TRANSOP_TIMEOUT
},
10353 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_OBSIDIAN
,
10354 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_572A
, 0, 0, 0 },
10355 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_OBSIDIAN
,
10356 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_572B
, 0, 0,
10357 IPR_USE_LONG_TRANSOP_TIMEOUT
},
10358 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_OBSIDIAN
,
10359 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_575C
, 0, 0,
10360 IPR_USE_LONG_TRANSOP_TIMEOUT
},
10361 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_OBSIDIAN_E
,
10362 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_574E
, 0, 0,
10363 IPR_USE_LONG_TRANSOP_TIMEOUT
},
10364 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_OBSIDIAN_E
,
10365 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_57B3
, 0, 0, 0 },
10366 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_OBSIDIAN_E
,
10367 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_57CC
, 0, 0, 0 },
10368 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_OBSIDIAN_E
,
10369 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_57B7
, 0, 0,
10370 IPR_USE_LONG_TRANSOP_TIMEOUT
| IPR_USE_PCI_WARM_RESET
},
10371 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_SNIPE
,
10372 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_2780
, 0, 0, 0 },
10373 { PCI_VENDOR_ID_ADAPTEC2
, PCI_DEVICE_ID_ADAPTEC2_SCAMP
,
10374 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_571E
, 0, 0, 0 },
10375 { PCI_VENDOR_ID_ADAPTEC2
, PCI_DEVICE_ID_ADAPTEC2_SCAMP
,
10376 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_571F
, 0, 0,
10377 IPR_USE_LONG_TRANSOP_TIMEOUT
},
10378 { PCI_VENDOR_ID_ADAPTEC2
, PCI_DEVICE_ID_ADAPTEC2_SCAMP
,
10379 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_572F
, 0, 0,
10380 IPR_USE_LONG_TRANSOP_TIMEOUT
},
10381 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_CROC_FPGA_E2
,
10382 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_57B5
, 0, 0, 0 },
10383 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_CROC_FPGA_E2
,
10384 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_574D
, 0, 0, 0 },
10385 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_CROC_FPGA_E2
,
10386 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_57B2
, 0, 0, 0 },
10387 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_CROC_FPGA_E2
,
10388 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_57C0
, 0, 0, 0 },
10389 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_CROC_FPGA_E2
,
10390 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_57C3
, 0, 0, 0 },
10391 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_CROC_FPGA_E2
,
10392 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_57C4
, 0, 0, 0 },
10393 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_CROCODILE
,
10394 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_57B4
, 0, 0, 0 },
10395 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_CROCODILE
,
10396 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_57B1
, 0, 0, 0 },
10397 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_CROCODILE
,
10398 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_57C6
, 0, 0, 0 },
10399 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_CROCODILE
,
10400 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_57C8
, 0, 0, 0 },
10401 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_CROCODILE
,
10402 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_57CE
, 0, 0, 0 },
10403 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_CROCODILE
,
10404 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_57D5
, 0, 0, 0 },
10405 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_CROCODILE
,
10406 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_57D6
, 0, 0, 0 },
10407 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_CROCODILE
,
10408 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_57D7
, 0, 0, 0 },
10409 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_CROCODILE
,
10410 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_57D8
, 0, 0, 0 },
10411 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_CROCODILE
,
10412 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_57D9
, 0, 0, 0 },
10413 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_CROCODILE
,
10414 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_57DA
, 0, 0, 0 },
10415 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_CROCODILE
,
10416 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_57EB
, 0, 0, 0 },
10417 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_CROCODILE
,
10418 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_57EC
, 0, 0, 0 },
10419 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_CROCODILE
,
10420 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_57ED
, 0, 0, 0 },
10421 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_CROCODILE
,
10422 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_57EE
, 0, 0, 0 },
10423 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_CROCODILE
,
10424 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_57EF
, 0, 0, 0 },
10425 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_CROCODILE
,
10426 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_57F0
, 0, 0, 0 },
10427 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_CROCODILE
,
10428 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_2CCA
, 0, 0, 0 },
10429 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_CROCODILE
,
10430 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_2CD2
, 0, 0, 0 },
10431 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_CROCODILE
,
10432 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_2CCD
, 0, 0, 0 },
10435 MODULE_DEVICE_TABLE(pci
, ipr_pci_table
);
10437 static const struct pci_error_handlers ipr_err_handler
= {
10438 .error_detected
= ipr_pci_error_detected
,
10439 .mmio_enabled
= ipr_pci_mmio_enabled
,
10440 .slot_reset
= ipr_pci_slot_reset
,
10443 static struct pci_driver ipr_driver
= {
10445 .id_table
= ipr_pci_table
,
10446 .probe
= ipr_probe
,
10447 .remove
= ipr_remove
,
10448 .shutdown
= ipr_shutdown
,
10449 .err_handler
= &ipr_err_handler
,
10453 * ipr_halt_done - Shutdown prepare completion
10458 static void ipr_halt_done(struct ipr_cmnd
*ipr_cmd
)
10460 list_add_tail(&ipr_cmd
->queue
, &ipr_cmd
->hrrq
->hrrq_free_q
);
10464 * ipr_halt - Issue shutdown prepare to all adapters
10467 * NOTIFY_OK on success / NOTIFY_DONE on failure
10469 static int ipr_halt(struct notifier_block
*nb
, ulong event
, void *buf
)
10471 struct ipr_cmnd
*ipr_cmd
;
10472 struct ipr_ioa_cfg
*ioa_cfg
;
10473 unsigned long flags
= 0, driver_lock_flags
;
10475 if (event
!= SYS_RESTART
&& event
!= SYS_HALT
&& event
!= SYS_POWER_OFF
)
10476 return NOTIFY_DONE
;
10478 spin_lock_irqsave(&ipr_driver_lock
, driver_lock_flags
);
10480 list_for_each_entry(ioa_cfg
, &ipr_ioa_head
, queue
) {
10481 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, flags
);
10482 if (!ioa_cfg
->hrrq
[IPR_INIT_HRRQ
].allow_cmds
||
10483 (ipr_fast_reboot
&& event
== SYS_RESTART
&& ioa_cfg
->sis64
)) {
10484 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, flags
);
10488 ipr_cmd
= ipr_get_free_ipr_cmnd(ioa_cfg
);
10489 ipr_cmd
->ioarcb
.res_handle
= cpu_to_be32(IPR_IOA_RES_HANDLE
);
10490 ipr_cmd
->ioarcb
.cmd_pkt
.request_type
= IPR_RQTYPE_IOACMD
;
10491 ipr_cmd
->ioarcb
.cmd_pkt
.cdb
[0] = IPR_IOA_SHUTDOWN
;
10492 ipr_cmd
->ioarcb
.cmd_pkt
.cdb
[1] = IPR_SHUTDOWN_PREPARE_FOR_NORMAL
;
10494 ipr_do_req(ipr_cmd
, ipr_halt_done
, ipr_timeout
, IPR_DEVICE_RESET_TIMEOUT
);
10495 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, flags
);
10497 spin_unlock_irqrestore(&ipr_driver_lock
, driver_lock_flags
);
10502 static struct notifier_block ipr_notifier
= {
10507 * ipr_init - Module entry point
10510 * 0 on success / negative value on failure
10512 static int __init
ipr_init(void)
10514 ipr_info("IBM Power RAID SCSI Device Driver version: %s %s\n",
10515 IPR_DRIVER_VERSION
, IPR_DRIVER_DATE
);
10517 register_reboot_notifier(&ipr_notifier
);
10518 return pci_register_driver(&ipr_driver
);
10522 * ipr_exit - Module unload
10524 * Module unload entry point.
10529 static void __exit
ipr_exit(void)
10531 unregister_reboot_notifier(&ipr_notifier
);
10532 pci_unregister_driver(&ipr_driver
);
10535 module_init(ipr_init
);
10536 module_exit(ipr_exit
);