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/ioport.h>
64 #include <linux/delay.h>
65 #include <linux/pci.h>
66 #include <linux/wait.h>
67 #include <linux/spinlock.h>
68 #include <linux/sched.h>
69 #include <linux/interrupt.h>
70 #include <linux/blkdev.h>
71 #include <linux/firmware.h>
72 #include <linux/module.h>
73 #include <linux/moduleparam.h>
74 #include <linux/libata.h>
75 #include <linux/hdreg.h>
76 #include <linux/reboot.h>
77 #include <linux/stringify.h>
80 #include <asm/processor.h>
81 #include <scsi/scsi.h>
82 #include <scsi/scsi_host.h>
83 #include <scsi/scsi_tcq.h>
84 #include <scsi/scsi_eh.h>
85 #include <scsi/scsi_cmnd.h>
91 static LIST_HEAD(ipr_ioa_head
);
92 static unsigned int ipr_log_level
= IPR_DEFAULT_LOG_LEVEL
;
93 static unsigned int ipr_max_speed
= 1;
94 static int ipr_testmode
= 0;
95 static unsigned int ipr_fastfail
= 0;
96 static unsigned int ipr_transop_timeout
= 0;
97 static unsigned int ipr_debug
= 0;
98 static unsigned int ipr_max_devs
= IPR_DEFAULT_SIS64_DEVS
;
99 static unsigned int ipr_dual_ioa_raid
= 1;
100 static DEFINE_SPINLOCK(ipr_driver_lock
);
102 /* This table describes the differences between DMA controller chips */
103 static const struct ipr_chip_cfg_t ipr_chip_cfg
[] = {
104 { /* Gemstone, Citrine, Obsidian, and Obsidian-E */
106 .cache_line_size
= 0x20,
108 .set_interrupt_mask_reg
= 0x0022C,
109 .clr_interrupt_mask_reg
= 0x00230,
110 .clr_interrupt_mask_reg32
= 0x00230,
111 .sense_interrupt_mask_reg
= 0x0022C,
112 .sense_interrupt_mask_reg32
= 0x0022C,
113 .clr_interrupt_reg
= 0x00228,
114 .clr_interrupt_reg32
= 0x00228,
115 .sense_interrupt_reg
= 0x00224,
116 .sense_interrupt_reg32
= 0x00224,
117 .ioarrin_reg
= 0x00404,
118 .sense_uproc_interrupt_reg
= 0x00214,
119 .sense_uproc_interrupt_reg32
= 0x00214,
120 .set_uproc_interrupt_reg
= 0x00214,
121 .set_uproc_interrupt_reg32
= 0x00214,
122 .clr_uproc_interrupt_reg
= 0x00218,
123 .clr_uproc_interrupt_reg32
= 0x00218
126 { /* Snipe and Scamp */
128 .cache_line_size
= 0x20,
130 .set_interrupt_mask_reg
= 0x00288,
131 .clr_interrupt_mask_reg
= 0x0028C,
132 .clr_interrupt_mask_reg32
= 0x0028C,
133 .sense_interrupt_mask_reg
= 0x00288,
134 .sense_interrupt_mask_reg32
= 0x00288,
135 .clr_interrupt_reg
= 0x00284,
136 .clr_interrupt_reg32
= 0x00284,
137 .sense_interrupt_reg
= 0x00280,
138 .sense_interrupt_reg32
= 0x00280,
139 .ioarrin_reg
= 0x00504,
140 .sense_uproc_interrupt_reg
= 0x00290,
141 .sense_uproc_interrupt_reg32
= 0x00290,
142 .set_uproc_interrupt_reg
= 0x00290,
143 .set_uproc_interrupt_reg32
= 0x00290,
144 .clr_uproc_interrupt_reg
= 0x00294,
145 .clr_uproc_interrupt_reg32
= 0x00294
150 .cache_line_size
= 0x20,
152 .set_interrupt_mask_reg
= 0x00010,
153 .clr_interrupt_mask_reg
= 0x00018,
154 .clr_interrupt_mask_reg32
= 0x0001C,
155 .sense_interrupt_mask_reg
= 0x00010,
156 .sense_interrupt_mask_reg32
= 0x00014,
157 .clr_interrupt_reg
= 0x00008,
158 .clr_interrupt_reg32
= 0x0000C,
159 .sense_interrupt_reg
= 0x00000,
160 .sense_interrupt_reg32
= 0x00004,
161 .ioarrin_reg
= 0x00070,
162 .sense_uproc_interrupt_reg
= 0x00020,
163 .sense_uproc_interrupt_reg32
= 0x00024,
164 .set_uproc_interrupt_reg
= 0x00020,
165 .set_uproc_interrupt_reg32
= 0x00024,
166 .clr_uproc_interrupt_reg
= 0x00028,
167 .clr_uproc_interrupt_reg32
= 0x0002C,
168 .init_feedback_reg
= 0x0005C,
169 .dump_addr_reg
= 0x00064,
170 .dump_data_reg
= 0x00068
175 static const struct ipr_chip_t ipr_chip
[] = {
176 { PCI_VENDOR_ID_MYLEX
, PCI_DEVICE_ID_IBM_GEMSTONE
, IPR_USE_LSI
, IPR_SIS32
, &ipr_chip_cfg
[0] },
177 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_CITRINE
, IPR_USE_LSI
, IPR_SIS32
, &ipr_chip_cfg
[0] },
178 { PCI_VENDOR_ID_ADAPTEC2
, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN
, IPR_USE_LSI
, IPR_SIS32
, &ipr_chip_cfg
[0] },
179 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_OBSIDIAN
, IPR_USE_LSI
, IPR_SIS32
, &ipr_chip_cfg
[0] },
180 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_OBSIDIAN_E
, IPR_USE_MSI
, IPR_SIS32
, &ipr_chip_cfg
[0] },
181 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_SNIPE
, IPR_USE_LSI
, IPR_SIS32
, &ipr_chip_cfg
[1] },
182 { PCI_VENDOR_ID_ADAPTEC2
, PCI_DEVICE_ID_ADAPTEC2_SCAMP
, IPR_USE_LSI
, IPR_SIS32
, &ipr_chip_cfg
[1] },
183 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_CROC_FPGA_E2
, IPR_USE_MSI
, IPR_SIS64
, &ipr_chip_cfg
[2] },
184 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_CROC_ASIC_E2
, IPR_USE_MSI
, IPR_SIS64
, &ipr_chip_cfg
[2] }
187 static int ipr_max_bus_speeds
[] = {
188 IPR_80MBs_SCSI_RATE
, IPR_U160_SCSI_RATE
, IPR_U320_SCSI_RATE
191 MODULE_AUTHOR("Brian King <brking@us.ibm.com>");
192 MODULE_DESCRIPTION("IBM Power RAID SCSI Adapter Driver");
193 module_param_named(max_speed
, ipr_max_speed
, uint
, 0);
194 MODULE_PARM_DESC(max_speed
, "Maximum bus speed (0-2). Default: 1=U160. Speeds: 0=80 MB/s, 1=U160, 2=U320");
195 module_param_named(log_level
, ipr_log_level
, uint
, 0);
196 MODULE_PARM_DESC(log_level
, "Set to 0 - 4 for increasing verbosity of device driver");
197 module_param_named(testmode
, ipr_testmode
, int, 0);
198 MODULE_PARM_DESC(testmode
, "DANGEROUS!!! Allows unsupported configurations");
199 module_param_named(fastfail
, ipr_fastfail
, int, S_IRUGO
| S_IWUSR
);
200 MODULE_PARM_DESC(fastfail
, "Reduce timeouts and retries");
201 module_param_named(transop_timeout
, ipr_transop_timeout
, int, 0);
202 MODULE_PARM_DESC(transop_timeout
, "Time in seconds to wait for adapter to come operational (default: 300)");
203 module_param_named(debug
, ipr_debug
, int, S_IRUGO
| S_IWUSR
);
204 MODULE_PARM_DESC(debug
, "Enable device driver debugging logging. Set to 1 to enable. (default: 0)");
205 module_param_named(dual_ioa_raid
, ipr_dual_ioa_raid
, int, 0);
206 MODULE_PARM_DESC(dual_ioa_raid
, "Enable dual adapter RAID support. Set to 1 to enable. (default: 1)");
207 module_param_named(max_devs
, ipr_max_devs
, int, 0);
208 MODULE_PARM_DESC(max_devs
, "Specify the maximum number of physical devices. "
209 "[Default=" __stringify(IPR_DEFAULT_SIS64_DEVS
) "]");
210 MODULE_LICENSE("GPL");
211 MODULE_VERSION(IPR_DRIVER_VERSION
);
213 /* A constant array of IOASCs/URCs/Error Messages */
215 struct ipr_error_table_t ipr_error_table
[] = {
216 {0x00000000, 1, IPR_DEFAULT_LOG_LEVEL
,
217 "8155: An unknown error was received"},
219 "Soft underlength error"},
221 "Command to be cancelled not found"},
223 "Qualified success"},
224 {0x01080000, 1, IPR_DEFAULT_LOG_LEVEL
,
225 "FFFE: Soft device bus error recovered by the IOA"},
226 {0x01088100, 0, IPR_DEFAULT_LOG_LEVEL
,
227 "4101: Soft device bus fabric error"},
228 {0x01100100, 0, IPR_DEFAULT_LOG_LEVEL
,
229 "FFFC: Logical block guard error recovered by the device"},
230 {0x01100300, 0, IPR_DEFAULT_LOG_LEVEL
,
231 "FFFC: Logical block reference tag error recovered by the device"},
232 {0x01108300, 0, IPR_DEFAULT_LOG_LEVEL
,
233 "4171: Recovered scatter list tag / sequence number error"},
234 {0x01109000, 0, IPR_DEFAULT_LOG_LEVEL
,
235 "FF3D: Recovered logical block CRC error on IOA to Host transfer"},
236 {0x01109200, 0, IPR_DEFAULT_LOG_LEVEL
,
237 "4171: Recovered logical block sequence number error on IOA to Host transfer"},
238 {0x0110A000, 0, IPR_DEFAULT_LOG_LEVEL
,
239 "FFFD: Recovered logical block reference tag error detected by the IOA"},
240 {0x0110A100, 0, IPR_DEFAULT_LOG_LEVEL
,
241 "FFFD: Logical block guard error recovered by the IOA"},
242 {0x01170600, 0, IPR_DEFAULT_LOG_LEVEL
,
243 "FFF9: Device sector reassign successful"},
244 {0x01170900, 0, IPR_DEFAULT_LOG_LEVEL
,
245 "FFF7: Media error recovered by device rewrite procedures"},
246 {0x01180200, 0, IPR_DEFAULT_LOG_LEVEL
,
247 "7001: IOA sector reassignment successful"},
248 {0x01180500, 0, IPR_DEFAULT_LOG_LEVEL
,
249 "FFF9: Soft media error. Sector reassignment recommended"},
250 {0x01180600, 0, IPR_DEFAULT_LOG_LEVEL
,
251 "FFF7: Media error recovered by IOA rewrite procedures"},
252 {0x01418000, 0, IPR_DEFAULT_LOG_LEVEL
,
253 "FF3D: Soft PCI bus error recovered by the IOA"},
254 {0x01440000, 1, IPR_DEFAULT_LOG_LEVEL
,
255 "FFF6: Device hardware error recovered by the IOA"},
256 {0x01448100, 0, IPR_DEFAULT_LOG_LEVEL
,
257 "FFF6: Device hardware error recovered by the device"},
258 {0x01448200, 1, IPR_DEFAULT_LOG_LEVEL
,
259 "FF3D: Soft IOA error recovered by the IOA"},
260 {0x01448300, 0, IPR_DEFAULT_LOG_LEVEL
,
261 "FFFA: Undefined device response recovered by the IOA"},
262 {0x014A0000, 1, IPR_DEFAULT_LOG_LEVEL
,
263 "FFF6: Device bus error, message or command phase"},
264 {0x014A8000, 0, IPR_DEFAULT_LOG_LEVEL
,
265 "FFFE: Task Management Function failed"},
266 {0x015D0000, 0, IPR_DEFAULT_LOG_LEVEL
,
267 "FFF6: Failure prediction threshold exceeded"},
268 {0x015D9200, 0, IPR_DEFAULT_LOG_LEVEL
,
269 "8009: Impending cache battery pack failure"},
271 "34FF: Disk device format in progress"},
272 {0x02048000, 0, IPR_DEFAULT_LOG_LEVEL
,
273 "9070: IOA requested reset"},
275 "Synchronization required"},
277 "No ready, IOA shutdown"},
279 "Not ready, IOA has been shutdown"},
280 {0x02670100, 0, IPR_DEFAULT_LOG_LEVEL
,
281 "3020: Storage subsystem configuration error"},
283 "FFF5: Medium error, data unreadable, recommend reassign"},
285 "7000: Medium error, data unreadable, do not reassign"},
286 {0x03310000, 0, IPR_DEFAULT_LOG_LEVEL
,
287 "FFF3: Disk media format bad"},
288 {0x04050000, 0, IPR_DEFAULT_LOG_LEVEL
,
289 "3002: Addressed device failed to respond to selection"},
290 {0x04080000, 1, IPR_DEFAULT_LOG_LEVEL
,
291 "3100: Device bus error"},
292 {0x04080100, 0, IPR_DEFAULT_LOG_LEVEL
,
293 "3109: IOA timed out a device command"},
295 "3120: SCSI bus is not operational"},
296 {0x04088100, 0, IPR_DEFAULT_LOG_LEVEL
,
297 "4100: Hard device bus fabric error"},
298 {0x04100100, 0, IPR_DEFAULT_LOG_LEVEL
,
299 "310C: Logical block guard error detected by the device"},
300 {0x04100300, 0, IPR_DEFAULT_LOG_LEVEL
,
301 "310C: Logical block reference tag error detected by the device"},
302 {0x04108300, 1, IPR_DEFAULT_LOG_LEVEL
,
303 "4170: Scatter list tag / sequence number error"},
304 {0x04109000, 1, IPR_DEFAULT_LOG_LEVEL
,
305 "8150: Logical block CRC error on IOA to Host transfer"},
306 {0x04109200, 1, IPR_DEFAULT_LOG_LEVEL
,
307 "4170: Logical block sequence number error on IOA to Host transfer"},
308 {0x0410A000, 0, IPR_DEFAULT_LOG_LEVEL
,
309 "310D: Logical block reference tag error detected by the IOA"},
310 {0x0410A100, 0, IPR_DEFAULT_LOG_LEVEL
,
311 "310D: Logical block guard error detected by the IOA"},
312 {0x04118000, 0, IPR_DEFAULT_LOG_LEVEL
,
313 "9000: IOA reserved area data check"},
314 {0x04118100, 0, IPR_DEFAULT_LOG_LEVEL
,
315 "9001: IOA reserved area invalid data pattern"},
316 {0x04118200, 0, IPR_DEFAULT_LOG_LEVEL
,
317 "9002: IOA reserved area LRC error"},
318 {0x04118300, 1, IPR_DEFAULT_LOG_LEVEL
,
319 "Hardware Error, IOA metadata access error"},
320 {0x04320000, 0, IPR_DEFAULT_LOG_LEVEL
,
321 "102E: Out of alternate sectors for disk storage"},
322 {0x04330000, 1, IPR_DEFAULT_LOG_LEVEL
,
323 "FFF4: Data transfer underlength error"},
324 {0x04338000, 1, IPR_DEFAULT_LOG_LEVEL
,
325 "FFF4: Data transfer overlength error"},
326 {0x043E0100, 0, IPR_DEFAULT_LOG_LEVEL
,
327 "3400: Logical unit failure"},
328 {0x04408500, 0, IPR_DEFAULT_LOG_LEVEL
,
329 "FFF4: Device microcode is corrupt"},
330 {0x04418000, 1, IPR_DEFAULT_LOG_LEVEL
,
331 "8150: PCI bus error"},
333 "Unsupported device bus message received"},
334 {0x04440000, 1, IPR_DEFAULT_LOG_LEVEL
,
335 "FFF4: Disk device problem"},
336 {0x04448200, 1, IPR_DEFAULT_LOG_LEVEL
,
337 "8150: Permanent IOA failure"},
338 {0x04448300, 0, IPR_DEFAULT_LOG_LEVEL
,
339 "3010: Disk device returned wrong response to IOA"},
340 {0x04448400, 0, IPR_DEFAULT_LOG_LEVEL
,
341 "8151: IOA microcode error"},
343 "Device bus status error"},
344 {0x04448600, 0, IPR_DEFAULT_LOG_LEVEL
,
345 "8157: IOA error requiring IOA reset to recover"},
347 "ATA device status error"},
349 "Message reject received from the device"},
350 {0x04449200, 0, IPR_DEFAULT_LOG_LEVEL
,
351 "8008: A permanent cache battery pack failure occurred"},
352 {0x0444A000, 0, IPR_DEFAULT_LOG_LEVEL
,
353 "9090: Disk unit has been modified after the last known status"},
354 {0x0444A200, 0, IPR_DEFAULT_LOG_LEVEL
,
355 "9081: IOA detected device error"},
356 {0x0444A300, 0, IPR_DEFAULT_LOG_LEVEL
,
357 "9082: IOA detected device error"},
358 {0x044A0000, 1, IPR_DEFAULT_LOG_LEVEL
,
359 "3110: Device bus error, message or command phase"},
360 {0x044A8000, 1, IPR_DEFAULT_LOG_LEVEL
,
361 "3110: SAS Command / Task Management Function failed"},
362 {0x04670400, 0, IPR_DEFAULT_LOG_LEVEL
,
363 "9091: Incorrect hardware configuration change has been detected"},
364 {0x04678000, 0, IPR_DEFAULT_LOG_LEVEL
,
365 "9073: Invalid multi-adapter configuration"},
366 {0x04678100, 0, IPR_DEFAULT_LOG_LEVEL
,
367 "4010: Incorrect connection between cascaded expanders"},
368 {0x04678200, 0, IPR_DEFAULT_LOG_LEVEL
,
369 "4020: Connections exceed IOA design limits"},
370 {0x04678300, 0, IPR_DEFAULT_LOG_LEVEL
,
371 "4030: Incorrect multipath connection"},
372 {0x04679000, 0, IPR_DEFAULT_LOG_LEVEL
,
373 "4110: Unsupported enclosure function"},
374 {0x046E0000, 0, IPR_DEFAULT_LOG_LEVEL
,
375 "FFF4: Command to logical unit failed"},
377 "Illegal request, invalid request type or request packet"},
379 "Illegal request, invalid resource handle"},
381 "Illegal request, commands not allowed to this device"},
383 "Illegal request, command not allowed to a secondary adapter"},
385 "Illegal request, command not allowed to a non-optimized resource"},
387 "Illegal request, invalid field in parameter list"},
389 "Illegal request, parameter not supported"},
391 "Illegal request, parameter value invalid"},
393 "Illegal request, command sequence error"},
395 "Illegal request, dual adapter support not enabled"},
396 {0x06040500, 0, IPR_DEFAULT_LOG_LEVEL
,
397 "9031: Array protection temporarily suspended, protection resuming"},
398 {0x06040600, 0, IPR_DEFAULT_LOG_LEVEL
,
399 "9040: Array protection temporarily suspended, protection resuming"},
400 {0x06288000, 0, IPR_DEFAULT_LOG_LEVEL
,
401 "3140: Device bus not ready to ready transition"},
402 {0x06290000, 0, IPR_DEFAULT_LOG_LEVEL
,
403 "FFFB: SCSI bus was reset"},
405 "FFFE: SCSI bus transition to single ended"},
407 "FFFE: SCSI bus transition to LVD"},
408 {0x06298000, 0, IPR_DEFAULT_LOG_LEVEL
,
409 "FFFB: SCSI bus was reset by another initiator"},
410 {0x063F0300, 0, IPR_DEFAULT_LOG_LEVEL
,
411 "3029: A device replacement has occurred"},
412 {0x064C8000, 0, IPR_DEFAULT_LOG_LEVEL
,
413 "9051: IOA cache data exists for a missing or failed device"},
414 {0x064C8100, 0, IPR_DEFAULT_LOG_LEVEL
,
415 "9055: Auxiliary cache IOA contains cache data needed by the primary IOA"},
416 {0x06670100, 0, IPR_DEFAULT_LOG_LEVEL
,
417 "9025: Disk unit is not supported at its physical location"},
418 {0x06670600, 0, IPR_DEFAULT_LOG_LEVEL
,
419 "3020: IOA detected a SCSI bus configuration error"},
420 {0x06678000, 0, IPR_DEFAULT_LOG_LEVEL
,
421 "3150: SCSI bus configuration error"},
422 {0x06678100, 0, IPR_DEFAULT_LOG_LEVEL
,
423 "9074: Asymmetric advanced function disk configuration"},
424 {0x06678300, 0, IPR_DEFAULT_LOG_LEVEL
,
425 "4040: Incomplete multipath connection between IOA and enclosure"},
426 {0x06678400, 0, IPR_DEFAULT_LOG_LEVEL
,
427 "4041: Incomplete multipath connection between enclosure and device"},
428 {0x06678500, 0, IPR_DEFAULT_LOG_LEVEL
,
429 "9075: Incomplete multipath connection between IOA and remote IOA"},
430 {0x06678600, 0, IPR_DEFAULT_LOG_LEVEL
,
431 "9076: Configuration error, missing remote IOA"},
432 {0x06679100, 0, IPR_DEFAULT_LOG_LEVEL
,
433 "4050: Enclosure does not support a required multipath function"},
434 {0x06690000, 0, IPR_DEFAULT_LOG_LEVEL
,
435 "4070: Logically bad block written on device"},
436 {0x06690200, 0, IPR_DEFAULT_LOG_LEVEL
,
437 "9041: Array protection temporarily suspended"},
438 {0x06698200, 0, IPR_DEFAULT_LOG_LEVEL
,
439 "9042: Corrupt array parity detected on specified device"},
440 {0x066B0200, 0, IPR_DEFAULT_LOG_LEVEL
,
441 "9030: Array no longer protected due to missing or failed disk unit"},
442 {0x066B8000, 0, IPR_DEFAULT_LOG_LEVEL
,
443 "9071: Link operational transition"},
444 {0x066B8100, 0, IPR_DEFAULT_LOG_LEVEL
,
445 "9072: Link not operational transition"},
446 {0x066B8200, 0, IPR_DEFAULT_LOG_LEVEL
,
447 "9032: Array exposed but still protected"},
448 {0x066B8300, 0, IPR_DEFAULT_LOG_LEVEL
+ 1,
449 "70DD: Device forced failed by disrupt device command"},
450 {0x066B9100, 0, IPR_DEFAULT_LOG_LEVEL
,
451 "4061: Multipath redundancy level got better"},
452 {0x066B9200, 0, IPR_DEFAULT_LOG_LEVEL
,
453 "4060: Multipath redundancy level got worse"},
455 "Failure due to other device"},
456 {0x07278000, 0, IPR_DEFAULT_LOG_LEVEL
,
457 "9008: IOA does not support functions expected by devices"},
458 {0x07278100, 0, IPR_DEFAULT_LOG_LEVEL
,
459 "9010: Cache data associated with attached devices cannot be found"},
460 {0x07278200, 0, IPR_DEFAULT_LOG_LEVEL
,
461 "9011: Cache data belongs to devices other than those attached"},
462 {0x07278400, 0, IPR_DEFAULT_LOG_LEVEL
,
463 "9020: Array missing 2 or more devices with only 1 device present"},
464 {0x07278500, 0, IPR_DEFAULT_LOG_LEVEL
,
465 "9021: Array missing 2 or more devices with 2 or more devices present"},
466 {0x07278600, 0, IPR_DEFAULT_LOG_LEVEL
,
467 "9022: Exposed array is missing a required device"},
468 {0x07278700, 0, IPR_DEFAULT_LOG_LEVEL
,
469 "9023: Array member(s) not at required physical locations"},
470 {0x07278800, 0, IPR_DEFAULT_LOG_LEVEL
,
471 "9024: Array not functional due to present hardware configuration"},
472 {0x07278900, 0, IPR_DEFAULT_LOG_LEVEL
,
473 "9026: Array not functional due to present hardware configuration"},
474 {0x07278A00, 0, IPR_DEFAULT_LOG_LEVEL
,
475 "9027: Array is missing a device and parity is out of sync"},
476 {0x07278B00, 0, IPR_DEFAULT_LOG_LEVEL
,
477 "9028: Maximum number of arrays already exist"},
478 {0x07278C00, 0, IPR_DEFAULT_LOG_LEVEL
,
479 "9050: Required cache data cannot be located for a disk unit"},
480 {0x07278D00, 0, IPR_DEFAULT_LOG_LEVEL
,
481 "9052: Cache data exists for a device that has been modified"},
482 {0x07278F00, 0, IPR_DEFAULT_LOG_LEVEL
,
483 "9054: IOA resources not available due to previous problems"},
484 {0x07279100, 0, IPR_DEFAULT_LOG_LEVEL
,
485 "9092: Disk unit requires initialization before use"},
486 {0x07279200, 0, IPR_DEFAULT_LOG_LEVEL
,
487 "9029: Incorrect hardware configuration change has been detected"},
488 {0x07279600, 0, IPR_DEFAULT_LOG_LEVEL
,
489 "9060: One or more disk pairs are missing from an array"},
490 {0x07279700, 0, IPR_DEFAULT_LOG_LEVEL
,
491 "9061: One or more disks are missing from an array"},
492 {0x07279800, 0, IPR_DEFAULT_LOG_LEVEL
,
493 "9062: One or more disks are missing from an array"},
494 {0x07279900, 0, IPR_DEFAULT_LOG_LEVEL
,
495 "9063: Maximum number of functional arrays has been exceeded"},
497 "Aborted command, invalid descriptor"},
499 "Command terminated by host"}
502 static const struct ipr_ses_table_entry ipr_ses_table
[] = {
503 { "2104-DL1 ", "XXXXXXXXXXXXXXXX", 80 },
504 { "2104-TL1 ", "XXXXXXXXXXXXXXXX", 80 },
505 { "HSBP07M P U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Hidive 7 slot */
506 { "HSBP05M P U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Hidive 5 slot */
507 { "HSBP05M S U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Bowtie */
508 { "HSBP06E ASU2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* MartinFenning */
509 { "2104-DU3 ", "XXXXXXXXXXXXXXXX", 160 },
510 { "2104-TU3 ", "XXXXXXXXXXXXXXXX", 160 },
511 { "HSBP04C RSU2SCSI", "XXXXXXX*XXXXXXXX", 160 },
512 { "HSBP06E RSU2SCSI", "XXXXXXX*XXXXXXXX", 160 },
513 { "St V1S2 ", "XXXXXXXXXXXXXXXX", 160 },
514 { "HSBPD4M PU3SCSI", "XXXXXXX*XXXXXXXX", 160 },
515 { "VSBPD1H U3SCSI", "XXXXXXX*XXXXXXXX", 160 }
519 * Function Prototypes
521 static int ipr_reset_alert(struct ipr_cmnd
*);
522 static void ipr_process_ccn(struct ipr_cmnd
*);
523 static void ipr_process_error(struct ipr_cmnd
*);
524 static void ipr_reset_ioa_job(struct ipr_cmnd
*);
525 static void ipr_initiate_ioa_reset(struct ipr_ioa_cfg
*,
526 enum ipr_shutdown_type
);
528 #ifdef CONFIG_SCSI_IPR_TRACE
530 * ipr_trc_hook - Add a trace entry to the driver trace
531 * @ipr_cmd: ipr command struct
533 * @add_data: additional data
538 static void ipr_trc_hook(struct ipr_cmnd
*ipr_cmd
,
539 u8 type
, u32 add_data
)
541 struct ipr_trace_entry
*trace_entry
;
542 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
544 trace_entry
= &ioa_cfg
->trace
[ioa_cfg
->trace_index
++];
545 trace_entry
->time
= jiffies
;
546 trace_entry
->op_code
= ipr_cmd
->ioarcb
.cmd_pkt
.cdb
[0];
547 trace_entry
->type
= type
;
548 if (ipr_cmd
->ioa_cfg
->sis64
)
549 trace_entry
->ata_op_code
= ipr_cmd
->i
.ata_ioadl
.regs
.command
;
551 trace_entry
->ata_op_code
= ipr_cmd
->ioarcb
.u
.add_data
.u
.regs
.command
;
552 trace_entry
->cmd_index
= ipr_cmd
->cmd_index
& 0xff;
553 trace_entry
->res_handle
= ipr_cmd
->ioarcb
.res_handle
;
554 trace_entry
->u
.add_data
= add_data
;
557 #define ipr_trc_hook(ipr_cmd, type, add_data) do { } while(0)
561 * ipr_reinit_ipr_cmnd - Re-initialize an IPR Cmnd block for reuse
562 * @ipr_cmd: ipr command struct
567 static void ipr_reinit_ipr_cmnd(struct ipr_cmnd
*ipr_cmd
)
569 struct ipr_ioarcb
*ioarcb
= &ipr_cmd
->ioarcb
;
570 struct ipr_ioasa
*ioasa
= &ipr_cmd
->ioasa
;
571 dma_addr_t dma_addr
= ipr_cmd
->dma_addr
;
573 memset(&ioarcb
->cmd_pkt
, 0, sizeof(struct ipr_cmd_pkt
));
574 ioarcb
->data_transfer_length
= 0;
575 ioarcb
->read_data_transfer_length
= 0;
576 ioarcb
->ioadl_len
= 0;
577 ioarcb
->read_ioadl_len
= 0;
579 if (ipr_cmd
->ioa_cfg
->sis64
)
580 ioarcb
->u
.sis64_addr_data
.data_ioadl_addr
=
581 cpu_to_be64(dma_addr
+ offsetof(struct ipr_cmnd
, i
.ioadl64
));
583 ioarcb
->write_ioadl_addr
=
584 cpu_to_be32(dma_addr
+ offsetof(struct ipr_cmnd
, i
.ioadl
));
585 ioarcb
->read_ioadl_addr
= ioarcb
->write_ioadl_addr
;
589 ioasa
->residual_data_len
= 0;
590 ioasa
->u
.gata
.status
= 0;
592 ipr_cmd
->scsi_cmd
= NULL
;
594 ipr_cmd
->sense_buffer
[0] = 0;
595 ipr_cmd
->dma_use_sg
= 0;
599 * ipr_init_ipr_cmnd - Initialize an IPR Cmnd block
600 * @ipr_cmd: ipr command struct
605 static void ipr_init_ipr_cmnd(struct ipr_cmnd
*ipr_cmd
)
607 ipr_reinit_ipr_cmnd(ipr_cmd
);
608 ipr_cmd
->u
.scratch
= 0;
609 ipr_cmd
->sibling
= NULL
;
610 init_timer(&ipr_cmd
->timer
);
614 * ipr_get_free_ipr_cmnd - Get a free IPR Cmnd block
615 * @ioa_cfg: ioa config struct
618 * pointer to ipr command struct
621 struct ipr_cmnd
*ipr_get_free_ipr_cmnd(struct ipr_ioa_cfg
*ioa_cfg
)
623 struct ipr_cmnd
*ipr_cmd
;
625 ipr_cmd
= list_entry(ioa_cfg
->free_q
.next
, struct ipr_cmnd
, queue
);
626 list_del(&ipr_cmd
->queue
);
627 ipr_init_ipr_cmnd(ipr_cmd
);
633 * ipr_mask_and_clear_interrupts - Mask all and clear specified interrupts
634 * @ioa_cfg: ioa config struct
635 * @clr_ints: interrupts to clear
637 * This function masks all interrupts on the adapter, then clears the
638 * interrupts specified in the mask
643 static void ipr_mask_and_clear_interrupts(struct ipr_ioa_cfg
*ioa_cfg
,
646 volatile u32 int_reg
;
648 /* Stop new interrupts */
649 ioa_cfg
->allow_interrupts
= 0;
651 /* Set interrupt mask to stop all new interrupts */
653 writeq(~0, ioa_cfg
->regs
.set_interrupt_mask_reg
);
655 writel(~0, ioa_cfg
->regs
.set_interrupt_mask_reg
);
657 /* Clear any pending interrupts */
659 writel(~0, ioa_cfg
->regs
.clr_interrupt_reg
);
660 writel(clr_ints
, ioa_cfg
->regs
.clr_interrupt_reg32
);
661 int_reg
= readl(ioa_cfg
->regs
.sense_interrupt_reg
);
665 * ipr_save_pcix_cmd_reg - Save PCI-X command register
666 * @ioa_cfg: ioa config struct
669 * 0 on success / -EIO on failure
671 static int ipr_save_pcix_cmd_reg(struct ipr_ioa_cfg
*ioa_cfg
)
673 int pcix_cmd_reg
= pci_find_capability(ioa_cfg
->pdev
, PCI_CAP_ID_PCIX
);
675 if (pcix_cmd_reg
== 0)
678 if (pci_read_config_word(ioa_cfg
->pdev
, pcix_cmd_reg
+ PCI_X_CMD
,
679 &ioa_cfg
->saved_pcix_cmd_reg
) != PCIBIOS_SUCCESSFUL
) {
680 dev_err(&ioa_cfg
->pdev
->dev
, "Failed to save PCI-X command register\n");
684 ioa_cfg
->saved_pcix_cmd_reg
|= PCI_X_CMD_DPERR_E
| PCI_X_CMD_ERO
;
689 * ipr_set_pcix_cmd_reg - Setup PCI-X command register
690 * @ioa_cfg: ioa config struct
693 * 0 on success / -EIO on failure
695 static int ipr_set_pcix_cmd_reg(struct ipr_ioa_cfg
*ioa_cfg
)
697 int pcix_cmd_reg
= pci_find_capability(ioa_cfg
->pdev
, PCI_CAP_ID_PCIX
);
700 if (pci_write_config_word(ioa_cfg
->pdev
, pcix_cmd_reg
+ PCI_X_CMD
,
701 ioa_cfg
->saved_pcix_cmd_reg
) != PCIBIOS_SUCCESSFUL
) {
702 dev_err(&ioa_cfg
->pdev
->dev
, "Failed to setup PCI-X command register\n");
711 * ipr_sata_eh_done - done function for aborted SATA commands
712 * @ipr_cmd: ipr command struct
714 * This function is invoked for ops generated to SATA
715 * devices which are being aborted.
720 static void ipr_sata_eh_done(struct ipr_cmnd
*ipr_cmd
)
722 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
723 struct ata_queued_cmd
*qc
= ipr_cmd
->qc
;
724 struct ipr_sata_port
*sata_port
= qc
->ap
->private_data
;
726 qc
->err_mask
|= AC_ERR_OTHER
;
727 sata_port
->ioasa
.status
|= ATA_BUSY
;
728 list_add_tail(&ipr_cmd
->queue
, &ioa_cfg
->free_q
);
733 * ipr_scsi_eh_done - mid-layer done function for aborted ops
734 * @ipr_cmd: ipr command struct
736 * This function is invoked by the interrupt handler for
737 * ops generated by the SCSI mid-layer which are being aborted.
742 static void ipr_scsi_eh_done(struct ipr_cmnd
*ipr_cmd
)
744 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
745 struct scsi_cmnd
*scsi_cmd
= ipr_cmd
->scsi_cmd
;
747 scsi_cmd
->result
|= (DID_ERROR
<< 16);
749 scsi_dma_unmap(ipr_cmd
->scsi_cmd
);
750 scsi_cmd
->scsi_done(scsi_cmd
);
751 list_add_tail(&ipr_cmd
->queue
, &ioa_cfg
->free_q
);
755 * ipr_fail_all_ops - Fails all outstanding ops.
756 * @ioa_cfg: ioa config struct
758 * This function fails all outstanding ops.
763 static void ipr_fail_all_ops(struct ipr_ioa_cfg
*ioa_cfg
)
765 struct ipr_cmnd
*ipr_cmd
, *temp
;
768 list_for_each_entry_safe(ipr_cmd
, temp
, &ioa_cfg
->pending_q
, queue
) {
769 list_del(&ipr_cmd
->queue
);
771 ipr_cmd
->ioasa
.ioasc
= cpu_to_be32(IPR_IOASC_IOA_WAS_RESET
);
772 ipr_cmd
->ioasa
.ilid
= cpu_to_be32(IPR_DRIVER_ILID
);
774 if (ipr_cmd
->scsi_cmd
)
775 ipr_cmd
->done
= ipr_scsi_eh_done
;
776 else if (ipr_cmd
->qc
)
777 ipr_cmd
->done
= ipr_sata_eh_done
;
779 ipr_trc_hook(ipr_cmd
, IPR_TRACE_FINISH
, IPR_IOASC_IOA_WAS_RESET
);
780 del_timer(&ipr_cmd
->timer
);
781 ipr_cmd
->done(ipr_cmd
);
788 * ipr_send_command - Send driver initiated requests.
789 * @ipr_cmd: ipr command struct
791 * This function sends a command to the adapter using the correct write call.
792 * In the case of sis64, calculate the ioarcb size required. Then or in the
798 static void ipr_send_command(struct ipr_cmnd
*ipr_cmd
)
800 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
801 dma_addr_t send_dma_addr
= ipr_cmd
->dma_addr
;
803 if (ioa_cfg
->sis64
) {
804 /* The default size is 256 bytes */
805 send_dma_addr
|= 0x1;
807 /* If the number of ioadls * size of ioadl > 128 bytes,
808 then use a 512 byte ioarcb */
809 if (ipr_cmd
->dma_use_sg
* sizeof(struct ipr_ioadl64_desc
) > 128 )
810 send_dma_addr
|= 0x4;
811 writeq(send_dma_addr
, ioa_cfg
->regs
.ioarrin_reg
);
813 writel(send_dma_addr
, ioa_cfg
->regs
.ioarrin_reg
);
817 * ipr_do_req - Send driver initiated requests.
818 * @ipr_cmd: ipr command struct
819 * @done: done function
820 * @timeout_func: timeout function
821 * @timeout: timeout value
823 * This function sends the specified command to the adapter with the
824 * timeout given. The done function is invoked on command completion.
829 static void ipr_do_req(struct ipr_cmnd
*ipr_cmd
,
830 void (*done
) (struct ipr_cmnd
*),
831 void (*timeout_func
) (struct ipr_cmnd
*), u32 timeout
)
833 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
835 list_add_tail(&ipr_cmd
->queue
, &ioa_cfg
->pending_q
);
837 ipr_cmd
->done
= done
;
839 ipr_cmd
->timer
.data
= (unsigned long) ipr_cmd
;
840 ipr_cmd
->timer
.expires
= jiffies
+ timeout
;
841 ipr_cmd
->timer
.function
= (void (*)(unsigned long))timeout_func
;
843 add_timer(&ipr_cmd
->timer
);
845 ipr_trc_hook(ipr_cmd
, IPR_TRACE_START
, 0);
849 ipr_send_command(ipr_cmd
);
853 * ipr_internal_cmd_done - Op done function for an internally generated op.
854 * @ipr_cmd: ipr command struct
856 * This function is the op done function for an internally generated,
857 * blocking op. It simply wakes the sleeping thread.
862 static void ipr_internal_cmd_done(struct ipr_cmnd
*ipr_cmd
)
864 if (ipr_cmd
->sibling
)
865 ipr_cmd
->sibling
= NULL
;
867 complete(&ipr_cmd
->completion
);
871 * ipr_init_ioadl - initialize the ioadl for the correct SIS type
872 * @ipr_cmd: ipr command struct
873 * @dma_addr: dma address
874 * @len: transfer length
875 * @flags: ioadl flag value
877 * This function initializes an ioadl in the case where there is only a single
883 static void ipr_init_ioadl(struct ipr_cmnd
*ipr_cmd
, dma_addr_t dma_addr
,
886 struct ipr_ioadl_desc
*ioadl
= ipr_cmd
->i
.ioadl
;
887 struct ipr_ioadl64_desc
*ioadl64
= ipr_cmd
->i
.ioadl64
;
889 ipr_cmd
->dma_use_sg
= 1;
891 if (ipr_cmd
->ioa_cfg
->sis64
) {
892 ioadl64
->flags
= cpu_to_be32(flags
);
893 ioadl64
->data_len
= cpu_to_be32(len
);
894 ioadl64
->address
= cpu_to_be64(dma_addr
);
896 ipr_cmd
->ioarcb
.ioadl_len
=
897 cpu_to_be32(sizeof(struct ipr_ioadl64_desc
));
898 ipr_cmd
->ioarcb
.data_transfer_length
= cpu_to_be32(len
);
900 ioadl
->flags_and_data_len
= cpu_to_be32(flags
| len
);
901 ioadl
->address
= cpu_to_be32(dma_addr
);
903 if (flags
== IPR_IOADL_FLAGS_READ_LAST
) {
904 ipr_cmd
->ioarcb
.read_ioadl_len
=
905 cpu_to_be32(sizeof(struct ipr_ioadl_desc
));
906 ipr_cmd
->ioarcb
.read_data_transfer_length
= cpu_to_be32(len
);
908 ipr_cmd
->ioarcb
.ioadl_len
=
909 cpu_to_be32(sizeof(struct ipr_ioadl_desc
));
910 ipr_cmd
->ioarcb
.data_transfer_length
= cpu_to_be32(len
);
916 * ipr_send_blocking_cmd - Send command and sleep on its completion.
917 * @ipr_cmd: ipr command struct
918 * @timeout_func: function to invoke if command times out
924 static void ipr_send_blocking_cmd(struct ipr_cmnd
*ipr_cmd
,
925 void (*timeout_func
) (struct ipr_cmnd
*ipr_cmd
),
928 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
930 init_completion(&ipr_cmd
->completion
);
931 ipr_do_req(ipr_cmd
, ipr_internal_cmd_done
, timeout_func
, timeout
);
933 spin_unlock_irq(ioa_cfg
->host
->host_lock
);
934 wait_for_completion(&ipr_cmd
->completion
);
935 spin_lock_irq(ioa_cfg
->host
->host_lock
);
939 * ipr_send_hcam - Send an HCAM to the adapter.
940 * @ioa_cfg: ioa config struct
942 * @hostrcb: hostrcb struct
944 * This function will send a Host Controlled Async command to the adapter.
945 * If HCAMs are currently not allowed to be issued to the adapter, it will
946 * place the hostrcb on the free queue.
951 static void ipr_send_hcam(struct ipr_ioa_cfg
*ioa_cfg
, u8 type
,
952 struct ipr_hostrcb
*hostrcb
)
954 struct ipr_cmnd
*ipr_cmd
;
955 struct ipr_ioarcb
*ioarcb
;
957 if (ioa_cfg
->allow_cmds
) {
958 ipr_cmd
= ipr_get_free_ipr_cmnd(ioa_cfg
);
959 list_add_tail(&ipr_cmd
->queue
, &ioa_cfg
->pending_q
);
960 list_add_tail(&hostrcb
->queue
, &ioa_cfg
->hostrcb_pending_q
);
962 ipr_cmd
->u
.hostrcb
= hostrcb
;
963 ioarcb
= &ipr_cmd
->ioarcb
;
965 ioarcb
->res_handle
= cpu_to_be32(IPR_IOA_RES_HANDLE
);
966 ioarcb
->cmd_pkt
.request_type
= IPR_RQTYPE_HCAM
;
967 ioarcb
->cmd_pkt
.cdb
[0] = IPR_HOST_CONTROLLED_ASYNC
;
968 ioarcb
->cmd_pkt
.cdb
[1] = type
;
969 ioarcb
->cmd_pkt
.cdb
[7] = (sizeof(hostrcb
->hcam
) >> 8) & 0xff;
970 ioarcb
->cmd_pkt
.cdb
[8] = sizeof(hostrcb
->hcam
) & 0xff;
972 ipr_init_ioadl(ipr_cmd
, hostrcb
->hostrcb_dma
,
973 sizeof(hostrcb
->hcam
), IPR_IOADL_FLAGS_READ_LAST
);
975 if (type
== IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE
)
976 ipr_cmd
->done
= ipr_process_ccn
;
978 ipr_cmd
->done
= ipr_process_error
;
980 ipr_trc_hook(ipr_cmd
, IPR_TRACE_START
, IPR_IOA_RES_ADDR
);
984 ipr_send_command(ipr_cmd
);
986 list_add_tail(&hostrcb
->queue
, &ioa_cfg
->hostrcb_free_q
);
991 * ipr_update_ata_class - Update the ata class in the resource entry
992 * @res: resource entry struct
993 * @proto: cfgte device bus protocol value
998 static void ipr_update_ata_class(struct ipr_resource_entry
*res
, unsigned int proto
)
1001 case IPR_PROTO_SATA
:
1002 case IPR_PROTO_SAS_STP
:
1003 res
->ata_class
= ATA_DEV_ATA
;
1005 case IPR_PROTO_SATA_ATAPI
:
1006 case IPR_PROTO_SAS_STP_ATAPI
:
1007 res
->ata_class
= ATA_DEV_ATAPI
;
1010 res
->ata_class
= ATA_DEV_UNKNOWN
;
1016 * ipr_init_res_entry - Initialize a resource entry struct.
1017 * @res: resource entry struct
1018 * @cfgtew: config table entry wrapper struct
1023 static void ipr_init_res_entry(struct ipr_resource_entry
*res
,
1024 struct ipr_config_table_entry_wrapper
*cfgtew
)
1028 struct ipr_ioa_cfg
*ioa_cfg
= res
->ioa_cfg
;
1029 struct ipr_resource_entry
*gscsi_res
= NULL
;
1031 res
->needs_sync_complete
= 0;
1034 res
->del_from_ml
= 0;
1035 res
->resetting_device
= 0;
1037 res
->sata_port
= NULL
;
1039 if (ioa_cfg
->sis64
) {
1040 proto
= cfgtew
->u
.cfgte64
->proto
;
1041 res
->res_flags
= cfgtew
->u
.cfgte64
->res_flags
;
1042 res
->qmodel
= IPR_QUEUEING_MODEL64(res
);
1043 res
->type
= cfgtew
->u
.cfgte64
->res_type
& 0x0f;
1045 memcpy(res
->res_path
, &cfgtew
->u
.cfgte64
->res_path
,
1046 sizeof(res
->res_path
));
1049 res
->lun
= scsilun_to_int(&res
->dev_lun
);
1051 if (res
->type
== IPR_RES_TYPE_GENERIC_SCSI
) {
1052 list_for_each_entry(gscsi_res
, &ioa_cfg
->used_res_q
, queue
) {
1053 if (gscsi_res
->dev_id
== cfgtew
->u
.cfgte64
->dev_id
) {
1055 res
->target
= gscsi_res
->target
;
1060 res
->target
= find_first_zero_bit(ioa_cfg
->target_ids
,
1061 ioa_cfg
->max_devs_supported
);
1062 set_bit(res
->target
, ioa_cfg
->target_ids
);
1065 memcpy(&res
->dev_lun
.scsi_lun
, &cfgtew
->u
.cfgte64
->lun
,
1066 sizeof(res
->dev_lun
.scsi_lun
));
1067 } else if (res
->type
== IPR_RES_TYPE_IOAFP
) {
1068 res
->bus
= IPR_IOAFP_VIRTUAL_BUS
;
1070 } else if (res
->type
== IPR_RES_TYPE_ARRAY
) {
1071 res
->bus
= IPR_ARRAY_VIRTUAL_BUS
;
1072 res
->target
= find_first_zero_bit(ioa_cfg
->array_ids
,
1073 ioa_cfg
->max_devs_supported
);
1074 set_bit(res
->target
, ioa_cfg
->array_ids
);
1075 } else if (res
->type
== IPR_RES_TYPE_VOLUME_SET
) {
1076 res
->bus
= IPR_VSET_VIRTUAL_BUS
;
1077 res
->target
= find_first_zero_bit(ioa_cfg
->vset_ids
,
1078 ioa_cfg
->max_devs_supported
);
1079 set_bit(res
->target
, ioa_cfg
->vset_ids
);
1081 res
->target
= find_first_zero_bit(ioa_cfg
->target_ids
,
1082 ioa_cfg
->max_devs_supported
);
1083 set_bit(res
->target
, ioa_cfg
->target_ids
);
1086 proto
= cfgtew
->u
.cfgte
->proto
;
1087 res
->qmodel
= IPR_QUEUEING_MODEL(res
);
1088 res
->flags
= cfgtew
->u
.cfgte
->flags
;
1089 if (res
->flags
& IPR_IS_IOA_RESOURCE
)
1090 res
->type
= IPR_RES_TYPE_IOAFP
;
1092 res
->type
= cfgtew
->u
.cfgte
->rsvd_subtype
& 0x0f;
1094 res
->bus
= cfgtew
->u
.cfgte
->res_addr
.bus
;
1095 res
->target
= cfgtew
->u
.cfgte
->res_addr
.target
;
1096 res
->lun
= cfgtew
->u
.cfgte
->res_addr
.lun
;
1099 ipr_update_ata_class(res
, proto
);
1103 * ipr_is_same_device - Determine if two devices are the same.
1104 * @res: resource entry struct
1105 * @cfgtew: config table entry wrapper struct
1108 * 1 if the devices are the same / 0 otherwise
1110 static int ipr_is_same_device(struct ipr_resource_entry
*res
,
1111 struct ipr_config_table_entry_wrapper
*cfgtew
)
1113 if (res
->ioa_cfg
->sis64
) {
1114 if (!memcmp(&res
->dev_id
, &cfgtew
->u
.cfgte64
->dev_id
,
1115 sizeof(cfgtew
->u
.cfgte64
->dev_id
)) &&
1116 !memcmp(&res
->lun
, &cfgtew
->u
.cfgte64
->lun
,
1117 sizeof(cfgtew
->u
.cfgte64
->lun
))) {
1121 if (res
->bus
== cfgtew
->u
.cfgte
->res_addr
.bus
&&
1122 res
->target
== cfgtew
->u
.cfgte
->res_addr
.target
&&
1123 res
->lun
== cfgtew
->u
.cfgte
->res_addr
.lun
)
1131 * ipr_format_resource_path - Format the resource path for printing.
1132 * @res_path: resource path
1138 static char *ipr_format_resource_path(u8
*res_path
, char *buffer
)
1142 sprintf(buffer
, "%02X", res_path
[0]);
1143 for (i
=1; res_path
[i
] != 0xff; i
++)
1144 sprintf(buffer
, "%s-%02X", buffer
, res_path
[i
]);
1150 * ipr_update_res_entry - Update the resource entry.
1151 * @res: resource entry struct
1152 * @cfgtew: config table entry wrapper struct
1157 static void ipr_update_res_entry(struct ipr_resource_entry
*res
,
1158 struct ipr_config_table_entry_wrapper
*cfgtew
)
1160 char buffer
[IPR_MAX_RES_PATH_LENGTH
];
1164 if (res
->ioa_cfg
->sis64
) {
1165 res
->flags
= cfgtew
->u
.cfgte64
->flags
;
1166 res
->res_flags
= cfgtew
->u
.cfgte64
->res_flags
;
1167 res
->type
= cfgtew
->u
.cfgte64
->res_type
& 0x0f;
1169 memcpy(&res
->std_inq_data
, &cfgtew
->u
.cfgte64
->std_inq_data
,
1170 sizeof(struct ipr_std_inq_data
));
1172 res
->qmodel
= IPR_QUEUEING_MODEL64(res
);
1173 proto
= cfgtew
->u
.cfgte64
->proto
;
1174 res
->res_handle
= cfgtew
->u
.cfgte64
->res_handle
;
1175 res
->dev_id
= cfgtew
->u
.cfgte64
->dev_id
;
1177 memcpy(&res
->dev_lun
.scsi_lun
, &cfgtew
->u
.cfgte64
->lun
,
1178 sizeof(res
->dev_lun
.scsi_lun
));
1180 if (memcmp(res
->res_path
, &cfgtew
->u
.cfgte64
->res_path
,
1181 sizeof(res
->res_path
))) {
1182 memcpy(res
->res_path
, &cfgtew
->u
.cfgte64
->res_path
,
1183 sizeof(res
->res_path
));
1187 if (res
->sdev
&& new_path
)
1188 sdev_printk(KERN_INFO
, res
->sdev
, "Resource path: %s\n",
1189 ipr_format_resource_path(&res
->res_path
[0], &buffer
[0]));
1191 res
->flags
= cfgtew
->u
.cfgte
->flags
;
1192 if (res
->flags
& IPR_IS_IOA_RESOURCE
)
1193 res
->type
= IPR_RES_TYPE_IOAFP
;
1195 res
->type
= cfgtew
->u
.cfgte
->rsvd_subtype
& 0x0f;
1197 memcpy(&res
->std_inq_data
, &cfgtew
->u
.cfgte
->std_inq_data
,
1198 sizeof(struct ipr_std_inq_data
));
1200 res
->qmodel
= IPR_QUEUEING_MODEL(res
);
1201 proto
= cfgtew
->u
.cfgte
->proto
;
1202 res
->res_handle
= cfgtew
->u
.cfgte
->res_handle
;
1205 ipr_update_ata_class(res
, proto
);
1209 * ipr_clear_res_target - Clear the bit in the bit map representing the target
1211 * @res: resource entry struct
1212 * @cfgtew: config table entry wrapper struct
1217 static void ipr_clear_res_target(struct ipr_resource_entry
*res
)
1219 struct ipr_resource_entry
*gscsi_res
= NULL
;
1220 struct ipr_ioa_cfg
*ioa_cfg
= res
->ioa_cfg
;
1222 if (!ioa_cfg
->sis64
)
1225 if (res
->bus
== IPR_ARRAY_VIRTUAL_BUS
)
1226 clear_bit(res
->target
, ioa_cfg
->array_ids
);
1227 else if (res
->bus
== IPR_VSET_VIRTUAL_BUS
)
1228 clear_bit(res
->target
, ioa_cfg
->vset_ids
);
1229 else if (res
->bus
== 0 && res
->type
== IPR_RES_TYPE_GENERIC_SCSI
) {
1230 list_for_each_entry(gscsi_res
, &ioa_cfg
->used_res_q
, queue
)
1231 if (gscsi_res
->dev_id
== res
->dev_id
&& gscsi_res
!= res
)
1233 clear_bit(res
->target
, ioa_cfg
->target_ids
);
1235 } else if (res
->bus
== 0)
1236 clear_bit(res
->target
, ioa_cfg
->target_ids
);
1240 * ipr_handle_config_change - Handle a config change from the adapter
1241 * @ioa_cfg: ioa config struct
1247 static void ipr_handle_config_change(struct ipr_ioa_cfg
*ioa_cfg
,
1248 struct ipr_hostrcb
*hostrcb
)
1250 struct ipr_resource_entry
*res
= NULL
;
1251 struct ipr_config_table_entry_wrapper cfgtew
;
1252 __be32 cc_res_handle
;
1256 if (ioa_cfg
->sis64
) {
1257 cfgtew
.u
.cfgte64
= &hostrcb
->hcam
.u
.ccn
.u
.cfgte64
;
1258 cc_res_handle
= cfgtew
.u
.cfgte64
->res_handle
;
1260 cfgtew
.u
.cfgte
= &hostrcb
->hcam
.u
.ccn
.u
.cfgte
;
1261 cc_res_handle
= cfgtew
.u
.cfgte
->res_handle
;
1264 list_for_each_entry(res
, &ioa_cfg
->used_res_q
, queue
) {
1265 if (res
->res_handle
== cc_res_handle
) {
1272 if (list_empty(&ioa_cfg
->free_res_q
)) {
1273 ipr_send_hcam(ioa_cfg
,
1274 IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE
,
1279 res
= list_entry(ioa_cfg
->free_res_q
.next
,
1280 struct ipr_resource_entry
, queue
);
1282 list_del(&res
->queue
);
1283 ipr_init_res_entry(res
, &cfgtew
);
1284 list_add_tail(&res
->queue
, &ioa_cfg
->used_res_q
);
1287 ipr_update_res_entry(res
, &cfgtew
);
1289 if (hostrcb
->hcam
.notify_type
== IPR_HOST_RCB_NOTIF_TYPE_REM_ENTRY
) {
1291 res
->del_from_ml
= 1;
1292 res
->res_handle
= IPR_INVALID_RES_HANDLE
;
1293 if (ioa_cfg
->allow_ml_add_del
)
1294 schedule_work(&ioa_cfg
->work_q
);
1296 ipr_clear_res_target(res
);
1297 list_move_tail(&res
->queue
, &ioa_cfg
->free_res_q
);
1299 } else if (!res
->sdev
) {
1301 if (ioa_cfg
->allow_ml_add_del
)
1302 schedule_work(&ioa_cfg
->work_q
);
1305 ipr_send_hcam(ioa_cfg
, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE
, hostrcb
);
1309 * ipr_process_ccn - Op done function for a CCN.
1310 * @ipr_cmd: ipr command struct
1312 * This function is the op done function for a configuration
1313 * change notification host controlled async from the adapter.
1318 static void ipr_process_ccn(struct ipr_cmnd
*ipr_cmd
)
1320 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
1321 struct ipr_hostrcb
*hostrcb
= ipr_cmd
->u
.hostrcb
;
1322 u32 ioasc
= be32_to_cpu(ipr_cmd
->ioasa
.ioasc
);
1324 list_del(&hostrcb
->queue
);
1325 list_add_tail(&ipr_cmd
->queue
, &ioa_cfg
->free_q
);
1328 if (ioasc
!= IPR_IOASC_IOA_WAS_RESET
)
1329 dev_err(&ioa_cfg
->pdev
->dev
,
1330 "Host RCB failed with IOASC: 0x%08X\n", ioasc
);
1332 ipr_send_hcam(ioa_cfg
, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE
, hostrcb
);
1334 ipr_handle_config_change(ioa_cfg
, hostrcb
);
1339 * strip_and_pad_whitespace - Strip and pad trailing whitespace.
1340 * @i: index into buffer
1341 * @buf: string to modify
1343 * This function will strip all trailing whitespace, pad the end
1344 * of the string with a single space, and NULL terminate the string.
1347 * new length of string
1349 static int strip_and_pad_whitespace(int i
, char *buf
)
1351 while (i
&& buf
[i
] == ' ')
1359 * ipr_log_vpd_compact - Log the passed extended VPD compactly.
1360 * @prefix: string to print at start of printk
1361 * @hostrcb: hostrcb pointer
1362 * @vpd: vendor/product id/sn struct
1367 static void ipr_log_vpd_compact(char *prefix
, struct ipr_hostrcb
*hostrcb
,
1368 struct ipr_vpd
*vpd
)
1370 char buffer
[IPR_VENDOR_ID_LEN
+ IPR_PROD_ID_LEN
+ IPR_SERIAL_NUM_LEN
+ 3];
1373 memcpy(buffer
, vpd
->vpids
.vendor_id
, IPR_VENDOR_ID_LEN
);
1374 i
= strip_and_pad_whitespace(IPR_VENDOR_ID_LEN
- 1, buffer
);
1376 memcpy(&buffer
[i
], vpd
->vpids
.product_id
, IPR_PROD_ID_LEN
);
1377 i
= strip_and_pad_whitespace(i
+ IPR_PROD_ID_LEN
- 1, buffer
);
1379 memcpy(&buffer
[i
], vpd
->sn
, IPR_SERIAL_NUM_LEN
);
1380 buffer
[IPR_SERIAL_NUM_LEN
+ i
] = '\0';
1382 ipr_hcam_err(hostrcb
, "%s VPID/SN: %s\n", prefix
, buffer
);
1386 * ipr_log_vpd - Log the passed VPD to the error log.
1387 * @vpd: vendor/product id/sn struct
1392 static void ipr_log_vpd(struct ipr_vpd
*vpd
)
1394 char buffer
[IPR_VENDOR_ID_LEN
+ IPR_PROD_ID_LEN
1395 + IPR_SERIAL_NUM_LEN
];
1397 memcpy(buffer
, vpd
->vpids
.vendor_id
, IPR_VENDOR_ID_LEN
);
1398 memcpy(buffer
+ IPR_VENDOR_ID_LEN
, vpd
->vpids
.product_id
,
1400 buffer
[IPR_VENDOR_ID_LEN
+ IPR_PROD_ID_LEN
] = '\0';
1401 ipr_err("Vendor/Product ID: %s\n", buffer
);
1403 memcpy(buffer
, vpd
->sn
, IPR_SERIAL_NUM_LEN
);
1404 buffer
[IPR_SERIAL_NUM_LEN
] = '\0';
1405 ipr_err(" Serial Number: %s\n", buffer
);
1409 * ipr_log_ext_vpd_compact - Log the passed extended VPD compactly.
1410 * @prefix: string to print at start of printk
1411 * @hostrcb: hostrcb pointer
1412 * @vpd: vendor/product id/sn/wwn struct
1417 static void ipr_log_ext_vpd_compact(char *prefix
, struct ipr_hostrcb
*hostrcb
,
1418 struct ipr_ext_vpd
*vpd
)
1420 ipr_log_vpd_compact(prefix
, hostrcb
, &vpd
->vpd
);
1421 ipr_hcam_err(hostrcb
, "%s WWN: %08X%08X\n", prefix
,
1422 be32_to_cpu(vpd
->wwid
[0]), be32_to_cpu(vpd
->wwid
[1]));
1426 * ipr_log_ext_vpd - Log the passed extended VPD to the error log.
1427 * @vpd: vendor/product id/sn/wwn struct
1432 static void ipr_log_ext_vpd(struct ipr_ext_vpd
*vpd
)
1434 ipr_log_vpd(&vpd
->vpd
);
1435 ipr_err(" WWN: %08X%08X\n", be32_to_cpu(vpd
->wwid
[0]),
1436 be32_to_cpu(vpd
->wwid
[1]));
1440 * ipr_log_enhanced_cache_error - Log a cache error.
1441 * @ioa_cfg: ioa config struct
1442 * @hostrcb: hostrcb struct
1447 static void ipr_log_enhanced_cache_error(struct ipr_ioa_cfg
*ioa_cfg
,
1448 struct ipr_hostrcb
*hostrcb
)
1450 struct ipr_hostrcb_type_12_error
*error
;
1453 error
= &hostrcb
->hcam
.u
.error64
.u
.type_12_error
;
1455 error
= &hostrcb
->hcam
.u
.error
.u
.type_12_error
;
1457 ipr_err("-----Current Configuration-----\n");
1458 ipr_err("Cache Directory Card Information:\n");
1459 ipr_log_ext_vpd(&error
->ioa_vpd
);
1460 ipr_err("Adapter Card Information:\n");
1461 ipr_log_ext_vpd(&error
->cfc_vpd
);
1463 ipr_err("-----Expected Configuration-----\n");
1464 ipr_err("Cache Directory Card Information:\n");
1465 ipr_log_ext_vpd(&error
->ioa_last_attached_to_cfc_vpd
);
1466 ipr_err("Adapter Card Information:\n");
1467 ipr_log_ext_vpd(&error
->cfc_last_attached_to_ioa_vpd
);
1469 ipr_err("Additional IOA Data: %08X %08X %08X\n",
1470 be32_to_cpu(error
->ioa_data
[0]),
1471 be32_to_cpu(error
->ioa_data
[1]),
1472 be32_to_cpu(error
->ioa_data
[2]));
1476 * ipr_log_cache_error - Log a cache error.
1477 * @ioa_cfg: ioa config struct
1478 * @hostrcb: hostrcb struct
1483 static void ipr_log_cache_error(struct ipr_ioa_cfg
*ioa_cfg
,
1484 struct ipr_hostrcb
*hostrcb
)
1486 struct ipr_hostrcb_type_02_error
*error
=
1487 &hostrcb
->hcam
.u
.error
.u
.type_02_error
;
1489 ipr_err("-----Current Configuration-----\n");
1490 ipr_err("Cache Directory Card Information:\n");
1491 ipr_log_vpd(&error
->ioa_vpd
);
1492 ipr_err("Adapter Card Information:\n");
1493 ipr_log_vpd(&error
->cfc_vpd
);
1495 ipr_err("-----Expected Configuration-----\n");
1496 ipr_err("Cache Directory Card Information:\n");
1497 ipr_log_vpd(&error
->ioa_last_attached_to_cfc_vpd
);
1498 ipr_err("Adapter Card Information:\n");
1499 ipr_log_vpd(&error
->cfc_last_attached_to_ioa_vpd
);
1501 ipr_err("Additional IOA Data: %08X %08X %08X\n",
1502 be32_to_cpu(error
->ioa_data
[0]),
1503 be32_to_cpu(error
->ioa_data
[1]),
1504 be32_to_cpu(error
->ioa_data
[2]));
1508 * ipr_log_enhanced_config_error - Log a configuration error.
1509 * @ioa_cfg: ioa config struct
1510 * @hostrcb: hostrcb struct
1515 static void ipr_log_enhanced_config_error(struct ipr_ioa_cfg
*ioa_cfg
,
1516 struct ipr_hostrcb
*hostrcb
)
1518 int errors_logged
, i
;
1519 struct ipr_hostrcb_device_data_entry_enhanced
*dev_entry
;
1520 struct ipr_hostrcb_type_13_error
*error
;
1522 error
= &hostrcb
->hcam
.u
.error
.u
.type_13_error
;
1523 errors_logged
= be32_to_cpu(error
->errors_logged
);
1525 ipr_err("Device Errors Detected/Logged: %d/%d\n",
1526 be32_to_cpu(error
->errors_detected
), errors_logged
);
1528 dev_entry
= error
->dev
;
1530 for (i
= 0; i
< errors_logged
; i
++, dev_entry
++) {
1533 ipr_phys_res_err(ioa_cfg
, dev_entry
->dev_res_addr
, "Device %d", i
+ 1);
1534 ipr_log_ext_vpd(&dev_entry
->vpd
);
1536 ipr_err("-----New Device Information-----\n");
1537 ipr_log_ext_vpd(&dev_entry
->new_vpd
);
1539 ipr_err("Cache Directory Card Information:\n");
1540 ipr_log_ext_vpd(&dev_entry
->ioa_last_with_dev_vpd
);
1542 ipr_err("Adapter Card Information:\n");
1543 ipr_log_ext_vpd(&dev_entry
->cfc_last_with_dev_vpd
);
1548 * ipr_log_sis64_config_error - Log a device error.
1549 * @ioa_cfg: ioa config struct
1550 * @hostrcb: hostrcb struct
1555 static void ipr_log_sis64_config_error(struct ipr_ioa_cfg
*ioa_cfg
,
1556 struct ipr_hostrcb
*hostrcb
)
1558 int errors_logged
, i
;
1559 struct ipr_hostrcb64_device_data_entry_enhanced
*dev_entry
;
1560 struct ipr_hostrcb_type_23_error
*error
;
1561 char buffer
[IPR_MAX_RES_PATH_LENGTH
];
1563 error
= &hostrcb
->hcam
.u
.error64
.u
.type_23_error
;
1564 errors_logged
= be32_to_cpu(error
->errors_logged
);
1566 ipr_err("Device Errors Detected/Logged: %d/%d\n",
1567 be32_to_cpu(error
->errors_detected
), errors_logged
);
1569 dev_entry
= error
->dev
;
1571 for (i
= 0; i
< errors_logged
; i
++, dev_entry
++) {
1574 ipr_err("Device %d : %s", i
+ 1,
1575 ipr_format_resource_path(&dev_entry
->res_path
[0], &buffer
[0]));
1576 ipr_log_ext_vpd(&dev_entry
->vpd
);
1578 ipr_err("-----New Device Information-----\n");
1579 ipr_log_ext_vpd(&dev_entry
->new_vpd
);
1581 ipr_err("Cache Directory Card Information:\n");
1582 ipr_log_ext_vpd(&dev_entry
->ioa_last_with_dev_vpd
);
1584 ipr_err("Adapter Card Information:\n");
1585 ipr_log_ext_vpd(&dev_entry
->cfc_last_with_dev_vpd
);
1590 * ipr_log_config_error - Log a configuration error.
1591 * @ioa_cfg: ioa config struct
1592 * @hostrcb: hostrcb struct
1597 static void ipr_log_config_error(struct ipr_ioa_cfg
*ioa_cfg
,
1598 struct ipr_hostrcb
*hostrcb
)
1600 int errors_logged
, i
;
1601 struct ipr_hostrcb_device_data_entry
*dev_entry
;
1602 struct ipr_hostrcb_type_03_error
*error
;
1604 error
= &hostrcb
->hcam
.u
.error
.u
.type_03_error
;
1605 errors_logged
= be32_to_cpu(error
->errors_logged
);
1607 ipr_err("Device Errors Detected/Logged: %d/%d\n",
1608 be32_to_cpu(error
->errors_detected
), errors_logged
);
1610 dev_entry
= error
->dev
;
1612 for (i
= 0; i
< errors_logged
; i
++, dev_entry
++) {
1615 ipr_phys_res_err(ioa_cfg
, dev_entry
->dev_res_addr
, "Device %d", i
+ 1);
1616 ipr_log_vpd(&dev_entry
->vpd
);
1618 ipr_err("-----New Device Information-----\n");
1619 ipr_log_vpd(&dev_entry
->new_vpd
);
1621 ipr_err("Cache Directory Card Information:\n");
1622 ipr_log_vpd(&dev_entry
->ioa_last_with_dev_vpd
);
1624 ipr_err("Adapter Card Information:\n");
1625 ipr_log_vpd(&dev_entry
->cfc_last_with_dev_vpd
);
1627 ipr_err("Additional IOA Data: %08X %08X %08X %08X %08X\n",
1628 be32_to_cpu(dev_entry
->ioa_data
[0]),
1629 be32_to_cpu(dev_entry
->ioa_data
[1]),
1630 be32_to_cpu(dev_entry
->ioa_data
[2]),
1631 be32_to_cpu(dev_entry
->ioa_data
[3]),
1632 be32_to_cpu(dev_entry
->ioa_data
[4]));
1637 * ipr_log_enhanced_array_error - Log an array configuration error.
1638 * @ioa_cfg: ioa config struct
1639 * @hostrcb: hostrcb struct
1644 static void ipr_log_enhanced_array_error(struct ipr_ioa_cfg
*ioa_cfg
,
1645 struct ipr_hostrcb
*hostrcb
)
1648 struct ipr_hostrcb_type_14_error
*error
;
1649 struct ipr_hostrcb_array_data_entry_enhanced
*array_entry
;
1650 const u8 zero_sn
[IPR_SERIAL_NUM_LEN
] = { [0 ... IPR_SERIAL_NUM_LEN
-1] = '0' };
1652 error
= &hostrcb
->hcam
.u
.error
.u
.type_14_error
;
1656 ipr_err("RAID %s Array Configuration: %d:%d:%d:%d\n",
1657 error
->protection_level
,
1658 ioa_cfg
->host
->host_no
,
1659 error
->last_func_vset_res_addr
.bus
,
1660 error
->last_func_vset_res_addr
.target
,
1661 error
->last_func_vset_res_addr
.lun
);
1665 array_entry
= error
->array_member
;
1666 num_entries
= min_t(u32
, be32_to_cpu(error
->num_entries
),
1667 sizeof(error
->array_member
));
1669 for (i
= 0; i
< num_entries
; i
++, array_entry
++) {
1670 if (!memcmp(array_entry
->vpd
.vpd
.sn
, zero_sn
, IPR_SERIAL_NUM_LEN
))
1673 if (be32_to_cpu(error
->exposed_mode_adn
) == i
)
1674 ipr_err("Exposed Array Member %d:\n", i
);
1676 ipr_err("Array Member %d:\n", i
);
1678 ipr_log_ext_vpd(&array_entry
->vpd
);
1679 ipr_phys_res_err(ioa_cfg
, array_entry
->dev_res_addr
, "Current Location");
1680 ipr_phys_res_err(ioa_cfg
, array_entry
->expected_dev_res_addr
,
1681 "Expected Location");
1688 * ipr_log_array_error - Log an array configuration error.
1689 * @ioa_cfg: ioa config struct
1690 * @hostrcb: hostrcb struct
1695 static void ipr_log_array_error(struct ipr_ioa_cfg
*ioa_cfg
,
1696 struct ipr_hostrcb
*hostrcb
)
1699 struct ipr_hostrcb_type_04_error
*error
;
1700 struct ipr_hostrcb_array_data_entry
*array_entry
;
1701 const u8 zero_sn
[IPR_SERIAL_NUM_LEN
] = { [0 ... IPR_SERIAL_NUM_LEN
-1] = '0' };
1703 error
= &hostrcb
->hcam
.u
.error
.u
.type_04_error
;
1707 ipr_err("RAID %s Array Configuration: %d:%d:%d:%d\n",
1708 error
->protection_level
,
1709 ioa_cfg
->host
->host_no
,
1710 error
->last_func_vset_res_addr
.bus
,
1711 error
->last_func_vset_res_addr
.target
,
1712 error
->last_func_vset_res_addr
.lun
);
1716 array_entry
= error
->array_member
;
1718 for (i
= 0; i
< 18; i
++) {
1719 if (!memcmp(array_entry
->vpd
.sn
, zero_sn
, IPR_SERIAL_NUM_LEN
))
1722 if (be32_to_cpu(error
->exposed_mode_adn
) == i
)
1723 ipr_err("Exposed Array Member %d:\n", i
);
1725 ipr_err("Array Member %d:\n", i
);
1727 ipr_log_vpd(&array_entry
->vpd
);
1729 ipr_phys_res_err(ioa_cfg
, array_entry
->dev_res_addr
, "Current Location");
1730 ipr_phys_res_err(ioa_cfg
, array_entry
->expected_dev_res_addr
,
1731 "Expected Location");
1736 array_entry
= error
->array_member2
;
1743 * ipr_log_hex_data - Log additional hex IOA error data.
1744 * @ioa_cfg: ioa config struct
1745 * @data: IOA error data
1751 static void ipr_log_hex_data(struct ipr_ioa_cfg
*ioa_cfg
, u32
*data
, int len
)
1758 if (ioa_cfg
->log_level
<= IPR_DEFAULT_LOG_LEVEL
)
1759 len
= min_t(int, len
, IPR_DEFAULT_MAX_ERROR_DUMP
);
1761 for (i
= 0; i
< len
/ 4; i
+= 4) {
1762 ipr_err("%08X: %08X %08X %08X %08X\n", i
*4,
1763 be32_to_cpu(data
[i
]),
1764 be32_to_cpu(data
[i
+1]),
1765 be32_to_cpu(data
[i
+2]),
1766 be32_to_cpu(data
[i
+3]));
1771 * ipr_log_enhanced_dual_ioa_error - Log an enhanced dual adapter error.
1772 * @ioa_cfg: ioa config struct
1773 * @hostrcb: hostrcb struct
1778 static void ipr_log_enhanced_dual_ioa_error(struct ipr_ioa_cfg
*ioa_cfg
,
1779 struct ipr_hostrcb
*hostrcb
)
1781 struct ipr_hostrcb_type_17_error
*error
;
1784 error
= &hostrcb
->hcam
.u
.error64
.u
.type_17_error
;
1786 error
= &hostrcb
->hcam
.u
.error
.u
.type_17_error
;
1788 error
->failure_reason
[sizeof(error
->failure_reason
) - 1] = '\0';
1789 strim(error
->failure_reason
);
1791 ipr_hcam_err(hostrcb
, "%s [PRC: %08X]\n", error
->failure_reason
,
1792 be32_to_cpu(hostrcb
->hcam
.u
.error
.prc
));
1793 ipr_log_ext_vpd_compact("Remote IOA", hostrcb
, &error
->vpd
);
1794 ipr_log_hex_data(ioa_cfg
, error
->data
,
1795 be32_to_cpu(hostrcb
->hcam
.length
) -
1796 (offsetof(struct ipr_hostrcb_error
, u
) +
1797 offsetof(struct ipr_hostrcb_type_17_error
, data
)));
1801 * ipr_log_dual_ioa_error - Log a dual adapter error.
1802 * @ioa_cfg: ioa config struct
1803 * @hostrcb: hostrcb struct
1808 static void ipr_log_dual_ioa_error(struct ipr_ioa_cfg
*ioa_cfg
,
1809 struct ipr_hostrcb
*hostrcb
)
1811 struct ipr_hostrcb_type_07_error
*error
;
1813 error
= &hostrcb
->hcam
.u
.error
.u
.type_07_error
;
1814 error
->failure_reason
[sizeof(error
->failure_reason
) - 1] = '\0';
1815 strim(error
->failure_reason
);
1817 ipr_hcam_err(hostrcb
, "%s [PRC: %08X]\n", error
->failure_reason
,
1818 be32_to_cpu(hostrcb
->hcam
.u
.error
.prc
));
1819 ipr_log_vpd_compact("Remote IOA", hostrcb
, &error
->vpd
);
1820 ipr_log_hex_data(ioa_cfg
, error
->data
,
1821 be32_to_cpu(hostrcb
->hcam
.length
) -
1822 (offsetof(struct ipr_hostrcb_error
, u
) +
1823 offsetof(struct ipr_hostrcb_type_07_error
, data
)));
1826 static const struct {
1829 } path_active_desc
[] = {
1830 { IPR_PATH_NO_INFO
, "Path" },
1831 { IPR_PATH_ACTIVE
, "Active path" },
1832 { IPR_PATH_NOT_ACTIVE
, "Inactive path" }
1835 static const struct {
1838 } path_state_desc
[] = {
1839 { IPR_PATH_STATE_NO_INFO
, "has no path state information available" },
1840 { IPR_PATH_HEALTHY
, "is healthy" },
1841 { IPR_PATH_DEGRADED
, "is degraded" },
1842 { IPR_PATH_FAILED
, "is failed" }
1846 * ipr_log_fabric_path - Log a fabric path error
1847 * @hostrcb: hostrcb struct
1848 * @fabric: fabric descriptor
1853 static void ipr_log_fabric_path(struct ipr_hostrcb
*hostrcb
,
1854 struct ipr_hostrcb_fabric_desc
*fabric
)
1857 u8 path_state
= fabric
->path_state
;
1858 u8 active
= path_state
& IPR_PATH_ACTIVE_MASK
;
1859 u8 state
= path_state
& IPR_PATH_STATE_MASK
;
1861 for (i
= 0; i
< ARRAY_SIZE(path_active_desc
); i
++) {
1862 if (path_active_desc
[i
].active
!= active
)
1865 for (j
= 0; j
< ARRAY_SIZE(path_state_desc
); j
++) {
1866 if (path_state_desc
[j
].state
!= state
)
1869 if (fabric
->cascaded_expander
== 0xff && fabric
->phy
== 0xff) {
1870 ipr_hcam_err(hostrcb
, "%s %s: IOA Port=%d\n",
1871 path_active_desc
[i
].desc
, path_state_desc
[j
].desc
,
1873 } else if (fabric
->cascaded_expander
== 0xff) {
1874 ipr_hcam_err(hostrcb
, "%s %s: IOA Port=%d, Phy=%d\n",
1875 path_active_desc
[i
].desc
, path_state_desc
[j
].desc
,
1876 fabric
->ioa_port
, fabric
->phy
);
1877 } else if (fabric
->phy
== 0xff) {
1878 ipr_hcam_err(hostrcb
, "%s %s: IOA Port=%d, Cascade=%d\n",
1879 path_active_desc
[i
].desc
, path_state_desc
[j
].desc
,
1880 fabric
->ioa_port
, fabric
->cascaded_expander
);
1882 ipr_hcam_err(hostrcb
, "%s %s: IOA Port=%d, Cascade=%d, Phy=%d\n",
1883 path_active_desc
[i
].desc
, path_state_desc
[j
].desc
,
1884 fabric
->ioa_port
, fabric
->cascaded_expander
, fabric
->phy
);
1890 ipr_err("Path state=%02X IOA Port=%d Cascade=%d Phy=%d\n", path_state
,
1891 fabric
->ioa_port
, fabric
->cascaded_expander
, fabric
->phy
);
1895 * ipr_log64_fabric_path - Log a fabric path error
1896 * @hostrcb: hostrcb struct
1897 * @fabric: fabric descriptor
1902 static void ipr_log64_fabric_path(struct ipr_hostrcb
*hostrcb
,
1903 struct ipr_hostrcb64_fabric_desc
*fabric
)
1906 u8 path_state
= fabric
->path_state
;
1907 u8 active
= path_state
& IPR_PATH_ACTIVE_MASK
;
1908 u8 state
= path_state
& IPR_PATH_STATE_MASK
;
1909 char buffer
[IPR_MAX_RES_PATH_LENGTH
];
1911 for (i
= 0; i
< ARRAY_SIZE(path_active_desc
); i
++) {
1912 if (path_active_desc
[i
].active
!= active
)
1915 for (j
= 0; j
< ARRAY_SIZE(path_state_desc
); j
++) {
1916 if (path_state_desc
[j
].state
!= state
)
1919 ipr_hcam_err(hostrcb
, "%s %s: Resource Path=%s\n",
1920 path_active_desc
[i
].desc
, path_state_desc
[j
].desc
,
1921 ipr_format_resource_path(&fabric
->res_path
[0], &buffer
[0]));
1926 ipr_err("Path state=%02X Resource Path=%s\n", path_state
,
1927 ipr_format_resource_path(&fabric
->res_path
[0], &buffer
[0]));
1930 static const struct {
1933 } path_type_desc
[] = {
1934 { IPR_PATH_CFG_IOA_PORT
, "IOA port" },
1935 { IPR_PATH_CFG_EXP_PORT
, "Expander port" },
1936 { IPR_PATH_CFG_DEVICE_PORT
, "Device port" },
1937 { IPR_PATH_CFG_DEVICE_LUN
, "Device LUN" }
1940 static const struct {
1943 } path_status_desc
[] = {
1944 { IPR_PATH_CFG_NO_PROB
, "Functional" },
1945 { IPR_PATH_CFG_DEGRADED
, "Degraded" },
1946 { IPR_PATH_CFG_FAILED
, "Failed" },
1947 { IPR_PATH_CFG_SUSPECT
, "Suspect" },
1948 { IPR_PATH_NOT_DETECTED
, "Missing" },
1949 { IPR_PATH_INCORRECT_CONN
, "Incorrectly connected" }
1952 static const char *link_rate
[] = {
1955 "phy reset problem",
1972 * ipr_log_path_elem - Log a fabric path element.
1973 * @hostrcb: hostrcb struct
1974 * @cfg: fabric path element struct
1979 static void ipr_log_path_elem(struct ipr_hostrcb
*hostrcb
,
1980 struct ipr_hostrcb_config_element
*cfg
)
1983 u8 type
= cfg
->type_status
& IPR_PATH_CFG_TYPE_MASK
;
1984 u8 status
= cfg
->type_status
& IPR_PATH_CFG_STATUS_MASK
;
1986 if (type
== IPR_PATH_CFG_NOT_EXIST
)
1989 for (i
= 0; i
< ARRAY_SIZE(path_type_desc
); i
++) {
1990 if (path_type_desc
[i
].type
!= type
)
1993 for (j
= 0; j
< ARRAY_SIZE(path_status_desc
); j
++) {
1994 if (path_status_desc
[j
].status
!= status
)
1997 if (type
== IPR_PATH_CFG_IOA_PORT
) {
1998 ipr_hcam_err(hostrcb
, "%s %s: Phy=%d, Link rate=%s, WWN=%08X%08X\n",
1999 path_status_desc
[j
].desc
, path_type_desc
[i
].desc
,
2000 cfg
->phy
, link_rate
[cfg
->link_rate
& IPR_PHY_LINK_RATE_MASK
],
2001 be32_to_cpu(cfg
->wwid
[0]), be32_to_cpu(cfg
->wwid
[1]));
2003 if (cfg
->cascaded_expander
== 0xff && cfg
->phy
== 0xff) {
2004 ipr_hcam_err(hostrcb
, "%s %s: Link rate=%s, WWN=%08X%08X\n",
2005 path_status_desc
[j
].desc
, path_type_desc
[i
].desc
,
2006 link_rate
[cfg
->link_rate
& IPR_PHY_LINK_RATE_MASK
],
2007 be32_to_cpu(cfg
->wwid
[0]), be32_to_cpu(cfg
->wwid
[1]));
2008 } else if (cfg
->cascaded_expander
== 0xff) {
2009 ipr_hcam_err(hostrcb
, "%s %s: Phy=%d, Link rate=%s, "
2010 "WWN=%08X%08X\n", path_status_desc
[j
].desc
,
2011 path_type_desc
[i
].desc
, cfg
->phy
,
2012 link_rate
[cfg
->link_rate
& IPR_PHY_LINK_RATE_MASK
],
2013 be32_to_cpu(cfg
->wwid
[0]), be32_to_cpu(cfg
->wwid
[1]));
2014 } else if (cfg
->phy
== 0xff) {
2015 ipr_hcam_err(hostrcb
, "%s %s: Cascade=%d, Link rate=%s, "
2016 "WWN=%08X%08X\n", path_status_desc
[j
].desc
,
2017 path_type_desc
[i
].desc
, cfg
->cascaded_expander
,
2018 link_rate
[cfg
->link_rate
& IPR_PHY_LINK_RATE_MASK
],
2019 be32_to_cpu(cfg
->wwid
[0]), be32_to_cpu(cfg
->wwid
[1]));
2021 ipr_hcam_err(hostrcb
, "%s %s: Cascade=%d, Phy=%d, Link rate=%s "
2022 "WWN=%08X%08X\n", path_status_desc
[j
].desc
,
2023 path_type_desc
[i
].desc
, cfg
->cascaded_expander
, cfg
->phy
,
2024 link_rate
[cfg
->link_rate
& IPR_PHY_LINK_RATE_MASK
],
2025 be32_to_cpu(cfg
->wwid
[0]), be32_to_cpu(cfg
->wwid
[1]));
2032 ipr_hcam_err(hostrcb
, "Path element=%02X: Cascade=%d Phy=%d Link rate=%s "
2033 "WWN=%08X%08X\n", cfg
->type_status
, cfg
->cascaded_expander
, cfg
->phy
,
2034 link_rate
[cfg
->link_rate
& IPR_PHY_LINK_RATE_MASK
],
2035 be32_to_cpu(cfg
->wwid
[0]), be32_to_cpu(cfg
->wwid
[1]));
2039 * ipr_log64_path_elem - Log a fabric path element.
2040 * @hostrcb: hostrcb struct
2041 * @cfg: fabric path element struct
2046 static void ipr_log64_path_elem(struct ipr_hostrcb
*hostrcb
,
2047 struct ipr_hostrcb64_config_element
*cfg
)
2050 u8 desc_id
= cfg
->descriptor_id
& IPR_DESCRIPTOR_MASK
;
2051 u8 type
= cfg
->type_status
& IPR_PATH_CFG_TYPE_MASK
;
2052 u8 status
= cfg
->type_status
& IPR_PATH_CFG_STATUS_MASK
;
2053 char buffer
[IPR_MAX_RES_PATH_LENGTH
];
2055 if (type
== IPR_PATH_CFG_NOT_EXIST
|| desc_id
!= IPR_DESCRIPTOR_SIS64
)
2058 for (i
= 0; i
< ARRAY_SIZE(path_type_desc
); i
++) {
2059 if (path_type_desc
[i
].type
!= type
)
2062 for (j
= 0; j
< ARRAY_SIZE(path_status_desc
); j
++) {
2063 if (path_status_desc
[j
].status
!= status
)
2066 ipr_hcam_err(hostrcb
, "%s %s: Resource Path=%s, Link rate=%s, WWN=%08X%08X\n",
2067 path_status_desc
[j
].desc
, path_type_desc
[i
].desc
,
2068 ipr_format_resource_path(&cfg
->res_path
[0], &buffer
[0]),
2069 link_rate
[cfg
->link_rate
& IPR_PHY_LINK_RATE_MASK
],
2070 be32_to_cpu(cfg
->wwid
[0]), be32_to_cpu(cfg
->wwid
[1]));
2074 ipr_hcam_err(hostrcb
, "Path element=%02X: Resource Path=%s, Link rate=%s "
2075 "WWN=%08X%08X\n", cfg
->type_status
,
2076 ipr_format_resource_path(&cfg
->res_path
[0], &buffer
[0]),
2077 link_rate
[cfg
->link_rate
& IPR_PHY_LINK_RATE_MASK
],
2078 be32_to_cpu(cfg
->wwid
[0]), be32_to_cpu(cfg
->wwid
[1]));
2082 * ipr_log_fabric_error - Log a fabric error.
2083 * @ioa_cfg: ioa config struct
2084 * @hostrcb: hostrcb struct
2089 static void ipr_log_fabric_error(struct ipr_ioa_cfg
*ioa_cfg
,
2090 struct ipr_hostrcb
*hostrcb
)
2092 struct ipr_hostrcb_type_20_error
*error
;
2093 struct ipr_hostrcb_fabric_desc
*fabric
;
2094 struct ipr_hostrcb_config_element
*cfg
;
2097 error
= &hostrcb
->hcam
.u
.error
.u
.type_20_error
;
2098 error
->failure_reason
[sizeof(error
->failure_reason
) - 1] = '\0';
2099 ipr_hcam_err(hostrcb
, "%s\n", error
->failure_reason
);
2101 add_len
= be32_to_cpu(hostrcb
->hcam
.length
) -
2102 (offsetof(struct ipr_hostrcb_error
, u
) +
2103 offsetof(struct ipr_hostrcb_type_20_error
, desc
));
2105 for (i
= 0, fabric
= error
->desc
; i
< error
->num_entries
; i
++) {
2106 ipr_log_fabric_path(hostrcb
, fabric
);
2107 for_each_fabric_cfg(fabric
, cfg
)
2108 ipr_log_path_elem(hostrcb
, cfg
);
2110 add_len
-= be16_to_cpu(fabric
->length
);
2111 fabric
= (struct ipr_hostrcb_fabric_desc
*)
2112 ((unsigned long)fabric
+ be16_to_cpu(fabric
->length
));
2115 ipr_log_hex_data(ioa_cfg
, (u32
*)fabric
, add_len
);
2119 * ipr_log_sis64_array_error - Log a sis64 array error.
2120 * @ioa_cfg: ioa config struct
2121 * @hostrcb: hostrcb struct
2126 static void ipr_log_sis64_array_error(struct ipr_ioa_cfg
*ioa_cfg
,
2127 struct ipr_hostrcb
*hostrcb
)
2130 struct ipr_hostrcb_type_24_error
*error
;
2131 struct ipr_hostrcb64_array_data_entry
*array_entry
;
2132 char buffer
[IPR_MAX_RES_PATH_LENGTH
];
2133 const u8 zero_sn
[IPR_SERIAL_NUM_LEN
] = { [0 ... IPR_SERIAL_NUM_LEN
-1] = '0' };
2135 error
= &hostrcb
->hcam
.u
.error64
.u
.type_24_error
;
2139 ipr_err("RAID %s Array Configuration: %s\n",
2140 error
->protection_level
,
2141 ipr_format_resource_path(&error
->last_res_path
[0], &buffer
[0]));
2145 array_entry
= error
->array_member
;
2146 num_entries
= min_t(u32
, be32_to_cpu(error
->num_entries
),
2147 sizeof(error
->array_member
));
2149 for (i
= 0; i
< num_entries
; i
++, array_entry
++) {
2151 if (!memcmp(array_entry
->vpd
.vpd
.sn
, zero_sn
, IPR_SERIAL_NUM_LEN
))
2154 if (error
->exposed_mode_adn
== i
)
2155 ipr_err("Exposed Array Member %d:\n", i
);
2157 ipr_err("Array Member %d:\n", i
);
2159 ipr_err("Array Member %d:\n", i
);
2160 ipr_log_ext_vpd(&array_entry
->vpd
);
2161 ipr_err("Current Location: %s",
2162 ipr_format_resource_path(&array_entry
->res_path
[0], &buffer
[0]));
2163 ipr_err("Expected Location: %s",
2164 ipr_format_resource_path(&array_entry
->expected_res_path
[0], &buffer
[0]));
2171 * ipr_log_sis64_fabric_error - Log a sis64 fabric error.
2172 * @ioa_cfg: ioa config struct
2173 * @hostrcb: hostrcb struct
2178 static void ipr_log_sis64_fabric_error(struct ipr_ioa_cfg
*ioa_cfg
,
2179 struct ipr_hostrcb
*hostrcb
)
2181 struct ipr_hostrcb_type_30_error
*error
;
2182 struct ipr_hostrcb64_fabric_desc
*fabric
;
2183 struct ipr_hostrcb64_config_element
*cfg
;
2186 error
= &hostrcb
->hcam
.u
.error64
.u
.type_30_error
;
2188 error
->failure_reason
[sizeof(error
->failure_reason
) - 1] = '\0';
2189 ipr_hcam_err(hostrcb
, "%s\n", error
->failure_reason
);
2191 add_len
= be32_to_cpu(hostrcb
->hcam
.length
) -
2192 (offsetof(struct ipr_hostrcb64_error
, u
) +
2193 offsetof(struct ipr_hostrcb_type_30_error
, desc
));
2195 for (i
= 0, fabric
= error
->desc
; i
< error
->num_entries
; i
++) {
2196 ipr_log64_fabric_path(hostrcb
, fabric
);
2197 for_each_fabric_cfg(fabric
, cfg
)
2198 ipr_log64_path_elem(hostrcb
, cfg
);
2200 add_len
-= be16_to_cpu(fabric
->length
);
2201 fabric
= (struct ipr_hostrcb64_fabric_desc
*)
2202 ((unsigned long)fabric
+ be16_to_cpu(fabric
->length
));
2205 ipr_log_hex_data(ioa_cfg
, (u32
*)fabric
, add_len
);
2209 * ipr_log_generic_error - Log an adapter error.
2210 * @ioa_cfg: ioa config struct
2211 * @hostrcb: hostrcb struct
2216 static void ipr_log_generic_error(struct ipr_ioa_cfg
*ioa_cfg
,
2217 struct ipr_hostrcb
*hostrcb
)
2219 ipr_log_hex_data(ioa_cfg
, hostrcb
->hcam
.u
.raw
.data
,
2220 be32_to_cpu(hostrcb
->hcam
.length
));
2224 * ipr_get_error - Find the specfied IOASC in the ipr_error_table.
2227 * This function will return the index of into the ipr_error_table
2228 * for the specified IOASC. If the IOASC is not in the table,
2229 * 0 will be returned, which points to the entry used for unknown errors.
2232 * index into the ipr_error_table
2234 static u32
ipr_get_error(u32 ioasc
)
2238 for (i
= 0; i
< ARRAY_SIZE(ipr_error_table
); i
++)
2239 if (ipr_error_table
[i
].ioasc
== (ioasc
& IPR_IOASC_IOASC_MASK
))
2246 * ipr_handle_log_data - Log an adapter error.
2247 * @ioa_cfg: ioa config struct
2248 * @hostrcb: hostrcb struct
2250 * This function logs an adapter error to the system.
2255 static void ipr_handle_log_data(struct ipr_ioa_cfg
*ioa_cfg
,
2256 struct ipr_hostrcb
*hostrcb
)
2261 if (hostrcb
->hcam
.notify_type
!= IPR_HOST_RCB_NOTIF_TYPE_ERROR_LOG_ENTRY
)
2264 if (hostrcb
->hcam
.notifications_lost
== IPR_HOST_RCB_NOTIFICATIONS_LOST
)
2265 dev_err(&ioa_cfg
->pdev
->dev
, "Error notifications lost\n");
2268 ioasc
= be32_to_cpu(hostrcb
->hcam
.u
.error64
.fd_ioasc
);
2270 ioasc
= be32_to_cpu(hostrcb
->hcam
.u
.error
.fd_ioasc
);
2272 if (!ioa_cfg
->sis64
&& (ioasc
== IPR_IOASC_BUS_WAS_RESET
||
2273 ioasc
== IPR_IOASC_BUS_WAS_RESET_BY_OTHER
)) {
2274 /* Tell the midlayer we had a bus reset so it will handle the UA properly */
2275 scsi_report_bus_reset(ioa_cfg
->host
,
2276 hostrcb
->hcam
.u
.error
.fd_res_addr
.bus
);
2279 error_index
= ipr_get_error(ioasc
);
2281 if (!ipr_error_table
[error_index
].log_hcam
)
2284 ipr_hcam_err(hostrcb
, "%s\n", ipr_error_table
[error_index
].error
);
2286 /* Set indication we have logged an error */
2287 ioa_cfg
->errors_logged
++;
2289 if (ioa_cfg
->log_level
< ipr_error_table
[error_index
].log_hcam
)
2291 if (be32_to_cpu(hostrcb
->hcam
.length
) > sizeof(hostrcb
->hcam
.u
.raw
))
2292 hostrcb
->hcam
.length
= cpu_to_be32(sizeof(hostrcb
->hcam
.u
.raw
));
2294 switch (hostrcb
->hcam
.overlay_id
) {
2295 case IPR_HOST_RCB_OVERLAY_ID_2
:
2296 ipr_log_cache_error(ioa_cfg
, hostrcb
);
2298 case IPR_HOST_RCB_OVERLAY_ID_3
:
2299 ipr_log_config_error(ioa_cfg
, hostrcb
);
2301 case IPR_HOST_RCB_OVERLAY_ID_4
:
2302 case IPR_HOST_RCB_OVERLAY_ID_6
:
2303 ipr_log_array_error(ioa_cfg
, hostrcb
);
2305 case IPR_HOST_RCB_OVERLAY_ID_7
:
2306 ipr_log_dual_ioa_error(ioa_cfg
, hostrcb
);
2308 case IPR_HOST_RCB_OVERLAY_ID_12
:
2309 ipr_log_enhanced_cache_error(ioa_cfg
, hostrcb
);
2311 case IPR_HOST_RCB_OVERLAY_ID_13
:
2312 ipr_log_enhanced_config_error(ioa_cfg
, hostrcb
);
2314 case IPR_HOST_RCB_OVERLAY_ID_14
:
2315 case IPR_HOST_RCB_OVERLAY_ID_16
:
2316 ipr_log_enhanced_array_error(ioa_cfg
, hostrcb
);
2318 case IPR_HOST_RCB_OVERLAY_ID_17
:
2319 ipr_log_enhanced_dual_ioa_error(ioa_cfg
, hostrcb
);
2321 case IPR_HOST_RCB_OVERLAY_ID_20
:
2322 ipr_log_fabric_error(ioa_cfg
, hostrcb
);
2324 case IPR_HOST_RCB_OVERLAY_ID_23
:
2325 ipr_log_sis64_config_error(ioa_cfg
, hostrcb
);
2327 case IPR_HOST_RCB_OVERLAY_ID_24
:
2328 case IPR_HOST_RCB_OVERLAY_ID_26
:
2329 ipr_log_sis64_array_error(ioa_cfg
, hostrcb
);
2331 case IPR_HOST_RCB_OVERLAY_ID_30
:
2332 ipr_log_sis64_fabric_error(ioa_cfg
, hostrcb
);
2334 case IPR_HOST_RCB_OVERLAY_ID_1
:
2335 case IPR_HOST_RCB_OVERLAY_ID_DEFAULT
:
2337 ipr_log_generic_error(ioa_cfg
, hostrcb
);
2343 * ipr_process_error - Op done function for an adapter error log.
2344 * @ipr_cmd: ipr command struct
2346 * This function is the op done function for an error log host
2347 * controlled async from the adapter. It will log the error and
2348 * send the HCAM back to the adapter.
2353 static void ipr_process_error(struct ipr_cmnd
*ipr_cmd
)
2355 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
2356 struct ipr_hostrcb
*hostrcb
= ipr_cmd
->u
.hostrcb
;
2357 u32 ioasc
= be32_to_cpu(ipr_cmd
->ioasa
.ioasc
);
2361 fd_ioasc
= be32_to_cpu(hostrcb
->hcam
.u
.error64
.fd_ioasc
);
2363 fd_ioasc
= be32_to_cpu(hostrcb
->hcam
.u
.error
.fd_ioasc
);
2365 list_del(&hostrcb
->queue
);
2366 list_add_tail(&ipr_cmd
->queue
, &ioa_cfg
->free_q
);
2369 ipr_handle_log_data(ioa_cfg
, hostrcb
);
2370 if (fd_ioasc
== IPR_IOASC_NR_IOA_RESET_REQUIRED
)
2371 ipr_initiate_ioa_reset(ioa_cfg
, IPR_SHUTDOWN_ABBREV
);
2372 } else if (ioasc
!= IPR_IOASC_IOA_WAS_RESET
) {
2373 dev_err(&ioa_cfg
->pdev
->dev
,
2374 "Host RCB failed with IOASC: 0x%08X\n", ioasc
);
2377 ipr_send_hcam(ioa_cfg
, IPR_HCAM_CDB_OP_CODE_LOG_DATA
, hostrcb
);
2381 * ipr_timeout - An internally generated op has timed out.
2382 * @ipr_cmd: ipr command struct
2384 * This function blocks host requests and initiates an
2390 static void ipr_timeout(struct ipr_cmnd
*ipr_cmd
)
2392 unsigned long lock_flags
= 0;
2393 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
2396 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
2398 ioa_cfg
->errors_logged
++;
2399 dev_err(&ioa_cfg
->pdev
->dev
,
2400 "Adapter being reset due to command timeout.\n");
2402 if (WAIT_FOR_DUMP
== ioa_cfg
->sdt_state
)
2403 ioa_cfg
->sdt_state
= GET_DUMP
;
2405 if (!ioa_cfg
->in_reset_reload
|| ioa_cfg
->reset_cmd
== ipr_cmd
)
2406 ipr_initiate_ioa_reset(ioa_cfg
, IPR_SHUTDOWN_NONE
);
2408 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
2413 * ipr_oper_timeout - Adapter timed out transitioning to operational
2414 * @ipr_cmd: ipr command struct
2416 * This function blocks host requests and initiates an
2422 static void ipr_oper_timeout(struct ipr_cmnd
*ipr_cmd
)
2424 unsigned long lock_flags
= 0;
2425 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
2428 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
2430 ioa_cfg
->errors_logged
++;
2431 dev_err(&ioa_cfg
->pdev
->dev
,
2432 "Adapter timed out transitioning to operational.\n");
2434 if (WAIT_FOR_DUMP
== ioa_cfg
->sdt_state
)
2435 ioa_cfg
->sdt_state
= GET_DUMP
;
2437 if (!ioa_cfg
->in_reset_reload
|| ioa_cfg
->reset_cmd
== ipr_cmd
) {
2439 ioa_cfg
->reset_retries
+= IPR_NUM_RESET_RELOAD_RETRIES
;
2440 ipr_initiate_ioa_reset(ioa_cfg
, IPR_SHUTDOWN_NONE
);
2443 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
2448 * ipr_reset_reload - Reset/Reload the IOA
2449 * @ioa_cfg: ioa config struct
2450 * @shutdown_type: shutdown type
2452 * This function resets the adapter and re-initializes it.
2453 * This function assumes that all new host commands have been stopped.
2457 static int ipr_reset_reload(struct ipr_ioa_cfg
*ioa_cfg
,
2458 enum ipr_shutdown_type shutdown_type
)
2460 if (!ioa_cfg
->in_reset_reload
)
2461 ipr_initiate_ioa_reset(ioa_cfg
, shutdown_type
);
2463 spin_unlock_irq(ioa_cfg
->host
->host_lock
);
2464 wait_event(ioa_cfg
->reset_wait_q
, !ioa_cfg
->in_reset_reload
);
2465 spin_lock_irq(ioa_cfg
->host
->host_lock
);
2467 /* If we got hit with a host reset while we were already resetting
2468 the adapter for some reason, and the reset failed. */
2469 if (ioa_cfg
->ioa_is_dead
) {
2478 * ipr_find_ses_entry - Find matching SES in SES table
2479 * @res: resource entry struct of SES
2482 * pointer to SES table entry / NULL on failure
2484 static const struct ipr_ses_table_entry
*
2485 ipr_find_ses_entry(struct ipr_resource_entry
*res
)
2488 struct ipr_std_inq_vpids
*vpids
;
2489 const struct ipr_ses_table_entry
*ste
= ipr_ses_table
;
2491 for (i
= 0; i
< ARRAY_SIZE(ipr_ses_table
); i
++, ste
++) {
2492 for (j
= 0, matches
= 0; j
< IPR_PROD_ID_LEN
; j
++) {
2493 if (ste
->compare_product_id_byte
[j
] == 'X') {
2494 vpids
= &res
->std_inq_data
.vpids
;
2495 if (vpids
->product_id
[j
] == ste
->product_id
[j
])
2503 if (matches
== IPR_PROD_ID_LEN
)
2511 * ipr_get_max_scsi_speed - Determine max SCSI speed for a given bus
2512 * @ioa_cfg: ioa config struct
2514 * @bus_width: bus width
2517 * SCSI bus speed in units of 100KHz, 1600 is 160 MHz
2518 * For a 2-byte wide SCSI bus, the maximum transfer speed is
2519 * twice the maximum transfer rate (e.g. for a wide enabled bus,
2520 * max 160MHz = max 320MB/sec).
2522 static u32
ipr_get_max_scsi_speed(struct ipr_ioa_cfg
*ioa_cfg
, u8 bus
, u8 bus_width
)
2524 struct ipr_resource_entry
*res
;
2525 const struct ipr_ses_table_entry
*ste
;
2526 u32 max_xfer_rate
= IPR_MAX_SCSI_RATE(bus_width
);
2528 /* Loop through each config table entry in the config table buffer */
2529 list_for_each_entry(res
, &ioa_cfg
->used_res_q
, queue
) {
2530 if (!(IPR_IS_SES_DEVICE(res
->std_inq_data
)))
2533 if (bus
!= res
->bus
)
2536 if (!(ste
= ipr_find_ses_entry(res
)))
2539 max_xfer_rate
= (ste
->max_bus_speed_limit
* 10) / (bus_width
/ 8);
2542 return max_xfer_rate
;
2546 * ipr_wait_iodbg_ack - Wait for an IODEBUG ACK from the IOA
2547 * @ioa_cfg: ioa config struct
2548 * @max_delay: max delay in micro-seconds to wait
2550 * Waits for an IODEBUG ACK from the IOA, doing busy looping.
2553 * 0 on success / other on failure
2555 static int ipr_wait_iodbg_ack(struct ipr_ioa_cfg
*ioa_cfg
, int max_delay
)
2557 volatile u32 pcii_reg
;
2560 /* Read interrupt reg until IOA signals IO Debug Acknowledge */
2561 while (delay
< max_delay
) {
2562 pcii_reg
= readl(ioa_cfg
->regs
.sense_interrupt_reg
);
2564 if (pcii_reg
& IPR_PCII_IO_DEBUG_ACKNOWLEDGE
)
2567 /* udelay cannot be used if delay is more than a few milliseconds */
2568 if ((delay
/ 1000) > MAX_UDELAY_MS
)
2569 mdelay(delay
/ 1000);
2579 * ipr_get_sis64_dump_data_section - Dump IOA memory
2580 * @ioa_cfg: ioa config struct
2581 * @start_addr: adapter address to dump
2582 * @dest: destination kernel buffer
2583 * @length_in_words: length to dump in 4 byte words
2588 static int ipr_get_sis64_dump_data_section(struct ipr_ioa_cfg
*ioa_cfg
,
2590 __be32
*dest
, u32 length_in_words
)
2594 for (i
= 0; i
< length_in_words
; i
++) {
2595 writel(start_addr
+(i
*4), ioa_cfg
->regs
.dump_addr_reg
);
2596 *dest
= cpu_to_be32(readl(ioa_cfg
->regs
.dump_data_reg
));
2604 * ipr_get_ldump_data_section - Dump IOA memory
2605 * @ioa_cfg: ioa config struct
2606 * @start_addr: adapter address to dump
2607 * @dest: destination kernel buffer
2608 * @length_in_words: length to dump in 4 byte words
2611 * 0 on success / -EIO on failure
2613 static int ipr_get_ldump_data_section(struct ipr_ioa_cfg
*ioa_cfg
,
2615 __be32
*dest
, u32 length_in_words
)
2617 volatile u32 temp_pcii_reg
;
2621 return ipr_get_sis64_dump_data_section(ioa_cfg
, start_addr
,
2622 dest
, length_in_words
);
2624 /* Write IOA interrupt reg starting LDUMP state */
2625 writel((IPR_UPROCI_RESET_ALERT
| IPR_UPROCI_IO_DEBUG_ALERT
),
2626 ioa_cfg
->regs
.set_uproc_interrupt_reg32
);
2628 /* Wait for IO debug acknowledge */
2629 if (ipr_wait_iodbg_ack(ioa_cfg
,
2630 IPR_LDUMP_MAX_LONG_ACK_DELAY_IN_USEC
)) {
2631 dev_err(&ioa_cfg
->pdev
->dev
,
2632 "IOA dump long data transfer timeout\n");
2636 /* Signal LDUMP interlocked - clear IO debug ack */
2637 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE
,
2638 ioa_cfg
->regs
.clr_interrupt_reg
);
2640 /* Write Mailbox with starting address */
2641 writel(start_addr
, ioa_cfg
->ioa_mailbox
);
2643 /* Signal address valid - clear IOA Reset alert */
2644 writel(IPR_UPROCI_RESET_ALERT
,
2645 ioa_cfg
->regs
.clr_uproc_interrupt_reg32
);
2647 for (i
= 0; i
< length_in_words
; i
++) {
2648 /* Wait for IO debug acknowledge */
2649 if (ipr_wait_iodbg_ack(ioa_cfg
,
2650 IPR_LDUMP_MAX_SHORT_ACK_DELAY_IN_USEC
)) {
2651 dev_err(&ioa_cfg
->pdev
->dev
,
2652 "IOA dump short data transfer timeout\n");
2656 /* Read data from mailbox and increment destination pointer */
2657 *dest
= cpu_to_be32(readl(ioa_cfg
->ioa_mailbox
));
2660 /* For all but the last word of data, signal data received */
2661 if (i
< (length_in_words
- 1)) {
2662 /* Signal dump data received - Clear IO debug Ack */
2663 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE
,
2664 ioa_cfg
->regs
.clr_interrupt_reg
);
2668 /* Signal end of block transfer. Set reset alert then clear IO debug ack */
2669 writel(IPR_UPROCI_RESET_ALERT
,
2670 ioa_cfg
->regs
.set_uproc_interrupt_reg32
);
2672 writel(IPR_UPROCI_IO_DEBUG_ALERT
,
2673 ioa_cfg
->regs
.clr_uproc_interrupt_reg32
);
2675 /* Signal dump data received - Clear IO debug Ack */
2676 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE
,
2677 ioa_cfg
->regs
.clr_interrupt_reg
);
2679 /* Wait for IOA to signal LDUMP exit - IOA reset alert will be cleared */
2680 while (delay
< IPR_LDUMP_MAX_SHORT_ACK_DELAY_IN_USEC
) {
2682 readl(ioa_cfg
->regs
.sense_uproc_interrupt_reg32
);
2684 if (!(temp_pcii_reg
& IPR_UPROCI_RESET_ALERT
))
2694 #ifdef CONFIG_SCSI_IPR_DUMP
2696 * ipr_sdt_copy - Copy Smart Dump Table to kernel buffer
2697 * @ioa_cfg: ioa config struct
2698 * @pci_address: adapter address
2699 * @length: length of data to copy
2701 * Copy data from PCI adapter to kernel buffer.
2702 * Note: length MUST be a 4 byte multiple
2704 * 0 on success / other on failure
2706 static int ipr_sdt_copy(struct ipr_ioa_cfg
*ioa_cfg
,
2707 unsigned long pci_address
, u32 length
)
2709 int bytes_copied
= 0;
2710 int cur_len
, rc
, rem_len
, rem_page_len
;
2712 unsigned long lock_flags
= 0;
2713 struct ipr_ioa_dump
*ioa_dump
= &ioa_cfg
->dump
->ioa_dump
;
2715 while (bytes_copied
< length
&&
2716 (ioa_dump
->hdr
.len
+ bytes_copied
) < IPR_MAX_IOA_DUMP_SIZE
) {
2717 if (ioa_dump
->page_offset
>= PAGE_SIZE
||
2718 ioa_dump
->page_offset
== 0) {
2719 page
= (__be32
*)__get_free_page(GFP_ATOMIC
);
2723 return bytes_copied
;
2726 ioa_dump
->page_offset
= 0;
2727 ioa_dump
->ioa_data
[ioa_dump
->next_page_index
] = page
;
2728 ioa_dump
->next_page_index
++;
2730 page
= ioa_dump
->ioa_data
[ioa_dump
->next_page_index
- 1];
2732 rem_len
= length
- bytes_copied
;
2733 rem_page_len
= PAGE_SIZE
- ioa_dump
->page_offset
;
2734 cur_len
= min(rem_len
, rem_page_len
);
2736 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
2737 if (ioa_cfg
->sdt_state
== ABORT_DUMP
) {
2740 rc
= ipr_get_ldump_data_section(ioa_cfg
,
2741 pci_address
+ bytes_copied
,
2742 &page
[ioa_dump
->page_offset
/ 4],
2743 (cur_len
/ sizeof(u32
)));
2745 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
2748 ioa_dump
->page_offset
+= cur_len
;
2749 bytes_copied
+= cur_len
;
2757 return bytes_copied
;
2761 * ipr_init_dump_entry_hdr - Initialize a dump entry header.
2762 * @hdr: dump entry header struct
2767 static void ipr_init_dump_entry_hdr(struct ipr_dump_entry_header
*hdr
)
2769 hdr
->eye_catcher
= IPR_DUMP_EYE_CATCHER
;
2771 hdr
->offset
= sizeof(*hdr
);
2772 hdr
->status
= IPR_DUMP_STATUS_SUCCESS
;
2776 * ipr_dump_ioa_type_data - Fill in the adapter type in the dump.
2777 * @ioa_cfg: ioa config struct
2778 * @driver_dump: driver dump struct
2783 static void ipr_dump_ioa_type_data(struct ipr_ioa_cfg
*ioa_cfg
,
2784 struct ipr_driver_dump
*driver_dump
)
2786 struct ipr_inquiry_page3
*ucode_vpd
= &ioa_cfg
->vpd_cbs
->page3_data
;
2788 ipr_init_dump_entry_hdr(&driver_dump
->ioa_type_entry
.hdr
);
2789 driver_dump
->ioa_type_entry
.hdr
.len
=
2790 sizeof(struct ipr_dump_ioa_type_entry
) -
2791 sizeof(struct ipr_dump_entry_header
);
2792 driver_dump
->ioa_type_entry
.hdr
.data_type
= IPR_DUMP_DATA_TYPE_BINARY
;
2793 driver_dump
->ioa_type_entry
.hdr
.id
= IPR_DUMP_DRIVER_TYPE_ID
;
2794 driver_dump
->ioa_type_entry
.type
= ioa_cfg
->type
;
2795 driver_dump
->ioa_type_entry
.fw_version
= (ucode_vpd
->major_release
<< 24) |
2796 (ucode_vpd
->card_type
<< 16) | (ucode_vpd
->minor_release
[0] << 8) |
2797 ucode_vpd
->minor_release
[1];
2798 driver_dump
->hdr
.num_entries
++;
2802 * ipr_dump_version_data - Fill in the driver version in the dump.
2803 * @ioa_cfg: ioa config struct
2804 * @driver_dump: driver dump struct
2809 static void ipr_dump_version_data(struct ipr_ioa_cfg
*ioa_cfg
,
2810 struct ipr_driver_dump
*driver_dump
)
2812 ipr_init_dump_entry_hdr(&driver_dump
->version_entry
.hdr
);
2813 driver_dump
->version_entry
.hdr
.len
=
2814 sizeof(struct ipr_dump_version_entry
) -
2815 sizeof(struct ipr_dump_entry_header
);
2816 driver_dump
->version_entry
.hdr
.data_type
= IPR_DUMP_DATA_TYPE_ASCII
;
2817 driver_dump
->version_entry
.hdr
.id
= IPR_DUMP_DRIVER_VERSION_ID
;
2818 strcpy(driver_dump
->version_entry
.version
, IPR_DRIVER_VERSION
);
2819 driver_dump
->hdr
.num_entries
++;
2823 * ipr_dump_trace_data - Fill in the IOA trace in the dump.
2824 * @ioa_cfg: ioa config struct
2825 * @driver_dump: driver dump struct
2830 static void ipr_dump_trace_data(struct ipr_ioa_cfg
*ioa_cfg
,
2831 struct ipr_driver_dump
*driver_dump
)
2833 ipr_init_dump_entry_hdr(&driver_dump
->trace_entry
.hdr
);
2834 driver_dump
->trace_entry
.hdr
.len
=
2835 sizeof(struct ipr_dump_trace_entry
) -
2836 sizeof(struct ipr_dump_entry_header
);
2837 driver_dump
->trace_entry
.hdr
.data_type
= IPR_DUMP_DATA_TYPE_BINARY
;
2838 driver_dump
->trace_entry
.hdr
.id
= IPR_DUMP_TRACE_ID
;
2839 memcpy(driver_dump
->trace_entry
.trace
, ioa_cfg
->trace
, IPR_TRACE_SIZE
);
2840 driver_dump
->hdr
.num_entries
++;
2844 * ipr_dump_location_data - Fill in the IOA location in the dump.
2845 * @ioa_cfg: ioa config struct
2846 * @driver_dump: driver dump struct
2851 static void ipr_dump_location_data(struct ipr_ioa_cfg
*ioa_cfg
,
2852 struct ipr_driver_dump
*driver_dump
)
2854 ipr_init_dump_entry_hdr(&driver_dump
->location_entry
.hdr
);
2855 driver_dump
->location_entry
.hdr
.len
=
2856 sizeof(struct ipr_dump_location_entry
) -
2857 sizeof(struct ipr_dump_entry_header
);
2858 driver_dump
->location_entry
.hdr
.data_type
= IPR_DUMP_DATA_TYPE_ASCII
;
2859 driver_dump
->location_entry
.hdr
.id
= IPR_DUMP_LOCATION_ID
;
2860 strcpy(driver_dump
->location_entry
.location
, dev_name(&ioa_cfg
->pdev
->dev
));
2861 driver_dump
->hdr
.num_entries
++;
2865 * ipr_get_ioa_dump - Perform a dump of the driver and adapter.
2866 * @ioa_cfg: ioa config struct
2867 * @dump: dump struct
2872 static void ipr_get_ioa_dump(struct ipr_ioa_cfg
*ioa_cfg
, struct ipr_dump
*dump
)
2874 unsigned long start_addr
, sdt_word
;
2875 unsigned long lock_flags
= 0;
2876 struct ipr_driver_dump
*driver_dump
= &dump
->driver_dump
;
2877 struct ipr_ioa_dump
*ioa_dump
= &dump
->ioa_dump
;
2878 u32 num_entries
, start_off
, end_off
;
2879 u32 bytes_to_copy
, bytes_copied
, rc
;
2880 struct ipr_sdt
*sdt
;
2886 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
2888 if (ioa_cfg
->sdt_state
!= GET_DUMP
) {
2889 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
2893 start_addr
= readl(ioa_cfg
->ioa_mailbox
);
2895 if (!ioa_cfg
->sis64
&& !ipr_sdt_is_fmt2(start_addr
)) {
2896 dev_err(&ioa_cfg
->pdev
->dev
,
2897 "Invalid dump table format: %lx\n", start_addr
);
2898 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
2902 dev_err(&ioa_cfg
->pdev
->dev
, "Dump of IOA initiated\n");
2904 driver_dump
->hdr
.eye_catcher
= IPR_DUMP_EYE_CATCHER
;
2906 /* Initialize the overall dump header */
2907 driver_dump
->hdr
.len
= sizeof(struct ipr_driver_dump
);
2908 driver_dump
->hdr
.num_entries
= 1;
2909 driver_dump
->hdr
.first_entry_offset
= sizeof(struct ipr_dump_header
);
2910 driver_dump
->hdr
.status
= IPR_DUMP_STATUS_SUCCESS
;
2911 driver_dump
->hdr
.os
= IPR_DUMP_OS_LINUX
;
2912 driver_dump
->hdr
.driver_name
= IPR_DUMP_DRIVER_NAME
;
2914 ipr_dump_version_data(ioa_cfg
, driver_dump
);
2915 ipr_dump_location_data(ioa_cfg
, driver_dump
);
2916 ipr_dump_ioa_type_data(ioa_cfg
, driver_dump
);
2917 ipr_dump_trace_data(ioa_cfg
, driver_dump
);
2919 /* Update dump_header */
2920 driver_dump
->hdr
.len
+= sizeof(struct ipr_dump_entry_header
);
2922 /* IOA Dump entry */
2923 ipr_init_dump_entry_hdr(&ioa_dump
->hdr
);
2924 ioa_dump
->hdr
.len
= 0;
2925 ioa_dump
->hdr
.data_type
= IPR_DUMP_DATA_TYPE_BINARY
;
2926 ioa_dump
->hdr
.id
= IPR_DUMP_IOA_DUMP_ID
;
2928 /* First entries in sdt are actually a list of dump addresses and
2929 lengths to gather the real dump data. sdt represents the pointer
2930 to the ioa generated dump table. Dump data will be extracted based
2931 on entries in this table */
2932 sdt
= &ioa_dump
->sdt
;
2934 rc
= ipr_get_ldump_data_section(ioa_cfg
, start_addr
, (__be32
*)sdt
,
2935 sizeof(struct ipr_sdt
) / sizeof(__be32
));
2937 /* Smart Dump table is ready to use and the first entry is valid */
2938 if (rc
|| ((be32_to_cpu(sdt
->hdr
.state
) != IPR_FMT3_SDT_READY_TO_USE
) &&
2939 (be32_to_cpu(sdt
->hdr
.state
) != IPR_FMT2_SDT_READY_TO_USE
))) {
2940 dev_err(&ioa_cfg
->pdev
->dev
,
2941 "Dump of IOA failed. Dump table not valid: %d, %X.\n",
2942 rc
, be32_to_cpu(sdt
->hdr
.state
));
2943 driver_dump
->hdr
.status
= IPR_DUMP_STATUS_FAILED
;
2944 ioa_cfg
->sdt_state
= DUMP_OBTAINED
;
2945 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
2949 num_entries
= be32_to_cpu(sdt
->hdr
.num_entries_used
);
2951 if (num_entries
> IPR_NUM_SDT_ENTRIES
)
2952 num_entries
= IPR_NUM_SDT_ENTRIES
;
2954 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
2956 for (i
= 0; i
< num_entries
; i
++) {
2957 if (ioa_dump
->hdr
.len
> IPR_MAX_IOA_DUMP_SIZE
) {
2958 driver_dump
->hdr
.status
= IPR_DUMP_STATUS_QUAL_SUCCESS
;
2962 if (sdt
->entry
[i
].flags
& IPR_SDT_VALID_ENTRY
) {
2963 sdt_word
= be32_to_cpu(sdt
->entry
[i
].start_token
);
2965 bytes_to_copy
= be32_to_cpu(sdt
->entry
[i
].end_token
);
2967 start_off
= sdt_word
& IPR_FMT2_MBX_ADDR_MASK
;
2968 end_off
= be32_to_cpu(sdt
->entry
[i
].end_token
);
2970 if (ipr_sdt_is_fmt2(sdt_word
) && sdt_word
)
2971 bytes_to_copy
= end_off
- start_off
;
2976 if (bytes_to_copy
> IPR_MAX_IOA_DUMP_SIZE
) {
2977 sdt
->entry
[i
].flags
&= ~IPR_SDT_VALID_ENTRY
;
2981 /* Copy data from adapter to driver buffers */
2982 bytes_copied
= ipr_sdt_copy(ioa_cfg
, sdt_word
,
2985 ioa_dump
->hdr
.len
+= bytes_copied
;
2987 if (bytes_copied
!= bytes_to_copy
) {
2988 driver_dump
->hdr
.status
= IPR_DUMP_STATUS_QUAL_SUCCESS
;
2995 dev_err(&ioa_cfg
->pdev
->dev
, "Dump of IOA completed.\n");
2997 /* Update dump_header */
2998 driver_dump
->hdr
.len
+= ioa_dump
->hdr
.len
;
3000 ioa_cfg
->sdt_state
= DUMP_OBTAINED
;
3005 #define ipr_get_ioa_dump(ioa_cfg, dump) do { } while(0)
3009 * ipr_release_dump - Free adapter dump memory
3010 * @kref: kref struct
3015 static void ipr_release_dump(struct kref
*kref
)
3017 struct ipr_dump
*dump
= container_of(kref
,struct ipr_dump
,kref
);
3018 struct ipr_ioa_cfg
*ioa_cfg
= dump
->ioa_cfg
;
3019 unsigned long lock_flags
= 0;
3023 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
3024 ioa_cfg
->dump
= NULL
;
3025 ioa_cfg
->sdt_state
= INACTIVE
;
3026 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3028 for (i
= 0; i
< dump
->ioa_dump
.next_page_index
; i
++)
3029 free_page((unsigned long) dump
->ioa_dump
.ioa_data
[i
]);
3036 * ipr_worker_thread - Worker thread
3037 * @work: ioa config struct
3039 * Called at task level from a work thread. This function takes care
3040 * of adding and removing device from the mid-layer as configuration
3041 * changes are detected by the adapter.
3046 static void ipr_worker_thread(struct work_struct
*work
)
3048 unsigned long lock_flags
;
3049 struct ipr_resource_entry
*res
;
3050 struct scsi_device
*sdev
;
3051 struct ipr_dump
*dump
;
3052 struct ipr_ioa_cfg
*ioa_cfg
=
3053 container_of(work
, struct ipr_ioa_cfg
, work_q
);
3054 u8 bus
, target
, lun
;
3058 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
3060 if (ioa_cfg
->sdt_state
== GET_DUMP
) {
3061 dump
= ioa_cfg
->dump
;
3063 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3066 kref_get(&dump
->kref
);
3067 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3068 ipr_get_ioa_dump(ioa_cfg
, dump
);
3069 kref_put(&dump
->kref
, ipr_release_dump
);
3071 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
3072 if (ioa_cfg
->sdt_state
== DUMP_OBTAINED
)
3073 ipr_initiate_ioa_reset(ioa_cfg
, IPR_SHUTDOWN_NONE
);
3074 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3081 if (!ioa_cfg
->allow_cmds
|| !ioa_cfg
->allow_ml_add_del
) {
3082 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3086 list_for_each_entry(res
, &ioa_cfg
->used_res_q
, queue
) {
3087 if (res
->del_from_ml
&& res
->sdev
) {
3090 if (!scsi_device_get(sdev
)) {
3091 list_move_tail(&res
->queue
, &ioa_cfg
->free_res_q
);
3092 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3093 scsi_remove_device(sdev
);
3094 scsi_device_put(sdev
);
3095 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
3102 list_for_each_entry(res
, &ioa_cfg
->used_res_q
, queue
) {
3103 if (res
->add_to_ml
) {
3105 target
= res
->target
;
3108 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3109 scsi_add_device(ioa_cfg
->host
, bus
, target
, lun
);
3110 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
3115 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3116 kobject_uevent(&ioa_cfg
->host
->shost_dev
.kobj
, KOBJ_CHANGE
);
3120 #ifdef CONFIG_SCSI_IPR_TRACE
3122 * ipr_read_trace - Dump the adapter trace
3123 * @kobj: kobject struct
3124 * @bin_attr: bin_attribute struct
3127 * @count: buffer size
3130 * number of bytes printed to buffer
3132 static ssize_t
ipr_read_trace(struct kobject
*kobj
,
3133 struct bin_attribute
*bin_attr
,
3134 char *buf
, loff_t off
, size_t count
)
3136 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3137 struct Scsi_Host
*shost
= class_to_shost(dev
);
3138 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*)shost
->hostdata
;
3139 unsigned long lock_flags
= 0;
3142 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
3143 ret
= memory_read_from_buffer(buf
, count
, &off
, ioa_cfg
->trace
,
3145 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3150 static struct bin_attribute ipr_trace_attr
= {
3156 .read
= ipr_read_trace
,
3161 * ipr_show_fw_version - Show the firmware version
3162 * @dev: class device struct
3166 * number of bytes printed to buffer
3168 static ssize_t
ipr_show_fw_version(struct device
*dev
,
3169 struct device_attribute
*attr
, char *buf
)
3171 struct Scsi_Host
*shost
= class_to_shost(dev
);
3172 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*)shost
->hostdata
;
3173 struct ipr_inquiry_page3
*ucode_vpd
= &ioa_cfg
->vpd_cbs
->page3_data
;
3174 unsigned long lock_flags
= 0;
3177 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
3178 len
= snprintf(buf
, PAGE_SIZE
, "%02X%02X%02X%02X\n",
3179 ucode_vpd
->major_release
, ucode_vpd
->card_type
,
3180 ucode_vpd
->minor_release
[0],
3181 ucode_vpd
->minor_release
[1]);
3182 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3186 static struct device_attribute ipr_fw_version_attr
= {
3188 .name
= "fw_version",
3191 .show
= ipr_show_fw_version
,
3195 * ipr_show_log_level - Show the adapter's error logging level
3196 * @dev: class device struct
3200 * number of bytes printed to buffer
3202 static ssize_t
ipr_show_log_level(struct device
*dev
,
3203 struct device_attribute
*attr
, char *buf
)
3205 struct Scsi_Host
*shost
= class_to_shost(dev
);
3206 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*)shost
->hostdata
;
3207 unsigned long lock_flags
= 0;
3210 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
3211 len
= snprintf(buf
, PAGE_SIZE
, "%d\n", ioa_cfg
->log_level
);
3212 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3217 * ipr_store_log_level - Change the adapter's error logging level
3218 * @dev: class device struct
3222 * number of bytes printed to buffer
3224 static ssize_t
ipr_store_log_level(struct device
*dev
,
3225 struct device_attribute
*attr
,
3226 const char *buf
, size_t count
)
3228 struct Scsi_Host
*shost
= class_to_shost(dev
);
3229 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*)shost
->hostdata
;
3230 unsigned long lock_flags
= 0;
3232 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
3233 ioa_cfg
->log_level
= simple_strtoul(buf
, NULL
, 10);
3234 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3238 static struct device_attribute ipr_log_level_attr
= {
3240 .name
= "log_level",
3241 .mode
= S_IRUGO
| S_IWUSR
,
3243 .show
= ipr_show_log_level
,
3244 .store
= ipr_store_log_level
3248 * ipr_store_diagnostics - IOA Diagnostics interface
3249 * @dev: device struct
3251 * @count: buffer size
3253 * This function will reset the adapter and wait a reasonable
3254 * amount of time for any errors that the adapter might log.
3257 * count on success / other on failure
3259 static ssize_t
ipr_store_diagnostics(struct device
*dev
,
3260 struct device_attribute
*attr
,
3261 const char *buf
, size_t count
)
3263 struct Scsi_Host
*shost
= class_to_shost(dev
);
3264 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*)shost
->hostdata
;
3265 unsigned long lock_flags
= 0;
3268 if (!capable(CAP_SYS_ADMIN
))
3271 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
3272 while(ioa_cfg
->in_reset_reload
) {
3273 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3274 wait_event(ioa_cfg
->reset_wait_q
, !ioa_cfg
->in_reset_reload
);
3275 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
3278 ioa_cfg
->errors_logged
= 0;
3279 ipr_initiate_ioa_reset(ioa_cfg
, IPR_SHUTDOWN_NORMAL
);
3281 if (ioa_cfg
->in_reset_reload
) {
3282 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3283 wait_event(ioa_cfg
->reset_wait_q
, !ioa_cfg
->in_reset_reload
);
3285 /* Wait for a second for any errors to be logged */
3288 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3292 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
3293 if (ioa_cfg
->in_reset_reload
|| ioa_cfg
->errors_logged
)
3295 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3300 static struct device_attribute ipr_diagnostics_attr
= {
3302 .name
= "run_diagnostics",
3305 .store
= ipr_store_diagnostics
3309 * ipr_show_adapter_state - Show the adapter's state
3310 * @class_dev: device struct
3314 * number of bytes printed to buffer
3316 static ssize_t
ipr_show_adapter_state(struct device
*dev
,
3317 struct device_attribute
*attr
, char *buf
)
3319 struct Scsi_Host
*shost
= class_to_shost(dev
);
3320 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*)shost
->hostdata
;
3321 unsigned long lock_flags
= 0;
3324 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
3325 if (ioa_cfg
->ioa_is_dead
)
3326 len
= snprintf(buf
, PAGE_SIZE
, "offline\n");
3328 len
= snprintf(buf
, PAGE_SIZE
, "online\n");
3329 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3334 * ipr_store_adapter_state - Change adapter state
3335 * @dev: device struct
3337 * @count: buffer size
3339 * This function will change the adapter's state.
3342 * count on success / other on failure
3344 static ssize_t
ipr_store_adapter_state(struct device
*dev
,
3345 struct device_attribute
*attr
,
3346 const char *buf
, size_t count
)
3348 struct Scsi_Host
*shost
= class_to_shost(dev
);
3349 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*)shost
->hostdata
;
3350 unsigned long lock_flags
;
3353 if (!capable(CAP_SYS_ADMIN
))
3356 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
3357 if (ioa_cfg
->ioa_is_dead
&& !strncmp(buf
, "online", 6)) {
3358 ioa_cfg
->ioa_is_dead
= 0;
3359 ioa_cfg
->reset_retries
= 0;
3360 ioa_cfg
->in_ioa_bringdown
= 0;
3361 ipr_initiate_ioa_reset(ioa_cfg
, IPR_SHUTDOWN_NONE
);
3363 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3364 wait_event(ioa_cfg
->reset_wait_q
, !ioa_cfg
->in_reset_reload
);
3369 static struct device_attribute ipr_ioa_state_attr
= {
3371 .name
= "online_state",
3372 .mode
= S_IRUGO
| S_IWUSR
,
3374 .show
= ipr_show_adapter_state
,
3375 .store
= ipr_store_adapter_state
3379 * ipr_store_reset_adapter - Reset the adapter
3380 * @dev: device struct
3382 * @count: buffer size
3384 * This function will reset the adapter.
3387 * count on success / other on failure
3389 static ssize_t
ipr_store_reset_adapter(struct device
*dev
,
3390 struct device_attribute
*attr
,
3391 const char *buf
, size_t count
)
3393 struct Scsi_Host
*shost
= class_to_shost(dev
);
3394 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*)shost
->hostdata
;
3395 unsigned long lock_flags
;
3398 if (!capable(CAP_SYS_ADMIN
))
3401 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
3402 if (!ioa_cfg
->in_reset_reload
)
3403 ipr_initiate_ioa_reset(ioa_cfg
, IPR_SHUTDOWN_NORMAL
);
3404 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3405 wait_event(ioa_cfg
->reset_wait_q
, !ioa_cfg
->in_reset_reload
);
3410 static struct device_attribute ipr_ioa_reset_attr
= {
3412 .name
= "reset_host",
3415 .store
= ipr_store_reset_adapter
3419 * ipr_alloc_ucode_buffer - Allocates a microcode download buffer
3420 * @buf_len: buffer length
3422 * Allocates a DMA'able buffer in chunks and assembles a scatter/gather
3423 * list to use for microcode download
3426 * pointer to sglist / NULL on failure
3428 static struct ipr_sglist
*ipr_alloc_ucode_buffer(int buf_len
)
3430 int sg_size
, order
, bsize_elem
, num_elem
, i
, j
;
3431 struct ipr_sglist
*sglist
;
3432 struct scatterlist
*scatterlist
;
3435 /* Get the minimum size per scatter/gather element */
3436 sg_size
= buf_len
/ (IPR_MAX_SGLIST
- 1);
3438 /* Get the actual size per element */
3439 order
= get_order(sg_size
);
3441 /* Determine the actual number of bytes per element */
3442 bsize_elem
= PAGE_SIZE
* (1 << order
);
3444 /* Determine the actual number of sg entries needed */
3445 if (buf_len
% bsize_elem
)
3446 num_elem
= (buf_len
/ bsize_elem
) + 1;
3448 num_elem
= buf_len
/ bsize_elem
;
3450 /* Allocate a scatter/gather list for the DMA */
3451 sglist
= kzalloc(sizeof(struct ipr_sglist
) +
3452 (sizeof(struct scatterlist
) * (num_elem
- 1)),
3455 if (sglist
== NULL
) {
3460 scatterlist
= sglist
->scatterlist
;
3461 sg_init_table(scatterlist
, num_elem
);
3463 sglist
->order
= order
;
3464 sglist
->num_sg
= num_elem
;
3466 /* Allocate a bunch of sg elements */
3467 for (i
= 0; i
< num_elem
; i
++) {
3468 page
= alloc_pages(GFP_KERNEL
, order
);
3472 /* Free up what we already allocated */
3473 for (j
= i
- 1; j
>= 0; j
--)
3474 __free_pages(sg_page(&scatterlist
[j
]), order
);
3479 sg_set_page(&scatterlist
[i
], page
, 0, 0);
3486 * ipr_free_ucode_buffer - Frees a microcode download buffer
3487 * @p_dnld: scatter/gather list pointer
3489 * Free a DMA'able ucode download buffer previously allocated with
3490 * ipr_alloc_ucode_buffer
3495 static void ipr_free_ucode_buffer(struct ipr_sglist
*sglist
)
3499 for (i
= 0; i
< sglist
->num_sg
; i
++)
3500 __free_pages(sg_page(&sglist
->scatterlist
[i
]), sglist
->order
);
3506 * ipr_copy_ucode_buffer - Copy user buffer to kernel buffer
3507 * @sglist: scatter/gather list pointer
3508 * @buffer: buffer pointer
3509 * @len: buffer length
3511 * Copy a microcode image from a user buffer into a buffer allocated by
3512 * ipr_alloc_ucode_buffer
3515 * 0 on success / other on failure
3517 static int ipr_copy_ucode_buffer(struct ipr_sglist
*sglist
,
3518 u8
*buffer
, u32 len
)
3520 int bsize_elem
, i
, result
= 0;
3521 struct scatterlist
*scatterlist
;
3524 /* Determine the actual number of bytes per element */
3525 bsize_elem
= PAGE_SIZE
* (1 << sglist
->order
);
3527 scatterlist
= sglist
->scatterlist
;
3529 for (i
= 0; i
< (len
/ bsize_elem
); i
++, buffer
+= bsize_elem
) {
3530 struct page
*page
= sg_page(&scatterlist
[i
]);
3533 memcpy(kaddr
, buffer
, bsize_elem
);
3536 scatterlist
[i
].length
= bsize_elem
;
3544 if (len
% bsize_elem
) {
3545 struct page
*page
= sg_page(&scatterlist
[i
]);
3548 memcpy(kaddr
, buffer
, len
% bsize_elem
);
3551 scatterlist
[i
].length
= len
% bsize_elem
;
3554 sglist
->buffer_len
= len
;
3559 * ipr_build_ucode_ioadl64 - Build a microcode download IOADL
3560 * @ipr_cmd: ipr command struct
3561 * @sglist: scatter/gather list
3563 * Builds a microcode download IOA data list (IOADL).
3566 static void ipr_build_ucode_ioadl64(struct ipr_cmnd
*ipr_cmd
,
3567 struct ipr_sglist
*sglist
)
3569 struct ipr_ioarcb
*ioarcb
= &ipr_cmd
->ioarcb
;
3570 struct ipr_ioadl64_desc
*ioadl64
= ipr_cmd
->i
.ioadl64
;
3571 struct scatterlist
*scatterlist
= sglist
->scatterlist
;
3574 ipr_cmd
->dma_use_sg
= sglist
->num_dma_sg
;
3575 ioarcb
->cmd_pkt
.flags_hi
|= IPR_FLAGS_HI_WRITE_NOT_READ
;
3576 ioarcb
->data_transfer_length
= cpu_to_be32(sglist
->buffer_len
);
3579 cpu_to_be32(sizeof(struct ipr_ioadl64_desc
) * ipr_cmd
->dma_use_sg
);
3580 for (i
= 0; i
< ipr_cmd
->dma_use_sg
; i
++) {
3581 ioadl64
[i
].flags
= cpu_to_be32(IPR_IOADL_FLAGS_WRITE
);
3582 ioadl64
[i
].data_len
= cpu_to_be32(sg_dma_len(&scatterlist
[i
]));
3583 ioadl64
[i
].address
= cpu_to_be64(sg_dma_address(&scatterlist
[i
]));
3586 ioadl64
[i
-1].flags
|= cpu_to_be32(IPR_IOADL_FLAGS_LAST
);
3590 * ipr_build_ucode_ioadl - Build a microcode download IOADL
3591 * @ipr_cmd: ipr command struct
3592 * @sglist: scatter/gather list
3594 * Builds a microcode download IOA data list (IOADL).
3597 static void ipr_build_ucode_ioadl(struct ipr_cmnd
*ipr_cmd
,
3598 struct ipr_sglist
*sglist
)
3600 struct ipr_ioarcb
*ioarcb
= &ipr_cmd
->ioarcb
;
3601 struct ipr_ioadl_desc
*ioadl
= ipr_cmd
->i
.ioadl
;
3602 struct scatterlist
*scatterlist
= sglist
->scatterlist
;
3605 ipr_cmd
->dma_use_sg
= sglist
->num_dma_sg
;
3606 ioarcb
->cmd_pkt
.flags_hi
|= IPR_FLAGS_HI_WRITE_NOT_READ
;
3607 ioarcb
->data_transfer_length
= cpu_to_be32(sglist
->buffer_len
);
3610 cpu_to_be32(sizeof(struct ipr_ioadl_desc
) * ipr_cmd
->dma_use_sg
);
3612 for (i
= 0; i
< ipr_cmd
->dma_use_sg
; i
++) {
3613 ioadl
[i
].flags_and_data_len
=
3614 cpu_to_be32(IPR_IOADL_FLAGS_WRITE
| sg_dma_len(&scatterlist
[i
]));
3616 cpu_to_be32(sg_dma_address(&scatterlist
[i
]));
3619 ioadl
[i
-1].flags_and_data_len
|=
3620 cpu_to_be32(IPR_IOADL_FLAGS_LAST
);
3624 * ipr_update_ioa_ucode - Update IOA's microcode
3625 * @ioa_cfg: ioa config struct
3626 * @sglist: scatter/gather list
3628 * Initiate an adapter reset to update the IOA's microcode
3631 * 0 on success / -EIO on failure
3633 static int ipr_update_ioa_ucode(struct ipr_ioa_cfg
*ioa_cfg
,
3634 struct ipr_sglist
*sglist
)
3636 unsigned long lock_flags
;
3638 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
3639 while(ioa_cfg
->in_reset_reload
) {
3640 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3641 wait_event(ioa_cfg
->reset_wait_q
, !ioa_cfg
->in_reset_reload
);
3642 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
3645 if (ioa_cfg
->ucode_sglist
) {
3646 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3647 dev_err(&ioa_cfg
->pdev
->dev
,
3648 "Microcode download already in progress\n");
3652 sglist
->num_dma_sg
= pci_map_sg(ioa_cfg
->pdev
, sglist
->scatterlist
,
3653 sglist
->num_sg
, DMA_TO_DEVICE
);
3655 if (!sglist
->num_dma_sg
) {
3656 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3657 dev_err(&ioa_cfg
->pdev
->dev
,
3658 "Failed to map microcode download buffer!\n");
3662 ioa_cfg
->ucode_sglist
= sglist
;
3663 ipr_initiate_ioa_reset(ioa_cfg
, IPR_SHUTDOWN_NORMAL
);
3664 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3665 wait_event(ioa_cfg
->reset_wait_q
, !ioa_cfg
->in_reset_reload
);
3667 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
3668 ioa_cfg
->ucode_sglist
= NULL
;
3669 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3674 * ipr_store_update_fw - Update the firmware on the adapter
3675 * @class_dev: device struct
3677 * @count: buffer size
3679 * This function will update the firmware on the adapter.
3682 * count on success / other on failure
3684 static ssize_t
ipr_store_update_fw(struct device
*dev
,
3685 struct device_attribute
*attr
,
3686 const char *buf
, size_t count
)
3688 struct Scsi_Host
*shost
= class_to_shost(dev
);
3689 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*)shost
->hostdata
;
3690 struct ipr_ucode_image_header
*image_hdr
;
3691 const struct firmware
*fw_entry
;
3692 struct ipr_sglist
*sglist
;
3695 int len
, result
, dnld_size
;
3697 if (!capable(CAP_SYS_ADMIN
))
3700 len
= snprintf(fname
, 99, "%s", buf
);
3701 fname
[len
-1] = '\0';
3703 if(request_firmware(&fw_entry
, fname
, &ioa_cfg
->pdev
->dev
)) {
3704 dev_err(&ioa_cfg
->pdev
->dev
, "Firmware file %s not found\n", fname
);
3708 image_hdr
= (struct ipr_ucode_image_header
*)fw_entry
->data
;
3710 if (be32_to_cpu(image_hdr
->header_length
) > fw_entry
->size
||
3711 (ioa_cfg
->vpd_cbs
->page3_data
.card_type
&&
3712 ioa_cfg
->vpd_cbs
->page3_data
.card_type
!= image_hdr
->card_type
)) {
3713 dev_err(&ioa_cfg
->pdev
->dev
, "Invalid microcode buffer\n");
3714 release_firmware(fw_entry
);
3718 src
= (u8
*)image_hdr
+ be32_to_cpu(image_hdr
->header_length
);
3719 dnld_size
= fw_entry
->size
- be32_to_cpu(image_hdr
->header_length
);
3720 sglist
= ipr_alloc_ucode_buffer(dnld_size
);
3723 dev_err(&ioa_cfg
->pdev
->dev
, "Microcode buffer allocation failed\n");
3724 release_firmware(fw_entry
);
3728 result
= ipr_copy_ucode_buffer(sglist
, src
, dnld_size
);
3731 dev_err(&ioa_cfg
->pdev
->dev
,
3732 "Microcode buffer copy to DMA buffer failed\n");
3736 result
= ipr_update_ioa_ucode(ioa_cfg
, sglist
);
3741 ipr_free_ucode_buffer(sglist
);
3742 release_firmware(fw_entry
);
3746 static struct device_attribute ipr_update_fw_attr
= {
3748 .name
= "update_fw",
3751 .store
= ipr_store_update_fw
3754 static struct device_attribute
*ipr_ioa_attrs
[] = {
3755 &ipr_fw_version_attr
,
3756 &ipr_log_level_attr
,
3757 &ipr_diagnostics_attr
,
3758 &ipr_ioa_state_attr
,
3759 &ipr_ioa_reset_attr
,
3760 &ipr_update_fw_attr
,
3764 #ifdef CONFIG_SCSI_IPR_DUMP
3766 * ipr_read_dump - Dump the adapter
3767 * @kobj: kobject struct
3768 * @bin_attr: bin_attribute struct
3771 * @count: buffer size
3774 * number of bytes printed to buffer
3776 static ssize_t
ipr_read_dump(struct kobject
*kobj
,
3777 struct bin_attribute
*bin_attr
,
3778 char *buf
, loff_t off
, size_t count
)
3780 struct device
*cdev
= container_of(kobj
, struct device
, kobj
);
3781 struct Scsi_Host
*shost
= class_to_shost(cdev
);
3782 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*)shost
->hostdata
;
3783 struct ipr_dump
*dump
;
3784 unsigned long lock_flags
= 0;
3789 if (!capable(CAP_SYS_ADMIN
))
3792 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
3793 dump
= ioa_cfg
->dump
;
3795 if (ioa_cfg
->sdt_state
!= DUMP_OBTAINED
|| !dump
) {
3796 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3799 kref_get(&dump
->kref
);
3800 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3802 if (off
> dump
->driver_dump
.hdr
.len
) {
3803 kref_put(&dump
->kref
, ipr_release_dump
);
3807 if (off
+ count
> dump
->driver_dump
.hdr
.len
) {
3808 count
= dump
->driver_dump
.hdr
.len
- off
;
3812 if (count
&& off
< sizeof(dump
->driver_dump
)) {
3813 if (off
+ count
> sizeof(dump
->driver_dump
))
3814 len
= sizeof(dump
->driver_dump
) - off
;
3817 src
= (u8
*)&dump
->driver_dump
+ off
;
3818 memcpy(buf
, src
, len
);
3824 off
-= sizeof(dump
->driver_dump
);
3826 if (count
&& off
< offsetof(struct ipr_ioa_dump
, ioa_data
)) {
3827 if (off
+ count
> offsetof(struct ipr_ioa_dump
, ioa_data
))
3828 len
= offsetof(struct ipr_ioa_dump
, ioa_data
) - off
;
3831 src
= (u8
*)&dump
->ioa_dump
+ off
;
3832 memcpy(buf
, src
, len
);
3838 off
-= offsetof(struct ipr_ioa_dump
, ioa_data
);
3841 if ((off
& PAGE_MASK
) != ((off
+ count
) & PAGE_MASK
))
3842 len
= PAGE_ALIGN(off
) - off
;
3845 src
= (u8
*)dump
->ioa_dump
.ioa_data
[(off
& PAGE_MASK
) >> PAGE_SHIFT
];
3846 src
+= off
& ~PAGE_MASK
;
3847 memcpy(buf
, src
, len
);
3853 kref_put(&dump
->kref
, ipr_release_dump
);
3858 * ipr_alloc_dump - Prepare for adapter dump
3859 * @ioa_cfg: ioa config struct
3862 * 0 on success / other on failure
3864 static int ipr_alloc_dump(struct ipr_ioa_cfg
*ioa_cfg
)
3866 struct ipr_dump
*dump
;
3867 unsigned long lock_flags
= 0;
3869 dump
= kzalloc(sizeof(struct ipr_dump
), GFP_KERNEL
);
3872 ipr_err("Dump memory allocation failed\n");
3876 kref_init(&dump
->kref
);
3877 dump
->ioa_cfg
= ioa_cfg
;
3879 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
3881 if (INACTIVE
!= ioa_cfg
->sdt_state
) {
3882 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3887 ioa_cfg
->dump
= dump
;
3888 ioa_cfg
->sdt_state
= WAIT_FOR_DUMP
;
3889 if (ioa_cfg
->ioa_is_dead
&& !ioa_cfg
->dump_taken
) {
3890 ioa_cfg
->dump_taken
= 1;
3891 schedule_work(&ioa_cfg
->work_q
);
3893 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3899 * ipr_free_dump - Free adapter dump memory
3900 * @ioa_cfg: ioa config struct
3903 * 0 on success / other on failure
3905 static int ipr_free_dump(struct ipr_ioa_cfg
*ioa_cfg
)
3907 struct ipr_dump
*dump
;
3908 unsigned long lock_flags
= 0;
3912 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
3913 dump
= ioa_cfg
->dump
;
3915 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3919 ioa_cfg
->dump
= NULL
;
3920 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
3922 kref_put(&dump
->kref
, ipr_release_dump
);
3929 * ipr_write_dump - Setup dump state of adapter
3930 * @kobj: kobject struct
3931 * @bin_attr: bin_attribute struct
3934 * @count: buffer size
3937 * number of bytes printed to buffer
3939 static ssize_t
ipr_write_dump(struct kobject
*kobj
,
3940 struct bin_attribute
*bin_attr
,
3941 char *buf
, loff_t off
, size_t count
)
3943 struct device
*cdev
= container_of(kobj
, struct device
, kobj
);
3944 struct Scsi_Host
*shost
= class_to_shost(cdev
);
3945 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*)shost
->hostdata
;
3948 if (!capable(CAP_SYS_ADMIN
))
3952 rc
= ipr_alloc_dump(ioa_cfg
);
3953 else if (buf
[0] == '0')
3954 rc
= ipr_free_dump(ioa_cfg
);
3964 static struct bin_attribute ipr_dump_attr
= {
3967 .mode
= S_IRUSR
| S_IWUSR
,
3970 .read
= ipr_read_dump
,
3971 .write
= ipr_write_dump
3974 static int ipr_free_dump(struct ipr_ioa_cfg
*ioa_cfg
) { return 0; };
3978 * ipr_change_queue_depth - Change the device's queue depth
3979 * @sdev: scsi device struct
3980 * @qdepth: depth to set
3981 * @reason: calling context
3986 static int ipr_change_queue_depth(struct scsi_device
*sdev
, int qdepth
,
3989 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*)sdev
->host
->hostdata
;
3990 struct ipr_resource_entry
*res
;
3991 unsigned long lock_flags
= 0;
3993 if (reason
!= SCSI_QDEPTH_DEFAULT
)
3996 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
3997 res
= (struct ipr_resource_entry
*)sdev
->hostdata
;
3999 if (res
&& ipr_is_gata(res
) && qdepth
> IPR_MAX_CMD_PER_ATA_LUN
)
4000 qdepth
= IPR_MAX_CMD_PER_ATA_LUN
;
4001 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
4003 scsi_adjust_queue_depth(sdev
, scsi_get_tag_type(sdev
), qdepth
);
4004 return sdev
->queue_depth
;
4008 * ipr_change_queue_type - Change the device's queue type
4009 * @dsev: scsi device struct
4010 * @tag_type: type of tags to use
4013 * actual queue type set
4015 static int ipr_change_queue_type(struct scsi_device
*sdev
, int tag_type
)
4017 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*)sdev
->host
->hostdata
;
4018 struct ipr_resource_entry
*res
;
4019 unsigned long lock_flags
= 0;
4021 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
4022 res
= (struct ipr_resource_entry
*)sdev
->hostdata
;
4025 if (ipr_is_gscsi(res
) && sdev
->tagged_supported
) {
4027 * We don't bother quiescing the device here since the
4028 * adapter firmware does it for us.
4030 scsi_set_tag_type(sdev
, tag_type
);
4033 scsi_activate_tcq(sdev
, sdev
->queue_depth
);
4035 scsi_deactivate_tcq(sdev
, sdev
->queue_depth
);
4041 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
4046 * ipr_show_adapter_handle - Show the adapter's resource handle for this device
4047 * @dev: device struct
4051 * number of bytes printed to buffer
4053 static ssize_t
ipr_show_adapter_handle(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
4055 struct scsi_device
*sdev
= to_scsi_device(dev
);
4056 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*)sdev
->host
->hostdata
;
4057 struct ipr_resource_entry
*res
;
4058 unsigned long lock_flags
= 0;
4059 ssize_t len
= -ENXIO
;
4061 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
4062 res
= (struct ipr_resource_entry
*)sdev
->hostdata
;
4064 len
= snprintf(buf
, PAGE_SIZE
, "%08X\n", res
->res_handle
);
4065 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
4069 static struct device_attribute ipr_adapter_handle_attr
= {
4071 .name
= "adapter_handle",
4074 .show
= ipr_show_adapter_handle
4078 * ipr_show_resource_path - Show the resource path for this device.
4079 * @dev: device struct
4083 * number of bytes printed to buffer
4085 static ssize_t
ipr_show_resource_path(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
4087 struct scsi_device
*sdev
= to_scsi_device(dev
);
4088 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*)sdev
->host
->hostdata
;
4089 struct ipr_resource_entry
*res
;
4090 unsigned long lock_flags
= 0;
4091 ssize_t len
= -ENXIO
;
4092 char buffer
[IPR_MAX_RES_PATH_LENGTH
];
4094 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
4095 res
= (struct ipr_resource_entry
*)sdev
->hostdata
;
4097 len
= snprintf(buf
, PAGE_SIZE
, "%s\n",
4098 ipr_format_resource_path(&res
->res_path
[0], &buffer
[0]));
4099 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
4103 static struct device_attribute ipr_resource_path_attr
= {
4105 .name
= "resource_path",
4108 .show
= ipr_show_resource_path
4111 static struct device_attribute
*ipr_dev_attrs
[] = {
4112 &ipr_adapter_handle_attr
,
4113 &ipr_resource_path_attr
,
4118 * ipr_biosparam - Return the HSC mapping
4119 * @sdev: scsi device struct
4120 * @block_device: block device pointer
4121 * @capacity: capacity of the device
4122 * @parm: Array containing returned HSC values.
4124 * This function generates the HSC parms that fdisk uses.
4125 * We want to make sure we return something that places partitions
4126 * on 4k boundaries for best performance with the IOA.
4131 static int ipr_biosparam(struct scsi_device
*sdev
,
4132 struct block_device
*block_device
,
4133 sector_t capacity
, int *parm
)
4141 cylinders
= capacity
;
4142 sector_div(cylinders
, (128 * 32));
4147 parm
[2] = cylinders
;
4153 * ipr_find_starget - Find target based on bus/target.
4154 * @starget: scsi target struct
4157 * resource entry pointer if found / NULL if not found
4159 static struct ipr_resource_entry
*ipr_find_starget(struct scsi_target
*starget
)
4161 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
4162 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*) shost
->hostdata
;
4163 struct ipr_resource_entry
*res
;
4165 list_for_each_entry(res
, &ioa_cfg
->used_res_q
, queue
) {
4166 if ((res
->bus
== starget
->channel
) &&
4167 (res
->target
== starget
->id
) &&
4176 static struct ata_port_info sata_port_info
;
4179 * ipr_target_alloc - Prepare for commands to a SCSI target
4180 * @starget: scsi target struct
4182 * If the device is a SATA device, this function allocates an
4183 * ATA port with libata, else it does nothing.
4186 * 0 on success / non-0 on failure
4188 static int ipr_target_alloc(struct scsi_target
*starget
)
4190 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
4191 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*) shost
->hostdata
;
4192 struct ipr_sata_port
*sata_port
;
4193 struct ata_port
*ap
;
4194 struct ipr_resource_entry
*res
;
4195 unsigned long lock_flags
;
4197 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
4198 res
= ipr_find_starget(starget
);
4199 starget
->hostdata
= NULL
;
4201 if (res
&& ipr_is_gata(res
)) {
4202 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
4203 sata_port
= kzalloc(sizeof(*sata_port
), GFP_KERNEL
);
4207 ap
= ata_sas_port_alloc(&ioa_cfg
->ata_host
, &sata_port_info
, shost
);
4209 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
4210 sata_port
->ioa_cfg
= ioa_cfg
;
4212 sata_port
->res
= res
;
4214 res
->sata_port
= sata_port
;
4215 ap
->private_data
= sata_port
;
4216 starget
->hostdata
= sata_port
;
4222 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
4228 * ipr_target_destroy - Destroy a SCSI target
4229 * @starget: scsi target struct
4231 * If the device was a SATA device, this function frees the libata
4232 * ATA port, else it does nothing.
4235 static void ipr_target_destroy(struct scsi_target
*starget
)
4237 struct ipr_sata_port
*sata_port
= starget
->hostdata
;
4238 struct Scsi_Host
*shost
= dev_to_shost(&starget
->dev
);
4239 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*) shost
->hostdata
;
4241 if (ioa_cfg
->sis64
) {
4242 if (starget
->channel
== IPR_ARRAY_VIRTUAL_BUS
)
4243 clear_bit(starget
->id
, ioa_cfg
->array_ids
);
4244 else if (starget
->channel
== IPR_VSET_VIRTUAL_BUS
)
4245 clear_bit(starget
->id
, ioa_cfg
->vset_ids
);
4246 else if (starget
->channel
== 0)
4247 clear_bit(starget
->id
, ioa_cfg
->target_ids
);
4251 starget
->hostdata
= NULL
;
4252 ata_sas_port_destroy(sata_port
->ap
);
4258 * ipr_find_sdev - Find device based on bus/target/lun.
4259 * @sdev: scsi device struct
4262 * resource entry pointer if found / NULL if not found
4264 static struct ipr_resource_entry
*ipr_find_sdev(struct scsi_device
*sdev
)
4266 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*) sdev
->host
->hostdata
;
4267 struct ipr_resource_entry
*res
;
4269 list_for_each_entry(res
, &ioa_cfg
->used_res_q
, queue
) {
4270 if ((res
->bus
== sdev
->channel
) &&
4271 (res
->target
== sdev
->id
) &&
4272 (res
->lun
== sdev
->lun
))
4280 * ipr_slave_destroy - Unconfigure a SCSI device
4281 * @sdev: scsi device struct
4286 static void ipr_slave_destroy(struct scsi_device
*sdev
)
4288 struct ipr_resource_entry
*res
;
4289 struct ipr_ioa_cfg
*ioa_cfg
;
4290 unsigned long lock_flags
= 0;
4292 ioa_cfg
= (struct ipr_ioa_cfg
*) sdev
->host
->hostdata
;
4294 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
4295 res
= (struct ipr_resource_entry
*) sdev
->hostdata
;
4298 ata_port_disable(res
->sata_port
->ap
);
4299 sdev
->hostdata
= NULL
;
4301 res
->sata_port
= NULL
;
4303 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
4307 * ipr_slave_configure - Configure a SCSI device
4308 * @sdev: scsi device struct
4310 * This function configures the specified scsi device.
4315 static int ipr_slave_configure(struct scsi_device
*sdev
)
4317 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*) sdev
->host
->hostdata
;
4318 struct ipr_resource_entry
*res
;
4319 struct ata_port
*ap
= NULL
;
4320 unsigned long lock_flags
= 0;
4321 char buffer
[IPR_MAX_RES_PATH_LENGTH
];
4323 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
4324 res
= sdev
->hostdata
;
4326 if (ipr_is_af_dasd_device(res
))
4327 sdev
->type
= TYPE_RAID
;
4328 if (ipr_is_af_dasd_device(res
) || ipr_is_ioa_resource(res
)) {
4329 sdev
->scsi_level
= 4;
4330 sdev
->no_uld_attach
= 1;
4332 if (ipr_is_vset_device(res
)) {
4333 blk_queue_rq_timeout(sdev
->request_queue
,
4334 IPR_VSET_RW_TIMEOUT
);
4335 blk_queue_max_hw_sectors(sdev
->request_queue
, IPR_VSET_MAX_SECTORS
);
4337 if (ipr_is_vset_device(res
) || ipr_is_scsi_disk(res
))
4338 sdev
->allow_restart
= 1;
4339 if (ipr_is_gata(res
) && res
->sata_port
)
4340 ap
= res
->sata_port
->ap
;
4341 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
4344 scsi_adjust_queue_depth(sdev
, 0, IPR_MAX_CMD_PER_ATA_LUN
);
4345 ata_sas_slave_configure(sdev
, ap
);
4347 scsi_adjust_queue_depth(sdev
, 0, sdev
->host
->cmd_per_lun
);
4349 sdev_printk(KERN_INFO
, sdev
, "Resource path: %s\n",
4350 ipr_format_resource_path(&res
->res_path
[0], &buffer
[0]));
4353 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
4358 * ipr_ata_slave_alloc - Prepare for commands to a SATA device
4359 * @sdev: scsi device struct
4361 * This function initializes an ATA port so that future commands
4362 * sent through queuecommand will work.
4367 static int ipr_ata_slave_alloc(struct scsi_device
*sdev
)
4369 struct ipr_sata_port
*sata_port
= NULL
;
4373 if (sdev
->sdev_target
)
4374 sata_port
= sdev
->sdev_target
->hostdata
;
4376 rc
= ata_sas_port_init(sata_port
->ap
);
4378 ipr_slave_destroy(sdev
);
4385 * ipr_slave_alloc - Prepare for commands to a device.
4386 * @sdev: scsi device struct
4388 * This function saves a pointer to the resource entry
4389 * in the scsi device struct if the device exists. We
4390 * can then use this pointer in ipr_queuecommand when
4391 * handling new commands.
4394 * 0 on success / -ENXIO if device does not exist
4396 static int ipr_slave_alloc(struct scsi_device
*sdev
)
4398 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*) sdev
->host
->hostdata
;
4399 struct ipr_resource_entry
*res
;
4400 unsigned long lock_flags
;
4403 sdev
->hostdata
= NULL
;
4405 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
4407 res
= ipr_find_sdev(sdev
);
4412 sdev
->hostdata
= res
;
4413 if (!ipr_is_naca_model(res
))
4414 res
->needs_sync_complete
= 1;
4416 if (ipr_is_gata(res
)) {
4417 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
4418 return ipr_ata_slave_alloc(sdev
);
4422 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
4428 * ipr_eh_host_reset - Reset the host adapter
4429 * @scsi_cmd: scsi command struct
4434 static int __ipr_eh_host_reset(struct scsi_cmnd
* scsi_cmd
)
4436 struct ipr_ioa_cfg
*ioa_cfg
;
4440 ioa_cfg
= (struct ipr_ioa_cfg
*) scsi_cmd
->device
->host
->hostdata
;
4442 dev_err(&ioa_cfg
->pdev
->dev
,
4443 "Adapter being reset as a result of error recovery.\n");
4445 if (WAIT_FOR_DUMP
== ioa_cfg
->sdt_state
)
4446 ioa_cfg
->sdt_state
= GET_DUMP
;
4448 rc
= ipr_reset_reload(ioa_cfg
, IPR_SHUTDOWN_ABBREV
);
4454 static int ipr_eh_host_reset(struct scsi_cmnd
* cmd
)
4458 spin_lock_irq(cmd
->device
->host
->host_lock
);
4459 rc
= __ipr_eh_host_reset(cmd
);
4460 spin_unlock_irq(cmd
->device
->host
->host_lock
);
4466 * ipr_device_reset - Reset the device
4467 * @ioa_cfg: ioa config struct
4468 * @res: resource entry struct
4470 * This function issues a device reset to the affected device.
4471 * If the device is a SCSI device, a LUN reset will be sent
4472 * to the device first. If that does not work, a target reset
4473 * will be sent. If the device is a SATA device, a PHY reset will
4477 * 0 on success / non-zero on failure
4479 static int ipr_device_reset(struct ipr_ioa_cfg
*ioa_cfg
,
4480 struct ipr_resource_entry
*res
)
4482 struct ipr_cmnd
*ipr_cmd
;
4483 struct ipr_ioarcb
*ioarcb
;
4484 struct ipr_cmd_pkt
*cmd_pkt
;
4485 struct ipr_ioarcb_ata_regs
*regs
;
4489 ipr_cmd
= ipr_get_free_ipr_cmnd(ioa_cfg
);
4490 ioarcb
= &ipr_cmd
->ioarcb
;
4491 cmd_pkt
= &ioarcb
->cmd_pkt
;
4493 if (ipr_cmd
->ioa_cfg
->sis64
) {
4494 regs
= &ipr_cmd
->i
.ata_ioadl
.regs
;
4495 ioarcb
->add_cmd_parms_offset
= cpu_to_be16(sizeof(*ioarcb
));
4497 regs
= &ioarcb
->u
.add_data
.u
.regs
;
4499 ioarcb
->res_handle
= res
->res_handle
;
4500 cmd_pkt
->request_type
= IPR_RQTYPE_IOACMD
;
4501 cmd_pkt
->cdb
[0] = IPR_RESET_DEVICE
;
4502 if (ipr_is_gata(res
)) {
4503 cmd_pkt
->cdb
[2] = IPR_ATA_PHY_RESET
;
4504 ioarcb
->add_cmd_parms_len
= cpu_to_be16(sizeof(regs
->flags
));
4505 regs
->flags
|= IPR_ATA_FLAG_STATUS_ON_GOOD_COMPLETION
;
4508 ipr_send_blocking_cmd(ipr_cmd
, ipr_timeout
, IPR_DEVICE_RESET_TIMEOUT
);
4509 ioasc
= be32_to_cpu(ipr_cmd
->ioasa
.ioasc
);
4510 list_add_tail(&ipr_cmd
->queue
, &ioa_cfg
->free_q
);
4511 if (ipr_is_gata(res
) && res
->sata_port
&& ioasc
!= IPR_IOASC_IOA_WAS_RESET
)
4512 memcpy(&res
->sata_port
->ioasa
, &ipr_cmd
->ioasa
.u
.gata
,
4513 sizeof(struct ipr_ioasa_gata
));
4516 return (IPR_IOASC_SENSE_KEY(ioasc
) ? -EIO
: 0);
4520 * ipr_sata_reset - Reset the SATA port
4521 * @link: SATA link to reset
4522 * @classes: class of the attached device
4524 * This function issues a SATA phy reset to the affected ATA link.
4527 * 0 on success / non-zero on failure
4529 static int ipr_sata_reset(struct ata_link
*link
, unsigned int *classes
,
4530 unsigned long deadline
)
4532 struct ipr_sata_port
*sata_port
= link
->ap
->private_data
;
4533 struct ipr_ioa_cfg
*ioa_cfg
= sata_port
->ioa_cfg
;
4534 struct ipr_resource_entry
*res
;
4535 unsigned long lock_flags
= 0;
4539 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
4540 while(ioa_cfg
->in_reset_reload
) {
4541 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
4542 wait_event(ioa_cfg
->reset_wait_q
, !ioa_cfg
->in_reset_reload
);
4543 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
4546 res
= sata_port
->res
;
4548 rc
= ipr_device_reset(ioa_cfg
, res
);
4549 *classes
= res
->ata_class
;
4552 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
4558 * ipr_eh_dev_reset - Reset the device
4559 * @scsi_cmd: scsi command struct
4561 * This function issues a device reset to the affected device.
4562 * A LUN reset will be sent to the device first. If that does
4563 * not work, a target reset will be sent.
4568 static int __ipr_eh_dev_reset(struct scsi_cmnd
* scsi_cmd
)
4570 struct ipr_cmnd
*ipr_cmd
;
4571 struct ipr_ioa_cfg
*ioa_cfg
;
4572 struct ipr_resource_entry
*res
;
4573 struct ata_port
*ap
;
4577 ioa_cfg
= (struct ipr_ioa_cfg
*) scsi_cmd
->device
->host
->hostdata
;
4578 res
= scsi_cmd
->device
->hostdata
;
4584 * If we are currently going through reset/reload, return failed. This will force the
4585 * mid-layer to call ipr_eh_host_reset, which will then go to sleep and wait for the
4588 if (ioa_cfg
->in_reset_reload
)
4590 if (ioa_cfg
->ioa_is_dead
)
4593 list_for_each_entry(ipr_cmd
, &ioa_cfg
->pending_q
, queue
) {
4594 if (ipr_cmd
->ioarcb
.res_handle
== res
->res_handle
) {
4595 if (ipr_cmd
->scsi_cmd
)
4596 ipr_cmd
->done
= ipr_scsi_eh_done
;
4598 ipr_cmd
->done
= ipr_sata_eh_done
;
4599 if (ipr_cmd
->qc
&& !(ipr_cmd
->qc
->flags
& ATA_QCFLAG_FAILED
)) {
4600 ipr_cmd
->qc
->err_mask
|= AC_ERR_TIMEOUT
;
4601 ipr_cmd
->qc
->flags
|= ATA_QCFLAG_FAILED
;
4606 res
->resetting_device
= 1;
4607 scmd_printk(KERN_ERR
, scsi_cmd
, "Resetting device\n");
4609 if (ipr_is_gata(res
) && res
->sata_port
) {
4610 ap
= res
->sata_port
->ap
;
4611 spin_unlock_irq(scsi_cmd
->device
->host
->host_lock
);
4612 ata_std_error_handler(ap
);
4613 spin_lock_irq(scsi_cmd
->device
->host
->host_lock
);
4615 list_for_each_entry(ipr_cmd
, &ioa_cfg
->pending_q
, queue
) {
4616 if (ipr_cmd
->ioarcb
.res_handle
== res
->res_handle
) {
4622 rc
= ipr_device_reset(ioa_cfg
, res
);
4623 res
->resetting_device
= 0;
4626 return (rc
? FAILED
: SUCCESS
);
4629 static int ipr_eh_dev_reset(struct scsi_cmnd
* cmd
)
4633 spin_lock_irq(cmd
->device
->host
->host_lock
);
4634 rc
= __ipr_eh_dev_reset(cmd
);
4635 spin_unlock_irq(cmd
->device
->host
->host_lock
);
4641 * ipr_bus_reset_done - Op done function for bus reset.
4642 * @ipr_cmd: ipr command struct
4644 * This function is the op done function for a bus reset
4649 static void ipr_bus_reset_done(struct ipr_cmnd
*ipr_cmd
)
4651 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
4652 struct ipr_resource_entry
*res
;
4655 if (!ioa_cfg
->sis64
)
4656 list_for_each_entry(res
, &ioa_cfg
->used_res_q
, queue
) {
4657 if (res
->res_handle
== ipr_cmd
->ioarcb
.res_handle
) {
4658 scsi_report_bus_reset(ioa_cfg
->host
, res
->bus
);
4664 * If abort has not completed, indicate the reset has, else call the
4665 * abort's done function to wake the sleeping eh thread
4667 if (ipr_cmd
->sibling
->sibling
)
4668 ipr_cmd
->sibling
->sibling
= NULL
;
4670 ipr_cmd
->sibling
->done(ipr_cmd
->sibling
);
4672 list_add_tail(&ipr_cmd
->queue
, &ioa_cfg
->free_q
);
4677 * ipr_abort_timeout - An abort task has timed out
4678 * @ipr_cmd: ipr command struct
4680 * This function handles when an abort task times out. If this
4681 * happens we issue a bus reset since we have resources tied
4682 * up that must be freed before returning to the midlayer.
4687 static void ipr_abort_timeout(struct ipr_cmnd
*ipr_cmd
)
4689 struct ipr_cmnd
*reset_cmd
;
4690 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
4691 struct ipr_cmd_pkt
*cmd_pkt
;
4692 unsigned long lock_flags
= 0;
4695 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
4696 if (ipr_cmd
->completion
.done
|| ioa_cfg
->in_reset_reload
) {
4697 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
4701 sdev_printk(KERN_ERR
, ipr_cmd
->u
.sdev
, "Abort timed out. Resetting bus.\n");
4702 reset_cmd
= ipr_get_free_ipr_cmnd(ioa_cfg
);
4703 ipr_cmd
->sibling
= reset_cmd
;
4704 reset_cmd
->sibling
= ipr_cmd
;
4705 reset_cmd
->ioarcb
.res_handle
= ipr_cmd
->ioarcb
.res_handle
;
4706 cmd_pkt
= &reset_cmd
->ioarcb
.cmd_pkt
;
4707 cmd_pkt
->request_type
= IPR_RQTYPE_IOACMD
;
4708 cmd_pkt
->cdb
[0] = IPR_RESET_DEVICE
;
4709 cmd_pkt
->cdb
[2] = IPR_RESET_TYPE_SELECT
| IPR_BUS_RESET
;
4711 ipr_do_req(reset_cmd
, ipr_bus_reset_done
, ipr_timeout
, IPR_DEVICE_RESET_TIMEOUT
);
4712 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
4717 * ipr_cancel_op - Cancel specified op
4718 * @scsi_cmd: scsi command struct
4720 * This function cancels specified op.
4725 static int ipr_cancel_op(struct scsi_cmnd
* scsi_cmd
)
4727 struct ipr_cmnd
*ipr_cmd
;
4728 struct ipr_ioa_cfg
*ioa_cfg
;
4729 struct ipr_resource_entry
*res
;
4730 struct ipr_cmd_pkt
*cmd_pkt
;
4735 ioa_cfg
= (struct ipr_ioa_cfg
*)scsi_cmd
->device
->host
->hostdata
;
4736 res
= scsi_cmd
->device
->hostdata
;
4738 /* If we are currently going through reset/reload, return failed.
4739 * This will force the mid-layer to call ipr_eh_host_reset,
4740 * which will then go to sleep and wait for the reset to complete
4742 if (ioa_cfg
->in_reset_reload
|| ioa_cfg
->ioa_is_dead
)
4744 if (!res
|| !ipr_is_gscsi(res
))
4747 list_for_each_entry(ipr_cmd
, &ioa_cfg
->pending_q
, queue
) {
4748 if (ipr_cmd
->scsi_cmd
== scsi_cmd
) {
4749 ipr_cmd
->done
= ipr_scsi_eh_done
;
4758 ipr_cmd
= ipr_get_free_ipr_cmnd(ioa_cfg
);
4759 ipr_cmd
->ioarcb
.res_handle
= res
->res_handle
;
4760 cmd_pkt
= &ipr_cmd
->ioarcb
.cmd_pkt
;
4761 cmd_pkt
->request_type
= IPR_RQTYPE_IOACMD
;
4762 cmd_pkt
->cdb
[0] = IPR_CANCEL_ALL_REQUESTS
;
4763 ipr_cmd
->u
.sdev
= scsi_cmd
->device
;
4765 scmd_printk(KERN_ERR
, scsi_cmd
, "Aborting command: %02X\n",
4767 ipr_send_blocking_cmd(ipr_cmd
, ipr_abort_timeout
, IPR_CANCEL_ALL_TIMEOUT
);
4768 ioasc
= be32_to_cpu(ipr_cmd
->ioasa
.ioasc
);
4771 * If the abort task timed out and we sent a bus reset, we will get
4772 * one the following responses to the abort
4774 if (ioasc
== IPR_IOASC_BUS_WAS_RESET
|| ioasc
== IPR_IOASC_SYNC_REQUIRED
) {
4779 list_add_tail(&ipr_cmd
->queue
, &ioa_cfg
->free_q
);
4780 if (!ipr_is_naca_model(res
))
4781 res
->needs_sync_complete
= 1;
4784 return (IPR_IOASC_SENSE_KEY(ioasc
) ? FAILED
: SUCCESS
);
4788 * ipr_eh_abort - Abort a single op
4789 * @scsi_cmd: scsi command struct
4794 static int ipr_eh_abort(struct scsi_cmnd
* scsi_cmd
)
4796 unsigned long flags
;
4801 spin_lock_irqsave(scsi_cmd
->device
->host
->host_lock
, flags
);
4802 rc
= ipr_cancel_op(scsi_cmd
);
4803 spin_unlock_irqrestore(scsi_cmd
->device
->host
->host_lock
, flags
);
4810 * ipr_handle_other_interrupt - Handle "other" interrupts
4811 * @ioa_cfg: ioa config struct
4812 * @int_reg: interrupt register
4815 * IRQ_NONE / IRQ_HANDLED
4817 static irqreturn_t
ipr_handle_other_interrupt(struct ipr_ioa_cfg
*ioa_cfg
,
4818 volatile u32 int_reg
)
4820 irqreturn_t rc
= IRQ_HANDLED
;
4822 if (int_reg
& IPR_PCII_IOA_TRANS_TO_OPER
) {
4823 /* Mask the interrupt */
4824 writel(IPR_PCII_IOA_TRANS_TO_OPER
, ioa_cfg
->regs
.set_interrupt_mask_reg
);
4826 /* Clear the interrupt */
4827 writel(IPR_PCII_IOA_TRANS_TO_OPER
, ioa_cfg
->regs
.clr_interrupt_reg
);
4828 int_reg
= readl(ioa_cfg
->regs
.sense_interrupt_reg
);
4830 list_del(&ioa_cfg
->reset_cmd
->queue
);
4831 del_timer(&ioa_cfg
->reset_cmd
->timer
);
4832 ipr_reset_ioa_job(ioa_cfg
->reset_cmd
);
4834 if (int_reg
& IPR_PCII_IOA_UNIT_CHECKED
)
4835 ioa_cfg
->ioa_unit_checked
= 1;
4837 dev_err(&ioa_cfg
->pdev
->dev
,
4838 "Permanent IOA failure. 0x%08X\n", int_reg
);
4840 if (WAIT_FOR_DUMP
== ioa_cfg
->sdt_state
)
4841 ioa_cfg
->sdt_state
= GET_DUMP
;
4843 ipr_mask_and_clear_interrupts(ioa_cfg
, ~0);
4844 ipr_initiate_ioa_reset(ioa_cfg
, IPR_SHUTDOWN_NONE
);
4851 * ipr_isr_eh - Interrupt service routine error handler
4852 * @ioa_cfg: ioa config struct
4853 * @msg: message to log
4858 static void ipr_isr_eh(struct ipr_ioa_cfg
*ioa_cfg
, char *msg
)
4860 ioa_cfg
->errors_logged
++;
4861 dev_err(&ioa_cfg
->pdev
->dev
, "%s\n", msg
);
4863 if (WAIT_FOR_DUMP
== ioa_cfg
->sdt_state
)
4864 ioa_cfg
->sdt_state
= GET_DUMP
;
4866 ipr_initiate_ioa_reset(ioa_cfg
, IPR_SHUTDOWN_NONE
);
4870 * ipr_isr - Interrupt service routine
4872 * @devp: pointer to ioa config struct
4875 * IRQ_NONE / IRQ_HANDLED
4877 static irqreturn_t
ipr_isr(int irq
, void *devp
)
4879 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*)devp
;
4880 unsigned long lock_flags
= 0;
4881 volatile u32 int_reg
, int_mask_reg
;
4885 struct ipr_cmnd
*ipr_cmd
;
4886 irqreturn_t rc
= IRQ_NONE
;
4888 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
4890 /* If interrupts are disabled, ignore the interrupt */
4891 if (!ioa_cfg
->allow_interrupts
) {
4892 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
4896 int_mask_reg
= readl(ioa_cfg
->regs
.sense_interrupt_mask_reg32
);
4897 int_reg
= readl(ioa_cfg
->regs
.sense_interrupt_reg32
) & ~int_mask_reg
;
4899 /* If an interrupt on the adapter did not occur, ignore it.
4900 * Or in the case of SIS 64, check for a stage change interrupt.
4902 if (unlikely((int_reg
& IPR_PCII_OPER_INTERRUPTS
) == 0)) {
4903 if (ioa_cfg
->sis64
) {
4904 int_mask_reg
= readl(ioa_cfg
->regs
.sense_interrupt_mask_reg
);
4905 int_reg
= readl(ioa_cfg
->regs
.sense_interrupt_reg
) & ~int_mask_reg
;
4906 if (int_reg
& IPR_PCII_IPL_STAGE_CHANGE
) {
4908 /* clear stage change */
4909 writel(IPR_PCII_IPL_STAGE_CHANGE
, ioa_cfg
->regs
.clr_interrupt_reg
);
4910 int_reg
= readl(ioa_cfg
->regs
.sense_interrupt_reg
) & ~int_mask_reg
;
4911 list_del(&ioa_cfg
->reset_cmd
->queue
);
4912 del_timer(&ioa_cfg
->reset_cmd
->timer
);
4913 ipr_reset_ioa_job(ioa_cfg
->reset_cmd
);
4914 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
4919 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
4926 while ((be32_to_cpu(*ioa_cfg
->hrrq_curr
) & IPR_HRRQ_TOGGLE_BIT
) ==
4927 ioa_cfg
->toggle_bit
) {
4929 cmd_index
= (be32_to_cpu(*ioa_cfg
->hrrq_curr
) &
4930 IPR_HRRQ_REQ_RESP_HANDLE_MASK
) >> IPR_HRRQ_REQ_RESP_HANDLE_SHIFT
;
4932 if (unlikely(cmd_index
>= IPR_NUM_CMD_BLKS
)) {
4933 ipr_isr_eh(ioa_cfg
, "Invalid response handle from IOA");
4934 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
4938 ipr_cmd
= ioa_cfg
->ipr_cmnd_list
[cmd_index
];
4940 ioasc
= be32_to_cpu(ipr_cmd
->ioasa
.ioasc
);
4942 ipr_trc_hook(ipr_cmd
, IPR_TRACE_FINISH
, ioasc
);
4944 list_del(&ipr_cmd
->queue
);
4945 del_timer(&ipr_cmd
->timer
);
4946 ipr_cmd
->done(ipr_cmd
);
4950 if (ioa_cfg
->hrrq_curr
< ioa_cfg
->hrrq_end
) {
4951 ioa_cfg
->hrrq_curr
++;
4953 ioa_cfg
->hrrq_curr
= ioa_cfg
->hrrq_start
;
4954 ioa_cfg
->toggle_bit
^= 1u;
4958 if (ipr_cmd
!= NULL
) {
4959 /* Clear the PCI interrupt */
4961 writel(IPR_PCII_HRRQ_UPDATED
, ioa_cfg
->regs
.clr_interrupt_reg32
);
4962 int_reg
= readl(ioa_cfg
->regs
.sense_interrupt_reg32
) & ~int_mask_reg
;
4963 } while (int_reg
& IPR_PCII_HRRQ_UPDATED
&&
4964 num_hrrq
++ < IPR_MAX_HRRQ_RETRIES
);
4966 if (int_reg
& IPR_PCII_HRRQ_UPDATED
) {
4967 ipr_isr_eh(ioa_cfg
, "Error clearing HRRQ");
4968 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
4976 if (unlikely(rc
== IRQ_NONE
))
4977 rc
= ipr_handle_other_interrupt(ioa_cfg
, int_reg
);
4979 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
4984 * ipr_build_ioadl64 - Build a scatter/gather list and map the buffer
4985 * @ioa_cfg: ioa config struct
4986 * @ipr_cmd: ipr command struct
4989 * 0 on success / -1 on failure
4991 static int ipr_build_ioadl64(struct ipr_ioa_cfg
*ioa_cfg
,
4992 struct ipr_cmnd
*ipr_cmd
)
4995 struct scatterlist
*sg
;
4997 u32 ioadl_flags
= 0;
4998 struct scsi_cmnd
*scsi_cmd
= ipr_cmd
->scsi_cmd
;
4999 struct ipr_ioarcb
*ioarcb
= &ipr_cmd
->ioarcb
;
5000 struct ipr_ioadl64_desc
*ioadl64
= ipr_cmd
->i
.ioadl64
;
5002 length
= scsi_bufflen(scsi_cmd
);
5006 nseg
= scsi_dma_map(scsi_cmd
);
5008 dev_err(&ioa_cfg
->pdev
->dev
, "pci_map_sg failed!\n");
5012 ipr_cmd
->dma_use_sg
= nseg
;
5014 if (scsi_cmd
->sc_data_direction
== DMA_TO_DEVICE
) {
5015 ioadl_flags
= IPR_IOADL_FLAGS_WRITE
;
5016 ioarcb
->cmd_pkt
.flags_hi
|= IPR_FLAGS_HI_WRITE_NOT_READ
;
5017 } else if (scsi_cmd
->sc_data_direction
== DMA_FROM_DEVICE
)
5018 ioadl_flags
= IPR_IOADL_FLAGS_READ
;
5020 scsi_for_each_sg(scsi_cmd
, sg
, ipr_cmd
->dma_use_sg
, i
) {
5021 ioadl64
[i
].flags
= cpu_to_be32(ioadl_flags
);
5022 ioadl64
[i
].data_len
= cpu_to_be32(sg_dma_len(sg
));
5023 ioadl64
[i
].address
= cpu_to_be64(sg_dma_address(sg
));
5026 ioadl64
[i
-1].flags
|= cpu_to_be32(IPR_IOADL_FLAGS_LAST
);
5031 * ipr_build_ioadl - Build a scatter/gather list and map the buffer
5032 * @ioa_cfg: ioa config struct
5033 * @ipr_cmd: ipr command struct
5036 * 0 on success / -1 on failure
5038 static int ipr_build_ioadl(struct ipr_ioa_cfg
*ioa_cfg
,
5039 struct ipr_cmnd
*ipr_cmd
)
5042 struct scatterlist
*sg
;
5044 u32 ioadl_flags
= 0;
5045 struct scsi_cmnd
*scsi_cmd
= ipr_cmd
->scsi_cmd
;
5046 struct ipr_ioarcb
*ioarcb
= &ipr_cmd
->ioarcb
;
5047 struct ipr_ioadl_desc
*ioadl
= ipr_cmd
->i
.ioadl
;
5049 length
= scsi_bufflen(scsi_cmd
);
5053 nseg
= scsi_dma_map(scsi_cmd
);
5055 dev_err(&ioa_cfg
->pdev
->dev
, "pci_map_sg failed!\n");
5059 ipr_cmd
->dma_use_sg
= nseg
;
5061 if (scsi_cmd
->sc_data_direction
== DMA_TO_DEVICE
) {
5062 ioadl_flags
= IPR_IOADL_FLAGS_WRITE
;
5063 ioarcb
->cmd_pkt
.flags_hi
|= IPR_FLAGS_HI_WRITE_NOT_READ
;
5064 ioarcb
->data_transfer_length
= cpu_to_be32(length
);
5066 cpu_to_be32(sizeof(struct ipr_ioadl_desc
) * ipr_cmd
->dma_use_sg
);
5067 } else if (scsi_cmd
->sc_data_direction
== DMA_FROM_DEVICE
) {
5068 ioadl_flags
= IPR_IOADL_FLAGS_READ
;
5069 ioarcb
->read_data_transfer_length
= cpu_to_be32(length
);
5070 ioarcb
->read_ioadl_len
=
5071 cpu_to_be32(sizeof(struct ipr_ioadl_desc
) * ipr_cmd
->dma_use_sg
);
5074 if (ipr_cmd
->dma_use_sg
<= ARRAY_SIZE(ioarcb
->u
.add_data
.u
.ioadl
)) {
5075 ioadl
= ioarcb
->u
.add_data
.u
.ioadl
;
5076 ioarcb
->write_ioadl_addr
= cpu_to_be32((ipr_cmd
->dma_addr
) +
5077 offsetof(struct ipr_ioarcb
, u
.add_data
));
5078 ioarcb
->read_ioadl_addr
= ioarcb
->write_ioadl_addr
;
5081 scsi_for_each_sg(scsi_cmd
, sg
, ipr_cmd
->dma_use_sg
, i
) {
5082 ioadl
[i
].flags_and_data_len
=
5083 cpu_to_be32(ioadl_flags
| sg_dma_len(sg
));
5084 ioadl
[i
].address
= cpu_to_be32(sg_dma_address(sg
));
5087 ioadl
[i
-1].flags_and_data_len
|= cpu_to_be32(IPR_IOADL_FLAGS_LAST
);
5092 * ipr_get_task_attributes - Translate SPI Q-Tag to task attributes
5093 * @scsi_cmd: scsi command struct
5098 static u8
ipr_get_task_attributes(struct scsi_cmnd
*scsi_cmd
)
5101 u8 rc
= IPR_FLAGS_LO_UNTAGGED_TASK
;
5103 if (scsi_populate_tag_msg(scsi_cmd
, tag
)) {
5105 case MSG_SIMPLE_TAG
:
5106 rc
= IPR_FLAGS_LO_SIMPLE_TASK
;
5109 rc
= IPR_FLAGS_LO_HEAD_OF_Q_TASK
;
5111 case MSG_ORDERED_TAG
:
5112 rc
= IPR_FLAGS_LO_ORDERED_TASK
;
5121 * ipr_erp_done - Process completion of ERP for a device
5122 * @ipr_cmd: ipr command struct
5124 * This function copies the sense buffer into the scsi_cmd
5125 * struct and pushes the scsi_done function.
5130 static void ipr_erp_done(struct ipr_cmnd
*ipr_cmd
)
5132 struct scsi_cmnd
*scsi_cmd
= ipr_cmd
->scsi_cmd
;
5133 struct ipr_resource_entry
*res
= scsi_cmd
->device
->hostdata
;
5134 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
5135 u32 ioasc
= be32_to_cpu(ipr_cmd
->ioasa
.ioasc
);
5137 if (IPR_IOASC_SENSE_KEY(ioasc
) > 0) {
5138 scsi_cmd
->result
|= (DID_ERROR
<< 16);
5139 scmd_printk(KERN_ERR
, scsi_cmd
,
5140 "Request Sense failed with IOASC: 0x%08X\n", ioasc
);
5142 memcpy(scsi_cmd
->sense_buffer
, ipr_cmd
->sense_buffer
,
5143 SCSI_SENSE_BUFFERSIZE
);
5147 if (!ipr_is_naca_model(res
))
5148 res
->needs_sync_complete
= 1;
5151 scsi_dma_unmap(ipr_cmd
->scsi_cmd
);
5152 list_add_tail(&ipr_cmd
->queue
, &ioa_cfg
->free_q
);
5153 scsi_cmd
->scsi_done(scsi_cmd
);
5157 * ipr_reinit_ipr_cmnd_for_erp - Re-initialize a cmnd block to be used for ERP
5158 * @ipr_cmd: ipr command struct
5163 static void ipr_reinit_ipr_cmnd_for_erp(struct ipr_cmnd
*ipr_cmd
)
5165 struct ipr_ioarcb
*ioarcb
= &ipr_cmd
->ioarcb
;
5166 struct ipr_ioasa
*ioasa
= &ipr_cmd
->ioasa
;
5167 dma_addr_t dma_addr
= ipr_cmd
->dma_addr
;
5169 memset(&ioarcb
->cmd_pkt
, 0, sizeof(struct ipr_cmd_pkt
));
5170 ioarcb
->data_transfer_length
= 0;
5171 ioarcb
->read_data_transfer_length
= 0;
5172 ioarcb
->ioadl_len
= 0;
5173 ioarcb
->read_ioadl_len
= 0;
5175 ioasa
->residual_data_len
= 0;
5177 if (ipr_cmd
->ioa_cfg
->sis64
)
5178 ioarcb
->u
.sis64_addr_data
.data_ioadl_addr
=
5179 cpu_to_be64(dma_addr
+ offsetof(struct ipr_cmnd
, i
.ioadl64
));
5181 ioarcb
->write_ioadl_addr
=
5182 cpu_to_be32(dma_addr
+ offsetof(struct ipr_cmnd
, i
.ioadl
));
5183 ioarcb
->read_ioadl_addr
= ioarcb
->write_ioadl_addr
;
5188 * ipr_erp_request_sense - Send request sense to a device
5189 * @ipr_cmd: ipr command struct
5191 * This function sends a request sense to a device as a result
5192 * of a check condition.
5197 static void ipr_erp_request_sense(struct ipr_cmnd
*ipr_cmd
)
5199 struct ipr_cmd_pkt
*cmd_pkt
= &ipr_cmd
->ioarcb
.cmd_pkt
;
5200 u32 ioasc
= be32_to_cpu(ipr_cmd
->ioasa
.ioasc
);
5202 if (IPR_IOASC_SENSE_KEY(ioasc
) > 0) {
5203 ipr_erp_done(ipr_cmd
);
5207 ipr_reinit_ipr_cmnd_for_erp(ipr_cmd
);
5209 cmd_pkt
->request_type
= IPR_RQTYPE_SCSICDB
;
5210 cmd_pkt
->cdb
[0] = REQUEST_SENSE
;
5211 cmd_pkt
->cdb
[4] = SCSI_SENSE_BUFFERSIZE
;
5212 cmd_pkt
->flags_hi
|= IPR_FLAGS_HI_SYNC_OVERRIDE
;
5213 cmd_pkt
->flags_hi
|= IPR_FLAGS_HI_NO_ULEN_CHK
;
5214 cmd_pkt
->timeout
= cpu_to_be16(IPR_REQUEST_SENSE_TIMEOUT
/ HZ
);
5216 ipr_init_ioadl(ipr_cmd
, ipr_cmd
->sense_buffer_dma
,
5217 SCSI_SENSE_BUFFERSIZE
, IPR_IOADL_FLAGS_READ_LAST
);
5219 ipr_do_req(ipr_cmd
, ipr_erp_done
, ipr_timeout
,
5220 IPR_REQUEST_SENSE_TIMEOUT
* 2);
5224 * ipr_erp_cancel_all - Send cancel all to a device
5225 * @ipr_cmd: ipr command struct
5227 * This function sends a cancel all to a device to clear the
5228 * queue. If we are running TCQ on the device, QERR is set to 1,
5229 * which means all outstanding ops have been dropped on the floor.
5230 * Cancel all will return them to us.
5235 static void ipr_erp_cancel_all(struct ipr_cmnd
*ipr_cmd
)
5237 struct scsi_cmnd
*scsi_cmd
= ipr_cmd
->scsi_cmd
;
5238 struct ipr_resource_entry
*res
= scsi_cmd
->device
->hostdata
;
5239 struct ipr_cmd_pkt
*cmd_pkt
;
5243 ipr_reinit_ipr_cmnd_for_erp(ipr_cmd
);
5245 if (!scsi_get_tag_type(scsi_cmd
->device
)) {
5246 ipr_erp_request_sense(ipr_cmd
);
5250 cmd_pkt
= &ipr_cmd
->ioarcb
.cmd_pkt
;
5251 cmd_pkt
->request_type
= IPR_RQTYPE_IOACMD
;
5252 cmd_pkt
->cdb
[0] = IPR_CANCEL_ALL_REQUESTS
;
5254 ipr_do_req(ipr_cmd
, ipr_erp_request_sense
, ipr_timeout
,
5255 IPR_CANCEL_ALL_TIMEOUT
);
5259 * ipr_dump_ioasa - Dump contents of IOASA
5260 * @ioa_cfg: ioa config struct
5261 * @ipr_cmd: ipr command struct
5262 * @res: resource entry struct
5264 * This function is invoked by the interrupt handler when ops
5265 * fail. It will log the IOASA if appropriate. Only called
5271 static void ipr_dump_ioasa(struct ipr_ioa_cfg
*ioa_cfg
,
5272 struct ipr_cmnd
*ipr_cmd
, struct ipr_resource_entry
*res
)
5276 u32 ioasc
, fd_ioasc
;
5277 struct ipr_ioasa
*ioasa
= &ipr_cmd
->ioasa
;
5278 __be32
*ioasa_data
= (__be32
*)ioasa
;
5281 ioasc
= be32_to_cpu(ioasa
->ioasc
) & IPR_IOASC_IOASC_MASK
;
5282 fd_ioasc
= be32_to_cpu(ioasa
->fd_ioasc
) & IPR_IOASC_IOASC_MASK
;
5287 if (ioa_cfg
->log_level
< IPR_DEFAULT_LOG_LEVEL
)
5290 if (ioasc
== IPR_IOASC_BUS_WAS_RESET
&& fd_ioasc
)
5291 error_index
= ipr_get_error(fd_ioasc
);
5293 error_index
= ipr_get_error(ioasc
);
5295 if (ioa_cfg
->log_level
< IPR_MAX_LOG_LEVEL
) {
5296 /* Don't log an error if the IOA already logged one */
5297 if (ioasa
->ilid
!= 0)
5300 if (!ipr_is_gscsi(res
))
5303 if (ipr_error_table
[error_index
].log_ioasa
== 0)
5307 ipr_res_err(ioa_cfg
, res
, "%s\n", ipr_error_table
[error_index
].error
);
5309 if (sizeof(struct ipr_ioasa
) < be16_to_cpu(ioasa
->ret_stat_len
))
5310 data_len
= sizeof(struct ipr_ioasa
);
5312 data_len
= be16_to_cpu(ioasa
->ret_stat_len
);
5314 ipr_err("IOASA Dump:\n");
5316 for (i
= 0; i
< data_len
/ 4; i
+= 4) {
5317 ipr_err("%08X: %08X %08X %08X %08X\n", i
*4,
5318 be32_to_cpu(ioasa_data
[i
]),
5319 be32_to_cpu(ioasa_data
[i
+1]),
5320 be32_to_cpu(ioasa_data
[i
+2]),
5321 be32_to_cpu(ioasa_data
[i
+3]));
5326 * ipr_gen_sense - Generate SCSI sense data from an IOASA
5328 * @sense_buf: sense data buffer
5333 static void ipr_gen_sense(struct ipr_cmnd
*ipr_cmd
)
5336 u8
*sense_buf
= ipr_cmd
->scsi_cmd
->sense_buffer
;
5337 struct ipr_resource_entry
*res
= ipr_cmd
->scsi_cmd
->device
->hostdata
;
5338 struct ipr_ioasa
*ioasa
= &ipr_cmd
->ioasa
;
5339 u32 ioasc
= be32_to_cpu(ioasa
->ioasc
);
5341 memset(sense_buf
, 0, SCSI_SENSE_BUFFERSIZE
);
5343 if (ioasc
>= IPR_FIRST_DRIVER_IOASC
)
5346 ipr_cmd
->scsi_cmd
->result
= SAM_STAT_CHECK_CONDITION
;
5348 if (ipr_is_vset_device(res
) &&
5349 ioasc
== IPR_IOASC_MED_DO_NOT_REALLOC
&&
5350 ioasa
->u
.vset
.failing_lba_hi
!= 0) {
5351 sense_buf
[0] = 0x72;
5352 sense_buf
[1] = IPR_IOASC_SENSE_KEY(ioasc
);
5353 sense_buf
[2] = IPR_IOASC_SENSE_CODE(ioasc
);
5354 sense_buf
[3] = IPR_IOASC_SENSE_QUAL(ioasc
);
5358 sense_buf
[9] = 0x0A;
5359 sense_buf
[10] = 0x80;
5361 failing_lba
= be32_to_cpu(ioasa
->u
.vset
.failing_lba_hi
);
5363 sense_buf
[12] = (failing_lba
& 0xff000000) >> 24;
5364 sense_buf
[13] = (failing_lba
& 0x00ff0000) >> 16;
5365 sense_buf
[14] = (failing_lba
& 0x0000ff00) >> 8;
5366 sense_buf
[15] = failing_lba
& 0x000000ff;
5368 failing_lba
= be32_to_cpu(ioasa
->u
.vset
.failing_lba_lo
);
5370 sense_buf
[16] = (failing_lba
& 0xff000000) >> 24;
5371 sense_buf
[17] = (failing_lba
& 0x00ff0000) >> 16;
5372 sense_buf
[18] = (failing_lba
& 0x0000ff00) >> 8;
5373 sense_buf
[19] = failing_lba
& 0x000000ff;
5375 sense_buf
[0] = 0x70;
5376 sense_buf
[2] = IPR_IOASC_SENSE_KEY(ioasc
);
5377 sense_buf
[12] = IPR_IOASC_SENSE_CODE(ioasc
);
5378 sense_buf
[13] = IPR_IOASC_SENSE_QUAL(ioasc
);
5380 /* Illegal request */
5381 if ((IPR_IOASC_SENSE_KEY(ioasc
) == 0x05) &&
5382 (be32_to_cpu(ioasa
->ioasc_specific
) & IPR_FIELD_POINTER_VALID
)) {
5383 sense_buf
[7] = 10; /* additional length */
5385 /* IOARCB was in error */
5386 if (IPR_IOASC_SENSE_CODE(ioasc
) == 0x24)
5387 sense_buf
[15] = 0xC0;
5388 else /* Parameter data was invalid */
5389 sense_buf
[15] = 0x80;
5392 ((IPR_FIELD_POINTER_MASK
&
5393 be32_to_cpu(ioasa
->ioasc_specific
)) >> 8) & 0xff;
5395 (IPR_FIELD_POINTER_MASK
&
5396 be32_to_cpu(ioasa
->ioasc_specific
)) & 0xff;
5398 if (ioasc
== IPR_IOASC_MED_DO_NOT_REALLOC
) {
5399 if (ipr_is_vset_device(res
))
5400 failing_lba
= be32_to_cpu(ioasa
->u
.vset
.failing_lba_lo
);
5402 failing_lba
= be32_to_cpu(ioasa
->u
.dasd
.failing_lba
);
5404 sense_buf
[0] |= 0x80; /* Or in the Valid bit */
5405 sense_buf
[3] = (failing_lba
& 0xff000000) >> 24;
5406 sense_buf
[4] = (failing_lba
& 0x00ff0000) >> 16;
5407 sense_buf
[5] = (failing_lba
& 0x0000ff00) >> 8;
5408 sense_buf
[6] = failing_lba
& 0x000000ff;
5411 sense_buf
[7] = 6; /* additional length */
5417 * ipr_get_autosense - Copy autosense data to sense buffer
5418 * @ipr_cmd: ipr command struct
5420 * This function copies the autosense buffer to the buffer
5421 * in the scsi_cmd, if there is autosense available.
5424 * 1 if autosense was available / 0 if not
5426 static int ipr_get_autosense(struct ipr_cmnd
*ipr_cmd
)
5428 struct ipr_ioasa
*ioasa
= &ipr_cmd
->ioasa
;
5430 if ((be32_to_cpu(ioasa
->ioasc_specific
) & IPR_AUTOSENSE_VALID
) == 0)
5433 memcpy(ipr_cmd
->scsi_cmd
->sense_buffer
, ioasa
->auto_sense
.data
,
5434 min_t(u16
, be16_to_cpu(ioasa
->auto_sense
.auto_sense_len
),
5435 SCSI_SENSE_BUFFERSIZE
));
5440 * ipr_erp_start - Process an error response for a SCSI op
5441 * @ioa_cfg: ioa config struct
5442 * @ipr_cmd: ipr command struct
5444 * This function determines whether or not to initiate ERP
5445 * on the affected device.
5450 static void ipr_erp_start(struct ipr_ioa_cfg
*ioa_cfg
,
5451 struct ipr_cmnd
*ipr_cmd
)
5453 struct scsi_cmnd
*scsi_cmd
= ipr_cmd
->scsi_cmd
;
5454 struct ipr_resource_entry
*res
= scsi_cmd
->device
->hostdata
;
5455 u32 ioasc
= be32_to_cpu(ipr_cmd
->ioasa
.ioasc
);
5456 u32 masked_ioasc
= ioasc
& IPR_IOASC_IOASC_MASK
;
5459 ipr_scsi_eh_done(ipr_cmd
);
5463 if (!ipr_is_gscsi(res
) && masked_ioasc
!= IPR_IOASC_HW_DEV_BUS_STATUS
)
5464 ipr_gen_sense(ipr_cmd
);
5466 ipr_dump_ioasa(ioa_cfg
, ipr_cmd
, res
);
5468 switch (masked_ioasc
) {
5469 case IPR_IOASC_ABORTED_CMD_TERM_BY_HOST
:
5470 if (ipr_is_naca_model(res
))
5471 scsi_cmd
->result
|= (DID_ABORT
<< 16);
5473 scsi_cmd
->result
|= (DID_IMM_RETRY
<< 16);
5475 case IPR_IOASC_IR_RESOURCE_HANDLE
:
5476 case IPR_IOASC_IR_NO_CMDS_TO_2ND_IOA
:
5477 scsi_cmd
->result
|= (DID_NO_CONNECT
<< 16);
5479 case IPR_IOASC_HW_SEL_TIMEOUT
:
5480 scsi_cmd
->result
|= (DID_NO_CONNECT
<< 16);
5481 if (!ipr_is_naca_model(res
))
5482 res
->needs_sync_complete
= 1;
5484 case IPR_IOASC_SYNC_REQUIRED
:
5486 res
->needs_sync_complete
= 1;
5487 scsi_cmd
->result
|= (DID_IMM_RETRY
<< 16);
5489 case IPR_IOASC_MED_DO_NOT_REALLOC
: /* prevent retries */
5490 case IPR_IOASA_IR_DUAL_IOA_DISABLED
:
5491 scsi_cmd
->result
|= (DID_PASSTHROUGH
<< 16);
5493 case IPR_IOASC_BUS_WAS_RESET
:
5494 case IPR_IOASC_BUS_WAS_RESET_BY_OTHER
:
5496 * Report the bus reset and ask for a retry. The device
5497 * will give CC/UA the next command.
5499 if (!res
->resetting_device
)
5500 scsi_report_bus_reset(ioa_cfg
->host
, scsi_cmd
->device
->channel
);
5501 scsi_cmd
->result
|= (DID_ERROR
<< 16);
5502 if (!ipr_is_naca_model(res
))
5503 res
->needs_sync_complete
= 1;
5505 case IPR_IOASC_HW_DEV_BUS_STATUS
:
5506 scsi_cmd
->result
|= IPR_IOASC_SENSE_STATUS(ioasc
);
5507 if (IPR_IOASC_SENSE_STATUS(ioasc
) == SAM_STAT_CHECK_CONDITION
) {
5508 if (!ipr_get_autosense(ipr_cmd
)) {
5509 if (!ipr_is_naca_model(res
)) {
5510 ipr_erp_cancel_all(ipr_cmd
);
5515 if (!ipr_is_naca_model(res
))
5516 res
->needs_sync_complete
= 1;
5518 case IPR_IOASC_NR_INIT_CMD_REQUIRED
:
5521 if (IPR_IOASC_SENSE_KEY(ioasc
) > RECOVERED_ERROR
)
5522 scsi_cmd
->result
|= (DID_ERROR
<< 16);
5523 if (!ipr_is_vset_device(res
) && !ipr_is_naca_model(res
))
5524 res
->needs_sync_complete
= 1;
5528 scsi_dma_unmap(ipr_cmd
->scsi_cmd
);
5529 list_add_tail(&ipr_cmd
->queue
, &ioa_cfg
->free_q
);
5530 scsi_cmd
->scsi_done(scsi_cmd
);
5534 * ipr_scsi_done - mid-layer done function
5535 * @ipr_cmd: ipr command struct
5537 * This function is invoked by the interrupt handler for
5538 * ops generated by the SCSI mid-layer
5543 static void ipr_scsi_done(struct ipr_cmnd
*ipr_cmd
)
5545 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
5546 struct scsi_cmnd
*scsi_cmd
= ipr_cmd
->scsi_cmd
;
5547 u32 ioasc
= be32_to_cpu(ipr_cmd
->ioasa
.ioasc
);
5549 scsi_set_resid(scsi_cmd
, be32_to_cpu(ipr_cmd
->ioasa
.residual_data_len
));
5551 if (likely(IPR_IOASC_SENSE_KEY(ioasc
) == 0)) {
5552 scsi_dma_unmap(ipr_cmd
->scsi_cmd
);
5553 list_add_tail(&ipr_cmd
->queue
, &ioa_cfg
->free_q
);
5554 scsi_cmd
->scsi_done(scsi_cmd
);
5556 ipr_erp_start(ioa_cfg
, ipr_cmd
);
5560 * ipr_queuecommand - Queue a mid-layer request
5561 * @scsi_cmd: scsi command struct
5562 * @done: done function
5564 * This function queues a request generated by the mid-layer.
5568 * SCSI_MLQUEUE_DEVICE_BUSY if device is busy
5569 * SCSI_MLQUEUE_HOST_BUSY if host is busy
5571 static int ipr_queuecommand(struct scsi_cmnd
*scsi_cmd
,
5572 void (*done
) (struct scsi_cmnd
*))
5574 struct ipr_ioa_cfg
*ioa_cfg
;
5575 struct ipr_resource_entry
*res
;
5576 struct ipr_ioarcb
*ioarcb
;
5577 struct ipr_cmnd
*ipr_cmd
;
5580 scsi_cmd
->scsi_done
= done
;
5581 ioa_cfg
= (struct ipr_ioa_cfg
*)scsi_cmd
->device
->host
->hostdata
;
5582 res
= scsi_cmd
->device
->hostdata
;
5583 scsi_cmd
->result
= (DID_OK
<< 16);
5586 * We are currently blocking all devices due to a host reset
5587 * We have told the host to stop giving us new requests, but
5588 * ERP ops don't count. FIXME
5590 if (unlikely(!ioa_cfg
->allow_cmds
&& !ioa_cfg
->ioa_is_dead
))
5591 return SCSI_MLQUEUE_HOST_BUSY
;
5594 * FIXME - Create scsi_set_host_offline interface
5595 * and the ioa_is_dead check can be removed
5597 if (unlikely(ioa_cfg
->ioa_is_dead
|| !res
)) {
5598 memset(scsi_cmd
->sense_buffer
, 0, SCSI_SENSE_BUFFERSIZE
);
5599 scsi_cmd
->result
= (DID_NO_CONNECT
<< 16);
5600 scsi_cmd
->scsi_done(scsi_cmd
);
5604 if (ipr_is_gata(res
) && res
->sata_port
)
5605 return ata_sas_queuecmd(scsi_cmd
, done
, res
->sata_port
->ap
);
5607 ipr_cmd
= ipr_get_free_ipr_cmnd(ioa_cfg
);
5608 ioarcb
= &ipr_cmd
->ioarcb
;
5609 list_add_tail(&ipr_cmd
->queue
, &ioa_cfg
->pending_q
);
5611 memcpy(ioarcb
->cmd_pkt
.cdb
, scsi_cmd
->cmnd
, scsi_cmd
->cmd_len
);
5612 ipr_cmd
->scsi_cmd
= scsi_cmd
;
5613 ioarcb
->res_handle
= res
->res_handle
;
5614 ipr_cmd
->done
= ipr_scsi_done
;
5615 ipr_trc_hook(ipr_cmd
, IPR_TRACE_START
, IPR_GET_RES_PHYS_LOC(res
));
5617 if (ipr_is_gscsi(res
) || ipr_is_vset_device(res
)) {
5618 if (scsi_cmd
->underflow
== 0)
5619 ioarcb
->cmd_pkt
.flags_hi
|= IPR_FLAGS_HI_NO_ULEN_CHK
;
5621 if (res
->needs_sync_complete
) {
5622 ioarcb
->cmd_pkt
.flags_hi
|= IPR_FLAGS_HI_SYNC_COMPLETE
;
5623 res
->needs_sync_complete
= 0;
5626 ioarcb
->cmd_pkt
.flags_hi
|= IPR_FLAGS_HI_NO_LINK_DESC
;
5627 ioarcb
->cmd_pkt
.flags_lo
|= IPR_FLAGS_LO_DELAY_AFTER_RST
;
5628 ioarcb
->cmd_pkt
.flags_lo
|= IPR_FLAGS_LO_ALIGNED_BFR
;
5629 ioarcb
->cmd_pkt
.flags_lo
|= ipr_get_task_attributes(scsi_cmd
);
5632 if (scsi_cmd
->cmnd
[0] >= 0xC0 &&
5633 (!ipr_is_gscsi(res
) || scsi_cmd
->cmnd
[0] == IPR_QUERY_RSRC_STATE
))
5634 ioarcb
->cmd_pkt
.request_type
= IPR_RQTYPE_IOACMD
;
5636 if (likely(rc
== 0)) {
5638 rc
= ipr_build_ioadl64(ioa_cfg
, ipr_cmd
);
5640 rc
= ipr_build_ioadl(ioa_cfg
, ipr_cmd
);
5643 if (likely(rc
== 0)) {
5645 ipr_send_command(ipr_cmd
);
5647 list_move_tail(&ipr_cmd
->queue
, &ioa_cfg
->free_q
);
5648 return SCSI_MLQUEUE_HOST_BUSY
;
5655 * ipr_ioctl - IOCTL handler
5656 * @sdev: scsi device struct
5661 * 0 on success / other on failure
5663 static int ipr_ioctl(struct scsi_device
*sdev
, int cmd
, void __user
*arg
)
5665 struct ipr_resource_entry
*res
;
5667 res
= (struct ipr_resource_entry
*)sdev
->hostdata
;
5668 if (res
&& ipr_is_gata(res
)) {
5669 if (cmd
== HDIO_GET_IDENTITY
)
5671 return ata_sas_scsi_ioctl(res
->sata_port
->ap
, sdev
, cmd
, arg
);
5678 * ipr_info - Get information about the card/driver
5679 * @scsi_host: scsi host struct
5682 * pointer to buffer with description string
5684 static const char * ipr_ioa_info(struct Scsi_Host
*host
)
5686 static char buffer
[512];
5687 struct ipr_ioa_cfg
*ioa_cfg
;
5688 unsigned long lock_flags
= 0;
5690 ioa_cfg
= (struct ipr_ioa_cfg
*) host
->hostdata
;
5692 spin_lock_irqsave(host
->host_lock
, lock_flags
);
5693 sprintf(buffer
, "IBM %X Storage Adapter", ioa_cfg
->type
);
5694 spin_unlock_irqrestore(host
->host_lock
, lock_flags
);
5699 static struct scsi_host_template driver_template
= {
5700 .module
= THIS_MODULE
,
5702 .info
= ipr_ioa_info
,
5704 .queuecommand
= ipr_queuecommand
,
5705 .eh_abort_handler
= ipr_eh_abort
,
5706 .eh_device_reset_handler
= ipr_eh_dev_reset
,
5707 .eh_host_reset_handler
= ipr_eh_host_reset
,
5708 .slave_alloc
= ipr_slave_alloc
,
5709 .slave_configure
= ipr_slave_configure
,
5710 .slave_destroy
= ipr_slave_destroy
,
5711 .target_alloc
= ipr_target_alloc
,
5712 .target_destroy
= ipr_target_destroy
,
5713 .change_queue_depth
= ipr_change_queue_depth
,
5714 .change_queue_type
= ipr_change_queue_type
,
5715 .bios_param
= ipr_biosparam
,
5716 .can_queue
= IPR_MAX_COMMANDS
,
5718 .sg_tablesize
= IPR_MAX_SGLIST
,
5719 .max_sectors
= IPR_IOA_MAX_SECTORS
,
5720 .cmd_per_lun
= IPR_MAX_CMD_PER_LUN
,
5721 .use_clustering
= ENABLE_CLUSTERING
,
5722 .shost_attrs
= ipr_ioa_attrs
,
5723 .sdev_attrs
= ipr_dev_attrs
,
5724 .proc_name
= IPR_NAME
5728 * ipr_ata_phy_reset - libata phy_reset handler
5729 * @ap: ata port to reset
5732 static void ipr_ata_phy_reset(struct ata_port
*ap
)
5734 unsigned long flags
;
5735 struct ipr_sata_port
*sata_port
= ap
->private_data
;
5736 struct ipr_resource_entry
*res
= sata_port
->res
;
5737 struct ipr_ioa_cfg
*ioa_cfg
= sata_port
->ioa_cfg
;
5741 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, flags
);
5742 while(ioa_cfg
->in_reset_reload
) {
5743 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, flags
);
5744 wait_event(ioa_cfg
->reset_wait_q
, !ioa_cfg
->in_reset_reload
);
5745 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, flags
);
5748 if (!ioa_cfg
->allow_cmds
)
5751 rc
= ipr_device_reset(ioa_cfg
, res
);
5754 ata_port_disable(ap
);
5758 ap
->link
.device
[0].class = res
->ata_class
;
5759 if (ap
->link
.device
[0].class == ATA_DEV_UNKNOWN
)
5760 ata_port_disable(ap
);
5763 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, flags
);
5768 * ipr_ata_post_internal - Cleanup after an internal command
5769 * @qc: ATA queued command
5774 static void ipr_ata_post_internal(struct ata_queued_cmd
*qc
)
5776 struct ipr_sata_port
*sata_port
= qc
->ap
->private_data
;
5777 struct ipr_ioa_cfg
*ioa_cfg
= sata_port
->ioa_cfg
;
5778 struct ipr_cmnd
*ipr_cmd
;
5779 unsigned long flags
;
5781 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, flags
);
5782 while(ioa_cfg
->in_reset_reload
) {
5783 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, flags
);
5784 wait_event(ioa_cfg
->reset_wait_q
, !ioa_cfg
->in_reset_reload
);
5785 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, flags
);
5788 list_for_each_entry(ipr_cmd
, &ioa_cfg
->pending_q
, queue
) {
5789 if (ipr_cmd
->qc
== qc
) {
5790 ipr_device_reset(ioa_cfg
, sata_port
->res
);
5794 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, flags
);
5798 * ipr_copy_sata_tf - Copy a SATA taskfile to an IOA data structure
5799 * @regs: destination
5800 * @tf: source ATA taskfile
5805 static void ipr_copy_sata_tf(struct ipr_ioarcb_ata_regs
*regs
,
5806 struct ata_taskfile
*tf
)
5808 regs
->feature
= tf
->feature
;
5809 regs
->nsect
= tf
->nsect
;
5810 regs
->lbal
= tf
->lbal
;
5811 regs
->lbam
= tf
->lbam
;
5812 regs
->lbah
= tf
->lbah
;
5813 regs
->device
= tf
->device
;
5814 regs
->command
= tf
->command
;
5815 regs
->hob_feature
= tf
->hob_feature
;
5816 regs
->hob_nsect
= tf
->hob_nsect
;
5817 regs
->hob_lbal
= tf
->hob_lbal
;
5818 regs
->hob_lbam
= tf
->hob_lbam
;
5819 regs
->hob_lbah
= tf
->hob_lbah
;
5820 regs
->ctl
= tf
->ctl
;
5824 * ipr_sata_done - done function for SATA commands
5825 * @ipr_cmd: ipr command struct
5827 * This function is invoked by the interrupt handler for
5828 * ops generated by the SCSI mid-layer to SATA devices
5833 static void ipr_sata_done(struct ipr_cmnd
*ipr_cmd
)
5835 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
5836 struct ata_queued_cmd
*qc
= ipr_cmd
->qc
;
5837 struct ipr_sata_port
*sata_port
= qc
->ap
->private_data
;
5838 struct ipr_resource_entry
*res
= sata_port
->res
;
5839 u32 ioasc
= be32_to_cpu(ipr_cmd
->ioasa
.ioasc
);
5841 memcpy(&sata_port
->ioasa
, &ipr_cmd
->ioasa
.u
.gata
,
5842 sizeof(struct ipr_ioasa_gata
));
5843 ipr_dump_ioasa(ioa_cfg
, ipr_cmd
, res
);
5845 if (be32_to_cpu(ipr_cmd
->ioasa
.ioasc_specific
) & IPR_ATA_DEVICE_WAS_RESET
)
5846 scsi_report_device_reset(ioa_cfg
->host
, res
->bus
, res
->target
);
5848 if (IPR_IOASC_SENSE_KEY(ioasc
) > RECOVERED_ERROR
)
5849 qc
->err_mask
|= __ac_err_mask(ipr_cmd
->ioasa
.u
.gata
.status
);
5851 qc
->err_mask
|= ac_err_mask(ipr_cmd
->ioasa
.u
.gata
.status
);
5852 list_add_tail(&ipr_cmd
->queue
, &ioa_cfg
->free_q
);
5853 ata_qc_complete(qc
);
5857 * ipr_build_ata_ioadl64 - Build an ATA scatter/gather list
5858 * @ipr_cmd: ipr command struct
5859 * @qc: ATA queued command
5862 static void ipr_build_ata_ioadl64(struct ipr_cmnd
*ipr_cmd
,
5863 struct ata_queued_cmd
*qc
)
5865 u32 ioadl_flags
= 0;
5866 struct ipr_ioarcb
*ioarcb
= &ipr_cmd
->ioarcb
;
5867 struct ipr_ioadl64_desc
*ioadl64
= ipr_cmd
->i
.ioadl64
;
5868 struct ipr_ioadl64_desc
*last_ioadl64
= NULL
;
5869 int len
= qc
->nbytes
;
5870 struct scatterlist
*sg
;
5872 dma_addr_t dma_addr
= ipr_cmd
->dma_addr
;
5877 if (qc
->dma_dir
== DMA_TO_DEVICE
) {
5878 ioadl_flags
= IPR_IOADL_FLAGS_WRITE
;
5879 ioarcb
->cmd_pkt
.flags_hi
|= IPR_FLAGS_HI_WRITE_NOT_READ
;
5880 } else if (qc
->dma_dir
== DMA_FROM_DEVICE
)
5881 ioadl_flags
= IPR_IOADL_FLAGS_READ
;
5883 ioarcb
->data_transfer_length
= cpu_to_be32(len
);
5885 cpu_to_be32(sizeof(struct ipr_ioadl64_desc
) * ipr_cmd
->dma_use_sg
);
5886 ioarcb
->u
.sis64_addr_data
.data_ioadl_addr
=
5887 cpu_to_be64(dma_addr
+ offsetof(struct ipr_cmnd
, i
.ata_ioadl
));
5889 for_each_sg(qc
->sg
, sg
, qc
->n_elem
, si
) {
5890 ioadl64
->flags
= cpu_to_be32(ioadl_flags
);
5891 ioadl64
->data_len
= cpu_to_be32(sg_dma_len(sg
));
5892 ioadl64
->address
= cpu_to_be64(sg_dma_address(sg
));
5894 last_ioadl64
= ioadl64
;
5898 if (likely(last_ioadl64
))
5899 last_ioadl64
->flags
|= cpu_to_be32(IPR_IOADL_FLAGS_LAST
);
5903 * ipr_build_ata_ioadl - Build an ATA scatter/gather list
5904 * @ipr_cmd: ipr command struct
5905 * @qc: ATA queued command
5908 static void ipr_build_ata_ioadl(struct ipr_cmnd
*ipr_cmd
,
5909 struct ata_queued_cmd
*qc
)
5911 u32 ioadl_flags
= 0;
5912 struct ipr_ioarcb
*ioarcb
= &ipr_cmd
->ioarcb
;
5913 struct ipr_ioadl_desc
*ioadl
= ipr_cmd
->i
.ioadl
;
5914 struct ipr_ioadl_desc
*last_ioadl
= NULL
;
5915 int len
= qc
->nbytes
;
5916 struct scatterlist
*sg
;
5922 if (qc
->dma_dir
== DMA_TO_DEVICE
) {
5923 ioadl_flags
= IPR_IOADL_FLAGS_WRITE
;
5924 ioarcb
->cmd_pkt
.flags_hi
|= IPR_FLAGS_HI_WRITE_NOT_READ
;
5925 ioarcb
->data_transfer_length
= cpu_to_be32(len
);
5927 cpu_to_be32(sizeof(struct ipr_ioadl_desc
) * ipr_cmd
->dma_use_sg
);
5928 } else if (qc
->dma_dir
== DMA_FROM_DEVICE
) {
5929 ioadl_flags
= IPR_IOADL_FLAGS_READ
;
5930 ioarcb
->read_data_transfer_length
= cpu_to_be32(len
);
5931 ioarcb
->read_ioadl_len
=
5932 cpu_to_be32(sizeof(struct ipr_ioadl_desc
) * ipr_cmd
->dma_use_sg
);
5935 for_each_sg(qc
->sg
, sg
, qc
->n_elem
, si
) {
5936 ioadl
->flags_and_data_len
= cpu_to_be32(ioadl_flags
| sg_dma_len(sg
));
5937 ioadl
->address
= cpu_to_be32(sg_dma_address(sg
));
5943 if (likely(last_ioadl
))
5944 last_ioadl
->flags_and_data_len
|= cpu_to_be32(IPR_IOADL_FLAGS_LAST
);
5948 * ipr_qc_issue - Issue a SATA qc to a device
5949 * @qc: queued command
5954 static unsigned int ipr_qc_issue(struct ata_queued_cmd
*qc
)
5956 struct ata_port
*ap
= qc
->ap
;
5957 struct ipr_sata_port
*sata_port
= ap
->private_data
;
5958 struct ipr_resource_entry
*res
= sata_port
->res
;
5959 struct ipr_ioa_cfg
*ioa_cfg
= sata_port
->ioa_cfg
;
5960 struct ipr_cmnd
*ipr_cmd
;
5961 struct ipr_ioarcb
*ioarcb
;
5962 struct ipr_ioarcb_ata_regs
*regs
;
5964 if (unlikely(!ioa_cfg
->allow_cmds
|| ioa_cfg
->ioa_is_dead
))
5965 return AC_ERR_SYSTEM
;
5967 ipr_cmd
= ipr_get_free_ipr_cmnd(ioa_cfg
);
5968 ioarcb
= &ipr_cmd
->ioarcb
;
5970 if (ioa_cfg
->sis64
) {
5971 regs
= &ipr_cmd
->i
.ata_ioadl
.regs
;
5972 ioarcb
->add_cmd_parms_offset
= cpu_to_be16(sizeof(*ioarcb
));
5974 regs
= &ioarcb
->u
.add_data
.u
.regs
;
5976 memset(regs
, 0, sizeof(*regs
));
5977 ioarcb
->add_cmd_parms_len
= cpu_to_be16(sizeof(*regs
));
5979 list_add_tail(&ipr_cmd
->queue
, &ioa_cfg
->pending_q
);
5981 ipr_cmd
->done
= ipr_sata_done
;
5982 ipr_cmd
->ioarcb
.res_handle
= res
->res_handle
;
5983 ioarcb
->cmd_pkt
.request_type
= IPR_RQTYPE_ATA_PASSTHRU
;
5984 ioarcb
->cmd_pkt
.flags_hi
|= IPR_FLAGS_HI_NO_LINK_DESC
;
5985 ioarcb
->cmd_pkt
.flags_hi
|= IPR_FLAGS_HI_NO_ULEN_CHK
;
5986 ipr_cmd
->dma_use_sg
= qc
->n_elem
;
5989 ipr_build_ata_ioadl64(ipr_cmd
, qc
);
5991 ipr_build_ata_ioadl(ipr_cmd
, qc
);
5993 regs
->flags
|= IPR_ATA_FLAG_STATUS_ON_GOOD_COMPLETION
;
5994 ipr_copy_sata_tf(regs
, &qc
->tf
);
5995 memcpy(ioarcb
->cmd_pkt
.cdb
, qc
->cdb
, IPR_MAX_CDB_LEN
);
5996 ipr_trc_hook(ipr_cmd
, IPR_TRACE_START
, IPR_GET_RES_PHYS_LOC(res
));
5998 switch (qc
->tf
.protocol
) {
5999 case ATA_PROT_NODATA
:
6004 regs
->flags
|= IPR_ATA_FLAG_XFER_TYPE_DMA
;
6007 case ATAPI_PROT_PIO
:
6008 case ATAPI_PROT_NODATA
:
6009 regs
->flags
|= IPR_ATA_FLAG_PACKET_CMD
;
6012 case ATAPI_PROT_DMA
:
6013 regs
->flags
|= IPR_ATA_FLAG_PACKET_CMD
;
6014 regs
->flags
|= IPR_ATA_FLAG_XFER_TYPE_DMA
;
6019 return AC_ERR_INVALID
;
6024 ipr_send_command(ipr_cmd
);
6030 * ipr_qc_fill_rtf - Read result TF
6031 * @qc: ATA queued command
6036 static bool ipr_qc_fill_rtf(struct ata_queued_cmd
*qc
)
6038 struct ipr_sata_port
*sata_port
= qc
->ap
->private_data
;
6039 struct ipr_ioasa_gata
*g
= &sata_port
->ioasa
;
6040 struct ata_taskfile
*tf
= &qc
->result_tf
;
6042 tf
->feature
= g
->error
;
6043 tf
->nsect
= g
->nsect
;
6047 tf
->device
= g
->device
;
6048 tf
->command
= g
->status
;
6049 tf
->hob_nsect
= g
->hob_nsect
;
6050 tf
->hob_lbal
= g
->hob_lbal
;
6051 tf
->hob_lbam
= g
->hob_lbam
;
6052 tf
->hob_lbah
= g
->hob_lbah
;
6053 tf
->ctl
= g
->alt_status
;
6058 static struct ata_port_operations ipr_sata_ops
= {
6059 .phy_reset
= ipr_ata_phy_reset
,
6060 .hardreset
= ipr_sata_reset
,
6061 .post_internal_cmd
= ipr_ata_post_internal
,
6062 .qc_prep
= ata_noop_qc_prep
,
6063 .qc_issue
= ipr_qc_issue
,
6064 .qc_fill_rtf
= ipr_qc_fill_rtf
,
6065 .port_start
= ata_sas_port_start
,
6066 .port_stop
= ata_sas_port_stop
6069 static struct ata_port_info sata_port_info
= {
6070 .flags
= ATA_FLAG_SATA
| ATA_FLAG_NO_LEGACY
| ATA_FLAG_SATA_RESET
|
6071 ATA_FLAG_MMIO
| ATA_FLAG_PIO_DMA
,
6072 .pio_mask
= 0x10, /* pio4 */
6074 .udma_mask
= 0x7f, /* udma0-6 */
6075 .port_ops
= &ipr_sata_ops
6078 #ifdef CONFIG_PPC_PSERIES
6079 static const u16 ipr_blocked_processors
[] = {
6091 * ipr_invalid_adapter - Determine if this adapter is supported on this hardware
6092 * @ioa_cfg: ioa cfg struct
6094 * Adapters that use Gemstone revision < 3.1 do not work reliably on
6095 * certain pSeries hardware. This function determines if the given
6096 * adapter is in one of these confgurations or not.
6099 * 1 if adapter is not supported / 0 if adapter is supported
6101 static int ipr_invalid_adapter(struct ipr_ioa_cfg
*ioa_cfg
)
6105 if ((ioa_cfg
->type
== 0x5702) && (ioa_cfg
->pdev
->revision
< 4)) {
6106 for (i
= 0; i
< ARRAY_SIZE(ipr_blocked_processors
); i
++){
6107 if (__is_processor(ipr_blocked_processors
[i
]))
6114 #define ipr_invalid_adapter(ioa_cfg) 0
6118 * ipr_ioa_bringdown_done - IOA bring down completion.
6119 * @ipr_cmd: ipr command struct
6121 * This function processes the completion of an adapter bring down.
6122 * It wakes any reset sleepers.
6127 static int ipr_ioa_bringdown_done(struct ipr_cmnd
*ipr_cmd
)
6129 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
6132 ioa_cfg
->in_reset_reload
= 0;
6133 ioa_cfg
->reset_retries
= 0;
6134 list_add_tail(&ipr_cmd
->queue
, &ioa_cfg
->free_q
);
6135 wake_up_all(&ioa_cfg
->reset_wait_q
);
6137 spin_unlock_irq(ioa_cfg
->host
->host_lock
);
6138 scsi_unblock_requests(ioa_cfg
->host
);
6139 spin_lock_irq(ioa_cfg
->host
->host_lock
);
6142 return IPR_RC_JOB_RETURN
;
6146 * ipr_ioa_reset_done - IOA reset completion.
6147 * @ipr_cmd: ipr command struct
6149 * This function processes the completion of an adapter reset.
6150 * It schedules any necessary mid-layer add/removes and
6151 * wakes any reset sleepers.
6156 static int ipr_ioa_reset_done(struct ipr_cmnd
*ipr_cmd
)
6158 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
6159 struct ipr_resource_entry
*res
;
6160 struct ipr_hostrcb
*hostrcb
, *temp
;
6164 ioa_cfg
->in_reset_reload
= 0;
6165 ioa_cfg
->allow_cmds
= 1;
6166 ioa_cfg
->reset_cmd
= NULL
;
6167 ioa_cfg
->doorbell
|= IPR_RUNTIME_RESET
;
6169 list_for_each_entry(res
, &ioa_cfg
->used_res_q
, queue
) {
6170 if (ioa_cfg
->allow_ml_add_del
&& (res
->add_to_ml
|| res
->del_from_ml
)) {
6175 schedule_work(&ioa_cfg
->work_q
);
6177 list_for_each_entry_safe(hostrcb
, temp
, &ioa_cfg
->hostrcb_free_q
, queue
) {
6178 list_del(&hostrcb
->queue
);
6179 if (i
++ < IPR_NUM_LOG_HCAMS
)
6180 ipr_send_hcam(ioa_cfg
, IPR_HCAM_CDB_OP_CODE_LOG_DATA
, hostrcb
);
6182 ipr_send_hcam(ioa_cfg
, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE
, hostrcb
);
6185 scsi_report_bus_reset(ioa_cfg
->host
, IPR_VSET_BUS
);
6186 dev_info(&ioa_cfg
->pdev
->dev
, "IOA initialized.\n");
6188 ioa_cfg
->reset_retries
= 0;
6189 list_add_tail(&ipr_cmd
->queue
, &ioa_cfg
->free_q
);
6190 wake_up_all(&ioa_cfg
->reset_wait_q
);
6192 spin_unlock(ioa_cfg
->host
->host_lock
);
6193 scsi_unblock_requests(ioa_cfg
->host
);
6194 spin_lock(ioa_cfg
->host
->host_lock
);
6196 if (!ioa_cfg
->allow_cmds
)
6197 scsi_block_requests(ioa_cfg
->host
);
6200 return IPR_RC_JOB_RETURN
;
6204 * ipr_set_sup_dev_dflt - Initialize a Set Supported Device buffer
6205 * @supported_dev: supported device struct
6206 * @vpids: vendor product id struct
6211 static void ipr_set_sup_dev_dflt(struct ipr_supported_device
*supported_dev
,
6212 struct ipr_std_inq_vpids
*vpids
)
6214 memset(supported_dev
, 0, sizeof(struct ipr_supported_device
));
6215 memcpy(&supported_dev
->vpids
, vpids
, sizeof(struct ipr_std_inq_vpids
));
6216 supported_dev
->num_records
= 1;
6217 supported_dev
->data_length
=
6218 cpu_to_be16(sizeof(struct ipr_supported_device
));
6219 supported_dev
->reserved
= 0;
6223 * ipr_set_supported_devs - Send Set Supported Devices for a device
6224 * @ipr_cmd: ipr command struct
6226 * This function sends a Set Supported Devices to the adapter
6229 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
6231 static int ipr_set_supported_devs(struct ipr_cmnd
*ipr_cmd
)
6233 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
6234 struct ipr_supported_device
*supp_dev
= &ioa_cfg
->vpd_cbs
->supp_dev
;
6235 struct ipr_ioarcb
*ioarcb
= &ipr_cmd
->ioarcb
;
6236 struct ipr_resource_entry
*res
= ipr_cmd
->u
.res
;
6238 ipr_cmd
->job_step
= ipr_ioa_reset_done
;
6240 list_for_each_entry_continue(res
, &ioa_cfg
->used_res_q
, queue
) {
6241 if (!ipr_is_scsi_disk(res
))
6244 ipr_cmd
->u
.res
= res
;
6245 ipr_set_sup_dev_dflt(supp_dev
, &res
->std_inq_data
.vpids
);
6247 ioarcb
->res_handle
= cpu_to_be32(IPR_IOA_RES_HANDLE
);
6248 ioarcb
->cmd_pkt
.flags_hi
|= IPR_FLAGS_HI_WRITE_NOT_READ
;
6249 ioarcb
->cmd_pkt
.request_type
= IPR_RQTYPE_IOACMD
;
6251 ioarcb
->cmd_pkt
.cdb
[0] = IPR_SET_SUPPORTED_DEVICES
;
6252 ioarcb
->cmd_pkt
.cdb
[1] = IPR_SET_ALL_SUPPORTED_DEVICES
;
6253 ioarcb
->cmd_pkt
.cdb
[7] = (sizeof(struct ipr_supported_device
) >> 8) & 0xff;
6254 ioarcb
->cmd_pkt
.cdb
[8] = sizeof(struct ipr_supported_device
) & 0xff;
6256 ipr_init_ioadl(ipr_cmd
,
6257 ioa_cfg
->vpd_cbs_dma
+
6258 offsetof(struct ipr_misc_cbs
, supp_dev
),
6259 sizeof(struct ipr_supported_device
),
6260 IPR_IOADL_FLAGS_WRITE_LAST
);
6262 ipr_do_req(ipr_cmd
, ipr_reset_ioa_job
, ipr_timeout
,
6263 IPR_SET_SUP_DEVICE_TIMEOUT
);
6265 if (!ioa_cfg
->sis64
)
6266 ipr_cmd
->job_step
= ipr_set_supported_devs
;
6267 return IPR_RC_JOB_RETURN
;
6270 return IPR_RC_JOB_CONTINUE
;
6274 * ipr_get_mode_page - Locate specified mode page
6275 * @mode_pages: mode page buffer
6276 * @page_code: page code to find
6277 * @len: minimum required length for mode page
6280 * pointer to mode page / NULL on failure
6282 static void *ipr_get_mode_page(struct ipr_mode_pages
*mode_pages
,
6283 u32 page_code
, u32 len
)
6285 struct ipr_mode_page_hdr
*mode_hdr
;
6289 if (!mode_pages
|| (mode_pages
->hdr
.length
== 0))
6292 length
= (mode_pages
->hdr
.length
+ 1) - 4 - mode_pages
->hdr
.block_desc_len
;
6293 mode_hdr
= (struct ipr_mode_page_hdr
*)
6294 (mode_pages
->data
+ mode_pages
->hdr
.block_desc_len
);
6297 if (IPR_GET_MODE_PAGE_CODE(mode_hdr
) == page_code
) {
6298 if (mode_hdr
->page_length
>= (len
- sizeof(struct ipr_mode_page_hdr
)))
6302 page_length
= (sizeof(struct ipr_mode_page_hdr
) +
6303 mode_hdr
->page_length
);
6304 length
-= page_length
;
6305 mode_hdr
= (struct ipr_mode_page_hdr
*)
6306 ((unsigned long)mode_hdr
+ page_length
);
6313 * ipr_check_term_power - Check for term power errors
6314 * @ioa_cfg: ioa config struct
6315 * @mode_pages: IOAFP mode pages buffer
6317 * Check the IOAFP's mode page 28 for term power errors
6322 static void ipr_check_term_power(struct ipr_ioa_cfg
*ioa_cfg
,
6323 struct ipr_mode_pages
*mode_pages
)
6327 struct ipr_dev_bus_entry
*bus
;
6328 struct ipr_mode_page28
*mode_page
;
6330 mode_page
= ipr_get_mode_page(mode_pages
, 0x28,
6331 sizeof(struct ipr_mode_page28
));
6333 entry_length
= mode_page
->entry_length
;
6335 bus
= mode_page
->bus
;
6337 for (i
= 0; i
< mode_page
->num_entries
; i
++) {
6338 if (bus
->flags
& IPR_SCSI_ATTR_NO_TERM_PWR
) {
6339 dev_err(&ioa_cfg
->pdev
->dev
,
6340 "Term power is absent on scsi bus %d\n",
6344 bus
= (struct ipr_dev_bus_entry
*)((char *)bus
+ entry_length
);
6349 * ipr_scsi_bus_speed_limit - Limit the SCSI speed based on SES table
6350 * @ioa_cfg: ioa config struct
6352 * Looks through the config table checking for SES devices. If
6353 * the SES device is in the SES table indicating a maximum SCSI
6354 * bus speed, the speed is limited for the bus.
6359 static void ipr_scsi_bus_speed_limit(struct ipr_ioa_cfg
*ioa_cfg
)
6364 for (i
= 0; i
< IPR_MAX_NUM_BUSES
; i
++) {
6365 max_xfer_rate
= ipr_get_max_scsi_speed(ioa_cfg
, i
,
6366 ioa_cfg
->bus_attr
[i
].bus_width
);
6368 if (max_xfer_rate
< ioa_cfg
->bus_attr
[i
].max_xfer_rate
)
6369 ioa_cfg
->bus_attr
[i
].max_xfer_rate
= max_xfer_rate
;
6374 * ipr_modify_ioafp_mode_page_28 - Modify IOAFP Mode Page 28
6375 * @ioa_cfg: ioa config struct
6376 * @mode_pages: mode page 28 buffer
6378 * Updates mode page 28 based on driver configuration
6383 static void ipr_modify_ioafp_mode_page_28(struct ipr_ioa_cfg
*ioa_cfg
,
6384 struct ipr_mode_pages
*mode_pages
)
6386 int i
, entry_length
;
6387 struct ipr_dev_bus_entry
*bus
;
6388 struct ipr_bus_attributes
*bus_attr
;
6389 struct ipr_mode_page28
*mode_page
;
6391 mode_page
= ipr_get_mode_page(mode_pages
, 0x28,
6392 sizeof(struct ipr_mode_page28
));
6394 entry_length
= mode_page
->entry_length
;
6396 /* Loop for each device bus entry */
6397 for (i
= 0, bus
= mode_page
->bus
;
6398 i
< mode_page
->num_entries
;
6399 i
++, bus
= (struct ipr_dev_bus_entry
*)((u8
*)bus
+ entry_length
)) {
6400 if (bus
->res_addr
.bus
> IPR_MAX_NUM_BUSES
) {
6401 dev_err(&ioa_cfg
->pdev
->dev
,
6402 "Invalid resource address reported: 0x%08X\n",
6403 IPR_GET_PHYS_LOC(bus
->res_addr
));
6407 bus_attr
= &ioa_cfg
->bus_attr
[i
];
6408 bus
->extended_reset_delay
= IPR_EXTENDED_RESET_DELAY
;
6409 bus
->bus_width
= bus_attr
->bus_width
;
6410 bus
->max_xfer_rate
= cpu_to_be32(bus_attr
->max_xfer_rate
);
6411 bus
->flags
&= ~IPR_SCSI_ATTR_QAS_MASK
;
6412 if (bus_attr
->qas_enabled
)
6413 bus
->flags
|= IPR_SCSI_ATTR_ENABLE_QAS
;
6415 bus
->flags
|= IPR_SCSI_ATTR_DISABLE_QAS
;
6420 * ipr_build_mode_select - Build a mode select command
6421 * @ipr_cmd: ipr command struct
6422 * @res_handle: resource handle to send command to
6423 * @parm: Byte 2 of Mode Sense command
6424 * @dma_addr: DMA buffer address
6425 * @xfer_len: data transfer length
6430 static void ipr_build_mode_select(struct ipr_cmnd
*ipr_cmd
,
6431 __be32 res_handle
, u8 parm
,
6432 dma_addr_t dma_addr
, u8 xfer_len
)
6434 struct ipr_ioarcb
*ioarcb
= &ipr_cmd
->ioarcb
;
6436 ioarcb
->res_handle
= res_handle
;
6437 ioarcb
->cmd_pkt
.request_type
= IPR_RQTYPE_SCSICDB
;
6438 ioarcb
->cmd_pkt
.flags_hi
|= IPR_FLAGS_HI_WRITE_NOT_READ
;
6439 ioarcb
->cmd_pkt
.cdb
[0] = MODE_SELECT
;
6440 ioarcb
->cmd_pkt
.cdb
[1] = parm
;
6441 ioarcb
->cmd_pkt
.cdb
[4] = xfer_len
;
6443 ipr_init_ioadl(ipr_cmd
, dma_addr
, xfer_len
, IPR_IOADL_FLAGS_WRITE_LAST
);
6447 * ipr_ioafp_mode_select_page28 - Issue Mode Select Page 28 to IOA
6448 * @ipr_cmd: ipr command struct
6450 * This function sets up the SCSI bus attributes and sends
6451 * a Mode Select for Page 28 to activate them.
6456 static int ipr_ioafp_mode_select_page28(struct ipr_cmnd
*ipr_cmd
)
6458 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
6459 struct ipr_mode_pages
*mode_pages
= &ioa_cfg
->vpd_cbs
->mode_pages
;
6463 ipr_scsi_bus_speed_limit(ioa_cfg
);
6464 ipr_check_term_power(ioa_cfg
, mode_pages
);
6465 ipr_modify_ioafp_mode_page_28(ioa_cfg
, mode_pages
);
6466 length
= mode_pages
->hdr
.length
+ 1;
6467 mode_pages
->hdr
.length
= 0;
6469 ipr_build_mode_select(ipr_cmd
, cpu_to_be32(IPR_IOA_RES_HANDLE
), 0x11,
6470 ioa_cfg
->vpd_cbs_dma
+ offsetof(struct ipr_misc_cbs
, mode_pages
),
6473 ipr_cmd
->job_step
= ipr_set_supported_devs
;
6474 ipr_cmd
->u
.res
= list_entry(ioa_cfg
->used_res_q
.next
,
6475 struct ipr_resource_entry
, queue
);
6476 ipr_do_req(ipr_cmd
, ipr_reset_ioa_job
, ipr_timeout
, IPR_INTERNAL_TIMEOUT
);
6479 return IPR_RC_JOB_RETURN
;
6483 * ipr_build_mode_sense - Builds a mode sense command
6484 * @ipr_cmd: ipr command struct
6485 * @res: resource entry struct
6486 * @parm: Byte 2 of mode sense command
6487 * @dma_addr: DMA address of mode sense buffer
6488 * @xfer_len: Size of DMA buffer
6493 static void ipr_build_mode_sense(struct ipr_cmnd
*ipr_cmd
,
6495 u8 parm
, dma_addr_t dma_addr
, u8 xfer_len
)
6497 struct ipr_ioarcb
*ioarcb
= &ipr_cmd
->ioarcb
;
6499 ioarcb
->res_handle
= res_handle
;
6500 ioarcb
->cmd_pkt
.cdb
[0] = MODE_SENSE
;
6501 ioarcb
->cmd_pkt
.cdb
[2] = parm
;
6502 ioarcb
->cmd_pkt
.cdb
[4] = xfer_len
;
6503 ioarcb
->cmd_pkt
.request_type
= IPR_RQTYPE_SCSICDB
;
6505 ipr_init_ioadl(ipr_cmd
, dma_addr
, xfer_len
, IPR_IOADL_FLAGS_READ_LAST
);
6509 * ipr_reset_cmd_failed - Handle failure of IOA reset command
6510 * @ipr_cmd: ipr command struct
6512 * This function handles the failure of an IOA bringup command.
6517 static int ipr_reset_cmd_failed(struct ipr_cmnd
*ipr_cmd
)
6519 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
6520 u32 ioasc
= be32_to_cpu(ipr_cmd
->ioasa
.ioasc
);
6522 dev_err(&ioa_cfg
->pdev
->dev
,
6523 "0x%02X failed with IOASC: 0x%08X\n",
6524 ipr_cmd
->ioarcb
.cmd_pkt
.cdb
[0], ioasc
);
6526 ipr_initiate_ioa_reset(ioa_cfg
, IPR_SHUTDOWN_NONE
);
6527 list_add_tail(&ipr_cmd
->queue
, &ioa_cfg
->free_q
);
6528 return IPR_RC_JOB_RETURN
;
6532 * ipr_reset_mode_sense_failed - Handle failure of IOAFP mode sense
6533 * @ipr_cmd: ipr command struct
6535 * This function handles the failure of a Mode Sense to the IOAFP.
6536 * Some adapters do not handle all mode pages.
6539 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
6541 static int ipr_reset_mode_sense_failed(struct ipr_cmnd
*ipr_cmd
)
6543 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
6544 u32 ioasc
= be32_to_cpu(ipr_cmd
->ioasa
.ioasc
);
6546 if (ioasc
== IPR_IOASC_IR_INVALID_REQ_TYPE_OR_PKT
) {
6547 ipr_cmd
->job_step
= ipr_set_supported_devs
;
6548 ipr_cmd
->u
.res
= list_entry(ioa_cfg
->used_res_q
.next
,
6549 struct ipr_resource_entry
, queue
);
6550 return IPR_RC_JOB_CONTINUE
;
6553 return ipr_reset_cmd_failed(ipr_cmd
);
6557 * ipr_ioafp_mode_sense_page28 - Issue Mode Sense Page 28 to IOA
6558 * @ipr_cmd: ipr command struct
6560 * This function send a Page 28 mode sense to the IOA to
6561 * retrieve SCSI bus attributes.
6566 static int ipr_ioafp_mode_sense_page28(struct ipr_cmnd
*ipr_cmd
)
6568 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
6571 ipr_build_mode_sense(ipr_cmd
, cpu_to_be32(IPR_IOA_RES_HANDLE
),
6572 0x28, ioa_cfg
->vpd_cbs_dma
+
6573 offsetof(struct ipr_misc_cbs
, mode_pages
),
6574 sizeof(struct ipr_mode_pages
));
6576 ipr_cmd
->job_step
= ipr_ioafp_mode_select_page28
;
6577 ipr_cmd
->job_step_failed
= ipr_reset_mode_sense_failed
;
6579 ipr_do_req(ipr_cmd
, ipr_reset_ioa_job
, ipr_timeout
, IPR_INTERNAL_TIMEOUT
);
6582 return IPR_RC_JOB_RETURN
;
6586 * ipr_ioafp_mode_select_page24 - Issue Mode Select to IOA
6587 * @ipr_cmd: ipr command struct
6589 * This function enables dual IOA RAID support if possible.
6594 static int ipr_ioafp_mode_select_page24(struct ipr_cmnd
*ipr_cmd
)
6596 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
6597 struct ipr_mode_pages
*mode_pages
= &ioa_cfg
->vpd_cbs
->mode_pages
;
6598 struct ipr_mode_page24
*mode_page
;
6602 mode_page
= ipr_get_mode_page(mode_pages
, 0x24,
6603 sizeof(struct ipr_mode_page24
));
6606 mode_page
->flags
|= IPR_ENABLE_DUAL_IOA_AF
;
6608 length
= mode_pages
->hdr
.length
+ 1;
6609 mode_pages
->hdr
.length
= 0;
6611 ipr_build_mode_select(ipr_cmd
, cpu_to_be32(IPR_IOA_RES_HANDLE
), 0x11,
6612 ioa_cfg
->vpd_cbs_dma
+ offsetof(struct ipr_misc_cbs
, mode_pages
),
6615 ipr_cmd
->job_step
= ipr_ioafp_mode_sense_page28
;
6616 ipr_do_req(ipr_cmd
, ipr_reset_ioa_job
, ipr_timeout
, IPR_INTERNAL_TIMEOUT
);
6619 return IPR_RC_JOB_RETURN
;
6623 * ipr_reset_mode_sense_page24_failed - Handle failure of IOAFP mode sense
6624 * @ipr_cmd: ipr command struct
6626 * This function handles the failure of a Mode Sense to the IOAFP.
6627 * Some adapters do not handle all mode pages.
6630 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
6632 static int ipr_reset_mode_sense_page24_failed(struct ipr_cmnd
*ipr_cmd
)
6634 u32 ioasc
= be32_to_cpu(ipr_cmd
->ioasa
.ioasc
);
6636 if (ioasc
== IPR_IOASC_IR_INVALID_REQ_TYPE_OR_PKT
) {
6637 ipr_cmd
->job_step
= ipr_ioafp_mode_sense_page28
;
6638 return IPR_RC_JOB_CONTINUE
;
6641 return ipr_reset_cmd_failed(ipr_cmd
);
6645 * ipr_ioafp_mode_sense_page24 - Issue Page 24 Mode Sense to IOA
6646 * @ipr_cmd: ipr command struct
6648 * This function send a mode sense to the IOA to retrieve
6649 * the IOA Advanced Function Control mode page.
6654 static int ipr_ioafp_mode_sense_page24(struct ipr_cmnd
*ipr_cmd
)
6656 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
6659 ipr_build_mode_sense(ipr_cmd
, cpu_to_be32(IPR_IOA_RES_HANDLE
),
6660 0x24, ioa_cfg
->vpd_cbs_dma
+
6661 offsetof(struct ipr_misc_cbs
, mode_pages
),
6662 sizeof(struct ipr_mode_pages
));
6664 ipr_cmd
->job_step
= ipr_ioafp_mode_select_page24
;
6665 ipr_cmd
->job_step_failed
= ipr_reset_mode_sense_page24_failed
;
6667 ipr_do_req(ipr_cmd
, ipr_reset_ioa_job
, ipr_timeout
, IPR_INTERNAL_TIMEOUT
);
6670 return IPR_RC_JOB_RETURN
;
6674 * ipr_init_res_table - Initialize the resource table
6675 * @ipr_cmd: ipr command struct
6677 * This function looks through the existing resource table, comparing
6678 * it with the config table. This function will take care of old/new
6679 * devices and schedule adding/removing them from the mid-layer
6683 * IPR_RC_JOB_CONTINUE
6685 static int ipr_init_res_table(struct ipr_cmnd
*ipr_cmd
)
6687 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
6688 struct ipr_resource_entry
*res
, *temp
;
6689 struct ipr_config_table_entry_wrapper cfgtew
;
6690 int entries
, found
, flag
, i
;
6695 flag
= ioa_cfg
->u
.cfg_table64
->hdr64
.flags
;
6697 flag
= ioa_cfg
->u
.cfg_table
->hdr
.flags
;
6699 if (flag
& IPR_UCODE_DOWNLOAD_REQ
)
6700 dev_err(&ioa_cfg
->pdev
->dev
, "Microcode download required\n");
6702 list_for_each_entry_safe(res
, temp
, &ioa_cfg
->used_res_q
, queue
)
6703 list_move_tail(&res
->queue
, &old_res
);
6706 entries
= ioa_cfg
->u
.cfg_table64
->hdr64
.num_entries
;
6708 entries
= ioa_cfg
->u
.cfg_table
->hdr
.num_entries
;
6710 for (i
= 0; i
< entries
; i
++) {
6712 cfgtew
.u
.cfgte64
= &ioa_cfg
->u
.cfg_table64
->dev
[i
];
6714 cfgtew
.u
.cfgte
= &ioa_cfg
->u
.cfg_table
->dev
[i
];
6717 list_for_each_entry_safe(res
, temp
, &old_res
, queue
) {
6718 if (ipr_is_same_device(res
, &cfgtew
)) {
6719 list_move_tail(&res
->queue
, &ioa_cfg
->used_res_q
);
6726 if (list_empty(&ioa_cfg
->free_res_q
)) {
6727 dev_err(&ioa_cfg
->pdev
->dev
, "Too many devices attached\n");
6732 res
= list_entry(ioa_cfg
->free_res_q
.next
,
6733 struct ipr_resource_entry
, queue
);
6734 list_move_tail(&res
->queue
, &ioa_cfg
->used_res_q
);
6735 ipr_init_res_entry(res
, &cfgtew
);
6740 ipr_update_res_entry(res
, &cfgtew
);
6743 list_for_each_entry_safe(res
, temp
, &old_res
, queue
) {
6745 res
->del_from_ml
= 1;
6746 res
->res_handle
= IPR_INVALID_RES_HANDLE
;
6747 list_move_tail(&res
->queue
, &ioa_cfg
->used_res_q
);
6751 list_for_each_entry_safe(res
, temp
, &old_res
, queue
) {
6752 ipr_clear_res_target(res
);
6753 list_move_tail(&res
->queue
, &ioa_cfg
->free_res_q
);
6756 if (ioa_cfg
->dual_raid
&& ipr_dual_ioa_raid
)
6757 ipr_cmd
->job_step
= ipr_ioafp_mode_sense_page24
;
6759 ipr_cmd
->job_step
= ipr_ioafp_mode_sense_page28
;
6762 return IPR_RC_JOB_CONTINUE
;
6766 * ipr_ioafp_query_ioa_cfg - Send a Query IOA Config to the adapter.
6767 * @ipr_cmd: ipr command struct
6769 * This function sends a Query IOA Configuration command
6770 * to the adapter to retrieve the IOA configuration table.
6775 static int ipr_ioafp_query_ioa_cfg(struct ipr_cmnd
*ipr_cmd
)
6777 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
6778 struct ipr_ioarcb
*ioarcb
= &ipr_cmd
->ioarcb
;
6779 struct ipr_inquiry_page3
*ucode_vpd
= &ioa_cfg
->vpd_cbs
->page3_data
;
6780 struct ipr_inquiry_cap
*cap
= &ioa_cfg
->vpd_cbs
->cap
;
6783 if (cap
->cap
& IPR_CAP_DUAL_IOA_RAID
)
6784 ioa_cfg
->dual_raid
= 1;
6785 dev_info(&ioa_cfg
->pdev
->dev
, "Adapter firmware version: %02X%02X%02X%02X\n",
6786 ucode_vpd
->major_release
, ucode_vpd
->card_type
,
6787 ucode_vpd
->minor_release
[0], ucode_vpd
->minor_release
[1]);
6788 ioarcb
->cmd_pkt
.request_type
= IPR_RQTYPE_IOACMD
;
6789 ioarcb
->res_handle
= cpu_to_be32(IPR_IOA_RES_HANDLE
);
6791 ioarcb
->cmd_pkt
.cdb
[0] = IPR_QUERY_IOA_CONFIG
;
6792 ioarcb
->cmd_pkt
.cdb
[7] = (ioa_cfg
->cfg_table_size
>> 8) & 0xff;
6793 ioarcb
->cmd_pkt
.cdb
[8] = ioa_cfg
->cfg_table_size
& 0xff;
6795 ipr_init_ioadl(ipr_cmd
, ioa_cfg
->cfg_table_dma
, ioa_cfg
->cfg_table_size
,
6796 IPR_IOADL_FLAGS_READ_LAST
);
6798 ipr_cmd
->job_step
= ipr_init_res_table
;
6800 ipr_do_req(ipr_cmd
, ipr_reset_ioa_job
, ipr_timeout
, IPR_INTERNAL_TIMEOUT
);
6803 return IPR_RC_JOB_RETURN
;
6807 * ipr_ioafp_inquiry - Send an Inquiry to the adapter.
6808 * @ipr_cmd: ipr command struct
6810 * This utility function sends an inquiry to the adapter.
6815 static void ipr_ioafp_inquiry(struct ipr_cmnd
*ipr_cmd
, u8 flags
, u8 page
,
6816 dma_addr_t dma_addr
, u8 xfer_len
)
6818 struct ipr_ioarcb
*ioarcb
= &ipr_cmd
->ioarcb
;
6821 ioarcb
->cmd_pkt
.request_type
= IPR_RQTYPE_SCSICDB
;
6822 ioarcb
->res_handle
= cpu_to_be32(IPR_IOA_RES_HANDLE
);
6824 ioarcb
->cmd_pkt
.cdb
[0] = INQUIRY
;
6825 ioarcb
->cmd_pkt
.cdb
[1] = flags
;
6826 ioarcb
->cmd_pkt
.cdb
[2] = page
;
6827 ioarcb
->cmd_pkt
.cdb
[4] = xfer_len
;
6829 ipr_init_ioadl(ipr_cmd
, dma_addr
, xfer_len
, IPR_IOADL_FLAGS_READ_LAST
);
6831 ipr_do_req(ipr_cmd
, ipr_reset_ioa_job
, ipr_timeout
, IPR_INTERNAL_TIMEOUT
);
6836 * ipr_inquiry_page_supported - Is the given inquiry page supported
6837 * @page0: inquiry page 0 buffer
6840 * This function determines if the specified inquiry page is supported.
6843 * 1 if page is supported / 0 if not
6845 static int ipr_inquiry_page_supported(struct ipr_inquiry_page0
*page0
, u8 page
)
6849 for (i
= 0; i
< min_t(u8
, page0
->len
, IPR_INQUIRY_PAGE0_ENTRIES
); i
++)
6850 if (page0
->page
[i
] == page
)
6857 * ipr_ioafp_cap_inquiry - Send a Page 0xD0 Inquiry to the adapter.
6858 * @ipr_cmd: ipr command struct
6860 * This function sends a Page 0xD0 inquiry to the adapter
6861 * to retrieve adapter capabilities.
6864 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
6866 static int ipr_ioafp_cap_inquiry(struct ipr_cmnd
*ipr_cmd
)
6868 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
6869 struct ipr_inquiry_page0
*page0
= &ioa_cfg
->vpd_cbs
->page0_data
;
6870 struct ipr_inquiry_cap
*cap
= &ioa_cfg
->vpd_cbs
->cap
;
6873 ipr_cmd
->job_step
= ipr_ioafp_query_ioa_cfg
;
6874 memset(cap
, 0, sizeof(*cap
));
6876 if (ipr_inquiry_page_supported(page0
, 0xD0)) {
6877 ipr_ioafp_inquiry(ipr_cmd
, 1, 0xD0,
6878 ioa_cfg
->vpd_cbs_dma
+ offsetof(struct ipr_misc_cbs
, cap
),
6879 sizeof(struct ipr_inquiry_cap
));
6880 return IPR_RC_JOB_RETURN
;
6884 return IPR_RC_JOB_CONTINUE
;
6888 * ipr_ioafp_page3_inquiry - Send a Page 3 Inquiry to the adapter.
6889 * @ipr_cmd: ipr command struct
6891 * This function sends a Page 3 inquiry to the adapter
6892 * to retrieve software VPD information.
6895 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
6897 static int ipr_ioafp_page3_inquiry(struct ipr_cmnd
*ipr_cmd
)
6899 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
6903 ipr_cmd
->job_step
= ipr_ioafp_cap_inquiry
;
6905 ipr_ioafp_inquiry(ipr_cmd
, 1, 3,
6906 ioa_cfg
->vpd_cbs_dma
+ offsetof(struct ipr_misc_cbs
, page3_data
),
6907 sizeof(struct ipr_inquiry_page3
));
6910 return IPR_RC_JOB_RETURN
;
6914 * ipr_ioafp_page0_inquiry - Send a Page 0 Inquiry to the adapter.
6915 * @ipr_cmd: ipr command struct
6917 * This function sends a Page 0 inquiry to the adapter
6918 * to retrieve supported inquiry pages.
6921 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
6923 static int ipr_ioafp_page0_inquiry(struct ipr_cmnd
*ipr_cmd
)
6925 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
6930 /* Grab the type out of the VPD and store it away */
6931 memcpy(type
, ioa_cfg
->vpd_cbs
->ioa_vpd
.std_inq_data
.vpids
.product_id
, 4);
6933 ioa_cfg
->type
= simple_strtoul((char *)type
, NULL
, 16);
6935 ipr_cmd
->job_step
= ipr_ioafp_page3_inquiry
;
6937 ipr_ioafp_inquiry(ipr_cmd
, 1, 0,
6938 ioa_cfg
->vpd_cbs_dma
+ offsetof(struct ipr_misc_cbs
, page0_data
),
6939 sizeof(struct ipr_inquiry_page0
));
6942 return IPR_RC_JOB_RETURN
;
6946 * ipr_ioafp_std_inquiry - Send a Standard Inquiry to the adapter.
6947 * @ipr_cmd: ipr command struct
6949 * This function sends a standard inquiry to the adapter.
6954 static int ipr_ioafp_std_inquiry(struct ipr_cmnd
*ipr_cmd
)
6956 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
6959 ipr_cmd
->job_step
= ipr_ioafp_page0_inquiry
;
6961 ipr_ioafp_inquiry(ipr_cmd
, 0, 0,
6962 ioa_cfg
->vpd_cbs_dma
+ offsetof(struct ipr_misc_cbs
, ioa_vpd
),
6963 sizeof(struct ipr_ioa_vpd
));
6966 return IPR_RC_JOB_RETURN
;
6970 * ipr_ioafp_identify_hrrq - Send Identify Host RRQ.
6971 * @ipr_cmd: ipr command struct
6973 * This function send an Identify Host Request Response Queue
6974 * command to establish the HRRQ with the adapter.
6979 static int ipr_ioafp_identify_hrrq(struct ipr_cmnd
*ipr_cmd
)
6981 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
6982 struct ipr_ioarcb
*ioarcb
= &ipr_cmd
->ioarcb
;
6985 dev_info(&ioa_cfg
->pdev
->dev
, "Starting IOA initialization sequence.\n");
6987 ioarcb
->cmd_pkt
.cdb
[0] = IPR_ID_HOST_RR_Q
;
6988 ioarcb
->res_handle
= cpu_to_be32(IPR_IOA_RES_HANDLE
);
6990 ioarcb
->cmd_pkt
.request_type
= IPR_RQTYPE_IOACMD
;
6992 ioarcb
->cmd_pkt
.cdb
[1] = 0x1;
6993 ioarcb
->cmd_pkt
.cdb
[2] =
6994 ((u64
) ioa_cfg
->host_rrq_dma
>> 24) & 0xff;
6995 ioarcb
->cmd_pkt
.cdb
[3] =
6996 ((u64
) ioa_cfg
->host_rrq_dma
>> 16) & 0xff;
6997 ioarcb
->cmd_pkt
.cdb
[4] =
6998 ((u64
) ioa_cfg
->host_rrq_dma
>> 8) & 0xff;
6999 ioarcb
->cmd_pkt
.cdb
[5] =
7000 ((u64
) ioa_cfg
->host_rrq_dma
) & 0xff;
7001 ioarcb
->cmd_pkt
.cdb
[7] =
7002 ((sizeof(u32
) * IPR_NUM_CMD_BLKS
) >> 8) & 0xff;
7003 ioarcb
->cmd_pkt
.cdb
[8] =
7004 (sizeof(u32
) * IPR_NUM_CMD_BLKS
) & 0xff;
7006 if (ioa_cfg
->sis64
) {
7007 ioarcb
->cmd_pkt
.cdb
[10] =
7008 ((u64
) ioa_cfg
->host_rrq_dma
>> 56) & 0xff;
7009 ioarcb
->cmd_pkt
.cdb
[11] =
7010 ((u64
) ioa_cfg
->host_rrq_dma
>> 48) & 0xff;
7011 ioarcb
->cmd_pkt
.cdb
[12] =
7012 ((u64
) ioa_cfg
->host_rrq_dma
>> 40) & 0xff;
7013 ioarcb
->cmd_pkt
.cdb
[13] =
7014 ((u64
) ioa_cfg
->host_rrq_dma
>> 32) & 0xff;
7017 ipr_cmd
->job_step
= ipr_ioafp_std_inquiry
;
7019 ipr_do_req(ipr_cmd
, ipr_reset_ioa_job
, ipr_timeout
, IPR_INTERNAL_TIMEOUT
);
7022 return IPR_RC_JOB_RETURN
;
7026 * ipr_reset_timer_done - Adapter reset timer function
7027 * @ipr_cmd: ipr command struct
7029 * Description: This function is used in adapter reset processing
7030 * for timing events. If the reset_cmd pointer in the IOA
7031 * config struct is not this adapter's we are doing nested
7032 * resets and fail_all_ops will take care of freeing the
7038 static void ipr_reset_timer_done(struct ipr_cmnd
*ipr_cmd
)
7040 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
7041 unsigned long lock_flags
= 0;
7043 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
7045 if (ioa_cfg
->reset_cmd
== ipr_cmd
) {
7046 list_del(&ipr_cmd
->queue
);
7047 ipr_cmd
->done(ipr_cmd
);
7050 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
7054 * ipr_reset_start_timer - Start a timer for adapter reset job
7055 * @ipr_cmd: ipr command struct
7056 * @timeout: timeout value
7058 * Description: This function is used in adapter reset processing
7059 * for timing events. If the reset_cmd pointer in the IOA
7060 * config struct is not this adapter's we are doing nested
7061 * resets and fail_all_ops will take care of freeing the
7067 static void ipr_reset_start_timer(struct ipr_cmnd
*ipr_cmd
,
7068 unsigned long timeout
)
7070 list_add_tail(&ipr_cmd
->queue
, &ipr_cmd
->ioa_cfg
->pending_q
);
7071 ipr_cmd
->done
= ipr_reset_ioa_job
;
7073 ipr_cmd
->timer
.data
= (unsigned long) ipr_cmd
;
7074 ipr_cmd
->timer
.expires
= jiffies
+ timeout
;
7075 ipr_cmd
->timer
.function
= (void (*)(unsigned long))ipr_reset_timer_done
;
7076 add_timer(&ipr_cmd
->timer
);
7080 * ipr_init_ioa_mem - Initialize ioa_cfg control block
7081 * @ioa_cfg: ioa cfg struct
7086 static void ipr_init_ioa_mem(struct ipr_ioa_cfg
*ioa_cfg
)
7088 memset(ioa_cfg
->host_rrq
, 0, sizeof(u32
) * IPR_NUM_CMD_BLKS
);
7090 /* Initialize Host RRQ pointers */
7091 ioa_cfg
->hrrq_start
= ioa_cfg
->host_rrq
;
7092 ioa_cfg
->hrrq_end
= &ioa_cfg
->host_rrq
[IPR_NUM_CMD_BLKS
- 1];
7093 ioa_cfg
->hrrq_curr
= ioa_cfg
->hrrq_start
;
7094 ioa_cfg
->toggle_bit
= 1;
7096 /* Zero out config table */
7097 memset(ioa_cfg
->u
.cfg_table
, 0, ioa_cfg
->cfg_table_size
);
7101 * ipr_reset_next_stage - Process IPL stage change based on feedback register.
7102 * @ipr_cmd: ipr command struct
7105 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7107 static int ipr_reset_next_stage(struct ipr_cmnd
*ipr_cmd
)
7109 unsigned long stage
, stage_time
;
7111 volatile u32 int_reg
;
7112 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
7115 feedback
= readl(ioa_cfg
->regs
.init_feedback_reg
);
7116 stage
= feedback
& IPR_IPL_INIT_STAGE_MASK
;
7117 stage_time
= feedback
& IPR_IPL_INIT_STAGE_TIME_MASK
;
7119 ipr_dbg("IPL stage = 0x%lx, IPL stage time = %ld\n", stage
, stage_time
);
7121 /* sanity check the stage_time value */
7122 if (stage_time
< IPR_IPL_INIT_MIN_STAGE_TIME
)
7123 stage_time
= IPR_IPL_INIT_MIN_STAGE_TIME
;
7124 else if (stage_time
> IPR_LONG_OPERATIONAL_TIMEOUT
)
7125 stage_time
= IPR_LONG_OPERATIONAL_TIMEOUT
;
7127 if (stage
== IPR_IPL_INIT_STAGE_UNKNOWN
) {
7128 writel(IPR_PCII_IPL_STAGE_CHANGE
, ioa_cfg
->regs
.set_interrupt_mask_reg
);
7129 int_reg
= readl(ioa_cfg
->regs
.sense_interrupt_mask_reg
);
7130 stage_time
= ioa_cfg
->transop_timeout
;
7131 ipr_cmd
->job_step
= ipr_ioafp_identify_hrrq
;
7132 } else if (stage
== IPR_IPL_INIT_STAGE_TRANSOP
) {
7133 ipr_cmd
->job_step
= ipr_ioafp_identify_hrrq
;
7134 maskval
= IPR_PCII_IPL_STAGE_CHANGE
;
7135 maskval
= (maskval
<< 32) | IPR_PCII_IOA_TRANS_TO_OPER
;
7136 writeq(maskval
, ioa_cfg
->regs
.set_interrupt_mask_reg
);
7137 int_reg
= readl(ioa_cfg
->regs
.sense_interrupt_mask_reg
);
7138 return IPR_RC_JOB_CONTINUE
;
7141 ipr_cmd
->timer
.data
= (unsigned long) ipr_cmd
;
7142 ipr_cmd
->timer
.expires
= jiffies
+ stage_time
* HZ
;
7143 ipr_cmd
->timer
.function
= (void (*)(unsigned long))ipr_oper_timeout
;
7144 ipr_cmd
->done
= ipr_reset_ioa_job
;
7145 add_timer(&ipr_cmd
->timer
);
7146 list_add_tail(&ipr_cmd
->queue
, &ioa_cfg
->pending_q
);
7148 return IPR_RC_JOB_RETURN
;
7152 * ipr_reset_enable_ioa - Enable the IOA following a reset.
7153 * @ipr_cmd: ipr command struct
7155 * This function reinitializes some control blocks and
7156 * enables destructive diagnostics on the adapter.
7161 static int ipr_reset_enable_ioa(struct ipr_cmnd
*ipr_cmd
)
7163 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
7164 volatile u32 int_reg
;
7167 ipr_cmd
->job_step
= ipr_ioafp_identify_hrrq
;
7168 ipr_init_ioa_mem(ioa_cfg
);
7170 ioa_cfg
->allow_interrupts
= 1;
7171 int_reg
= readl(ioa_cfg
->regs
.sense_interrupt_reg
);
7173 if (int_reg
& IPR_PCII_IOA_TRANS_TO_OPER
) {
7174 writel((IPR_PCII_ERROR_INTERRUPTS
| IPR_PCII_HRRQ_UPDATED
),
7175 ioa_cfg
->regs
.clr_interrupt_mask_reg32
);
7176 int_reg
= readl(ioa_cfg
->regs
.sense_interrupt_mask_reg
);
7177 return IPR_RC_JOB_CONTINUE
;
7180 /* Enable destructive diagnostics on IOA */
7181 writel(ioa_cfg
->doorbell
, ioa_cfg
->regs
.set_uproc_interrupt_reg32
);
7183 writel(IPR_PCII_OPER_INTERRUPTS
, ioa_cfg
->regs
.clr_interrupt_mask_reg32
);
7185 writel(IPR_PCII_IPL_STAGE_CHANGE
, ioa_cfg
->regs
.clr_interrupt_mask_reg
);
7187 int_reg
= readl(ioa_cfg
->regs
.sense_interrupt_mask_reg
);
7189 dev_info(&ioa_cfg
->pdev
->dev
, "Initializing IOA.\n");
7191 if (ioa_cfg
->sis64
) {
7192 ipr_cmd
->job_step
= ipr_reset_next_stage
;
7193 return IPR_RC_JOB_CONTINUE
;
7196 ipr_cmd
->timer
.data
= (unsigned long) ipr_cmd
;
7197 ipr_cmd
->timer
.expires
= jiffies
+ (ioa_cfg
->transop_timeout
* HZ
);
7198 ipr_cmd
->timer
.function
= (void (*)(unsigned long))ipr_oper_timeout
;
7199 ipr_cmd
->done
= ipr_reset_ioa_job
;
7200 add_timer(&ipr_cmd
->timer
);
7201 list_add_tail(&ipr_cmd
->queue
, &ioa_cfg
->pending_q
);
7204 return IPR_RC_JOB_RETURN
;
7208 * ipr_reset_wait_for_dump - Wait for a dump to timeout.
7209 * @ipr_cmd: ipr command struct
7211 * This function is invoked when an adapter dump has run out
7212 * of processing time.
7215 * IPR_RC_JOB_CONTINUE
7217 static int ipr_reset_wait_for_dump(struct ipr_cmnd
*ipr_cmd
)
7219 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
7221 if (ioa_cfg
->sdt_state
== GET_DUMP
)
7222 ioa_cfg
->sdt_state
= ABORT_DUMP
;
7224 ipr_cmd
->job_step
= ipr_reset_alert
;
7226 return IPR_RC_JOB_CONTINUE
;
7230 * ipr_unit_check_no_data - Log a unit check/no data error log
7231 * @ioa_cfg: ioa config struct
7233 * Logs an error indicating the adapter unit checked, but for some
7234 * reason, we were unable to fetch the unit check buffer.
7239 static void ipr_unit_check_no_data(struct ipr_ioa_cfg
*ioa_cfg
)
7241 ioa_cfg
->errors_logged
++;
7242 dev_err(&ioa_cfg
->pdev
->dev
, "IOA unit check with no data\n");
7246 * ipr_get_unit_check_buffer - Get the unit check buffer from the IOA
7247 * @ioa_cfg: ioa config struct
7249 * Fetches the unit check buffer from the adapter by clocking the data
7250 * through the mailbox register.
7255 static void ipr_get_unit_check_buffer(struct ipr_ioa_cfg
*ioa_cfg
)
7257 unsigned long mailbox
;
7258 struct ipr_hostrcb
*hostrcb
;
7259 struct ipr_uc_sdt sdt
;
7263 mailbox
= readl(ioa_cfg
->ioa_mailbox
);
7265 if (!ioa_cfg
->sis64
&& !ipr_sdt_is_fmt2(mailbox
)) {
7266 ipr_unit_check_no_data(ioa_cfg
);
7270 memset(&sdt
, 0, sizeof(struct ipr_uc_sdt
));
7271 rc
= ipr_get_ldump_data_section(ioa_cfg
, mailbox
, (__be32
*) &sdt
,
7272 (sizeof(struct ipr_uc_sdt
)) / sizeof(__be32
));
7274 if (rc
|| !(sdt
.entry
[0].flags
& IPR_SDT_VALID_ENTRY
) ||
7275 ((be32_to_cpu(sdt
.hdr
.state
) != IPR_FMT3_SDT_READY_TO_USE
) &&
7276 (be32_to_cpu(sdt
.hdr
.state
) != IPR_FMT2_SDT_READY_TO_USE
))) {
7277 ipr_unit_check_no_data(ioa_cfg
);
7281 /* Find length of the first sdt entry (UC buffer) */
7282 if (be32_to_cpu(sdt
.hdr
.state
) == IPR_FMT3_SDT_READY_TO_USE
)
7283 length
= be32_to_cpu(sdt
.entry
[0].end_token
);
7285 length
= (be32_to_cpu(sdt
.entry
[0].end_token
) -
7286 be32_to_cpu(sdt
.entry
[0].start_token
)) &
7287 IPR_FMT2_MBX_ADDR_MASK
;
7289 hostrcb
= list_entry(ioa_cfg
->hostrcb_free_q
.next
,
7290 struct ipr_hostrcb
, queue
);
7291 list_del(&hostrcb
->queue
);
7292 memset(&hostrcb
->hcam
, 0, sizeof(hostrcb
->hcam
));
7294 rc
= ipr_get_ldump_data_section(ioa_cfg
,
7295 be32_to_cpu(sdt
.entry
[0].start_token
),
7296 (__be32
*)&hostrcb
->hcam
,
7297 min(length
, (int)sizeof(hostrcb
->hcam
)) / sizeof(__be32
));
7300 ipr_handle_log_data(ioa_cfg
, hostrcb
);
7301 ioasc
= be32_to_cpu(hostrcb
->hcam
.u
.error
.fd_ioasc
);
7302 if (ioasc
== IPR_IOASC_NR_IOA_RESET_REQUIRED
&&
7303 ioa_cfg
->sdt_state
== GET_DUMP
)
7304 ioa_cfg
->sdt_state
= WAIT_FOR_DUMP
;
7306 ipr_unit_check_no_data(ioa_cfg
);
7308 list_add_tail(&hostrcb
->queue
, &ioa_cfg
->hostrcb_free_q
);
7312 * ipr_reset_restore_cfg_space - Restore PCI config space.
7313 * @ipr_cmd: ipr command struct
7315 * Description: This function restores the saved PCI config space of
7316 * the adapter, fails all outstanding ops back to the callers, and
7317 * fetches the dump/unit check if applicable to this reset.
7320 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7322 static int ipr_reset_restore_cfg_space(struct ipr_cmnd
*ipr_cmd
)
7324 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
7328 ioa_cfg
->pdev
->state_saved
= true;
7329 rc
= pci_restore_state(ioa_cfg
->pdev
);
7331 if (rc
!= PCIBIOS_SUCCESSFUL
) {
7332 ipr_cmd
->ioasa
.ioasc
= cpu_to_be32(IPR_IOASC_PCI_ACCESS_ERROR
);
7333 return IPR_RC_JOB_CONTINUE
;
7336 if (ipr_set_pcix_cmd_reg(ioa_cfg
)) {
7337 ipr_cmd
->ioasa
.ioasc
= cpu_to_be32(IPR_IOASC_PCI_ACCESS_ERROR
);
7338 return IPR_RC_JOB_CONTINUE
;
7341 ipr_fail_all_ops(ioa_cfg
);
7343 if (ioa_cfg
->ioa_unit_checked
) {
7344 ioa_cfg
->ioa_unit_checked
= 0;
7345 ipr_get_unit_check_buffer(ioa_cfg
);
7346 ipr_cmd
->job_step
= ipr_reset_alert
;
7347 ipr_reset_start_timer(ipr_cmd
, 0);
7348 return IPR_RC_JOB_RETURN
;
7351 if (ioa_cfg
->in_ioa_bringdown
) {
7352 ipr_cmd
->job_step
= ipr_ioa_bringdown_done
;
7354 ipr_cmd
->job_step
= ipr_reset_enable_ioa
;
7356 if (GET_DUMP
== ioa_cfg
->sdt_state
) {
7357 ipr_reset_start_timer(ipr_cmd
, IPR_DUMP_TIMEOUT
);
7358 ipr_cmd
->job_step
= ipr_reset_wait_for_dump
;
7359 schedule_work(&ioa_cfg
->work_q
);
7360 return IPR_RC_JOB_RETURN
;
7365 return IPR_RC_JOB_CONTINUE
;
7369 * ipr_reset_bist_done - BIST has completed on the adapter.
7370 * @ipr_cmd: ipr command struct
7372 * Description: Unblock config space and resume the reset process.
7375 * IPR_RC_JOB_CONTINUE
7377 static int ipr_reset_bist_done(struct ipr_cmnd
*ipr_cmd
)
7380 pci_unblock_user_cfg_access(ipr_cmd
->ioa_cfg
->pdev
);
7381 ipr_cmd
->job_step
= ipr_reset_restore_cfg_space
;
7383 return IPR_RC_JOB_CONTINUE
;
7387 * ipr_reset_start_bist - Run BIST on the adapter.
7388 * @ipr_cmd: ipr command struct
7390 * Description: This function runs BIST on the adapter, then delays 2 seconds.
7393 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7395 static int ipr_reset_start_bist(struct ipr_cmnd
*ipr_cmd
)
7397 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
7401 pci_block_user_cfg_access(ioa_cfg
->pdev
);
7402 rc
= pci_write_config_byte(ioa_cfg
->pdev
, PCI_BIST
, PCI_BIST_START
);
7404 if (rc
!= PCIBIOS_SUCCESSFUL
) {
7405 pci_unblock_user_cfg_access(ipr_cmd
->ioa_cfg
->pdev
);
7406 ipr_cmd
->ioasa
.ioasc
= cpu_to_be32(IPR_IOASC_PCI_ACCESS_ERROR
);
7407 rc
= IPR_RC_JOB_CONTINUE
;
7409 ipr_cmd
->job_step
= ipr_reset_bist_done
;
7410 ipr_reset_start_timer(ipr_cmd
, IPR_WAIT_FOR_BIST_TIMEOUT
);
7411 rc
= IPR_RC_JOB_RETURN
;
7419 * ipr_reset_slot_reset_done - Clear PCI reset to the adapter
7420 * @ipr_cmd: ipr command struct
7422 * Description: This clears PCI reset to the adapter and delays two seconds.
7427 static int ipr_reset_slot_reset_done(struct ipr_cmnd
*ipr_cmd
)
7430 pci_set_pcie_reset_state(ipr_cmd
->ioa_cfg
->pdev
, pcie_deassert_reset
);
7431 ipr_cmd
->job_step
= ipr_reset_bist_done
;
7432 ipr_reset_start_timer(ipr_cmd
, IPR_WAIT_FOR_BIST_TIMEOUT
);
7434 return IPR_RC_JOB_RETURN
;
7438 * ipr_reset_slot_reset - Reset the PCI slot of the adapter.
7439 * @ipr_cmd: ipr command struct
7441 * Description: This asserts PCI reset to the adapter.
7446 static int ipr_reset_slot_reset(struct ipr_cmnd
*ipr_cmd
)
7448 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
7449 struct pci_dev
*pdev
= ioa_cfg
->pdev
;
7452 pci_block_user_cfg_access(pdev
);
7453 pci_set_pcie_reset_state(pdev
, pcie_warm_reset
);
7454 ipr_cmd
->job_step
= ipr_reset_slot_reset_done
;
7455 ipr_reset_start_timer(ipr_cmd
, IPR_PCI_RESET_TIMEOUT
);
7457 return IPR_RC_JOB_RETURN
;
7461 * ipr_reset_allowed - Query whether or not IOA can be reset
7462 * @ioa_cfg: ioa config struct
7465 * 0 if reset not allowed / non-zero if reset is allowed
7467 static int ipr_reset_allowed(struct ipr_ioa_cfg
*ioa_cfg
)
7469 volatile u32 temp_reg
;
7471 temp_reg
= readl(ioa_cfg
->regs
.sense_interrupt_reg
);
7472 return ((temp_reg
& IPR_PCII_CRITICAL_OPERATION
) == 0);
7476 * ipr_reset_wait_to_start_bist - Wait for permission to reset IOA.
7477 * @ipr_cmd: ipr command struct
7479 * Description: This function waits for adapter permission to run BIST,
7480 * then runs BIST. If the adapter does not give permission after a
7481 * reasonable time, we will reset the adapter anyway. The impact of
7482 * resetting the adapter without warning the adapter is the risk of
7483 * losing the persistent error log on the adapter. If the adapter is
7484 * reset while it is writing to the flash on the adapter, the flash
7485 * segment will have bad ECC and be zeroed.
7488 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7490 static int ipr_reset_wait_to_start_bist(struct ipr_cmnd
*ipr_cmd
)
7492 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
7493 int rc
= IPR_RC_JOB_RETURN
;
7495 if (!ipr_reset_allowed(ioa_cfg
) && ipr_cmd
->u
.time_left
) {
7496 ipr_cmd
->u
.time_left
-= IPR_CHECK_FOR_RESET_TIMEOUT
;
7497 ipr_reset_start_timer(ipr_cmd
, IPR_CHECK_FOR_RESET_TIMEOUT
);
7499 ipr_cmd
->job_step
= ioa_cfg
->reset
;
7500 rc
= IPR_RC_JOB_CONTINUE
;
7507 * ipr_reset_alert_part2 - Alert the adapter of a pending reset
7508 * @ipr_cmd: ipr command struct
7510 * Description: This function alerts the adapter that it will be reset.
7511 * If memory space is not currently enabled, proceed directly
7512 * to running BIST on the adapter. The timer must always be started
7513 * so we guarantee we do not run BIST from ipr_isr.
7518 static int ipr_reset_alert(struct ipr_cmnd
*ipr_cmd
)
7520 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
7525 rc
= pci_read_config_word(ioa_cfg
->pdev
, PCI_COMMAND
, &cmd_reg
);
7527 if ((rc
== PCIBIOS_SUCCESSFUL
) && (cmd_reg
& PCI_COMMAND_MEMORY
)) {
7528 ipr_mask_and_clear_interrupts(ioa_cfg
, ~0);
7529 writel(IPR_UPROCI_RESET_ALERT
, ioa_cfg
->regs
.set_uproc_interrupt_reg32
);
7530 ipr_cmd
->job_step
= ipr_reset_wait_to_start_bist
;
7532 ipr_cmd
->job_step
= ioa_cfg
->reset
;
7535 ipr_cmd
->u
.time_left
= IPR_WAIT_FOR_RESET_TIMEOUT
;
7536 ipr_reset_start_timer(ipr_cmd
, IPR_CHECK_FOR_RESET_TIMEOUT
);
7539 return IPR_RC_JOB_RETURN
;
7543 * ipr_reset_ucode_download_done - Microcode download completion
7544 * @ipr_cmd: ipr command struct
7546 * Description: This function unmaps the microcode download buffer.
7549 * IPR_RC_JOB_CONTINUE
7551 static int ipr_reset_ucode_download_done(struct ipr_cmnd
*ipr_cmd
)
7553 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
7554 struct ipr_sglist
*sglist
= ioa_cfg
->ucode_sglist
;
7556 pci_unmap_sg(ioa_cfg
->pdev
, sglist
->scatterlist
,
7557 sglist
->num_sg
, DMA_TO_DEVICE
);
7559 ipr_cmd
->job_step
= ipr_reset_alert
;
7560 return IPR_RC_JOB_CONTINUE
;
7564 * ipr_reset_ucode_download - Download microcode to the adapter
7565 * @ipr_cmd: ipr command struct
7567 * Description: This function checks to see if it there is microcode
7568 * to download to the adapter. If there is, a download is performed.
7571 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7573 static int ipr_reset_ucode_download(struct ipr_cmnd
*ipr_cmd
)
7575 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
7576 struct ipr_sglist
*sglist
= ioa_cfg
->ucode_sglist
;
7579 ipr_cmd
->job_step
= ipr_reset_alert
;
7582 return IPR_RC_JOB_CONTINUE
;
7584 ipr_cmd
->ioarcb
.res_handle
= cpu_to_be32(IPR_IOA_RES_HANDLE
);
7585 ipr_cmd
->ioarcb
.cmd_pkt
.request_type
= IPR_RQTYPE_SCSICDB
;
7586 ipr_cmd
->ioarcb
.cmd_pkt
.cdb
[0] = WRITE_BUFFER
;
7587 ipr_cmd
->ioarcb
.cmd_pkt
.cdb
[1] = IPR_WR_BUF_DOWNLOAD_AND_SAVE
;
7588 ipr_cmd
->ioarcb
.cmd_pkt
.cdb
[6] = (sglist
->buffer_len
& 0xff0000) >> 16;
7589 ipr_cmd
->ioarcb
.cmd_pkt
.cdb
[7] = (sglist
->buffer_len
& 0x00ff00) >> 8;
7590 ipr_cmd
->ioarcb
.cmd_pkt
.cdb
[8] = sglist
->buffer_len
& 0x0000ff;
7593 ipr_build_ucode_ioadl64(ipr_cmd
, sglist
);
7595 ipr_build_ucode_ioadl(ipr_cmd
, sglist
);
7596 ipr_cmd
->job_step
= ipr_reset_ucode_download_done
;
7598 ipr_do_req(ipr_cmd
, ipr_reset_ioa_job
, ipr_timeout
,
7599 IPR_WRITE_BUFFER_TIMEOUT
);
7602 return IPR_RC_JOB_RETURN
;
7606 * ipr_reset_shutdown_ioa - Shutdown the adapter
7607 * @ipr_cmd: ipr command struct
7609 * Description: This function issues an adapter shutdown of the
7610 * specified type to the specified adapter as part of the
7611 * adapter reset job.
7614 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7616 static int ipr_reset_shutdown_ioa(struct ipr_cmnd
*ipr_cmd
)
7618 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
7619 enum ipr_shutdown_type shutdown_type
= ipr_cmd
->u
.shutdown_type
;
7620 unsigned long timeout
;
7621 int rc
= IPR_RC_JOB_CONTINUE
;
7624 if (shutdown_type
!= IPR_SHUTDOWN_NONE
&& !ioa_cfg
->ioa_is_dead
) {
7625 ipr_cmd
->ioarcb
.res_handle
= cpu_to_be32(IPR_IOA_RES_HANDLE
);
7626 ipr_cmd
->ioarcb
.cmd_pkt
.request_type
= IPR_RQTYPE_IOACMD
;
7627 ipr_cmd
->ioarcb
.cmd_pkt
.cdb
[0] = IPR_IOA_SHUTDOWN
;
7628 ipr_cmd
->ioarcb
.cmd_pkt
.cdb
[1] = shutdown_type
;
7630 if (shutdown_type
== IPR_SHUTDOWN_NORMAL
)
7631 timeout
= IPR_SHUTDOWN_TIMEOUT
;
7632 else if (shutdown_type
== IPR_SHUTDOWN_PREPARE_FOR_NORMAL
)
7633 timeout
= IPR_INTERNAL_TIMEOUT
;
7634 else if (ioa_cfg
->dual_raid
&& ipr_dual_ioa_raid
)
7635 timeout
= IPR_DUAL_IOA_ABBR_SHUTDOWN_TO
;
7637 timeout
= IPR_ABBREV_SHUTDOWN_TIMEOUT
;
7639 ipr_do_req(ipr_cmd
, ipr_reset_ioa_job
, ipr_timeout
, timeout
);
7641 rc
= IPR_RC_JOB_RETURN
;
7642 ipr_cmd
->job_step
= ipr_reset_ucode_download
;
7644 ipr_cmd
->job_step
= ipr_reset_alert
;
7651 * ipr_reset_ioa_job - Adapter reset job
7652 * @ipr_cmd: ipr command struct
7654 * Description: This function is the job router for the adapter reset job.
7659 static void ipr_reset_ioa_job(struct ipr_cmnd
*ipr_cmd
)
7662 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
7665 ioasc
= be32_to_cpu(ipr_cmd
->ioasa
.ioasc
);
7667 if (ioa_cfg
->reset_cmd
!= ipr_cmd
) {
7669 * We are doing nested adapter resets and this is
7670 * not the current reset job.
7672 list_add_tail(&ipr_cmd
->queue
, &ioa_cfg
->free_q
);
7676 if (IPR_IOASC_SENSE_KEY(ioasc
)) {
7677 rc
= ipr_cmd
->job_step_failed(ipr_cmd
);
7678 if (rc
== IPR_RC_JOB_RETURN
)
7682 ipr_reinit_ipr_cmnd(ipr_cmd
);
7683 ipr_cmd
->job_step_failed
= ipr_reset_cmd_failed
;
7684 rc
= ipr_cmd
->job_step(ipr_cmd
);
7685 } while(rc
== IPR_RC_JOB_CONTINUE
);
7689 * _ipr_initiate_ioa_reset - Initiate an adapter reset
7690 * @ioa_cfg: ioa config struct
7691 * @job_step: first job step of reset job
7692 * @shutdown_type: shutdown type
7694 * Description: This function will initiate the reset of the given adapter
7695 * starting at the selected job step.
7696 * If the caller needs to wait on the completion of the reset,
7697 * the caller must sleep on the reset_wait_q.
7702 static void _ipr_initiate_ioa_reset(struct ipr_ioa_cfg
*ioa_cfg
,
7703 int (*job_step
) (struct ipr_cmnd
*),
7704 enum ipr_shutdown_type shutdown_type
)
7706 struct ipr_cmnd
*ipr_cmd
;
7708 ioa_cfg
->in_reset_reload
= 1;
7709 ioa_cfg
->allow_cmds
= 0;
7710 scsi_block_requests(ioa_cfg
->host
);
7712 ipr_cmd
= ipr_get_free_ipr_cmnd(ioa_cfg
);
7713 ioa_cfg
->reset_cmd
= ipr_cmd
;
7714 ipr_cmd
->job_step
= job_step
;
7715 ipr_cmd
->u
.shutdown_type
= shutdown_type
;
7717 ipr_reset_ioa_job(ipr_cmd
);
7721 * ipr_initiate_ioa_reset - Initiate an adapter reset
7722 * @ioa_cfg: ioa config struct
7723 * @shutdown_type: shutdown type
7725 * Description: This function will initiate the reset of the given adapter.
7726 * If the caller needs to wait on the completion of the reset,
7727 * the caller must sleep on the reset_wait_q.
7732 static void ipr_initiate_ioa_reset(struct ipr_ioa_cfg
*ioa_cfg
,
7733 enum ipr_shutdown_type shutdown_type
)
7735 if (ioa_cfg
->ioa_is_dead
)
7738 if (ioa_cfg
->in_reset_reload
&& ioa_cfg
->sdt_state
== GET_DUMP
)
7739 ioa_cfg
->sdt_state
= ABORT_DUMP
;
7741 if (ioa_cfg
->reset_retries
++ >= IPR_NUM_RESET_RELOAD_RETRIES
) {
7742 dev_err(&ioa_cfg
->pdev
->dev
,
7743 "IOA taken offline - error recovery failed\n");
7745 ioa_cfg
->reset_retries
= 0;
7746 ioa_cfg
->ioa_is_dead
= 1;
7748 if (ioa_cfg
->in_ioa_bringdown
) {
7749 ioa_cfg
->reset_cmd
= NULL
;
7750 ioa_cfg
->in_reset_reload
= 0;
7751 ipr_fail_all_ops(ioa_cfg
);
7752 wake_up_all(&ioa_cfg
->reset_wait_q
);
7754 spin_unlock_irq(ioa_cfg
->host
->host_lock
);
7755 scsi_unblock_requests(ioa_cfg
->host
);
7756 spin_lock_irq(ioa_cfg
->host
->host_lock
);
7759 ioa_cfg
->in_ioa_bringdown
= 1;
7760 shutdown_type
= IPR_SHUTDOWN_NONE
;
7764 _ipr_initiate_ioa_reset(ioa_cfg
, ipr_reset_shutdown_ioa
,
7769 * ipr_reset_freeze - Hold off all I/O activity
7770 * @ipr_cmd: ipr command struct
7772 * Description: If the PCI slot is frozen, hold off all I/O
7773 * activity; then, as soon as the slot is available again,
7774 * initiate an adapter reset.
7776 static int ipr_reset_freeze(struct ipr_cmnd
*ipr_cmd
)
7778 /* Disallow new interrupts, avoid loop */
7779 ipr_cmd
->ioa_cfg
->allow_interrupts
= 0;
7780 list_add_tail(&ipr_cmd
->queue
, &ipr_cmd
->ioa_cfg
->pending_q
);
7781 ipr_cmd
->done
= ipr_reset_ioa_job
;
7782 return IPR_RC_JOB_RETURN
;
7786 * ipr_pci_frozen - Called when slot has experienced a PCI bus error.
7787 * @pdev: PCI device struct
7789 * Description: This routine is called to tell us that the PCI bus
7790 * is down. Can't do anything here, except put the device driver
7791 * into a holding pattern, waiting for the PCI bus to come back.
7793 static void ipr_pci_frozen(struct pci_dev
*pdev
)
7795 unsigned long flags
= 0;
7796 struct ipr_ioa_cfg
*ioa_cfg
= pci_get_drvdata(pdev
);
7798 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, flags
);
7799 _ipr_initiate_ioa_reset(ioa_cfg
, ipr_reset_freeze
, IPR_SHUTDOWN_NONE
);
7800 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, flags
);
7804 * ipr_pci_slot_reset - Called when PCI slot has been reset.
7805 * @pdev: PCI device struct
7807 * Description: This routine is called by the pci error recovery
7808 * code after the PCI slot has been reset, just before we
7809 * should resume normal operations.
7811 static pci_ers_result_t
ipr_pci_slot_reset(struct pci_dev
*pdev
)
7813 unsigned long flags
= 0;
7814 struct ipr_ioa_cfg
*ioa_cfg
= pci_get_drvdata(pdev
);
7816 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, flags
);
7817 if (ioa_cfg
->needs_warm_reset
)
7818 ipr_initiate_ioa_reset(ioa_cfg
, IPR_SHUTDOWN_NONE
);
7820 _ipr_initiate_ioa_reset(ioa_cfg
, ipr_reset_restore_cfg_space
,
7822 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, flags
);
7823 return PCI_ERS_RESULT_RECOVERED
;
7827 * ipr_pci_perm_failure - Called when PCI slot is dead for good.
7828 * @pdev: PCI device struct
7830 * Description: This routine is called when the PCI bus has
7831 * permanently failed.
7833 static void ipr_pci_perm_failure(struct pci_dev
*pdev
)
7835 unsigned long flags
= 0;
7836 struct ipr_ioa_cfg
*ioa_cfg
= pci_get_drvdata(pdev
);
7838 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, flags
);
7839 if (ioa_cfg
->sdt_state
== WAIT_FOR_DUMP
)
7840 ioa_cfg
->sdt_state
= ABORT_DUMP
;
7841 ioa_cfg
->reset_retries
= IPR_NUM_RESET_RELOAD_RETRIES
;
7842 ioa_cfg
->in_ioa_bringdown
= 1;
7843 ioa_cfg
->allow_cmds
= 0;
7844 ipr_initiate_ioa_reset(ioa_cfg
, IPR_SHUTDOWN_NONE
);
7845 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, flags
);
7849 * ipr_pci_error_detected - Called when a PCI error is detected.
7850 * @pdev: PCI device struct
7851 * @state: PCI channel state
7853 * Description: Called when a PCI error is detected.
7856 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
7858 static pci_ers_result_t
ipr_pci_error_detected(struct pci_dev
*pdev
,
7859 pci_channel_state_t state
)
7862 case pci_channel_io_frozen
:
7863 ipr_pci_frozen(pdev
);
7864 return PCI_ERS_RESULT_NEED_RESET
;
7865 case pci_channel_io_perm_failure
:
7866 ipr_pci_perm_failure(pdev
);
7867 return PCI_ERS_RESULT_DISCONNECT
;
7872 return PCI_ERS_RESULT_NEED_RESET
;
7876 * ipr_probe_ioa_part2 - Initializes IOAs found in ipr_probe_ioa(..)
7877 * @ioa_cfg: ioa cfg struct
7879 * Description: This is the second phase of adapter intialization
7880 * This function takes care of initilizing the adapter to the point
7881 * where it can accept new commands.
7884 * 0 on success / -EIO on failure
7886 static int __devinit
ipr_probe_ioa_part2(struct ipr_ioa_cfg
*ioa_cfg
)
7889 unsigned long host_lock_flags
= 0;
7892 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, host_lock_flags
);
7893 dev_dbg(&ioa_cfg
->pdev
->dev
, "ioa_cfg adx: 0x%p\n", ioa_cfg
);
7894 if (ioa_cfg
->needs_hard_reset
) {
7895 ioa_cfg
->needs_hard_reset
= 0;
7896 ipr_initiate_ioa_reset(ioa_cfg
, IPR_SHUTDOWN_NONE
);
7898 _ipr_initiate_ioa_reset(ioa_cfg
, ipr_reset_enable_ioa
,
7901 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, host_lock_flags
);
7902 wait_event(ioa_cfg
->reset_wait_q
, !ioa_cfg
->in_reset_reload
);
7903 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, host_lock_flags
);
7905 if (ioa_cfg
->ioa_is_dead
) {
7907 } else if (ipr_invalid_adapter(ioa_cfg
)) {
7911 dev_err(&ioa_cfg
->pdev
->dev
,
7912 "Adapter not supported in this hardware configuration.\n");
7915 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, host_lock_flags
);
7922 * ipr_free_cmd_blks - Frees command blocks allocated for an adapter
7923 * @ioa_cfg: ioa config struct
7928 static void ipr_free_cmd_blks(struct ipr_ioa_cfg
*ioa_cfg
)
7932 for (i
= 0; i
< IPR_NUM_CMD_BLKS
; i
++) {
7933 if (ioa_cfg
->ipr_cmnd_list
[i
])
7934 pci_pool_free(ioa_cfg
->ipr_cmd_pool
,
7935 ioa_cfg
->ipr_cmnd_list
[i
],
7936 ioa_cfg
->ipr_cmnd_list_dma
[i
]);
7938 ioa_cfg
->ipr_cmnd_list
[i
] = NULL
;
7941 if (ioa_cfg
->ipr_cmd_pool
)
7942 pci_pool_destroy (ioa_cfg
->ipr_cmd_pool
);
7944 ioa_cfg
->ipr_cmd_pool
= NULL
;
7948 * ipr_free_mem - Frees memory allocated for an adapter
7949 * @ioa_cfg: ioa cfg struct
7954 static void ipr_free_mem(struct ipr_ioa_cfg
*ioa_cfg
)
7958 kfree(ioa_cfg
->res_entries
);
7959 pci_free_consistent(ioa_cfg
->pdev
, sizeof(struct ipr_misc_cbs
),
7960 ioa_cfg
->vpd_cbs
, ioa_cfg
->vpd_cbs_dma
);
7961 ipr_free_cmd_blks(ioa_cfg
);
7962 pci_free_consistent(ioa_cfg
->pdev
, sizeof(u32
) * IPR_NUM_CMD_BLKS
,
7963 ioa_cfg
->host_rrq
, ioa_cfg
->host_rrq_dma
);
7964 pci_free_consistent(ioa_cfg
->pdev
, ioa_cfg
->cfg_table_size
,
7965 ioa_cfg
->u
.cfg_table
,
7966 ioa_cfg
->cfg_table_dma
);
7968 for (i
= 0; i
< IPR_NUM_HCAMS
; i
++) {
7969 pci_free_consistent(ioa_cfg
->pdev
,
7970 sizeof(struct ipr_hostrcb
),
7971 ioa_cfg
->hostrcb
[i
],
7972 ioa_cfg
->hostrcb_dma
[i
]);
7975 ipr_free_dump(ioa_cfg
);
7976 kfree(ioa_cfg
->trace
);
7980 * ipr_free_all_resources - Free all allocated resources for an adapter.
7981 * @ipr_cmd: ipr command struct
7983 * This function frees all allocated resources for the
7984 * specified adapter.
7989 static void ipr_free_all_resources(struct ipr_ioa_cfg
*ioa_cfg
)
7991 struct pci_dev
*pdev
= ioa_cfg
->pdev
;
7994 free_irq(pdev
->irq
, ioa_cfg
);
7995 pci_disable_msi(pdev
);
7996 iounmap(ioa_cfg
->hdw_dma_regs
);
7997 pci_release_regions(pdev
);
7998 ipr_free_mem(ioa_cfg
);
7999 scsi_host_put(ioa_cfg
->host
);
8000 pci_disable_device(pdev
);
8005 * ipr_alloc_cmd_blks - Allocate command blocks for an adapter
8006 * @ioa_cfg: ioa config struct
8009 * 0 on success / -ENOMEM on allocation failure
8011 static int __devinit
ipr_alloc_cmd_blks(struct ipr_ioa_cfg
*ioa_cfg
)
8013 struct ipr_cmnd
*ipr_cmd
;
8014 struct ipr_ioarcb
*ioarcb
;
8015 dma_addr_t dma_addr
;
8018 ioa_cfg
->ipr_cmd_pool
= pci_pool_create (IPR_NAME
, ioa_cfg
->pdev
,
8019 sizeof(struct ipr_cmnd
), 16, 0);
8021 if (!ioa_cfg
->ipr_cmd_pool
)
8024 for (i
= 0; i
< IPR_NUM_CMD_BLKS
; i
++) {
8025 ipr_cmd
= pci_pool_alloc (ioa_cfg
->ipr_cmd_pool
, GFP_KERNEL
, &dma_addr
);
8028 ipr_free_cmd_blks(ioa_cfg
);
8032 memset(ipr_cmd
, 0, sizeof(*ipr_cmd
));
8033 ioa_cfg
->ipr_cmnd_list
[i
] = ipr_cmd
;
8034 ioa_cfg
->ipr_cmnd_list_dma
[i
] = dma_addr
;
8036 ioarcb
= &ipr_cmd
->ioarcb
;
8037 ipr_cmd
->dma_addr
= dma_addr
;
8039 ioarcb
->a
.ioarcb_host_pci_addr64
= cpu_to_be64(dma_addr
);
8041 ioarcb
->a
.ioarcb_host_pci_addr
= cpu_to_be32(dma_addr
);
8043 ioarcb
->host_response_handle
= cpu_to_be32(i
<< 2);
8044 if (ioa_cfg
->sis64
) {
8045 ioarcb
->u
.sis64_addr_data
.data_ioadl_addr
=
8046 cpu_to_be64(dma_addr
+ offsetof(struct ipr_cmnd
, i
.ioadl64
));
8047 ioarcb
->u
.sis64_addr_data
.ioasa_host_pci_addr
=
8048 cpu_to_be64(dma_addr
+ offsetof(struct ipr_cmnd
, ioasa
));
8050 ioarcb
->write_ioadl_addr
=
8051 cpu_to_be32(dma_addr
+ offsetof(struct ipr_cmnd
, i
.ioadl
));
8052 ioarcb
->read_ioadl_addr
= ioarcb
->write_ioadl_addr
;
8053 ioarcb
->ioasa_host_pci_addr
=
8054 cpu_to_be32(dma_addr
+ offsetof(struct ipr_cmnd
, ioasa
));
8056 ioarcb
->ioasa_len
= cpu_to_be16(sizeof(struct ipr_ioasa
));
8057 ipr_cmd
->cmd_index
= i
;
8058 ipr_cmd
->ioa_cfg
= ioa_cfg
;
8059 ipr_cmd
->sense_buffer_dma
= dma_addr
+
8060 offsetof(struct ipr_cmnd
, sense_buffer
);
8062 list_add_tail(&ipr_cmd
->queue
, &ioa_cfg
->free_q
);
8069 * ipr_alloc_mem - Allocate memory for an adapter
8070 * @ioa_cfg: ioa config struct
8073 * 0 on success / non-zero for error
8075 static int __devinit
ipr_alloc_mem(struct ipr_ioa_cfg
*ioa_cfg
)
8077 struct pci_dev
*pdev
= ioa_cfg
->pdev
;
8078 int i
, rc
= -ENOMEM
;
8081 ioa_cfg
->res_entries
= kzalloc(sizeof(struct ipr_resource_entry
) *
8082 ioa_cfg
->max_devs_supported
, GFP_KERNEL
);
8084 if (!ioa_cfg
->res_entries
)
8087 if (ioa_cfg
->sis64
) {
8088 ioa_cfg
->target_ids
= kzalloc(sizeof(unsigned long) *
8089 BITS_TO_LONGS(ioa_cfg
->max_devs_supported
), GFP_KERNEL
);
8090 ioa_cfg
->array_ids
= kzalloc(sizeof(unsigned long) *
8091 BITS_TO_LONGS(ioa_cfg
->max_devs_supported
), GFP_KERNEL
);
8092 ioa_cfg
->vset_ids
= kzalloc(sizeof(unsigned long) *
8093 BITS_TO_LONGS(ioa_cfg
->max_devs_supported
), GFP_KERNEL
);
8096 for (i
= 0; i
< ioa_cfg
->max_devs_supported
; i
++) {
8097 list_add_tail(&ioa_cfg
->res_entries
[i
].queue
, &ioa_cfg
->free_res_q
);
8098 ioa_cfg
->res_entries
[i
].ioa_cfg
= ioa_cfg
;
8101 ioa_cfg
->vpd_cbs
= pci_alloc_consistent(ioa_cfg
->pdev
,
8102 sizeof(struct ipr_misc_cbs
),
8103 &ioa_cfg
->vpd_cbs_dma
);
8105 if (!ioa_cfg
->vpd_cbs
)
8106 goto out_free_res_entries
;
8108 if (ipr_alloc_cmd_blks(ioa_cfg
))
8109 goto out_free_vpd_cbs
;
8111 ioa_cfg
->host_rrq
= pci_alloc_consistent(ioa_cfg
->pdev
,
8112 sizeof(u32
) * IPR_NUM_CMD_BLKS
,
8113 &ioa_cfg
->host_rrq_dma
);
8115 if (!ioa_cfg
->host_rrq
)
8116 goto out_ipr_free_cmd_blocks
;
8118 ioa_cfg
->u
.cfg_table
= pci_alloc_consistent(ioa_cfg
->pdev
,
8119 ioa_cfg
->cfg_table_size
,
8120 &ioa_cfg
->cfg_table_dma
);
8122 if (!ioa_cfg
->u
.cfg_table
)
8123 goto out_free_host_rrq
;
8125 for (i
= 0; i
< IPR_NUM_HCAMS
; i
++) {
8126 ioa_cfg
->hostrcb
[i
] = pci_alloc_consistent(ioa_cfg
->pdev
,
8127 sizeof(struct ipr_hostrcb
),
8128 &ioa_cfg
->hostrcb_dma
[i
]);
8130 if (!ioa_cfg
->hostrcb
[i
])
8131 goto out_free_hostrcb_dma
;
8133 ioa_cfg
->hostrcb
[i
]->hostrcb_dma
=
8134 ioa_cfg
->hostrcb_dma
[i
] + offsetof(struct ipr_hostrcb
, hcam
);
8135 ioa_cfg
->hostrcb
[i
]->ioa_cfg
= ioa_cfg
;
8136 list_add_tail(&ioa_cfg
->hostrcb
[i
]->queue
, &ioa_cfg
->hostrcb_free_q
);
8139 ioa_cfg
->trace
= kzalloc(sizeof(struct ipr_trace_entry
) *
8140 IPR_NUM_TRACE_ENTRIES
, GFP_KERNEL
);
8142 if (!ioa_cfg
->trace
)
8143 goto out_free_hostrcb_dma
;
8150 out_free_hostrcb_dma
:
8152 pci_free_consistent(pdev
, sizeof(struct ipr_hostrcb
),
8153 ioa_cfg
->hostrcb
[i
],
8154 ioa_cfg
->hostrcb_dma
[i
]);
8156 pci_free_consistent(pdev
, ioa_cfg
->cfg_table_size
,
8157 ioa_cfg
->u
.cfg_table
,
8158 ioa_cfg
->cfg_table_dma
);
8160 pci_free_consistent(pdev
, sizeof(u32
) * IPR_NUM_CMD_BLKS
,
8161 ioa_cfg
->host_rrq
, ioa_cfg
->host_rrq_dma
);
8162 out_ipr_free_cmd_blocks
:
8163 ipr_free_cmd_blks(ioa_cfg
);
8165 pci_free_consistent(pdev
, sizeof(struct ipr_misc_cbs
),
8166 ioa_cfg
->vpd_cbs
, ioa_cfg
->vpd_cbs_dma
);
8167 out_free_res_entries
:
8168 kfree(ioa_cfg
->res_entries
);
8173 * ipr_initialize_bus_attr - Initialize SCSI bus attributes to default values
8174 * @ioa_cfg: ioa config struct
8179 static void __devinit
ipr_initialize_bus_attr(struct ipr_ioa_cfg
*ioa_cfg
)
8183 for (i
= 0; i
< IPR_MAX_NUM_BUSES
; i
++) {
8184 ioa_cfg
->bus_attr
[i
].bus
= i
;
8185 ioa_cfg
->bus_attr
[i
].qas_enabled
= 0;
8186 ioa_cfg
->bus_attr
[i
].bus_width
= IPR_DEFAULT_BUS_WIDTH
;
8187 if (ipr_max_speed
< ARRAY_SIZE(ipr_max_bus_speeds
))
8188 ioa_cfg
->bus_attr
[i
].max_xfer_rate
= ipr_max_bus_speeds
[ipr_max_speed
];
8190 ioa_cfg
->bus_attr
[i
].max_xfer_rate
= IPR_U160_SCSI_RATE
;
8195 * ipr_init_ioa_cfg - Initialize IOA config struct
8196 * @ioa_cfg: ioa config struct
8197 * @host: scsi host struct
8198 * @pdev: PCI dev struct
8203 static void __devinit
ipr_init_ioa_cfg(struct ipr_ioa_cfg
*ioa_cfg
,
8204 struct Scsi_Host
*host
, struct pci_dev
*pdev
)
8206 const struct ipr_interrupt_offsets
*p
;
8207 struct ipr_interrupts
*t
;
8210 ioa_cfg
->host
= host
;
8211 ioa_cfg
->pdev
= pdev
;
8212 ioa_cfg
->log_level
= ipr_log_level
;
8213 ioa_cfg
->doorbell
= IPR_DOORBELL
;
8214 sprintf(ioa_cfg
->eye_catcher
, IPR_EYECATCHER
);
8215 sprintf(ioa_cfg
->trace_start
, IPR_TRACE_START_LABEL
);
8216 sprintf(ioa_cfg
->ipr_free_label
, IPR_FREEQ_LABEL
);
8217 sprintf(ioa_cfg
->ipr_pending_label
, IPR_PENDQ_LABEL
);
8218 sprintf(ioa_cfg
->cfg_table_start
, IPR_CFG_TBL_START
);
8219 sprintf(ioa_cfg
->resource_table_label
, IPR_RES_TABLE_LABEL
);
8220 sprintf(ioa_cfg
->ipr_hcam_label
, IPR_HCAM_LABEL
);
8221 sprintf(ioa_cfg
->ipr_cmd_label
, IPR_CMD_LABEL
);
8223 INIT_LIST_HEAD(&ioa_cfg
->free_q
);
8224 INIT_LIST_HEAD(&ioa_cfg
->pending_q
);
8225 INIT_LIST_HEAD(&ioa_cfg
->hostrcb_free_q
);
8226 INIT_LIST_HEAD(&ioa_cfg
->hostrcb_pending_q
);
8227 INIT_LIST_HEAD(&ioa_cfg
->free_res_q
);
8228 INIT_LIST_HEAD(&ioa_cfg
->used_res_q
);
8229 INIT_WORK(&ioa_cfg
->work_q
, ipr_worker_thread
);
8230 init_waitqueue_head(&ioa_cfg
->reset_wait_q
);
8231 init_waitqueue_head(&ioa_cfg
->msi_wait_q
);
8232 ioa_cfg
->sdt_state
= INACTIVE
;
8234 ipr_initialize_bus_attr(ioa_cfg
);
8235 ioa_cfg
->max_devs_supported
= ipr_max_devs
;
8237 if (ioa_cfg
->sis64
) {
8238 host
->max_id
= IPR_MAX_SIS64_TARGETS_PER_BUS
;
8239 host
->max_lun
= IPR_MAX_SIS64_LUNS_PER_TARGET
;
8240 if (ipr_max_devs
> IPR_MAX_SIS64_DEVS
)
8241 ioa_cfg
->max_devs_supported
= IPR_MAX_SIS64_DEVS
;
8243 host
->max_id
= IPR_MAX_NUM_TARGETS_PER_BUS
;
8244 host
->max_lun
= IPR_MAX_NUM_LUNS_PER_TARGET
;
8245 if (ipr_max_devs
> IPR_MAX_PHYSICAL_DEVS
)
8246 ioa_cfg
->max_devs_supported
= IPR_MAX_PHYSICAL_DEVS
;
8248 host
->max_channel
= IPR_MAX_BUS_TO_SCAN
;
8249 host
->unique_id
= host
->host_no
;
8250 host
->max_cmd_len
= IPR_MAX_CDB_LEN
;
8251 pci_set_drvdata(pdev
, ioa_cfg
);
8253 p
= &ioa_cfg
->chip_cfg
->regs
;
8255 base
= ioa_cfg
->hdw_dma_regs
;
8257 t
->set_interrupt_mask_reg
= base
+ p
->set_interrupt_mask_reg
;
8258 t
->clr_interrupt_mask_reg
= base
+ p
->clr_interrupt_mask_reg
;
8259 t
->clr_interrupt_mask_reg32
= base
+ p
->clr_interrupt_mask_reg32
;
8260 t
->sense_interrupt_mask_reg
= base
+ p
->sense_interrupt_mask_reg
;
8261 t
->sense_interrupt_mask_reg32
= base
+ p
->sense_interrupt_mask_reg32
;
8262 t
->clr_interrupt_reg
= base
+ p
->clr_interrupt_reg
;
8263 t
->clr_interrupt_reg32
= base
+ p
->clr_interrupt_reg32
;
8264 t
->sense_interrupt_reg
= base
+ p
->sense_interrupt_reg
;
8265 t
->sense_interrupt_reg32
= base
+ p
->sense_interrupt_reg32
;
8266 t
->ioarrin_reg
= base
+ p
->ioarrin_reg
;
8267 t
->sense_uproc_interrupt_reg
= base
+ p
->sense_uproc_interrupt_reg
;
8268 t
->sense_uproc_interrupt_reg32
= base
+ p
->sense_uproc_interrupt_reg32
;
8269 t
->set_uproc_interrupt_reg
= base
+ p
->set_uproc_interrupt_reg
;
8270 t
->set_uproc_interrupt_reg32
= base
+ p
->set_uproc_interrupt_reg32
;
8271 t
->clr_uproc_interrupt_reg
= base
+ p
->clr_uproc_interrupt_reg
;
8272 t
->clr_uproc_interrupt_reg32
= base
+ p
->clr_uproc_interrupt_reg32
;
8274 if (ioa_cfg
->sis64
) {
8275 t
->init_feedback_reg
= base
+ p
->init_feedback_reg
;
8276 t
->dump_addr_reg
= base
+ p
->dump_addr_reg
;
8277 t
->dump_data_reg
= base
+ p
->dump_data_reg
;
8282 * ipr_get_chip_info - Find adapter chip information
8283 * @dev_id: PCI device id struct
8286 * ptr to chip information on success / NULL on failure
8288 static const struct ipr_chip_t
* __devinit
8289 ipr_get_chip_info(const struct pci_device_id
*dev_id
)
8293 for (i
= 0; i
< ARRAY_SIZE(ipr_chip
); i
++)
8294 if (ipr_chip
[i
].vendor
== dev_id
->vendor
&&
8295 ipr_chip
[i
].device
== dev_id
->device
)
8296 return &ipr_chip
[i
];
8301 * ipr_test_intr - Handle the interrupt generated in ipr_test_msi().
8302 * @pdev: PCI device struct
8304 * Description: Simply set the msi_received flag to 1 indicating that
8305 * Message Signaled Interrupts are supported.
8308 * 0 on success / non-zero on failure
8310 static irqreturn_t __devinit
ipr_test_intr(int irq
, void *devp
)
8312 struct ipr_ioa_cfg
*ioa_cfg
= (struct ipr_ioa_cfg
*)devp
;
8313 unsigned long lock_flags
= 0;
8314 irqreturn_t rc
= IRQ_HANDLED
;
8316 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
8318 ioa_cfg
->msi_received
= 1;
8319 wake_up(&ioa_cfg
->msi_wait_q
);
8321 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
8326 * ipr_test_msi - Test for Message Signaled Interrupt (MSI) support.
8327 * @pdev: PCI device struct
8329 * Description: The return value from pci_enable_msi() can not always be
8330 * trusted. This routine sets up and initiates a test interrupt to determine
8331 * if the interrupt is received via the ipr_test_intr() service routine.
8332 * If the tests fails, the driver will fall back to LSI.
8335 * 0 on success / non-zero on failure
8337 static int __devinit
ipr_test_msi(struct ipr_ioa_cfg
*ioa_cfg
,
8338 struct pci_dev
*pdev
)
8341 volatile u32 int_reg
;
8342 unsigned long lock_flags
= 0;
8346 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
8347 init_waitqueue_head(&ioa_cfg
->msi_wait_q
);
8348 ioa_cfg
->msi_received
= 0;
8349 ipr_mask_and_clear_interrupts(ioa_cfg
, ~IPR_PCII_IOA_TRANS_TO_OPER
);
8350 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE
, ioa_cfg
->regs
.clr_interrupt_mask_reg32
);
8351 int_reg
= readl(ioa_cfg
->regs
.sense_interrupt_mask_reg
);
8352 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
8354 rc
= request_irq(pdev
->irq
, ipr_test_intr
, 0, IPR_NAME
, ioa_cfg
);
8356 dev_err(&pdev
->dev
, "Can not assign irq %d\n", pdev
->irq
);
8358 } else if (ipr_debug
)
8359 dev_info(&pdev
->dev
, "IRQ assigned: %d\n", pdev
->irq
);
8361 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE
, ioa_cfg
->regs
.sense_interrupt_reg32
);
8362 int_reg
= readl(ioa_cfg
->regs
.sense_interrupt_reg
);
8363 wait_event_timeout(ioa_cfg
->msi_wait_q
, ioa_cfg
->msi_received
, HZ
);
8364 ipr_mask_and_clear_interrupts(ioa_cfg
, ~IPR_PCII_IOA_TRANS_TO_OPER
);
8366 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
8367 if (!ioa_cfg
->msi_received
) {
8368 /* MSI test failed */
8369 dev_info(&pdev
->dev
, "MSI test failed. Falling back to LSI.\n");
8371 } else if (ipr_debug
)
8372 dev_info(&pdev
->dev
, "MSI test succeeded.\n");
8374 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
8376 free_irq(pdev
->irq
, ioa_cfg
);
8384 * ipr_probe_ioa - Allocates memory and does first stage of initialization
8385 * @pdev: PCI device struct
8386 * @dev_id: PCI device id struct
8389 * 0 on success / non-zero on failure
8391 static int __devinit
ipr_probe_ioa(struct pci_dev
*pdev
,
8392 const struct pci_device_id
*dev_id
)
8394 struct ipr_ioa_cfg
*ioa_cfg
;
8395 struct Scsi_Host
*host
;
8396 unsigned long ipr_regs_pci
;
8397 void __iomem
*ipr_regs
;
8398 int rc
= PCIBIOS_SUCCESSFUL
;
8399 volatile u32 mask
, uproc
, interrupts
;
8403 if ((rc
= pci_enable_device(pdev
))) {
8404 dev_err(&pdev
->dev
, "Cannot enable adapter\n");
8408 dev_info(&pdev
->dev
, "Found IOA with IRQ: %d\n", pdev
->irq
);
8410 host
= scsi_host_alloc(&driver_template
, sizeof(*ioa_cfg
));
8413 dev_err(&pdev
->dev
, "call to scsi_host_alloc failed!\n");
8418 ioa_cfg
= (struct ipr_ioa_cfg
*)host
->hostdata
;
8419 memset(ioa_cfg
, 0, sizeof(struct ipr_ioa_cfg
));
8420 ata_host_init(&ioa_cfg
->ata_host
, &pdev
->dev
,
8421 sata_port_info
.flags
, &ipr_sata_ops
);
8423 ioa_cfg
->ipr_chip
= ipr_get_chip_info(dev_id
);
8425 if (!ioa_cfg
->ipr_chip
) {
8426 dev_err(&pdev
->dev
, "Unknown adapter chipset 0x%04X 0x%04X\n",
8427 dev_id
->vendor
, dev_id
->device
);
8428 goto out_scsi_host_put
;
8431 /* set SIS 32 or SIS 64 */
8432 ioa_cfg
->sis64
= ioa_cfg
->ipr_chip
->sis_type
== IPR_SIS64
? 1 : 0;
8433 ioa_cfg
->chip_cfg
= ioa_cfg
->ipr_chip
->cfg
;
8435 if (ipr_transop_timeout
)
8436 ioa_cfg
->transop_timeout
= ipr_transop_timeout
;
8437 else if (dev_id
->driver_data
& IPR_USE_LONG_TRANSOP_TIMEOUT
)
8438 ioa_cfg
->transop_timeout
= IPR_LONG_OPERATIONAL_TIMEOUT
;
8440 ioa_cfg
->transop_timeout
= IPR_OPERATIONAL_TIMEOUT
;
8442 ioa_cfg
->revid
= pdev
->revision
;
8444 ipr_regs_pci
= pci_resource_start(pdev
, 0);
8446 rc
= pci_request_regions(pdev
, IPR_NAME
);
8449 "Couldn't register memory range of registers\n");
8450 goto out_scsi_host_put
;
8453 ipr_regs
= pci_ioremap_bar(pdev
, 0);
8457 "Couldn't map memory range of registers\n");
8459 goto out_release_regions
;
8462 ioa_cfg
->hdw_dma_regs
= ipr_regs
;
8463 ioa_cfg
->hdw_dma_regs_pci
= ipr_regs_pci
;
8464 ioa_cfg
->ioa_mailbox
= ioa_cfg
->chip_cfg
->mailbox
+ ipr_regs
;
8466 ipr_init_ioa_cfg(ioa_cfg
, host
, pdev
);
8468 pci_set_master(pdev
);
8470 if (ioa_cfg
->sis64
) {
8471 rc
= pci_set_dma_mask(pdev
, DMA_BIT_MASK(64));
8473 dev_dbg(&pdev
->dev
, "Failed to set 64 bit PCI DMA mask\n");
8474 rc
= pci_set_dma_mask(pdev
, DMA_BIT_MASK(32));
8478 rc
= pci_set_dma_mask(pdev
, DMA_BIT_MASK(32));
8481 dev_err(&pdev
->dev
, "Failed to set PCI DMA mask\n");
8485 rc
= pci_write_config_byte(pdev
, PCI_CACHE_LINE_SIZE
,
8486 ioa_cfg
->chip_cfg
->cache_line_size
);
8488 if (rc
!= PCIBIOS_SUCCESSFUL
) {
8489 dev_err(&pdev
->dev
, "Write of cache line size failed\n");
8494 /* Enable MSI style interrupts if they are supported. */
8495 if (ioa_cfg
->ipr_chip
->intr_type
== IPR_USE_MSI
&& !pci_enable_msi(pdev
)) {
8496 rc
= ipr_test_msi(ioa_cfg
, pdev
);
8497 if (rc
== -EOPNOTSUPP
)
8498 pci_disable_msi(pdev
);
8500 goto out_msi_disable
;
8502 dev_info(&pdev
->dev
, "MSI enabled with IRQ: %d\n", pdev
->irq
);
8503 } else if (ipr_debug
)
8504 dev_info(&pdev
->dev
, "Cannot enable MSI.\n");
8506 /* Save away PCI config space for use following IOA reset */
8507 rc
= pci_save_state(pdev
);
8509 if (rc
!= PCIBIOS_SUCCESSFUL
) {
8510 dev_err(&pdev
->dev
, "Failed to save PCI config space\n");
8515 if ((rc
= ipr_save_pcix_cmd_reg(ioa_cfg
)))
8518 if ((rc
= ipr_set_pcix_cmd_reg(ioa_cfg
)))
8522 ioa_cfg
->cfg_table_size
= (sizeof(struct ipr_config_table_hdr64
)
8523 + ((sizeof(struct ipr_config_table_entry64
)
8524 * ioa_cfg
->max_devs_supported
)));
8526 ioa_cfg
->cfg_table_size
= (sizeof(struct ipr_config_table_hdr
)
8527 + ((sizeof(struct ipr_config_table_entry
)
8528 * ioa_cfg
->max_devs_supported
)));
8530 rc
= ipr_alloc_mem(ioa_cfg
);
8533 "Couldn't allocate enough memory for device driver!\n");
8538 * If HRRQ updated interrupt is not masked, or reset alert is set,
8539 * the card is in an unknown state and needs a hard reset
8541 mask
= readl(ioa_cfg
->regs
.sense_interrupt_mask_reg32
);
8542 interrupts
= readl(ioa_cfg
->regs
.sense_interrupt_reg32
);
8543 uproc
= readl(ioa_cfg
->regs
.sense_uproc_interrupt_reg32
);
8544 if ((mask
& IPR_PCII_HRRQ_UPDATED
) == 0 || (uproc
& IPR_UPROCI_RESET_ALERT
))
8545 ioa_cfg
->needs_hard_reset
= 1;
8546 if (interrupts
& IPR_PCII_ERROR_INTERRUPTS
)
8547 ioa_cfg
->needs_hard_reset
= 1;
8548 if (interrupts
& IPR_PCII_IOA_UNIT_CHECKED
)
8549 ioa_cfg
->ioa_unit_checked
= 1;
8551 ipr_mask_and_clear_interrupts(ioa_cfg
, ~IPR_PCII_IOA_TRANS_TO_OPER
);
8552 rc
= request_irq(pdev
->irq
, ipr_isr
,
8553 ioa_cfg
->msi_received
? 0 : IRQF_SHARED
,
8557 dev_err(&pdev
->dev
, "Couldn't register IRQ %d! rc=%d\n",
8562 if ((dev_id
->driver_data
& IPR_USE_PCI_WARM_RESET
) ||
8563 (dev_id
->device
== PCI_DEVICE_ID_IBM_OBSIDIAN_E
&& !ioa_cfg
->revid
)) {
8564 ioa_cfg
->needs_warm_reset
= 1;
8565 ioa_cfg
->reset
= ipr_reset_slot_reset
;
8567 ioa_cfg
->reset
= ipr_reset_start_bist
;
8569 spin_lock(&ipr_driver_lock
);
8570 list_add_tail(&ioa_cfg
->queue
, &ipr_ioa_head
);
8571 spin_unlock(&ipr_driver_lock
);
8578 ipr_free_mem(ioa_cfg
);
8582 pci_disable_msi(pdev
);
8583 out_release_regions
:
8584 pci_release_regions(pdev
);
8586 scsi_host_put(host
);
8588 pci_disable_device(pdev
);
8593 * ipr_scan_vsets - Scans for VSET devices
8594 * @ioa_cfg: ioa config struct
8596 * Description: Since the VSET resources do not follow SAM in that we can have
8597 * sparse LUNs with no LUN 0, we have to scan for these ourselves.
8602 static void ipr_scan_vsets(struct ipr_ioa_cfg
*ioa_cfg
)
8606 for (target
= 0; target
< IPR_MAX_NUM_TARGETS_PER_BUS
; target
++)
8607 for (lun
= 0; lun
< IPR_MAX_NUM_VSET_LUNS_PER_TARGET
; lun
++ )
8608 scsi_add_device(ioa_cfg
->host
, IPR_VSET_BUS
, target
, lun
);
8612 * ipr_initiate_ioa_bringdown - Bring down an adapter
8613 * @ioa_cfg: ioa config struct
8614 * @shutdown_type: shutdown type
8616 * Description: This function will initiate bringing down the adapter.
8617 * This consists of issuing an IOA shutdown to the adapter
8618 * to flush the cache, and running BIST.
8619 * If the caller needs to wait on the completion of the reset,
8620 * the caller must sleep on the reset_wait_q.
8625 static void ipr_initiate_ioa_bringdown(struct ipr_ioa_cfg
*ioa_cfg
,
8626 enum ipr_shutdown_type shutdown_type
)
8629 if (ioa_cfg
->sdt_state
== WAIT_FOR_DUMP
)
8630 ioa_cfg
->sdt_state
= ABORT_DUMP
;
8631 ioa_cfg
->reset_retries
= 0;
8632 ioa_cfg
->in_ioa_bringdown
= 1;
8633 ipr_initiate_ioa_reset(ioa_cfg
, shutdown_type
);
8638 * __ipr_remove - Remove a single adapter
8639 * @pdev: pci device struct
8641 * Adapter hot plug remove entry point.
8646 static void __ipr_remove(struct pci_dev
*pdev
)
8648 unsigned long host_lock_flags
= 0;
8649 struct ipr_ioa_cfg
*ioa_cfg
= pci_get_drvdata(pdev
);
8652 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, host_lock_flags
);
8653 while(ioa_cfg
->in_reset_reload
) {
8654 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, host_lock_flags
);
8655 wait_event(ioa_cfg
->reset_wait_q
, !ioa_cfg
->in_reset_reload
);
8656 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, host_lock_flags
);
8659 ipr_initiate_ioa_bringdown(ioa_cfg
, IPR_SHUTDOWN_NORMAL
);
8661 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, host_lock_flags
);
8662 wait_event(ioa_cfg
->reset_wait_q
, !ioa_cfg
->in_reset_reload
);
8663 flush_scheduled_work();
8664 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, host_lock_flags
);
8666 spin_lock(&ipr_driver_lock
);
8667 list_del(&ioa_cfg
->queue
);
8668 spin_unlock(&ipr_driver_lock
);
8670 if (ioa_cfg
->sdt_state
== ABORT_DUMP
)
8671 ioa_cfg
->sdt_state
= WAIT_FOR_DUMP
;
8672 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, host_lock_flags
);
8674 ipr_free_all_resources(ioa_cfg
);
8680 * ipr_remove - IOA hot plug remove entry point
8681 * @pdev: pci device struct
8683 * Adapter hot plug remove entry point.
8688 static void __devexit
ipr_remove(struct pci_dev
*pdev
)
8690 struct ipr_ioa_cfg
*ioa_cfg
= pci_get_drvdata(pdev
);
8694 ipr_remove_trace_file(&ioa_cfg
->host
->shost_dev
.kobj
,
8696 ipr_remove_dump_file(&ioa_cfg
->host
->shost_dev
.kobj
,
8698 scsi_remove_host(ioa_cfg
->host
);
8706 * ipr_probe - Adapter hot plug add entry point
8709 * 0 on success / non-zero on failure
8711 static int __devinit
ipr_probe(struct pci_dev
*pdev
,
8712 const struct pci_device_id
*dev_id
)
8714 struct ipr_ioa_cfg
*ioa_cfg
;
8717 rc
= ipr_probe_ioa(pdev
, dev_id
);
8722 ioa_cfg
= pci_get_drvdata(pdev
);
8723 rc
= ipr_probe_ioa_part2(ioa_cfg
);
8730 rc
= scsi_add_host(ioa_cfg
->host
, &pdev
->dev
);
8737 rc
= ipr_create_trace_file(&ioa_cfg
->host
->shost_dev
.kobj
,
8741 scsi_remove_host(ioa_cfg
->host
);
8746 rc
= ipr_create_dump_file(&ioa_cfg
->host
->shost_dev
.kobj
,
8750 ipr_remove_trace_file(&ioa_cfg
->host
->shost_dev
.kobj
,
8752 scsi_remove_host(ioa_cfg
->host
);
8757 scsi_scan_host(ioa_cfg
->host
);
8758 ipr_scan_vsets(ioa_cfg
);
8759 scsi_add_device(ioa_cfg
->host
, IPR_IOA_BUS
, IPR_IOA_TARGET
, IPR_IOA_LUN
);
8760 ioa_cfg
->allow_ml_add_del
= 1;
8761 ioa_cfg
->host
->max_channel
= IPR_VSET_BUS
;
8762 schedule_work(&ioa_cfg
->work_q
);
8767 * ipr_shutdown - Shutdown handler.
8768 * @pdev: pci device struct
8770 * This function is invoked upon system shutdown/reboot. It will issue
8771 * an adapter shutdown to the adapter to flush the write cache.
8776 static void ipr_shutdown(struct pci_dev
*pdev
)
8778 struct ipr_ioa_cfg
*ioa_cfg
= pci_get_drvdata(pdev
);
8779 unsigned long lock_flags
= 0;
8781 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
8782 while(ioa_cfg
->in_reset_reload
) {
8783 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
8784 wait_event(ioa_cfg
->reset_wait_q
, !ioa_cfg
->in_reset_reload
);
8785 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, lock_flags
);
8788 ipr_initiate_ioa_bringdown(ioa_cfg
, IPR_SHUTDOWN_NORMAL
);
8789 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, lock_flags
);
8790 wait_event(ioa_cfg
->reset_wait_q
, !ioa_cfg
->in_reset_reload
);
8793 static struct pci_device_id ipr_pci_table
[] __devinitdata
= {
8794 { PCI_VENDOR_ID_MYLEX
, PCI_DEVICE_ID_IBM_GEMSTONE
,
8795 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_5702
, 0, 0, 0 },
8796 { PCI_VENDOR_ID_MYLEX
, PCI_DEVICE_ID_IBM_GEMSTONE
,
8797 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_5703
, 0, 0, 0 },
8798 { PCI_VENDOR_ID_MYLEX
, PCI_DEVICE_ID_IBM_GEMSTONE
,
8799 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_573D
, 0, 0, 0 },
8800 { PCI_VENDOR_ID_MYLEX
, PCI_DEVICE_ID_IBM_GEMSTONE
,
8801 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_573E
, 0, 0, 0 },
8802 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_CITRINE
,
8803 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_571B
, 0, 0, 0 },
8804 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_CITRINE
,
8805 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_572E
, 0, 0, 0 },
8806 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_CITRINE
,
8807 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_571A
, 0, 0, 0 },
8808 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_CITRINE
,
8809 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_575B
, 0, 0,
8810 IPR_USE_LONG_TRANSOP_TIMEOUT
},
8811 { PCI_VENDOR_ID_ADAPTEC2
, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN
,
8812 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_572A
, 0, 0, 0 },
8813 { PCI_VENDOR_ID_ADAPTEC2
, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN
,
8814 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_572B
, 0, 0,
8815 IPR_USE_LONG_TRANSOP_TIMEOUT
},
8816 { PCI_VENDOR_ID_ADAPTEC2
, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN
,
8817 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_575C
, 0, 0,
8818 IPR_USE_LONG_TRANSOP_TIMEOUT
},
8819 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_OBSIDIAN
,
8820 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_572A
, 0, 0, 0 },
8821 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_OBSIDIAN
,
8822 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_572B
, 0, 0,
8823 IPR_USE_LONG_TRANSOP_TIMEOUT
},
8824 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_OBSIDIAN
,
8825 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_575C
, 0, 0,
8826 IPR_USE_LONG_TRANSOP_TIMEOUT
},
8827 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_OBSIDIAN_E
,
8828 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_574E
, 0, 0,
8829 IPR_USE_LONG_TRANSOP_TIMEOUT
},
8830 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_OBSIDIAN_E
,
8831 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_57B3
, 0, 0, 0 },
8832 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_OBSIDIAN_E
,
8833 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_57B7
, 0, 0,
8834 IPR_USE_LONG_TRANSOP_TIMEOUT
| IPR_USE_PCI_WARM_RESET
},
8835 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_SNIPE
,
8836 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_2780
, 0, 0, 0 },
8837 { PCI_VENDOR_ID_ADAPTEC2
, PCI_DEVICE_ID_ADAPTEC2_SCAMP
,
8838 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_571E
, 0, 0, 0 },
8839 { PCI_VENDOR_ID_ADAPTEC2
, PCI_DEVICE_ID_ADAPTEC2_SCAMP
,
8840 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_571F
, 0, 0,
8841 IPR_USE_LONG_TRANSOP_TIMEOUT
},
8842 { PCI_VENDOR_ID_ADAPTEC2
, PCI_DEVICE_ID_ADAPTEC2_SCAMP
,
8843 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_572F
, 0, 0,
8844 IPR_USE_LONG_TRANSOP_TIMEOUT
},
8845 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_CROC_FPGA_E2
,
8846 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_57B5
, 0, 0, 0 },
8847 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_CROC_FPGA_E2
,
8848 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_574D
, 0, 0, 0 },
8849 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_CROC_FPGA_E2
,
8850 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_57B2
, 0, 0, 0 },
8851 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_CROC_ASIC_E2
,
8852 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_57B4
, 0, 0, 0 },
8853 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_CROC_ASIC_E2
,
8854 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_57B1
, 0, 0, 0 },
8855 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_CROC_ASIC_E2
,
8856 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_57C6
, 0, 0, 0 },
8857 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_CROC_ASIC_E2
,
8858 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_575D
, 0, 0, 0 },
8859 { PCI_VENDOR_ID_IBM
, PCI_DEVICE_ID_IBM_CROC_ASIC_E2
,
8860 PCI_VENDOR_ID_IBM
, IPR_SUBS_DEV_ID_57CE
, 0, 0, 0 },
8863 MODULE_DEVICE_TABLE(pci
, ipr_pci_table
);
8865 static struct pci_error_handlers ipr_err_handler
= {
8866 .error_detected
= ipr_pci_error_detected
,
8867 .slot_reset
= ipr_pci_slot_reset
,
8870 static struct pci_driver ipr_driver
= {
8872 .id_table
= ipr_pci_table
,
8874 .remove
= __devexit_p(ipr_remove
),
8875 .shutdown
= ipr_shutdown
,
8876 .err_handler
= &ipr_err_handler
,
8880 * ipr_halt_done - Shutdown prepare completion
8885 static void ipr_halt_done(struct ipr_cmnd
*ipr_cmd
)
8887 struct ipr_ioa_cfg
*ioa_cfg
= ipr_cmd
->ioa_cfg
;
8889 list_add_tail(&ipr_cmd
->queue
, &ioa_cfg
->free_q
);
8893 * ipr_halt - Issue shutdown prepare to all adapters
8896 * NOTIFY_OK on success / NOTIFY_DONE on failure
8898 static int ipr_halt(struct notifier_block
*nb
, ulong event
, void *buf
)
8900 struct ipr_cmnd
*ipr_cmd
;
8901 struct ipr_ioa_cfg
*ioa_cfg
;
8902 unsigned long flags
= 0;
8904 if (event
!= SYS_RESTART
&& event
!= SYS_HALT
&& event
!= SYS_POWER_OFF
)
8907 spin_lock(&ipr_driver_lock
);
8909 list_for_each_entry(ioa_cfg
, &ipr_ioa_head
, queue
) {
8910 spin_lock_irqsave(ioa_cfg
->host
->host_lock
, flags
);
8911 if (!ioa_cfg
->allow_cmds
) {
8912 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, flags
);
8916 ipr_cmd
= ipr_get_free_ipr_cmnd(ioa_cfg
);
8917 ipr_cmd
->ioarcb
.res_handle
= cpu_to_be32(IPR_IOA_RES_HANDLE
);
8918 ipr_cmd
->ioarcb
.cmd_pkt
.request_type
= IPR_RQTYPE_IOACMD
;
8919 ipr_cmd
->ioarcb
.cmd_pkt
.cdb
[0] = IPR_IOA_SHUTDOWN
;
8920 ipr_cmd
->ioarcb
.cmd_pkt
.cdb
[1] = IPR_SHUTDOWN_PREPARE_FOR_NORMAL
;
8922 ipr_do_req(ipr_cmd
, ipr_halt_done
, ipr_timeout
, IPR_DEVICE_RESET_TIMEOUT
);
8923 spin_unlock_irqrestore(ioa_cfg
->host
->host_lock
, flags
);
8925 spin_unlock(&ipr_driver_lock
);
8930 static struct notifier_block ipr_notifier
= {
8935 * ipr_init - Module entry point
8938 * 0 on success / negative value on failure
8940 static int __init
ipr_init(void)
8942 ipr_info("IBM Power RAID SCSI Device Driver version: %s %s\n",
8943 IPR_DRIVER_VERSION
, IPR_DRIVER_DATE
);
8945 register_reboot_notifier(&ipr_notifier
);
8946 return pci_register_driver(&ipr_driver
);
8950 * ipr_exit - Module unload
8952 * Module unload entry point.
8957 static void __exit
ipr_exit(void)
8959 unregister_reboot_notifier(&ipr_notifier
);
8960 pci_unregister_driver(&ipr_driver
);
8963 module_init(ipr_init
);
8964 module_exit(ipr_exit
);