blob: 822b695e5b459bcaca92887e774f03b6443b280c [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Adaptec AAC series RAID controller driver
Alan Coxfa195af2008-10-27 15:16:36 +00003 * (c) Copyright 2001 Red Hat Inc.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
5 * based on the old aacraid driver that is..
6 * Adaptec aacraid device driver for Linux.
7 *
Mahesh Rajashekharae8b12f02011-03-17 02:10:32 -07008 * Copyright (c) 2000-2010 Adaptec, Inc.
9 * 2010 PMC-Sierra, Inc. (aacraid@pmc-sierra.com)
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2, or (at your option)
14 * any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; see the file COPYING. If not, write to
23 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24 *
25 * Module Name:
26 * linit.c
27 *
28 * Abstract: Linux Driver entry module for Adaptec RAID Array Controller
29 */
30
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
32#include <linux/compat.h>
33#include <linux/blkdev.h>
34#include <linux/completion.h>
35#include <linux/init.h>
36#include <linux/interrupt.h>
37#include <linux/kernel.h>
38#include <linux/module.h>
39#include <linux/moduleparam.h>
40#include <linux/pci.h>
Raghava Aditya Renukunta5c63f7f2016-02-03 15:06:01 -080041#include <linux/aer.h>
Vasily Averincf161232011-11-11 13:42:16 +040042#include <linux/pci-aspm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070043#include <linux/slab.h>
Arnd Bergmannc45d15d2010-06-02 14:28:52 +020044#include <linux/mutex.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#include <linux/spinlock.h>
46#include <linux/syscalls.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#include <linux/delay.h>
Christoph Hellwigfe273812006-02-14 18:45:06 +010048#include <linux/kthread.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
50#include <scsi/scsi.h>
51#include <scsi/scsi_cmnd.h>
52#include <scsi/scsi_device.h>
53#include <scsi/scsi_host.h>
54#include <scsi/scsi_tcq.h>
55#include <scsi/scsicam.h>
56#include <scsi/scsi_eh.h>
57
58#include "aacraid.h"
59
Mahesh Rajashekharaf20dffc2015-03-26 10:41:32 -040060#define AAC_DRIVER_VERSION "1.2-1"
Mark Haverkamp9a72f972006-03-27 09:44:37 -080061#ifndef AAC_DRIVER_BRANCH
62#define AAC_DRIVER_BRANCH ""
63#endif
Mark Haverkamp9a72f972006-03-27 09:44:37 -080064#define AAC_DRIVERNAME "aacraid"
65
Mark Haverkampc7f47602005-08-03 15:38:55 -070066#ifdef AAC_DRIVER_BUILD
67#define _str(x) #x
68#define str(x) _str(x)
69#define AAC_DRIVER_FULL_VERSION AAC_DRIVER_VERSION "[" str(AAC_DRIVER_BUILD) "]" AAC_DRIVER_BRANCH
70#else
Michal Marek571b16d2011-04-01 12:41:20 +020071#define AAC_DRIVER_FULL_VERSION AAC_DRIVER_VERSION AAC_DRIVER_BRANCH
Mark Haverkampc7f47602005-08-03 15:38:55 -070072#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
74MODULE_AUTHOR("Red Hat Inc and Adaptec");
75MODULE_DESCRIPTION("Dell PERC2, 2/Si, 3/Si, 3/Di, "
76 "Adaptec Advanced Raid Products, "
Mark Haverkamp1241f352006-03-27 09:44:23 -080077 "HP NetRAID-4M, IBM ServeRAID & ICP SCSI driver");
Linus Torvalds1da177e2005-04-16 15:20:36 -070078MODULE_LICENSE("GPL");
Mark Haverkampc7f47602005-08-03 15:38:55 -070079MODULE_VERSION(AAC_DRIVER_FULL_VERSION);
Linus Torvalds1da177e2005-04-16 15:20:36 -070080
Arnd Bergmannc45d15d2010-06-02 14:28:52 +020081static DEFINE_MUTEX(aac_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -070082static LIST_HEAD(aac_devices);
83static int aac_cfg_major = -1;
Mark Haverkampc7f47602005-08-03 15:38:55 -070084char aac_driver_version[] = AAC_DRIVER_FULL_VERSION;
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
86/*
87 * Because of the way Linux names scsi devices, the order in this table has
88 * become important. Check for on-board Raid first, add-in cards second.
89 *
90 * Note: The last field is used to index into aac_drivers below.
91 */
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -080092static const struct pci_device_id aac_pci_tbl[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 { 0x1028, 0x0001, 0x1028, 0x0001, 0, 0, 0 }, /* PERC 2/Si (Iguana/PERC2Si) */
94 { 0x1028, 0x0002, 0x1028, 0x0002, 0, 0, 1 }, /* PERC 3/Di (Opal/PERC3Di) */
95 { 0x1028, 0x0003, 0x1028, 0x0003, 0, 0, 2 }, /* PERC 3/Si (SlimFast/PERC3Si */
96 { 0x1028, 0x0004, 0x1028, 0x00d0, 0, 0, 3 }, /* PERC 3/Di (Iguana FlipChip/PERC3DiF */
97 { 0x1028, 0x0002, 0x1028, 0x00d1, 0, 0, 4 }, /* PERC 3/Di (Viper/PERC3DiV) */
98 { 0x1028, 0x0002, 0x1028, 0x00d9, 0, 0, 5 }, /* PERC 3/Di (Lexus/PERC3DiL) */
99 { 0x1028, 0x000a, 0x1028, 0x0106, 0, 0, 6 }, /* PERC 3/Di (Jaguar/PERC3DiJ) */
100 { 0x1028, 0x000a, 0x1028, 0x011b, 0, 0, 7 }, /* PERC 3/Di (Dagger/PERC3DiD) */
101 { 0x1028, 0x000a, 0x1028, 0x0121, 0, 0, 8 }, /* PERC 3/Di (Boxster/PERC3DiB) */
102 { 0x9005, 0x0283, 0x9005, 0x0283, 0, 0, 9 }, /* catapult */
103 { 0x9005, 0x0284, 0x9005, 0x0284, 0, 0, 10 }, /* tomcat */
104 { 0x9005, 0x0285, 0x9005, 0x0286, 0, 0, 11 }, /* Adaptec 2120S (Crusader) */
105 { 0x9005, 0x0285, 0x9005, 0x0285, 0, 0, 12 }, /* Adaptec 2200S (Vulcan) */
106 { 0x9005, 0x0285, 0x9005, 0x0287, 0, 0, 13 }, /* Adaptec 2200S (Vulcan-2m) */
107 { 0x9005, 0x0285, 0x17aa, 0x0286, 0, 0, 14 }, /* Legend S220 (Legend Crusader) */
108 { 0x9005, 0x0285, 0x17aa, 0x0287, 0, 0, 15 }, /* Legend S230 (Legend Vulcan) */
109
110 { 0x9005, 0x0285, 0x9005, 0x0288, 0, 0, 16 }, /* Adaptec 3230S (Harrier) */
111 { 0x9005, 0x0285, 0x9005, 0x0289, 0, 0, 17 }, /* Adaptec 3240S (Tornado) */
112 { 0x9005, 0x0285, 0x9005, 0x028a, 0, 0, 18 }, /* ASR-2020ZCR SCSI PCI-X ZCR (Skyhawk) */
113 { 0x9005, 0x0285, 0x9005, 0x028b, 0, 0, 19 }, /* ASR-2025ZCR SCSI SO-DIMM PCI-X ZCR (Terminator) */
114 { 0x9005, 0x0286, 0x9005, 0x028c, 0, 0, 20 }, /* ASR-2230S + ASR-2230SLP PCI-X (Lancer) */
115 { 0x9005, 0x0286, 0x9005, 0x028d, 0, 0, 21 }, /* ASR-2130S (Lancer) */
116 { 0x9005, 0x0286, 0x9005, 0x029b, 0, 0, 22 }, /* AAR-2820SA (Intruder) */
117 { 0x9005, 0x0286, 0x9005, 0x029c, 0, 0, 23 }, /* AAR-2620SA (Intruder) */
118 { 0x9005, 0x0286, 0x9005, 0x029d, 0, 0, 24 }, /* AAR-2420SA (Intruder) */
Salyzyn, Mark8e9d58e2006-12-18 15:01:41 -0500119 { 0x9005, 0x0286, 0x9005, 0x029e, 0, 0, 25 }, /* ICP9024RO (Lancer) */
120 { 0x9005, 0x0286, 0x9005, 0x029f, 0, 0, 26 }, /* ICP9014RO (Lancer) */
Mark Haverkamp84971732005-06-20 11:55:24 -0700121 { 0x9005, 0x0286, 0x9005, 0x02a0, 0, 0, 27 }, /* ICP9047MA (Lancer) */
122 { 0x9005, 0x0286, 0x9005, 0x02a1, 0, 0, 28 }, /* ICP9087MA (Lancer) */
Mark Haverkamp75c36282006-06-08 13:55:42 -0700123 { 0x9005, 0x0286, 0x9005, 0x02a3, 0, 0, 29 }, /* ICP5445AU (Hurricane44) */
Mark Haverkamp84971732005-06-20 11:55:24 -0700124 { 0x9005, 0x0285, 0x9005, 0x02a4, 0, 0, 30 }, /* ICP9085LI (Marauder-X) */
125 { 0x9005, 0x0285, 0x9005, 0x02a5, 0, 0, 31 }, /* ICP5085BR (Marauder-E) */
Mark Haverkamp8e87c2f2005-08-08 14:20:43 -0700126 { 0x9005, 0x0286, 0x9005, 0x02a6, 0, 0, 32 }, /* ICP9067MA (Intruder-6) */
127 { 0x9005, 0x0287, 0x9005, 0x0800, 0, 0, 33 }, /* Themisto Jupiter Platform */
128 { 0x9005, 0x0200, 0x9005, 0x0200, 0, 0, 33 }, /* Themisto Jupiter Platform */
129 { 0x9005, 0x0286, 0x9005, 0x0800, 0, 0, 34 }, /* Callisto Jupiter Platform */
130 { 0x9005, 0x0285, 0x9005, 0x028e, 0, 0, 35 }, /* ASR-2020SA SATA PCI-X ZCR (Skyhawk) */
131 { 0x9005, 0x0285, 0x9005, 0x028f, 0, 0, 36 }, /* ASR-2025SA SATA SO-DIMM PCI-X ZCR (Terminator) */
132 { 0x9005, 0x0285, 0x9005, 0x0290, 0, 0, 37 }, /* AAR-2410SA PCI SATA 4ch (Jaguar II) */
133 { 0x9005, 0x0285, 0x1028, 0x0291, 0, 0, 38 }, /* CERC SATA RAID 2 PCI SATA 6ch (DellCorsair) */
134 { 0x9005, 0x0285, 0x9005, 0x0292, 0, 0, 39 }, /* AAR-2810SA PCI SATA 8ch (Corsair-8) */
135 { 0x9005, 0x0285, 0x9005, 0x0293, 0, 0, 40 }, /* AAR-21610SA PCI SATA 16ch (Corsair-16) */
136 { 0x9005, 0x0285, 0x9005, 0x0294, 0, 0, 41 }, /* ESD SO-DIMM PCI-X SATA ZCR (Prowler) */
137 { 0x9005, 0x0285, 0x103C, 0x3227, 0, 0, 42 }, /* AAR-2610SA PCI SATA 6ch */
138 { 0x9005, 0x0285, 0x9005, 0x0296, 0, 0, 43 }, /* ASR-2240S (SabreExpress) */
Salyzyn, Mark8e9d58e2006-12-18 15:01:41 -0500139 { 0x9005, 0x0285, 0x9005, 0x0297, 0, 0, 44 }, /* ASR-4005 */
Mark Haverkamp8e87c2f2005-08-08 14:20:43 -0700140 { 0x9005, 0x0285, 0x1014, 0x02F2, 0, 0, 45 }, /* IBM 8i (AvonPark) */
141 { 0x9005, 0x0285, 0x1014, 0x0312, 0, 0, 45 }, /* IBM 8i (AvonPark Lite) */
142 { 0x9005, 0x0286, 0x1014, 0x9580, 0, 0, 46 }, /* IBM 8k/8k-l8 (Aurora) */
143 { 0x9005, 0x0286, 0x1014, 0x9540, 0, 0, 47 }, /* IBM 8k/8k-l4 (Aurora Lite) */
Salyzyn, Mark8e9d58e2006-12-18 15:01:41 -0500144 { 0x9005, 0x0285, 0x9005, 0x0298, 0, 0, 48 }, /* ASR-4000 (BlackBird) */
Mark Haverkamp8e87c2f2005-08-08 14:20:43 -0700145 { 0x9005, 0x0285, 0x9005, 0x0299, 0, 0, 49 }, /* ASR-4800SAS (Marauder-X) */
146 { 0x9005, 0x0285, 0x9005, 0x029a, 0, 0, 50 }, /* ASR-4805SAS (Marauder-E) */
Salyzyn, Mark8e9d58e2006-12-18 15:01:41 -0500147 { 0x9005, 0x0286, 0x9005, 0x02a2, 0, 0, 51 }, /* ASR-3800 (Hurricane44) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148
Mark Haverkamp8e87c2f2005-08-08 14:20:43 -0700149 { 0x9005, 0x0285, 0x1028, 0x0287, 0, 0, 52 }, /* Perc 320/DC*/
150 { 0x1011, 0x0046, 0x9005, 0x0365, 0, 0, 53 }, /* Adaptec 5400S (Mustang)*/
151 { 0x1011, 0x0046, 0x9005, 0x0364, 0, 0, 54 }, /* Adaptec 5400S (Mustang)*/
152 { 0x1011, 0x0046, 0x9005, 0x1364, 0, 0, 55 }, /* Dell PERC2/QC */
153 { 0x1011, 0x0046, 0x103c, 0x10c2, 0, 0, 56 }, /* HP NetRAID-4M */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154
Mark Haverkamp8e87c2f2005-08-08 14:20:43 -0700155 { 0x9005, 0x0285, 0x1028, PCI_ANY_ID, 0, 0, 57 }, /* Dell Catchall */
156 { 0x9005, 0x0285, 0x17aa, PCI_ANY_ID, 0, 0, 58 }, /* Legend Catchall */
157 { 0x9005, 0x0285, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 59 }, /* Adaptec Catch All */
158 { 0x9005, 0x0286, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 60 }, /* Adaptec Rocket Catch All */
Mark Haverkamp239eab12007-01-23 15:00:13 -0800159 { 0x9005, 0x0288, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 61 }, /* Adaptec NEMER/ARK Catch All */
Mahesh Rajashekhara11604612012-02-08 22:51:04 -0800160 { 0x9005, 0x028b, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 62 }, /* Adaptec PMC Series 6 (Tupelo) */
161 { 0x9005, 0x028c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 63 }, /* Adaptec PMC Series 7 (Denali) */
162 { 0x9005, 0x028d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 64 }, /* Adaptec PMC Series 8 */
163 { 0x9005, 0x028f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 65 }, /* Adaptec PMC Series 9 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 { 0,}
165};
166MODULE_DEVICE_TABLE(pci, aac_pci_tbl);
167
168/*
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800169 * dmb - For now we add the number of channels to this structure.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 * In the future we should add a fib that reports the number of channels
171 * for the card. At that time we can remove the channels from here
172 */
173static struct aac_driver_ident aac_drivers[] = {
Salyzyn, Mark94cf6ba2007-12-13 16:14:18 -0800174 { aac_rx_init, "percraid", "DELL ", "PERCRAID ", 2, AAC_QUIRK_31BIT | AAC_QUIRK_34SG | AAC_QUIRK_SCSI_32 }, /* PERC 2/Si (Iguana/PERC2Si) */
175 { aac_rx_init, "percraid", "DELL ", "PERCRAID ", 2, AAC_QUIRK_31BIT | AAC_QUIRK_34SG | AAC_QUIRK_SCSI_32 }, /* PERC 3/Di (Opal/PERC3Di) */
176 { aac_rx_init, "percraid", "DELL ", "PERCRAID ", 2, AAC_QUIRK_31BIT | AAC_QUIRK_34SG | AAC_QUIRK_SCSI_32 }, /* PERC 3/Si (SlimFast/PERC3Si */
177 { aac_rx_init, "percraid", "DELL ", "PERCRAID ", 2, AAC_QUIRK_31BIT | AAC_QUIRK_34SG | AAC_QUIRK_SCSI_32 }, /* PERC 3/Di (Iguana FlipChip/PERC3DiF */
178 { aac_rx_init, "percraid", "DELL ", "PERCRAID ", 2, AAC_QUIRK_31BIT | AAC_QUIRK_34SG | AAC_QUIRK_SCSI_32 }, /* PERC 3/Di (Viper/PERC3DiV) */
179 { aac_rx_init, "percraid", "DELL ", "PERCRAID ", 2, AAC_QUIRK_31BIT | AAC_QUIRK_34SG | AAC_QUIRK_SCSI_32 }, /* PERC 3/Di (Lexus/PERC3DiL) */
180 { aac_rx_init, "percraid", "DELL ", "PERCRAID ", 1, AAC_QUIRK_31BIT | AAC_QUIRK_34SG | AAC_QUIRK_SCSI_32 }, /* PERC 3/Di (Jaguar/PERC3DiJ) */
181 { aac_rx_init, "percraid", "DELL ", "PERCRAID ", 2, AAC_QUIRK_31BIT | AAC_QUIRK_34SG | AAC_QUIRK_SCSI_32 }, /* PERC 3/Di (Dagger/PERC3DiD) */
182 { aac_rx_init, "percraid", "DELL ", "PERCRAID ", 2, AAC_QUIRK_31BIT | AAC_QUIRK_34SG | AAC_QUIRK_SCSI_32 }, /* PERC 3/Di (Boxster/PERC3DiB) */
183 { aac_rx_init, "aacraid", "ADAPTEC ", "catapult ", 2, AAC_QUIRK_31BIT | AAC_QUIRK_34SG | AAC_QUIRK_SCSI_32 }, /* catapult */
184 { aac_rx_init, "aacraid", "ADAPTEC ", "tomcat ", 2, AAC_QUIRK_31BIT | AAC_QUIRK_34SG | AAC_QUIRK_SCSI_32 }, /* tomcat */
Hillier, Gernotb21227c2008-09-17 16:03:06 +0200185 { aac_rx_init, "aacraid", "ADAPTEC ", "Adaptec 2120S ", 1, AAC_QUIRK_31BIT | AAC_QUIRK_34SG }, /* Adaptec 2120S (Crusader) */
186 { aac_rx_init, "aacraid", "ADAPTEC ", "Adaptec 2200S ", 2, AAC_QUIRK_31BIT | AAC_QUIRK_34SG }, /* Adaptec 2200S (Vulcan) */
Salyzyn, Mark94cf6ba2007-12-13 16:14:18 -0800187 { aac_rx_init, "aacraid", "ADAPTEC ", "Adaptec 2200S ", 2, AAC_QUIRK_31BIT | AAC_QUIRK_34SG | AAC_QUIRK_SCSI_32 }, /* Adaptec 2200S (Vulcan-2m) */
188 { aac_rx_init, "aacraid", "Legend ", "Legend S220 ", 1, AAC_QUIRK_31BIT | AAC_QUIRK_34SG | AAC_QUIRK_SCSI_32 }, /* Legend S220 (Legend Crusader) */
189 { aac_rx_init, "aacraid", "Legend ", "Legend S230 ", 2, AAC_QUIRK_31BIT | AAC_QUIRK_34SG | AAC_QUIRK_SCSI_32 }, /* Legend S230 (Legend Vulcan) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190
191 { aac_rx_init, "aacraid", "ADAPTEC ", "Adaptec 3230S ", 2 }, /* Adaptec 3230S (Harrier) */
192 { aac_rx_init, "aacraid", "ADAPTEC ", "Adaptec 3240S ", 2 }, /* Adaptec 3240S (Tornado) */
193 { aac_rx_init, "aacraid", "ADAPTEC ", "ASR-2020ZCR ", 2 }, /* ASR-2020ZCR SCSI PCI-X ZCR (Skyhawk) */
194 { aac_rx_init, "aacraid", "ADAPTEC ", "ASR-2025ZCR ", 2 }, /* ASR-2025ZCR SCSI SO-DIMM PCI-X ZCR (Terminator) */
195 { aac_rkt_init, "aacraid", "ADAPTEC ", "ASR-2230S PCI-X ", 2 }, /* ASR-2230S + ASR-2230SLP PCI-X (Lancer) */
196 { aac_rkt_init, "aacraid", "ADAPTEC ", "ASR-2130S PCI-X ", 1 }, /* ASR-2130S (Lancer) */
197 { aac_rkt_init, "aacraid", "ADAPTEC ", "AAR-2820SA ", 1 }, /* AAR-2820SA (Intruder) */
198 { aac_rkt_init, "aacraid", "ADAPTEC ", "AAR-2620SA ", 1 }, /* AAR-2620SA (Intruder) */
199 { aac_rkt_init, "aacraid", "ADAPTEC ", "AAR-2420SA ", 1 }, /* AAR-2420SA (Intruder) */
Salyzyn, Mark8e9d58e2006-12-18 15:01:41 -0500200 { aac_rkt_init, "aacraid", "ICP ", "ICP9024RO ", 2 }, /* ICP9024RO (Lancer) */
201 { aac_rkt_init, "aacraid", "ICP ", "ICP9014RO ", 1 }, /* ICP9014RO (Lancer) */
Mark Haverkamp84971732005-06-20 11:55:24 -0700202 { aac_rkt_init, "aacraid", "ICP ", "ICP9047MA ", 1 }, /* ICP9047MA (Lancer) */
203 { aac_rkt_init, "aacraid", "ICP ", "ICP9087MA ", 1 }, /* ICP9087MA (Lancer) */
Mark Haverkamp75c36282006-06-08 13:55:42 -0700204 { aac_rkt_init, "aacraid", "ICP ", "ICP5445AU ", 1 }, /* ICP5445AU (Hurricane44) */
Mark Haverkamp8e87c2f2005-08-08 14:20:43 -0700205 { aac_rx_init, "aacraid", "ICP ", "ICP9085LI ", 1 }, /* ICP9085LI (Marauder-X) */
206 { aac_rx_init, "aacraid", "ICP ", "ICP5085BR ", 1 }, /* ICP5085BR (Marauder-E) */
207 { aac_rkt_init, "aacraid", "ICP ", "ICP9067MA ", 1 }, /* ICP9067MA (Intruder-6) */
Mark Haverkamp84971732005-06-20 11:55:24 -0700208 { NULL , "aacraid", "ADAPTEC ", "Themisto ", 0, AAC_QUIRK_SLAVE }, /* Jupiter Platform */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 { aac_rkt_init, "aacraid", "ADAPTEC ", "Callisto ", 2, AAC_QUIRK_MASTER }, /* Jupiter Platform */
210 { aac_rx_init, "aacraid", "ADAPTEC ", "ASR-2020SA ", 1 }, /* ASR-2020SA SATA PCI-X ZCR (Skyhawk) */
211 { aac_rx_init, "aacraid", "ADAPTEC ", "ASR-2025SA ", 1 }, /* ASR-2025SA SATA SO-DIMM PCI-X ZCR (Terminator) */
Mark Haverkampdb39363c2006-01-11 09:28:29 -0800212 { aac_rx_init, "aacraid", "ADAPTEC ", "AAR-2410SA SATA ", 1, AAC_QUIRK_17SG }, /* AAR-2410SA PCI SATA 4ch (Jaguar II) */
213 { aac_rx_init, "aacraid", "DELL ", "CERC SR2 ", 1, AAC_QUIRK_17SG }, /* CERC SATA RAID 2 PCI SATA 6ch (DellCorsair) */
214 { aac_rx_init, "aacraid", "ADAPTEC ", "AAR-2810SA SATA ", 1, AAC_QUIRK_17SG }, /* AAR-2810SA PCI SATA 8ch (Corsair-8) */
215 { aac_rx_init, "aacraid", "ADAPTEC ", "AAR-21610SA SATA", 1, AAC_QUIRK_17SG }, /* AAR-21610SA PCI SATA 16ch (Corsair-16) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 { aac_rx_init, "aacraid", "ADAPTEC ", "ASR-2026ZCR ", 1 }, /* ESD SO-DIMM PCI-X SATA ZCR (Prowler) */
217 { aac_rx_init, "aacraid", "ADAPTEC ", "AAR-2610SA ", 1 }, /* SATA 6Ch (Bearcat) */
218 { aac_rx_init, "aacraid", "ADAPTEC ", "ASR-2240S ", 1 }, /* ASR-2240S (SabreExpress) */
Salyzyn, Mark8e9d58e2006-12-18 15:01:41 -0500219 { aac_rx_init, "aacraid", "ADAPTEC ", "ASR-4005 ", 1 }, /* ASR-4005 */
Mark Haverkamp84971732005-06-20 11:55:24 -0700220 { aac_rx_init, "ServeRAID","IBM ", "ServeRAID 8i ", 1 }, /* IBM 8i (AvonPark) */
Mark Haverkamp8e87c2f2005-08-08 14:20:43 -0700221 { aac_rkt_init, "ServeRAID","IBM ", "ServeRAID 8k-l8 ", 1 }, /* IBM 8k/8k-l8 (Aurora) */
222 { aac_rkt_init, "ServeRAID","IBM ", "ServeRAID 8k-l4 ", 1 }, /* IBM 8k/8k-l4 (Aurora Lite) */
Salyzyn, Mark8e9d58e2006-12-18 15:01:41 -0500223 { aac_rx_init, "aacraid", "ADAPTEC ", "ASR-4000 ", 1 }, /* ASR-4000 (BlackBird & AvonPark) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 { aac_rx_init, "aacraid", "ADAPTEC ", "ASR-4800SAS ", 1 }, /* ASR-4800SAS (Marauder-X) */
225 { aac_rx_init, "aacraid", "ADAPTEC ", "ASR-4805SAS ", 1 }, /* ASR-4805SAS (Marauder-E) */
Salyzyn, Mark8e9d58e2006-12-18 15:01:41 -0500226 { aac_rkt_init, "aacraid", "ADAPTEC ", "ASR-3800 ", 1 }, /* ASR-3800 (Hurricane44) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227
228 { aac_rx_init, "percraid", "DELL ", "PERC 320/DC ", 2, AAC_QUIRK_31BIT | AAC_QUIRK_34SG }, /* Perc 320/DC*/
229 { aac_sa_init, "aacraid", "ADAPTEC ", "Adaptec 5400S ", 4, AAC_QUIRK_34SG }, /* Adaptec 5400S (Mustang)*/
230 { aac_sa_init, "aacraid", "ADAPTEC ", "AAC-364 ", 4, AAC_QUIRK_34SG }, /* Adaptec 5400S (Mustang)*/
Salyzyn, Markb27e66d2007-06-19 16:05:12 -0400231 { aac_sa_init, "percraid", "DELL ", "PERCRAID ", 4, AAC_QUIRK_34SG }, /* Dell PERC2/QC */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 { aac_sa_init, "hpnraid", "HP ", "NetRAID ", 4, AAC_QUIRK_34SG }, /* HP NetRAID-4M */
233
Salyzyn, Mark94cf6ba2007-12-13 16:14:18 -0800234 { aac_rx_init, "aacraid", "DELL ", "RAID ", 2, AAC_QUIRK_31BIT | AAC_QUIRK_34SG | AAC_QUIRK_SCSI_32 }, /* Dell Catchall */
235 { aac_rx_init, "aacraid", "Legend ", "RAID ", 2, AAC_QUIRK_31BIT | AAC_QUIRK_34SG | AAC_QUIRK_SCSI_32 }, /* Legend Catchall */
Salyzyn, Markb27e66d2007-06-19 16:05:12 -0400236 { aac_rx_init, "aacraid", "ADAPTEC ", "RAID ", 2 }, /* Adaptec Catch All */
Mark Haverkamp239eab12007-01-23 15:00:13 -0800237 { aac_rkt_init, "aacraid", "ADAPTEC ", "RAID ", 2 }, /* Adaptec Rocket Catch All */
Mahesh Rajashekharae8b12f02011-03-17 02:10:32 -0700238 { aac_nark_init, "aacraid", "ADAPTEC ", "RAID ", 2 }, /* Adaptec NEMER/ARK Catch All */
Mahesh Rajashekhara11604612012-02-08 22:51:04 -0800239 { aac_src_init, "aacraid", "ADAPTEC ", "RAID ", 2 }, /* Adaptec PMC Series 6 (Tupelo) */
240 { aac_srcv_init, "aacraid", "ADAPTEC ", "RAID ", 2 }, /* Adaptec PMC Series 7 (Denali) */
241 { aac_srcv_init, "aacraid", "ADAPTEC ", "RAID ", 2 }, /* Adaptec PMC Series 8 */
242 { aac_srcv_init, "aacraid", "ADAPTEC ", "RAID ", 2 } /* Adaptec PMC Series 9 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243};
244
245/**
246 * aac_queuecommand - queue a SCSI command
247 * @cmd: SCSI command to queue
248 * @done: Function to call on command completion
249 *
250 * Queues a command for execution by the associated Host Adapter.
251 *
252 * TODO: unify with aac_scsi_cmd().
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800253 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254
Mahesh Rajashekharaef616232015-03-26 10:41:30 -0400255static int aac_queuecommand(struct Scsi_Host *shost,
256 struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257{
Mahesh Rajashekharaef616232015-03-26 10:41:30 -0400258 int r = 0;
Mark Haverkamp77d644d2006-03-27 09:43:40 -0800259 cmd->SCp.phase = AAC_OWNER_LOWLEVEL;
Mahesh Rajashekharaef616232015-03-26 10:41:30 -0400260 r = (aac_scsi_cmd(cmd) ? FAILED : 0);
261 return r;
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800262}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263
264/**
265 * aac_info - Returns the host adapter name
266 * @shost: Scsi host to report on
267 *
268 * Returns a static string describing the device in question
269 */
270
Adrian Bunk 48338692005-04-25 19:45:58 -0700271static const char *aac_info(struct Scsi_Host *shost)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272{
273 struct aac_dev *dev = (struct aac_dev *)shost->hostdata;
274 return aac_drivers[dev->cardtype].name;
275}
276
277/**
278 * aac_get_driver_ident
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800279 * @devtype: index into lookup table
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 *
Salyzyn, Mark8ef22242008-02-08 05:48:22 -0800281 * Returns a pointer to the entry in the driver lookup table.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 */
283
284struct aac_driver_ident* aac_get_driver_ident(int devtype)
285{
286 return &aac_drivers[devtype];
287}
288
289/**
290 * aac_biosparm - return BIOS parameters for disk
291 * @sdev: The scsi device corresponding to the disk
292 * @bdev: the block device corresponding to the disk
293 * @capacity: the sector capacity of the disk
294 * @geom: geometry block to fill in
295 *
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800296 * Return the Heads/Sectors/Cylinders BIOS Disk Parameters for Disk.
297 * The default disk geometry is 64 heads, 32 sectors, and the appropriate
298 * number of cylinders so as not to exceed drive capacity. In order for
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 * disks equal to or larger than 1 GB to be addressable by the BIOS
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800300 * without exceeding the BIOS limitation of 1024 cylinders, Extended
301 * Translation should be enabled. With Extended Translation enabled,
302 * drives between 1 GB inclusive and 2 GB exclusive are given a disk
303 * geometry of 128 heads and 32 sectors, and drives above 2 GB inclusive
304 * are given a disk geometry of 255 heads and 63 sectors. However, if
305 * the BIOS detects that the Extended Translation setting does not match
306 * the geometry in the partition table, then the translation inferred
307 * from the partition table will be used by the BIOS, and a warning may
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 * be displayed.
309 */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800310
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311static int aac_biosparm(struct scsi_device *sdev, struct block_device *bdev,
312 sector_t capacity, int *geom)
313{
314 struct diskparm *param = (struct diskparm *)geom;
315 unsigned char *buf;
316
317 dprintk((KERN_DEBUG "aac_biosparm.\n"));
318
319 /*
320 * Assuming extended translation is enabled - #REVISIT#
321 */
322 if (capacity >= 2 * 1024 * 1024) { /* 1 GB in 512 byte sectors */
323 if(capacity >= 4 * 1024 * 1024) { /* 2 GB in 512 byte sectors */
324 param->heads = 255;
325 param->sectors = 63;
326 } else {
327 param->heads = 128;
328 param->sectors = 32;
329 }
330 } else {
331 param->heads = 64;
332 param->sectors = 32;
333 }
334
335 param->cylinders = cap_to_cyls(capacity, param->heads * param->sectors);
336
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800337 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 * Read the first 1024 bytes from the disk device, if the boot
339 * sector partition table is valid, search for a partition table
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800340 * entry whose end_head matches one of the standard geometry
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 * translations ( 64/32, 128/32, 255/63 ).
342 */
343 buf = scsi_bios_ptable(bdev);
Mark Haverkamp8bdf8102005-11-30 12:01:39 -0800344 if (!buf)
345 return 0;
Mark Haverkamp 56b58712005-04-27 06:05:51 -0700346 if(*(__le16 *)(buf + 0x40) == cpu_to_le16(0xaa55)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 struct partition *first = (struct partition * )buf;
348 struct partition *entry = first;
349 int saved_cylinders = param->cylinders;
350 int num;
351 unsigned char end_head, end_sec;
352
353 for(num = 0; num < 4; num++) {
354 end_head = entry->end_head;
355 end_sec = entry->end_sector & 0x3f;
356
357 if(end_head == 63) {
358 param->heads = 64;
359 param->sectors = 32;
360 break;
361 } else if(end_head == 127) {
362 param->heads = 128;
363 param->sectors = 32;
364 break;
365 } else if(end_head == 254) {
366 param->heads = 255;
367 param->sectors = 63;
368 break;
369 }
370 entry++;
371 }
372
373 if (num == 4) {
374 end_head = first->end_head;
375 end_sec = first->end_sector & 0x3f;
376 }
377
378 param->cylinders = cap_to_cyls(capacity, param->heads * param->sectors);
379 if (num < 4 && end_sec == param->sectors) {
380 if (param->cylinders != saved_cylinders)
381 dprintk((KERN_DEBUG "Adopting geometry: heads=%d, sectors=%d from partition table %d.\n",
382 param->heads, param->sectors, num));
383 } else if (end_head > 0 || end_sec > 0) {
384 dprintk((KERN_DEBUG "Strange geometry: heads=%d, sectors=%d in partition table %d.\n",
385 end_head + 1, end_sec, num));
386 dprintk((KERN_DEBUG "Using geometry: heads=%d, sectors=%d.\n",
387 param->heads, param->sectors));
388 }
389 }
390 kfree(buf);
391 return 0;
392}
393
394/**
395 * aac_slave_configure - compute queue depths
396 * @sdev: SCSI device we are considering
397 *
398 * Selects queue depths for each target device based on the host adapter's
399 * total capacity and the queue depth supported by the target device.
400 * A queue depth of one automatically disables tagged queueing.
401 */
402
403static int aac_slave_configure(struct scsi_device *sdev)
404{
Salyzyn, Markb18268f2008-01-08 14:07:57 -0800405 struct aac_dev *aac = (struct aac_dev *)sdev->host->hostdata;
Mark Salyzyna4576b52008-04-30 15:47:35 -0400406 if (aac->jbod && (sdev->type == TYPE_DISK))
407 sdev->removable = 1;
Mark Haverkampbb08f922006-02-01 09:30:44 -0800408 if ((sdev->type == TYPE_DISK) &&
Salyzyn, Markb18268f2008-01-08 14:07:57 -0800409 (sdev_channel(sdev) != CONTAINER_CHANNEL) &&
Salyzyn, Markcb1042f2008-01-17 09:25:07 -0800410 (!aac->jbod || sdev->inq_periph_qual) &&
Salyzyn, Markb18268f2008-01-08 14:07:57 -0800411 (!aac->raid_scsi_mode || (sdev_channel(sdev) != 2))) {
Mark Haverkampe37ee4b2007-01-26 09:23:32 -0800412 if (expose_physicals == 0)
413 return -ENXIO;
Salyzyn, Markb18268f2008-01-08 14:07:57 -0800414 if (expose_physicals < 0)
415 sdev->no_uld_attach = 1;
Mark Haverkampbb08f922006-02-01 09:30:44 -0800416 }
417 if (sdev->tagged_supported && (sdev->type == TYPE_DISK) &&
Salyzyn, Markcb1042f2008-01-17 09:25:07 -0800418 (!aac->raid_scsi_mode || (sdev_channel(sdev) != 2)) &&
419 !sdev->no_uld_attach) {
Mark Haverkampbb08f922006-02-01 09:30:44 -0800420 struct scsi_device * dev;
421 struct Scsi_Host *host = sdev->host;
422 unsigned num_lsu = 0;
423 unsigned num_one = 0;
424 unsigned depth;
Salyzyn, Markb18268f2008-01-08 14:07:57 -0800425 unsigned cid;
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700426
Salyzyn, Mark94cf6ba2007-12-13 16:14:18 -0800427 /*
428 * Firmware has an individual device recovery time typically
429 * of 35 seconds, give us a margin.
430 */
James Bottomley8fbd64e2008-11-30 10:15:37 -0600431 if (sdev->request_queue->rq_timeout < (45 * HZ))
432 blk_queue_rq_timeout(sdev->request_queue, 45*HZ);
Salyzyn, Markb18268f2008-01-08 14:07:57 -0800433 for (cid = 0; cid < aac->maximum_num_containers; ++cid)
434 if (aac->fsa_dev[cid].valid)
435 ++num_lsu;
Mark Haverkampbb08f922006-02-01 09:30:44 -0800436 __shost_for_each_device(dev, host) {
437 if (dev->tagged_supported && (dev->type == TYPE_DISK) &&
Salyzyn, Markcb1042f2008-01-17 09:25:07 -0800438 (!aac->raid_scsi_mode ||
439 (sdev_channel(sdev) != 2)) &&
440 !dev->no_uld_attach) {
441 if ((sdev_channel(dev) != CONTAINER_CHANNEL)
442 || !aac->fsa_dev[sdev_id(dev)].valid)
Salyzyn, Markb18268f2008-01-08 14:07:57 -0800443 ++num_lsu;
444 } else
Mark Haverkampbb08f922006-02-01 09:30:44 -0800445 ++num_one;
446 }
447 if (num_lsu == 0)
448 ++num_lsu;
449 depth = (host->can_queue - num_one) / num_lsu;
450 if (depth > 256)
451 depth = 256;
452 else if (depth < 2)
453 depth = 2;
Christoph Hellwigdb5ed4d2014-11-13 15:08:42 +0100454 scsi_change_queue_depth(sdev, depth);
Mark Haverkampbb08f922006-02-01 09:30:44 -0800455 } else
Christoph Hellwigdb5ed4d2014-11-13 15:08:42 +0100456 scsi_change_queue_depth(sdev, 1);
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700457
Raghava Aditya Renukunta6bf3b632016-02-03 15:05:59 -0800458 sdev->tagged_supported = 1;
459
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 return 0;
461}
462
Salyzyn, Mark5c9cfed2007-05-30 10:01:14 -0400463/**
464 * aac_change_queue_depth - alter queue depths
465 * @sdev: SCSI device we are considering
466 * @depth: desired queue depth
467 *
468 * Alters queue depths for target device based on the host adapter's
469 * total capacity and the queue depth supported by the target device.
470 */
471
Christoph Hellwigdb5ed4d2014-11-13 15:08:42 +0100472static int aac_change_queue_depth(struct scsi_device *sdev, int depth)
Salyzyn, Mark5c9cfed2007-05-30 10:01:14 -0400473{
474 if (sdev->tagged_supported && (sdev->type == TYPE_DISK) &&
475 (sdev_channel(sdev) == CONTAINER_CHANNEL)) {
476 struct scsi_device * dev;
477 struct Scsi_Host *host = sdev->host;
478 unsigned num = 0;
479
480 __shost_for_each_device(dev, host) {
481 if (dev->tagged_supported && (dev->type == TYPE_DISK) &&
482 (sdev_channel(dev) == CONTAINER_CHANNEL))
483 ++num;
484 ++num;
485 }
486 if (num >= host->can_queue)
487 num = host->can_queue - 1;
488 if (depth > (host->can_queue - num))
489 depth = host->can_queue - num;
490 if (depth > 256)
491 depth = 256;
492 else if (depth < 2)
493 depth = 2;
Christoph Hellwigdb5ed4d2014-11-13 15:08:42 +0100494 return scsi_change_queue_depth(sdev, depth);
495 }
496
497 return scsi_change_queue_depth(sdev, 1);
Salyzyn, Mark5c9cfed2007-05-30 10:01:14 -0400498}
499
Salyzyn, Mark17eaace2008-01-08 12:23:49 -0800500static ssize_t aac_show_raid_level(struct device *dev, struct device_attribute *attr, char *buf)
501{
Salyzyn, Mark95f6fb52008-02-08 09:01:34 -0800502 struct scsi_device *sdev = to_scsi_device(dev);
503 struct aac_dev *aac = (struct aac_dev *)(sdev->host->hostdata);
Salyzyn, Mark17eaace2008-01-08 12:23:49 -0800504 if (sdev_channel(sdev) != CONTAINER_CHANNEL)
505 return snprintf(buf, PAGE_SIZE, sdev->no_uld_attach
Salyzyn, Mark95f6fb52008-02-08 09:01:34 -0800506 ? "Hidden\n" :
507 ((aac->jbod && (sdev->type == TYPE_DISK)) ? "JBOD\n" : ""));
Salyzyn, Mark17eaace2008-01-08 12:23:49 -0800508 return snprintf(buf, PAGE_SIZE, "%s\n",
Salyzyn, Mark95f6fb52008-02-08 09:01:34 -0800509 get_container_type(aac->fsa_dev[sdev_id(sdev)].type));
Salyzyn, Mark17eaace2008-01-08 12:23:49 -0800510}
511
512static struct device_attribute aac_raid_level_attr = {
513 .attr = {
514 .name = "level",
515 .mode = S_IRUGO,
516 },
517 .show = aac_show_raid_level
518};
519
520static struct device_attribute *aac_dev_attrs[] = {
521 &aac_raid_level_attr,
522 NULL,
523};
524
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525static int aac_ioctl(struct scsi_device *sdev, int cmd, void __user * arg)
526{
527 struct aac_dev *dev = (struct aac_dev *)sdev->host->hostdata;
Alan Coxd496f942007-11-07 23:58:10 +0000528 if (!capable(CAP_SYS_RAWIO))
529 return -EPERM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 return aac_do_ioctl(dev, cmd, arg);
531}
532
Mark Haverkamp03d44332007-03-15 10:27:45 -0700533static int aac_eh_abort(struct scsi_cmnd* cmd)
534{
Salyzyn, Mark802ae2f2007-03-21 13:49:47 -0400535 struct scsi_device * dev = cmd->device;
536 struct Scsi_Host * host = dev->host;
Mark Haverkamp03d44332007-03-15 10:27:45 -0700537 struct aac_dev * aac = (struct aac_dev *)host->hostdata;
538 int count;
539 int ret = FAILED;
540
Hannes Reinecke9cb78c12014-06-25 15:27:36 +0200541 printk(KERN_ERR "%s: Host adapter abort request (%d,%d,%d,%llu)\n",
Mark Haverkamp03d44332007-03-15 10:27:45 -0700542 AAC_DRIVERNAME,
Salyzyn, Mark802ae2f2007-03-21 13:49:47 -0400543 host->host_no, sdev_channel(dev), sdev_id(dev), dev->lun);
Mark Haverkamp03d44332007-03-15 10:27:45 -0700544 switch (cmd->cmnd[0]) {
Hannes Reineckeeb846d92014-11-17 14:25:19 +0100545 case SERVICE_ACTION_IN_16:
Mark Haverkamp03d44332007-03-15 10:27:45 -0700546 if (!(aac->raw_io_interface) ||
547 !(aac->raw_io_64) ||
548 ((cmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
549 break;
550 case INQUIRY:
551 case READ_CAPACITY:
Mark Haverkamp03d44332007-03-15 10:27:45 -0700552 /* Mark associated FIB to not complete, eh handler does this */
553 for (count = 0; count < (host->can_queue + AAC_NUM_MGT_FIB); ++count) {
554 struct fib * fib = &aac->fibs[count];
555 if (fib->hw_fib_va->header.XferState &&
Salyzyn, Markb6ef70f2008-01-08 13:26:43 -0800556 (fib->flags & FIB_CONTEXT_FLAG) &&
Mark Haverkamp03d44332007-03-15 10:27:45 -0700557 (fib->callback_data == cmd)) {
558 fib->flags |= FIB_CONTEXT_FLAG_TIMED_OUT;
559 cmd->SCp.phase = AAC_OWNER_ERROR_HANDLER;
560 ret = SUCCESS;
561 }
562 }
Salyzyn, Markb6ef70f2008-01-08 13:26:43 -0800563 break;
564 case TEST_UNIT_READY:
565 /* Mark associated FIB to not complete, eh handler does this */
566 for (count = 0; count < (host->can_queue + AAC_NUM_MGT_FIB); ++count) {
567 struct scsi_cmnd * command;
568 struct fib * fib = &aac->fibs[count];
569 if ((fib->hw_fib_va->header.XferState & cpu_to_le32(Async | NoResponseExpected)) &&
570 (fib->flags & FIB_CONTEXT_FLAG) &&
571 ((command = fib->callback_data)) &&
572 (command->device == cmd->device)) {
573 fib->flags |= FIB_CONTEXT_FLAG_TIMED_OUT;
574 command->SCp.phase = AAC_OWNER_ERROR_HANDLER;
575 if (command == cmd)
576 ret = SUCCESS;
577 }
578 }
Mark Haverkamp03d44332007-03-15 10:27:45 -0700579 }
580 return ret;
581}
582
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 * aac_eh_reset - Reset command handling
585 * @scsi_cmd: SCSI command block causing the reset
586 *
587 */
588static int aac_eh_reset(struct scsi_cmnd* cmd)
589{
590 struct scsi_device * dev = cmd->device;
591 struct Scsi_Host * host = dev->host;
592 struct scsi_cmnd * command;
593 int count;
Mark Haverkamp03d44332007-03-15 10:27:45 -0700594 struct aac_dev * aac = (struct aac_dev *)host->hostdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 unsigned long flags;
596
Mark Haverkamp03d44332007-03-15 10:27:45 -0700597 /* Mark the associated FIB to not complete, eh handler does this */
598 for (count = 0; count < (host->can_queue + AAC_NUM_MGT_FIB); ++count) {
599 struct fib * fib = &aac->fibs[count];
600 if (fib->hw_fib_va->header.XferState &&
Salyzyn, Markb6ef70f2008-01-08 13:26:43 -0800601 (fib->flags & FIB_CONTEXT_FLAG) &&
Mark Haverkamp03d44332007-03-15 10:27:45 -0700602 (fib->callback_data == cmd)) {
603 fib->flags |= FIB_CONTEXT_FLAG_TIMED_OUT;
604 cmd->SCp.phase = AAC_OWNER_ERROR_HANDLER;
605 }
606 }
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800607 printk(KERN_ERR "%s: Host adapter reset request. SCSI hang ?\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 AAC_DRIVERNAME);
Mark Haverkamp8c867b22006-08-03 08:03:30 -0700609
610 if ((count = aac_check_health(aac)))
611 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 /*
613 * Wait for all commands to complete to this specific
614 * target (block maximum 60 seconds).
615 */
616 for (count = 60; count; --count) {
Mark Haverkamp8c867b22006-08-03 08:03:30 -0700617 int active = aac->in_reset;
618
619 if (active == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 __shost_for_each_device(dev, host) {
621 spin_lock_irqsave(&dev->list_lock, flags);
622 list_for_each_entry(command, &dev->cmd_list, list) {
Mark Haverkamp77d644d2006-03-27 09:43:40 -0800623 if ((command != cmd) &&
624 (command->SCp.phase == AAC_OWNER_FIRMWARE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 active++;
626 break;
627 }
628 }
629 spin_unlock_irqrestore(&dev->list_lock, flags);
630 if (active)
631 break;
632
633 }
634 /*
635 * We can exit If all the commands are complete
636 */
637 if (active == 0)
638 return SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 ssleep(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 }
641 printk(KERN_ERR "%s: SCSI bus appears hung\n", AAC_DRIVERNAME);
Salyzyn, Mark29c97682007-06-12 09:33:54 -0400642 /*
643 * This adapter needs a blind reset, only do so for Adapters that
644 * support a register, instead of a commanded, reset.
645 */
Mahesh Rajashekharae8b12f02011-03-17 02:10:32 -0700646 if (((aac->supplement_adapter_info.SupportedOptions2 &
647 AAC_OPTION_MU_RESET) ||
648 (aac->supplement_adapter_info.SupportedOptions2 &
649 AAC_OPTION_DOORBELL_RESET)) &&
Salyzyn, Marka3940da2008-01-08 12:48:25 -0800650 aac_check_reset &&
651 ((aac_check_reset != 1) ||
Salyzyn, Mark2f7ecc52008-02-08 08:36:23 -0800652 !(aac->supplement_adapter_info.SupportedOptions2 &
Salyzyn, Marka3940da2008-01-08 12:48:25 -0800653 AAC_OPTION_IGNORE_RESET)))
Salyzyn, Mark29c97682007-06-12 09:33:54 -0400654 aac_reset_adapter(aac, 2); /* Bypass wait for command quiesce */
Mark Haverkamp03d44332007-03-15 10:27:45 -0700655 return SUCCESS; /* Cause an immediate retry of the command with a ten second delay after successful tur */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656}
657
658/**
659 * aac_cfg_open - open a configuration file
660 * @inode: inode being opened
661 * @file: file handle attached
662 *
663 * Called when the configuration device is opened. Does the needed
664 * set up on the handle and then returns
665 *
666 * Bugs: This needs extending to check a given adapter is present
667 * so we can support hot plugging, and to ref count adapters.
668 */
669
670static int aac_cfg_open(struct inode *inode, struct file *file)
671{
672 struct aac_dev *aac;
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700673 unsigned minor_number = iminor(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 int err = -ENODEV;
675
Arnd Bergmannc45d15d2010-06-02 14:28:52 +0200676 mutex_lock(&aac_mutex); /* BKL pushdown: nothing else protects this list */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 list_for_each_entry(aac, &aac_devices, entry) {
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700678 if (aac->id == minor_number) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 file->private_data = aac;
680 err = 0;
681 break;
682 }
683 }
Arnd Bergmannc45d15d2010-06-02 14:28:52 +0200684 mutex_unlock(&aac_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685
Mark Haverkamp036d6182005-04-26 22:54:58 -0700686 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687}
688
689/**
690 * aac_cfg_ioctl - AAC configuration request
691 * @inode: inode of device
692 * @file: file handle
693 * @cmd: ioctl command code
694 * @arg: argument
695 *
696 * Handles a configuration ioctl. Currently this involves wrapping it
697 * up and feeding it into the nasty windowsalike glue layer.
698 *
699 * Bugs: Needs locking against parallel ioctls lower down
700 * Bugs: Needs to handle hot plugging
701 */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800702
Arnd Bergmannf4927c42010-04-27 00:24:01 +0200703static long aac_cfg_ioctl(struct file *file,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 unsigned int cmd, unsigned long arg)
705{
Arnd Bergmannf4927c42010-04-27 00:24:01 +0200706 int ret;
Mahesh Rajashekharaf9c42592015-03-26 10:41:29 -0400707 struct aac_dev *aac;
708 aac = (struct aac_dev *)file->private_data;
709 if (!capable(CAP_SYS_RAWIO) || aac->adapter_shutdown)
Alan Cox60395bb2007-07-23 14:51:05 +0100710 return -EPERM;
Arnd Bergmannc45d15d2010-06-02 14:28:52 +0200711 mutex_lock(&aac_mutex);
Arnd Bergmannf4927c42010-04-27 00:24:01 +0200712 ret = aac_do_ioctl(file->private_data, cmd, (void __user *)arg);
Arnd Bergmannc45d15d2010-06-02 14:28:52 +0200713 mutex_unlock(&aac_mutex);
Arnd Bergmannf4927c42010-04-27 00:24:01 +0200714
715 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716}
717
718#ifdef CONFIG_COMPAT
719static long aac_compat_do_ioctl(struct aac_dev *dev, unsigned cmd, unsigned long arg)
720{
721 long ret;
Arnd Bergmannc45d15d2010-06-02 14:28:52 +0200722 mutex_lock(&aac_mutex);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800723 switch (cmd) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 case FSACTL_MINIPORT_REV_CHECK:
725 case FSACTL_SENDFIB:
726 case FSACTL_OPEN_GET_ADAPTER_FIB:
727 case FSACTL_CLOSE_GET_ADAPTER_FIB:
728 case FSACTL_SEND_RAW_SRB:
729 case FSACTL_GET_PCI_INFO:
730 case FSACTL_QUERY_DISK:
731 case FSACTL_DELETE_DISK:
732 case FSACTL_FORCE_DELETE_DISK:
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800733 case FSACTL_GET_CONTAINERS:
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -0700734 case FSACTL_SEND_LARGE_FIB:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 ret = aac_do_ioctl(dev, cmd, (void __user *)arg);
736 break;
737
738 case FSACTL_GET_NEXT_ADAPTER_FIB: {
739 struct fib_ioctl __user *f;
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800740
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741 f = compat_alloc_user_space(sizeof(*f));
742 ret = 0;
Mark Haverkamp821499a2006-06-12 10:53:58 -0700743 if (clear_user(f, sizeof(*f)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 ret = -EFAULT;
745 if (copy_in_user(f, (void __user *)arg, sizeof(struct fib_ioctl) - sizeof(u32)))
746 ret = -EFAULT;
747 if (!ret)
Mark Haverkamp3d2f98a2006-03-27 09:44:33 -0800748 ret = aac_do_ioctl(dev, cmd, f);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 break;
750 }
751
752 default:
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800753 ret = -ENOIOCTLCMD;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754 break;
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800755 }
Arnd Bergmannc45d15d2010-06-02 14:28:52 +0200756 mutex_unlock(&aac_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 return ret;
758}
759
760static int aac_compat_ioctl(struct scsi_device *sdev, int cmd, void __user *arg)
761{
762 struct aac_dev *dev = (struct aac_dev *)sdev->host->hostdata;
Dan Carpenterf8565672013-10-29 22:11:06 +0300763 if (!capable(CAP_SYS_RAWIO))
764 return -EPERM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765 return aac_compat_do_ioctl(dev, cmd, (unsigned long)arg);
766}
767
768static long aac_compat_cfg_ioctl(struct file *file, unsigned cmd, unsigned long arg)
769{
Alan Cox5f78e892007-11-07 23:58:10 +0000770 if (!capable(CAP_SYS_RAWIO))
Alan Cox60395bb2007-07-23 14:51:05 +0100771 return -EPERM;
Joe Perches35df8392010-09-04 18:52:46 -0700772 return aac_compat_do_ioctl(file->private_data, cmd, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773}
774#endif
775
Tony Jonesee959b02008-02-22 00:13:36 +0100776static ssize_t aac_show_model(struct device *device,
777 struct device_attribute *attr, char *buf)
Mark Haverkamp0bb14af2005-06-01 10:24:38 -0700778{
Tony Jonesee959b02008-02-22 00:13:36 +0100779 struct aac_dev *dev = (struct aac_dev*)class_to_shost(device)->hostdata;
Mark Haverkamp0bb14af2005-06-01 10:24:38 -0700780 int len;
781
Mark Haverkamp7686f132006-01-11 09:28:16 -0800782 if (dev->supplement_adapter_info.AdapterTypeText[0]) {
783 char * cp = dev->supplement_adapter_info.AdapterTypeText;
784 while (*cp && *cp != ' ')
785 ++cp;
786 while (*cp == ' ')
787 ++cp;
788 len = snprintf(buf, PAGE_SIZE, "%s\n", cp);
789 } else
790 len = snprintf(buf, PAGE_SIZE, "%s\n",
Mark Haverkamp0bb14af2005-06-01 10:24:38 -0700791 aac_drivers[dev->cardtype].model);
792 return len;
793}
794
Tony Jonesee959b02008-02-22 00:13:36 +0100795static ssize_t aac_show_vendor(struct device *device,
796 struct device_attribute *attr, char *buf)
Mark Haverkamp0bb14af2005-06-01 10:24:38 -0700797{
Tony Jonesee959b02008-02-22 00:13:36 +0100798 struct aac_dev *dev = (struct aac_dev*)class_to_shost(device)->hostdata;
Mark Haverkamp0bb14af2005-06-01 10:24:38 -0700799 int len;
800
Mark Haverkamp7686f132006-01-11 09:28:16 -0800801 if (dev->supplement_adapter_info.AdapterTypeText[0]) {
802 char * cp = dev->supplement_adapter_info.AdapterTypeText;
803 while (*cp && *cp != ' ')
804 ++cp;
805 len = snprintf(buf, PAGE_SIZE, "%.*s\n",
806 (int)(cp - (char *)dev->supplement_adapter_info.AdapterTypeText),
807 dev->supplement_adapter_info.AdapterTypeText);
808 } else
809 len = snprintf(buf, PAGE_SIZE, "%s\n",
Mark Haverkamp0bb14af2005-06-01 10:24:38 -0700810 aac_drivers[dev->cardtype].vname);
811 return len;
812}
813
Tony Jonesee959b02008-02-22 00:13:36 +0100814static ssize_t aac_show_flags(struct device *cdev,
815 struct device_attribute *attr, char *buf)
Salyzyn, Mark2ca39c42008-01-17 09:24:56 -0800816{
817 int len = 0;
Tony Jonesee959b02008-02-22 00:13:36 +0100818 struct aac_dev *dev = (struct aac_dev*)class_to_shost(cdev)->hostdata;
Salyzyn, Mark2ca39c42008-01-17 09:24:56 -0800819
820 if (nblank(dprintk(x)))
821 len = snprintf(buf, PAGE_SIZE, "dprintk\n");
822#ifdef AAC_DETAILED_STATUS_INFO
823 len += snprintf(buf + len, PAGE_SIZE - len,
824 "AAC_DETAILED_STATUS_INFO\n");
825#endif
826 if (dev->raw_io_interface && dev->raw_io_64)
827 len += snprintf(buf + len, PAGE_SIZE - len,
828 "SAI_READ_CAPACITY_16\n");
Salyzyn, Markcb1042f2008-01-17 09:25:07 -0800829 if (dev->jbod)
830 len += snprintf(buf + len, PAGE_SIZE - len, "SUPPORTED_JBOD\n");
Mark Salyzyn655d7222008-04-30 16:03:42 -0400831 if (dev->supplement_adapter_info.SupportedOptions2 &
832 AAC_OPTION_POWER_MANAGEMENT)
833 len += snprintf(buf + len, PAGE_SIZE - len,
834 "SUPPORTED_POWER_MANAGEMENT\n");
835 if (dev->msi)
836 len += snprintf(buf + len, PAGE_SIZE - len, "PCI_HAS_MSI\n");
Salyzyn, Mark2ca39c42008-01-17 09:24:56 -0800837 return len;
838}
839
Tony Jonesee959b02008-02-22 00:13:36 +0100840static ssize_t aac_show_kernel_version(struct device *device,
841 struct device_attribute *attr,
842 char *buf)
Mark Haverkamp0bb14af2005-06-01 10:24:38 -0700843{
Tony Jonesee959b02008-02-22 00:13:36 +0100844 struct aac_dev *dev = (struct aac_dev*)class_to_shost(device)->hostdata;
Mark Haverkamp0bb14af2005-06-01 10:24:38 -0700845 int len, tmp;
846
847 tmp = le32_to_cpu(dev->adapter_info.kernelrev);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800848 len = snprintf(buf, PAGE_SIZE, "%d.%d-%d[%d]\n",
Mark Haverkamp0bb14af2005-06-01 10:24:38 -0700849 tmp >> 24, (tmp >> 16) & 0xff, tmp & 0xff,
850 le32_to_cpu(dev->adapter_info.kernelbuild));
851 return len;
852}
853
Tony Jonesee959b02008-02-22 00:13:36 +0100854static ssize_t aac_show_monitor_version(struct device *device,
855 struct device_attribute *attr,
856 char *buf)
Mark Haverkamp0bb14af2005-06-01 10:24:38 -0700857{
Tony Jonesee959b02008-02-22 00:13:36 +0100858 struct aac_dev *dev = (struct aac_dev*)class_to_shost(device)->hostdata;
Mark Haverkamp0bb14af2005-06-01 10:24:38 -0700859 int len, tmp;
860
861 tmp = le32_to_cpu(dev->adapter_info.monitorrev);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800862 len = snprintf(buf, PAGE_SIZE, "%d.%d-%d[%d]\n",
Mark Haverkamp0bb14af2005-06-01 10:24:38 -0700863 tmp >> 24, (tmp >> 16) & 0xff, tmp & 0xff,
864 le32_to_cpu(dev->adapter_info.monitorbuild));
865 return len;
866}
867
Tony Jonesee959b02008-02-22 00:13:36 +0100868static ssize_t aac_show_bios_version(struct device *device,
869 struct device_attribute *attr,
870 char *buf)
Mark Haverkamp0bb14af2005-06-01 10:24:38 -0700871{
Tony Jonesee959b02008-02-22 00:13:36 +0100872 struct aac_dev *dev = (struct aac_dev*)class_to_shost(device)->hostdata;
Mark Haverkamp0bb14af2005-06-01 10:24:38 -0700873 int len, tmp;
874
875 tmp = le32_to_cpu(dev->adapter_info.biosrev);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -0800876 len = snprintf(buf, PAGE_SIZE, "%d.%d-%d[%d]\n",
Mark Haverkamp0bb14af2005-06-01 10:24:38 -0700877 tmp >> 24, (tmp >> 16) & 0xff, tmp & 0xff,
878 le32_to_cpu(dev->adapter_info.biosbuild));
879 return len;
880}
881
Harvey Harrison13a17fd2008-05-08 12:08:53 -0700882static ssize_t aac_show_serial_number(struct device *device,
Tony Jonesee959b02008-02-22 00:13:36 +0100883 struct device_attribute *attr, char *buf)
Mark Haverkamp0bb14af2005-06-01 10:24:38 -0700884{
Tony Jonesee959b02008-02-22 00:13:36 +0100885 struct aac_dev *dev = (struct aac_dev*)class_to_shost(device)->hostdata;
Mark Haverkamp0bb14af2005-06-01 10:24:38 -0700886 int len = 0;
887
888 if (le32_to_cpu(dev->adapter_info.serial[0]) != 0xBAD0)
Dan Carpenterdc55b822011-10-08 13:45:07 +0300889 len = snprintf(buf, 16, "%06X\n",
Mark Haverkamp0bb14af2005-06-01 10:24:38 -0700890 le32_to_cpu(dev->adapter_info.serial[0]));
Salyzyn, Mark24f02e12007-06-19 16:29:24 -0400891 if (len &&
892 !memcmp(&dev->supplement_adapter_info.MfgPcbaSerialNo[
Salyzyn, Mark95f6fb52008-02-08 09:01:34 -0800893 sizeof(dev->supplement_adapter_info.MfgPcbaSerialNo)-len],
894 buf, len-1))
Dan Carpenterdc55b822011-10-08 13:45:07 +0300895 len = snprintf(buf, 16, "%.*s\n",
Salyzyn, Mark24f02e12007-06-19 16:29:24 -0400896 (int)sizeof(dev->supplement_adapter_info.MfgPcbaSerialNo),
897 dev->supplement_adapter_info.MfgPcbaSerialNo);
Dan Carpenterdc55b822011-10-08 13:45:07 +0300898
899 return min(len, 16);
Mark Haverkamp0bb14af2005-06-01 10:24:38 -0700900}
901
Tony Jonesee959b02008-02-22 00:13:36 +0100902static ssize_t aac_show_max_channel(struct device *device,
903 struct device_attribute *attr, char *buf)
Mark Haverkampd1ad94a2006-03-27 09:44:29 -0800904{
905 return snprintf(buf, PAGE_SIZE, "%d\n",
Tony Jonesee959b02008-02-22 00:13:36 +0100906 class_to_shost(device)->max_channel);
Mark Haverkampd1ad94a2006-03-27 09:44:29 -0800907}
908
Tony Jonesee959b02008-02-22 00:13:36 +0100909static ssize_t aac_show_max_id(struct device *device,
910 struct device_attribute *attr, char *buf)
Mark Haverkampd1ad94a2006-03-27 09:44:29 -0800911{
912 return snprintf(buf, PAGE_SIZE, "%d\n",
Tony Jonesee959b02008-02-22 00:13:36 +0100913 class_to_shost(device)->max_id);
Mark Haverkampd1ad94a2006-03-27 09:44:29 -0800914}
915
Tony Jonesee959b02008-02-22 00:13:36 +0100916static ssize_t aac_store_reset_adapter(struct device *device,
917 struct device_attribute *attr,
918 const char *buf, size_t count)
Salyzyn, Mark29c97682007-06-12 09:33:54 -0400919{
920 int retval = -EACCES;
921
922 if (!capable(CAP_SYS_ADMIN))
923 return retval;
Tony Jonesee959b02008-02-22 00:13:36 +0100924 retval = aac_reset_adapter((struct aac_dev*)class_to_shost(device)->hostdata, buf[0] == '!');
Salyzyn, Mark29c97682007-06-12 09:33:54 -0400925 if (retval >= 0)
926 retval = count;
927 return retval;
928}
929
Tony Jonesee959b02008-02-22 00:13:36 +0100930static ssize_t aac_show_reset_adapter(struct device *device,
931 struct device_attribute *attr,
932 char *buf)
Salyzyn, Mark29c97682007-06-12 09:33:54 -0400933{
Tony Jonesee959b02008-02-22 00:13:36 +0100934 struct aac_dev *dev = (struct aac_dev*)class_to_shost(device)->hostdata;
Salyzyn, Mark29c97682007-06-12 09:33:54 -0400935 int len, tmp;
936
937 tmp = aac_adapter_check_health(dev);
938 if ((tmp == 0) && dev->in_reset)
939 tmp = -EBUSY;
Salyzyn, Markbbf17d62007-07-23 10:13:48 -0400940 len = snprintf(buf, PAGE_SIZE, "0x%x\n", tmp);
Salyzyn, Mark29c97682007-06-12 09:33:54 -0400941 return len;
942}
Mark Haverkamp0bb14af2005-06-01 10:24:38 -0700943
Tony Jonesee959b02008-02-22 00:13:36 +0100944static struct device_attribute aac_model = {
Mark Haverkamp0bb14af2005-06-01 10:24:38 -0700945 .attr = {
946 .name = "model",
947 .mode = S_IRUGO,
948 },
949 .show = aac_show_model,
950};
Tony Jonesee959b02008-02-22 00:13:36 +0100951static struct device_attribute aac_vendor = {
Mark Haverkamp0bb14af2005-06-01 10:24:38 -0700952 .attr = {
953 .name = "vendor",
954 .mode = S_IRUGO,
955 },
956 .show = aac_show_vendor,
957};
Tony Jonesee959b02008-02-22 00:13:36 +0100958static struct device_attribute aac_flags = {
Salyzyn, Mark2ca39c42008-01-17 09:24:56 -0800959 .attr = {
960 .name = "flags",
961 .mode = S_IRUGO,
962 },
963 .show = aac_show_flags,
964};
Tony Jonesee959b02008-02-22 00:13:36 +0100965static struct device_attribute aac_kernel_version = {
Mark Haverkamp0bb14af2005-06-01 10:24:38 -0700966 .attr = {
967 .name = "hba_kernel_version",
968 .mode = S_IRUGO,
969 },
970 .show = aac_show_kernel_version,
971};
Tony Jonesee959b02008-02-22 00:13:36 +0100972static struct device_attribute aac_monitor_version = {
Mark Haverkamp0bb14af2005-06-01 10:24:38 -0700973 .attr = {
974 .name = "hba_monitor_version",
975 .mode = S_IRUGO,
976 },
977 .show = aac_show_monitor_version,
978};
Tony Jonesee959b02008-02-22 00:13:36 +0100979static struct device_attribute aac_bios_version = {
Mark Haverkamp0bb14af2005-06-01 10:24:38 -0700980 .attr = {
981 .name = "hba_bios_version",
982 .mode = S_IRUGO,
983 },
984 .show = aac_show_bios_version,
985};
Tony Jonesee959b02008-02-22 00:13:36 +0100986static struct device_attribute aac_serial_number = {
Mark Haverkamp0bb14af2005-06-01 10:24:38 -0700987 .attr = {
988 .name = "serial_number",
989 .mode = S_IRUGO,
990 },
991 .show = aac_show_serial_number,
992};
Tony Jonesee959b02008-02-22 00:13:36 +0100993static struct device_attribute aac_max_channel = {
Mark Haverkampd1ad94a2006-03-27 09:44:29 -0800994 .attr = {
995 .name = "max_channel",
996 .mode = S_IRUGO,
997 },
998 .show = aac_show_max_channel,
999};
Tony Jonesee959b02008-02-22 00:13:36 +01001000static struct device_attribute aac_max_id = {
Mark Haverkampd1ad94a2006-03-27 09:44:29 -08001001 .attr = {
1002 .name = "max_id",
1003 .mode = S_IRUGO,
1004 },
1005 .show = aac_show_max_id,
1006};
Tony Jonesee959b02008-02-22 00:13:36 +01001007static struct device_attribute aac_reset = {
Salyzyn, Mark29c97682007-06-12 09:33:54 -04001008 .attr = {
1009 .name = "reset_host",
1010 .mode = S_IWUSR|S_IRUGO,
1011 },
1012 .store = aac_store_reset_adapter,
1013 .show = aac_show_reset_adapter,
1014};
Mark Haverkamp0bb14af2005-06-01 10:24:38 -07001015
Tony Jonesee959b02008-02-22 00:13:36 +01001016static struct device_attribute *aac_attrs[] = {
Mark Haverkamp0bb14af2005-06-01 10:24:38 -07001017 &aac_model,
1018 &aac_vendor,
Salyzyn, Mark2ca39c42008-01-17 09:24:56 -08001019 &aac_flags,
Mark Haverkamp0bb14af2005-06-01 10:24:38 -07001020 &aac_kernel_version,
1021 &aac_monitor_version,
1022 &aac_bios_version,
1023 &aac_serial_number,
Mark Haverkampd1ad94a2006-03-27 09:44:29 -08001024 &aac_max_channel,
1025 &aac_max_id,
Salyzyn, Mark29c97682007-06-12 09:33:54 -04001026 &aac_reset,
Mark Haverkamp0bb14af2005-06-01 10:24:38 -07001027 NULL
1028};
1029
Tony Jonesee959b02008-02-22 00:13:36 +01001030ssize_t aac_get_serial_number(struct device *device, char *buf)
1031{
1032 return aac_show_serial_number(device, &aac_serial_number, buf);
1033}
Mark Haverkamp0bb14af2005-06-01 10:24:38 -07001034
Arjan van de Ven00977a52007-02-12 00:55:34 -08001035static const struct file_operations aac_cfg_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 .owner = THIS_MODULE,
Arnd Bergmannf4927c42010-04-27 00:24:01 +02001037 .unlocked_ioctl = aac_cfg_ioctl,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038#ifdef CONFIG_COMPAT
1039 .compat_ioctl = aac_compat_cfg_ioctl,
1040#endif
1041 .open = aac_cfg_open,
Arnd Bergmann6038f372010-08-15 18:52:59 +02001042 .llseek = noop_llseek,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043};
1044
1045static struct scsi_host_template aac_driver_template = {
1046 .module = THIS_MODULE,
Salyzyn, Mark8ef22242008-02-08 05:48:22 -08001047 .name = "AAC",
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001048 .proc_name = AAC_DRIVERNAME,
Salyzyn, Mark8ef22242008-02-08 05:48:22 -08001049 .info = aac_info,
1050 .ioctl = aac_ioctl,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051#ifdef CONFIG_COMPAT
1052 .compat_ioctl = aac_compat_ioctl,
1053#endif
Salyzyn, Mark8ef22242008-02-08 05:48:22 -08001054 .queuecommand = aac_queuecommand,
1055 .bios_param = aac_biosparm,
Mark Haverkamp0bb14af2005-06-01 10:24:38 -07001056 .shost_attrs = aac_attrs,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057 .slave_configure = aac_slave_configure,
Salyzyn, Mark5c9cfed2007-05-30 10:01:14 -04001058 .change_queue_depth = aac_change_queue_depth,
Salyzyn, Mark17eaace2008-01-08 12:23:49 -08001059 .sdev_attrs = aac_dev_attrs,
Mark Haverkamp03d44332007-03-15 10:27:45 -07001060 .eh_abort_handler = aac_eh_abort,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061 .eh_host_reset_handler = aac_eh_reset,
Salyzyn, Mark8ef22242008-02-08 05:48:22 -08001062 .can_queue = AAC_NUM_IO_FIB,
1063 .this_id = MAXIMUM_NUM_CONTAINERS,
1064 .sg_tablesize = 16,
1065 .max_sectors = 128,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066#if (AAC_NUM_IO_FIB > 256)
1067 .cmd_per_lun = 256,
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001068#else
Salyzyn, Mark8ef22242008-02-08 05:48:22 -08001069 .cmd_per_lun = AAC_NUM_IO_FIB,
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001070#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071 .use_clustering = ENABLE_CLUSTERING,
Salyzyn, Mark8ef22242008-02-08 05:48:22 -08001072 .emulated = 1,
Martin K. Petersen54b2b502013-10-23 06:25:40 -04001073 .no_write_same = 1,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074};
1075
Salyzyn, Mark94774a32007-05-30 11:59:13 -04001076static void __aac_shutdown(struct aac_dev * aac)
1077{
Mahesh Rajashekhara495c0212015-03-26 10:41:25 -04001078 int i;
Mahesh Rajashekharaef616232015-03-26 10:41:30 -04001079 int cpu;
Mahesh Rajashekhara495c0212015-03-26 10:41:25 -04001080
Ben Collins361ee9c2012-06-11 14:16:36 -04001081 if (aac->aif_thread) {
1082 int i;
1083 /* Clear out events first */
1084 for (i = 0; i < (aac->scsi_host_ptr->can_queue + AAC_NUM_MGT_FIB); i++) {
1085 struct fib *fib = &aac->fibs[i];
1086 if (!(fib->hw_fib_va->header.XferState & cpu_to_le32(NoResponseExpected | Async)) &&
1087 (fib->hw_fib_va->header.XferState & cpu_to_le32(ResponseExpected)))
1088 up(&fib->event_wait);
1089 }
Salyzyn, Marke85fbc52007-10-31 16:40:37 -04001090 kthread_stop(aac->thread);
Ben Collins361ee9c2012-06-11 14:16:36 -04001091 }
Salyzyn, Mark94774a32007-05-30 11:59:13 -04001092 aac_send_shutdown(aac);
1093 aac_adapter_disable_int(aac);
Mahesh Rajashekharaef616232015-03-26 10:41:30 -04001094 cpu = cpumask_first(cpu_online_mask);
Mahesh Rajashekhara495c0212015-03-26 10:41:25 -04001095 if (aac->pdev->device == PMC_DEVICE_S6 ||
1096 aac->pdev->device == PMC_DEVICE_S7 ||
1097 aac->pdev->device == PMC_DEVICE_S8 ||
1098 aac->pdev->device == PMC_DEVICE_S9) {
1099 if (aac->max_msix > 1) {
Mahesh Rajashekharaef616232015-03-26 10:41:30 -04001100 for (i = 0; i < aac->max_msix; i++) {
1101 if (irq_set_affinity_hint(
1102 aac->msixentry[i].vector,
1103 NULL)) {
1104 printk(KERN_ERR "%s%d: Failed to reset IRQ affinity for cpu %d\n",
1105 aac->name,
1106 aac->id,
1107 cpu);
1108 }
1109 cpu = cpumask_next(cpu,
1110 cpu_online_mask);
Mahesh Rajashekhara495c0212015-03-26 10:41:25 -04001111 free_irq(aac->msixentry[i].vector,
1112 &(aac->aac_msix[i]));
Mahesh Rajashekharaef616232015-03-26 10:41:30 -04001113 }
Mahesh Rajashekhara495c0212015-03-26 10:41:25 -04001114 } else {
1115 free_irq(aac->pdev->irq,
1116 &(aac->aac_msix[0]));
1117 }
1118 } else {
1119 free_irq(aac->pdev->irq, aac);
1120 }
Salyzyn, Mark8ef22242008-02-08 05:48:22 -08001121 if (aac->msi)
1122 pci_disable_msi(aac->pdev);
Mahesh Rajashekhara495c0212015-03-26 10:41:25 -04001123 else if (aac->max_msix > 1)
1124 pci_disable_msix(aac->pdev);
Salyzyn, Mark94774a32007-05-30 11:59:13 -04001125}
1126
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08001127static int aac_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128{
1129 unsigned index = id->driver_data;
1130 struct Scsi_Host *shost;
1131 struct aac_dev *aac;
1132 struct list_head *insert = &aac_devices;
1133 int error = -ENODEV;
1134 int unique_id = 0;
Rolf Eike Beer0dcae662009-07-01 22:43:39 +02001135 u64 dmamask;
Mahesh Rajashekhara11604612012-02-08 22:51:04 -08001136 extern int aac_sync_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137
1138 list_for_each_entry(aac, &aac_devices, entry) {
1139 if (aac->id > unique_id)
1140 break;
1141 insert = &aac->entry;
1142 unique_id++;
1143 }
1144
Vasily Averincf161232011-11-11 13:42:16 +04001145 pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1 |
1146 PCIE_LINK_STATE_CLKPM);
1147
Mark Haverkamp08efb7b2005-09-20 12:56:36 -07001148 error = pci_enable_device(pdev);
1149 if (error)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150 goto out;
Mark Haverkampe61b17f2006-03-27 09:44:11 -08001151 error = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153 /*
1154 * If the quirk31 bit is set, the adapter needs adapter
1155 * to driver communication memory to be allocated below 2gig
1156 */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001157 if (aac_drivers[index].quirks & AAC_QUIRK_31BIT)
Rolf Eike Beer0dcae662009-07-01 22:43:39 +02001158 dmamask = DMA_BIT_MASK(31);
1159 else
1160 dmamask = DMA_BIT_MASK(32);
1161
1162 if (pci_set_dma_mask(pdev, dmamask) ||
1163 pci_set_consistent_dma_mask(pdev, dmamask))
1164 goto out_disable_pdev;
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001165
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166 pci_set_master(pdev);
1167
1168 shost = scsi_host_alloc(&aac_driver_template, sizeof(struct aac_dev));
1169 if (!shost)
1170 goto out_disable_pdev;
1171
1172 shost->irq = pdev->irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173 shost->unique_id = unique_id;
Mark Haverkamp7a8cf292005-09-22 09:15:24 -07001174 shost->max_cmd_len = 16;
Kashyap.Desai@avagotech.com64bdcbc2014-08-20 19:24:33 +05301175 shost->use_cmd_list = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176
1177 aac = (struct aac_dev *)shost->hostdata;
Ben Collinsff087842012-06-11 14:05:02 -04001178 aac->base_start = pci_resource_start(pdev, 0);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001179 aac->scsi_host_ptr = shost;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180 aac->pdev = pdev;
1181 aac->name = aac_driver_template.name;
1182 aac->id = shost->unique_id;
Mark Salyzyna4576b52008-04-30 15:47:35 -04001183 aac->cardtype = index;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184 INIT_LIST_HEAD(&aac->entry);
1185
Mahesh Rajashekhara85d22bb2012-07-14 18:18:51 +05301186 aac->fibs = kzalloc(sizeof(struct fib) * (shost->can_queue + AAC_NUM_MGT_FIB), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187 if (!aac->fibs)
1188 goto out_free_host;
1189 spin_lock_init(&aac->fib_lock);
1190
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -07001191 /*
1192 * Map in the registers from the adapter.
1193 */
1194 aac->base_size = AAC_MIN_FOOTPRINT_SIZE;
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -07001195 if ((*aac_drivers[index].init)(aac))
1196 goto out_unmap;
1197
Mahesh Rajashekhara11604612012-02-08 22:51:04 -08001198 if (aac->sync_mode) {
1199 if (aac_sync_mode)
1200 printk(KERN_INFO "%s%d: Sync. mode enforced "
1201 "by driver parameter. This will cause "
1202 "a significant performance decrease!\n",
1203 aac->name,
1204 aac->id);
1205 else
1206 printk(KERN_INFO "%s%d: Async. mode not supported "
1207 "by current driver, sync. mode enforced."
1208 "\nPlease update driver to get full performance.\n",
1209 aac->name,
1210 aac->id);
1211 }
1212
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -07001213 /*
1214 * Start any kernel threads needed
1215 */
Christoph Hellwigfe273812006-02-14 18:45:06 +01001216 aac->thread = kthread_run(aac_command_thread, aac, AAC_DRIVERNAME);
1217 if (IS_ERR(aac->thread)) {
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -07001218 printk(KERN_ERR "aacraid: Unable to create command thread.\n");
Christoph Hellwigfe273812006-02-14 18:45:06 +01001219 error = PTR_ERR(aac->thread);
Ben Collins361ee9c2012-06-11 14:16:36 -04001220 aac->thread = NULL;
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -07001221 goto out_deinit;
1222 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223
1224 /*
1225 * If we had set a smaller DMA mask earlier, set it to 4gig
1226 * now since the adapter can dma data to at least a 4gig
1227 * address space.
1228 */
1229 if (aac_drivers[index].quirks & AAC_QUIRK_31BIT)
Yang Hongyang284901a2009-04-06 19:01:15 -07001230 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)))
James Bottomley71e0f322005-10-28 11:21:10 -05001231 goto out_deinit;
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001232
Mark Haverkamp84971732005-06-20 11:55:24 -07001233 aac->maximum_num_channels = aac_drivers[index].channels;
Mark Haverkamp08efb7b2005-09-20 12:56:36 -07001234 error = aac_get_adapter_info(aac);
1235 if (error < 0)
1236 goto out_deinit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237
1238 /*
Mark Salyzyna4576b52008-04-30 15:47:35 -04001239 * Lets override negotiations and drop the maximum SG limit to 34
1240 */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001241 if ((aac_drivers[index].quirks & AAC_QUIRK_34SG) &&
Salyzyn, Mark62e9f5c2008-02-06 09:00:46 -08001242 (shost->sg_tablesize > 34)) {
1243 shost->sg_tablesize = 34;
1244 shost->max_sectors = (shost->sg_tablesize * 8) + 112;
Mark Salyzyna4576b52008-04-30 15:47:35 -04001245 }
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001246
Mark Salyzyna4576b52008-04-30 15:47:35 -04001247 if ((aac_drivers[index].quirks & AAC_QUIRK_17SG) &&
Salyzyn, Mark62e9f5c2008-02-06 09:00:46 -08001248 (shost->sg_tablesize > 17)) {
1249 shost->sg_tablesize = 17;
1250 shost->max_sectors = (shost->sg_tablesize * 8) + 112;
Mark Salyzyna4576b52008-04-30 15:47:35 -04001251 }
Mark Haverkampdb39363c2006-01-11 09:28:29 -08001252
Salyzyn, Mark62e9f5c2008-02-06 09:00:46 -08001253 error = pci_set_dma_max_seg_size(pdev,
1254 (aac->adapter_info.options & AAC_OPT_NEW_COMM) ?
1255 (shost->max_sectors << 9) : 65536);
1256 if (error)
1257 goto out_deinit;
1258
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001259 /*
Salyzyn, Mark62e9f5c2008-02-06 09:00:46 -08001260 * Firmware printf works only with older firmware.
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001261 */
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001262 if (aac_drivers[index].quirks & AAC_QUIRK_34SG)
Mark Haverkamp 7c00ffa2005-05-16 18:28:42 -07001263 aac->printf_enabled = 1;
1264 else
1265 aac->printf_enabled = 0;
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001266
Mark Salyzyna4576b52008-04-30 15:47:35 -04001267 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268 * max channel will be the physical channels plus 1 virtual channel
Mark Haverkampbb08f922006-02-01 09:30:44 -08001269 * all containers are on the virtual channel 0 (CONTAINER_CHANNEL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270 * physical channels are address by their actual physical number+1
1271 */
Salyzyn, Markcb1042f2008-01-17 09:25:07 -08001272 if (aac->nondasd_support || expose_physicals || aac->jbod)
Mark Haverkamp95433ba2006-03-27 09:44:15 -08001273 shost->max_channel = aac->maximum_num_channels;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274 else
Mark Haverkamp95433ba2006-03-27 09:44:15 -08001275 shost->max_channel = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276
Mark Haverkamp8c867b22006-08-03 08:03:30 -07001277 aac_get_config_status(aac, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278 aac_get_containers(aac);
1279 list_add(&aac->entry, insert);
1280
1281 shost->max_id = aac->maximum_num_containers;
Mark Haverkamp84971732005-06-20 11:55:24 -07001282 if (shost->max_id < aac->maximum_num_physicals)
1283 shost->max_id = aac->maximum_num_physicals;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284 if (shost->max_id < MAXIMUM_NUM_CONTAINERS)
1285 shost->max_id = MAXIMUM_NUM_CONTAINERS;
1286 else
1287 shost->this_id = shost->max_id;
1288
1289 /*
1290 * dmb - we may need to move the setting of these parms somewhere else once
1291 * we get a fib that can report the actual numbers
1292 */
1293 shost->max_lun = AAC_MAX_LUN;
1294
1295 pci_set_drvdata(pdev, shost);
1296
1297 error = scsi_add_host(shost, &pdev->dev);
1298 if (error)
1299 goto out_deinit;
1300 scsi_scan_host(shost);
1301
Raghava Aditya Renukunta5c63f7f2016-02-03 15:06:01 -08001302 pci_enable_pcie_error_reporting(pdev);
1303 pci_save_state(pdev);
1304
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305 return 0;
1306
Mark Haverkampbd1aac82005-08-03 15:39:01 -07001307 out_deinit:
Salyzyn, Mark94774a32007-05-30 11:59:13 -04001308 __aac_shutdown(aac);
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -07001309 out_unmap:
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001310 aac_fib_map_free(aac);
Salyzyn, Mark2b053722007-08-02 15:38:59 -04001311 if (aac->comm_addr)
1312 pci_free_consistent(aac->pdev, aac->comm_size, aac->comm_addr,
1313 aac->comm_phys);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314 kfree(aac->queues);
Mark Haverkamp76a7f8f2006-09-19 09:00:02 -07001315 aac_adapter_ioremap(aac, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316 kfree(aac->fibs);
1317 kfree(aac->fsa_dev);
1318 out_free_host:
1319 scsi_host_put(shost);
1320 out_disable_pdev:
1321 pci_disable_device(pdev);
1322 out:
1323 return error;
1324}
1325
Fengguang Wufe0798c2015-11-10 13:59:06 +08001326static void aac_release_resources(struct aac_dev *aac)
Mahesh Rajashekharade665f22015-08-28 06:38:34 -04001327{
1328 int i;
1329
1330 aac_adapter_disable_int(aac);
1331 if (aac->pdev->device == PMC_DEVICE_S6 ||
1332 aac->pdev->device == PMC_DEVICE_S7 ||
1333 aac->pdev->device == PMC_DEVICE_S8 ||
1334 aac->pdev->device == PMC_DEVICE_S9) {
1335 if (aac->max_msix > 1) {
1336 for (i = 0; i < aac->max_msix; i++)
1337 free_irq(aac->msixentry[i].vector,
1338 &(aac->aac_msix[i]));
1339 } else {
1340 free_irq(aac->pdev->irq, &(aac->aac_msix[0]));
1341 }
1342 } else {
1343 free_irq(aac->pdev->irq, aac);
1344 }
1345 if (aac->msi)
1346 pci_disable_msi(aac->pdev);
1347 else if (aac->max_msix > 1)
1348 pci_disable_msix(aac->pdev);
1349
1350}
1351
1352static int aac_acquire_resources(struct aac_dev *dev)
1353{
1354 int i, j;
1355 int instance = dev->id;
1356 const char *name = dev->name;
1357 unsigned long status;
1358 /*
1359 * First clear out all interrupts. Then enable the one's that we
1360 * can handle.
1361 */
1362 while (!((status = src_readl(dev, MUnit.OMR)) & KERNEL_UP_AND_RUNNING)
1363 || status == 0xffffffff)
1364 msleep(20);
1365
1366 aac_adapter_disable_int(dev);
1367 aac_adapter_enable_int(dev);
1368
1369
1370 if ((dev->pdev->device == PMC_DEVICE_S7 ||
1371 dev->pdev->device == PMC_DEVICE_S8 ||
1372 dev->pdev->device == PMC_DEVICE_S9))
1373 aac_define_int_mode(dev);
1374
1375 if (dev->msi_enabled)
1376 aac_src_access_devreg(dev, AAC_ENABLE_MSIX);
1377
1378 if (!dev->sync_mode && dev->msi_enabled && dev->max_msix > 1) {
1379 for (i = 0; i < dev->max_msix; i++) {
1380 dev->aac_msix[i].vector_no = i;
1381 dev->aac_msix[i].dev = dev;
1382
1383 if (request_irq(dev->msixentry[i].vector,
1384 dev->a_ops.adapter_intr,
1385 0, "aacraid", &(dev->aac_msix[i]))) {
1386 printk(KERN_ERR "%s%d: Failed to register IRQ for vector %d.\n",
1387 name, instance, i);
1388 for (j = 0 ; j < i ; j++)
1389 free_irq(dev->msixentry[j].vector,
1390 &(dev->aac_msix[j]));
1391 pci_disable_msix(dev->pdev);
1392 goto error_iounmap;
1393 }
1394 }
1395 } else {
1396 dev->aac_msix[0].vector_no = 0;
1397 dev->aac_msix[0].dev = dev;
1398
1399 if (request_irq(dev->pdev->irq, dev->a_ops.adapter_intr,
1400 IRQF_SHARED, "aacraid",
1401 &(dev->aac_msix[0])) < 0) {
1402 if (dev->msi)
1403 pci_disable_msi(dev->pdev);
1404 printk(KERN_ERR "%s%d: Interrupt unavailable.\n",
1405 name, instance);
1406 goto error_iounmap;
1407 }
1408 }
1409
1410 aac_adapter_enable_int(dev);
1411
1412 if (!dev->sync_mode)
1413 aac_adapter_start(dev);
1414 return 0;
1415
1416error_iounmap:
1417 return -1;
1418
1419}
Raghava Aditya Renukunta5c63f7f2016-02-03 15:06:01 -08001420
1421#if (defined(CONFIG_PM))
Mahesh Rajashekharade665f22015-08-28 06:38:34 -04001422static int aac_suspend(struct pci_dev *pdev, pm_message_t state)
1423{
1424
1425 struct Scsi_Host *shost = pci_get_drvdata(pdev);
1426 struct aac_dev *aac = (struct aac_dev *)shost->hostdata;
1427
1428 scsi_block_requests(shost);
1429 aac_send_shutdown(aac);
1430
1431 aac_release_resources(aac);
1432
1433 pci_set_drvdata(pdev, shost);
1434 pci_save_state(pdev);
1435 pci_disable_device(pdev);
1436 pci_set_power_state(pdev, pci_choose_state(pdev, state));
1437
1438 return 0;
1439}
1440
1441static int aac_resume(struct pci_dev *pdev)
1442{
1443 struct Scsi_Host *shost = pci_get_drvdata(pdev);
1444 struct aac_dev *aac = (struct aac_dev *)shost->hostdata;
1445 int r;
1446
1447 pci_set_power_state(pdev, PCI_D0);
1448 pci_enable_wake(pdev, PCI_D0, 0);
1449 pci_restore_state(pdev);
1450 r = pci_enable_device(pdev);
1451
1452 if (r)
1453 goto fail_device;
1454
1455 pci_set_master(pdev);
1456 if (aac_acquire_resources(aac))
1457 goto fail_device;
Mahesh Rajashekharae728f8e2015-08-28 06:38:39 -04001458 /*
1459 * reset this flag to unblock ioctl() as it was set at
1460 * aac_send_shutdown() to block ioctls from upperlayer
1461 */
1462 aac->adapter_shutdown = 0;
Mahesh Rajashekharade665f22015-08-28 06:38:34 -04001463 scsi_unblock_requests(shost);
1464
1465 return 0;
1466
1467fail_device:
1468 printk(KERN_INFO "%s%d: resume failed.\n", aac->name, aac->id);
1469 scsi_host_put(shost);
1470 pci_disable_device(pdev);
1471 return -ENODEV;
1472}
1473#endif
1474
Mark Haverkampbd1aac82005-08-03 15:39:01 -07001475static void aac_shutdown(struct pci_dev *dev)
1476{
1477 struct Scsi_Host *shost = pci_get_drvdata(dev);
Salyzyn, Mark94774a32007-05-30 11:59:13 -04001478 scsi_block_requests(shost);
Salyzyn, Markc835e372007-07-26 14:20:02 -04001479 __aac_shutdown((struct aac_dev *)shost->hostdata);
Mark Haverkampbd1aac82005-08-03 15:39:01 -07001480}
1481
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08001482static void aac_remove_one(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483{
1484 struct Scsi_Host *shost = pci_get_drvdata(pdev);
1485 struct aac_dev *aac = (struct aac_dev *)shost->hostdata;
1486
1487 scsi_remove_host(shost);
1488
Salyzyn, Mark94774a32007-05-30 11:59:13 -04001489 __aac_shutdown(aac);
Mark Haverkampbfb35aa82006-02-01 09:30:55 -08001490 aac_fib_map_free(aac);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491 pci_free_consistent(aac->pdev, aac->comm_size, aac->comm_addr,
1492 aac->comm_phys);
1493 kfree(aac->queues);
1494
Mark Haverkamp76a7f8f2006-09-19 09:00:02 -07001495 aac_adapter_ioremap(aac, 0);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001496
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497 kfree(aac->fibs);
Mark Haverkamp8e0c5eb2005-10-24 10:52:22 -07001498 kfree(aac->fsa_dev);
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001499
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500 list_del(&aac->entry);
1501 scsi_host_put(shost);
1502 pci_disable_device(pdev);
Mark Haverkamp90ee3462006-08-03 08:03:07 -07001503 if (list_empty(&aac_devices)) {
1504 unregister_chrdev(aac_cfg_major, "aac");
1505 aac_cfg_major = -1;
1506 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507}
1508
Raghava Aditya Renukunta5c63f7f2016-02-03 15:06:01 -08001509static void aac_flush_ios(struct aac_dev *aac)
1510{
1511 int i;
1512 struct scsi_cmnd *cmd;
1513
1514 for (i = 0; i < aac->scsi_host_ptr->can_queue; i++) {
1515 cmd = (struct scsi_cmnd *)aac->fibs[i].callback_data;
1516 if (cmd && (cmd->SCp.phase == AAC_OWNER_FIRMWARE)) {
1517 scsi_dma_unmap(cmd);
1518
1519 if (aac->handle_pci_error)
1520 cmd->result = DID_NO_CONNECT << 16;
1521 else
1522 cmd->result = DID_RESET << 16;
1523
1524 cmd->scsi_done(cmd);
1525 }
1526 }
1527}
1528
1529static pci_ers_result_t aac_pci_error_detected(struct pci_dev *pdev,
1530 enum pci_channel_state error)
1531{
1532 struct Scsi_Host *shost = pci_get_drvdata(pdev);
1533 struct aac_dev *aac = shost_priv(shost);
1534
1535 dev_err(&pdev->dev, "aacraid: PCI error detected %x\n", error);
1536
1537 switch (error) {
1538 case pci_channel_io_normal:
1539 return PCI_ERS_RESULT_CAN_RECOVER;
1540 case pci_channel_io_frozen:
1541 aac->handle_pci_error = 1;
1542
1543 scsi_block_requests(aac->scsi_host_ptr);
1544 aac_flush_ios(aac);
1545 aac_release_resources(aac);
1546
1547 pci_disable_pcie_error_reporting(pdev);
1548 aac_adapter_ioremap(aac, 0);
1549
1550 return PCI_ERS_RESULT_NEED_RESET;
1551 case pci_channel_io_perm_failure:
1552 aac->handle_pci_error = 1;
1553
1554 aac_flush_ios(aac);
1555 return PCI_ERS_RESULT_DISCONNECT;
1556 }
1557
1558 return PCI_ERS_RESULT_NEED_RESET;
1559}
1560
1561static pci_ers_result_t aac_pci_mmio_enabled(struct pci_dev *pdev)
1562{
1563 dev_err(&pdev->dev, "aacraid: PCI error - mmio enabled\n");
1564 return PCI_ERS_RESULT_NEED_RESET;
1565}
1566
1567static pci_ers_result_t aac_pci_slot_reset(struct pci_dev *pdev)
1568{
1569 dev_err(&pdev->dev, "aacraid: PCI error - slot reset\n");
1570 pci_restore_state(pdev);
1571 if (pci_enable_device(pdev)) {
1572 dev_warn(&pdev->dev,
1573 "aacraid: failed to enable slave\n");
1574 goto fail_device;
1575 }
1576
1577 pci_set_master(pdev);
1578
1579 if (pci_enable_device_mem(pdev)) {
1580 dev_err(&pdev->dev, "pci_enable_device_mem failed\n");
1581 goto fail_device;
1582 }
1583
1584 return PCI_ERS_RESULT_RECOVERED;
1585
1586fail_device:
1587 dev_err(&pdev->dev, "aacraid: PCI error - slot reset failed\n");
1588 return PCI_ERS_RESULT_DISCONNECT;
1589}
1590
1591
1592static void aac_pci_resume(struct pci_dev *pdev)
1593{
1594 struct Scsi_Host *shost = pci_get_drvdata(pdev);
1595 struct scsi_device *sdev = NULL;
1596 struct aac_dev *aac = (struct aac_dev *)shost_priv(shost);
1597
1598 pci_cleanup_aer_uncorrect_error_status(pdev);
1599
1600 if (aac_adapter_ioremap(aac, aac->base_size)) {
1601
1602 dev_err(&pdev->dev, "aacraid: ioremap failed\n");
1603 /* remap failed, go back ... */
1604 aac->comm_interface = AAC_COMM_PRODUCER;
1605 if (aac_adapter_ioremap(aac, AAC_MIN_FOOTPRINT_SIZE)) {
1606 dev_warn(&pdev->dev,
1607 "aacraid: unable to map adapter.\n");
1608
1609 return;
1610 }
1611 }
1612
1613 msleep(10000);
1614
1615 aac_acquire_resources(aac);
1616
1617 /*
1618 * reset this flag to unblock ioctl() as it was set
1619 * at aac_send_shutdown() to block ioctls from upperlayer
1620 */
1621 aac->adapter_shutdown = 0;
1622 aac->handle_pci_error = 0;
1623
1624 shost_for_each_device(sdev, shost)
1625 if (sdev->sdev_state == SDEV_OFFLINE)
1626 sdev->sdev_state = SDEV_RUNNING;
1627 scsi_unblock_requests(aac->scsi_host_ptr);
1628 scsi_scan_host(aac->scsi_host_ptr);
1629 pci_save_state(pdev);
1630
1631 dev_err(&pdev->dev, "aacraid: PCI error - resume\n");
1632}
1633
1634static struct pci_error_handlers aac_pci_err_handler = {
1635 .error_detected = aac_pci_error_detected,
1636 .mmio_enabled = aac_pci_mmio_enabled,
1637 .slot_reset = aac_pci_slot_reset,
1638 .resume = aac_pci_resume,
1639};
1640
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641static struct pci_driver aac_pci_driver = {
1642 .name = AAC_DRIVERNAME,
1643 .id_table = aac_pci_tbl,
1644 .probe = aac_probe_one,
Greg Kroah-Hartman6f039792012-12-21 13:08:55 -08001645 .remove = aac_remove_one,
Mahesh Rajashekharade665f22015-08-28 06:38:34 -04001646#if (defined(CONFIG_PM))
1647 .suspend = aac_suspend,
1648 .resume = aac_resume,
1649#endif
Salyzyn, Mark8ef22242008-02-08 05:48:22 -08001650 .shutdown = aac_shutdown,
Raghava Aditya Renukunta5c63f7f2016-02-03 15:06:01 -08001651 .err_handler = &aac_pci_err_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001652};
1653
1654static int __init aac_init(void)
1655{
1656 int error;
Salyzyn, Mark8ce3eca2008-01-16 07:39:06 -08001657
Salyzyn, Mark29c97682007-06-12 09:33:54 -04001658 printk(KERN_INFO "Adaptec %s driver %s\n",
Mark Haverkampc7f47602005-08-03 15:38:55 -07001659 AAC_DRIVERNAME, aac_driver_version);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660
Mark Haverkamp08efb7b2005-09-20 12:56:36 -07001661 error = pci_register_driver(&aac_pci_driver);
1662 if (error < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663 return error;
1664
1665 aac_cfg_major = register_chrdev( 0, "aac", &aac_cfg_fops);
1666 if (aac_cfg_major < 0) {
1667 printk(KERN_WARNING
Salyzyn, Mark8ef22242008-02-08 05:48:22 -08001668 "aacraid: unable to register \"aac\" device.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669 }
Mark Haverkampbd1aac82005-08-03 15:39:01 -07001670
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671 return 0;
1672}
1673
1674static void __exit aac_exit(void)
1675{
Mark Haverkamp53926272006-03-27 09:44:19 -08001676 if (aac_cfg_major > -1)
1677 unregister_chrdev(aac_cfg_major, "aac");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678 pci_unregister_driver(&aac_pci_driver);
1679}
1680
1681module_init(aac_init);
1682module_exit(aac_exit);