blob: 29f66de4e8f16ef7ac421b9216fcff7f598deb25 [file] [log] [blame]
Moore, Eric Dean 2496af32005-04-22 18:02:41 -04001/*
2 * linux/drivers/message/fusion/mptfc.c
3 * For use with LSI Logic PCI chip/adapter(s)
4 * running LSI Logic Fusion MPT (Message Passing Technology) firmware.
5 *
6 * Copyright (c) 1999-2005 LSI Logic Corporation
7 * (mailto:mpt_linux_developer@lsil.com)
8 *
9 */
10/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
11/*
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; version 2 of the License.
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 NO WARRANTY
22 THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
23 CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
24 LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
25 MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
26 solely responsible for determining the appropriateness of using and
27 distributing the Program and assumes all risks associated with its
28 exercise of rights under this Agreement, including but not limited to
29 the risks and costs of program errors, damage to or loss of data,
30 programs or equipment, and unavailability or interruption of operations.
31
32 DISCLAIMER OF LIABILITY
33 NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
34 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
35 DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
36 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
37 TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
38 USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
39 HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
40
41 You should have received a copy of the GNU General Public License
42 along with this program; if not, write to the Free Software
43 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
44*/
45/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
46#include "linux_compat.h" /* linux-2.6 tweaks */
47#include <linux/module.h>
48#include <linux/kernel.h>
49#include <linux/init.h>
50#include <linux/errno.h>
51#include <linux/kdev_t.h>
52#include <linux/blkdev.h>
53#include <linux/delay.h> /* for mdelay */
54#include <linux/interrupt.h> /* needed for in_interrupt() proto */
55#include <linux/reboot.h> /* notifier code */
56#include <linux/sched.h>
57#include <linux/workqueue.h>
58
59#include <scsi/scsi.h>
60#include <scsi/scsi_cmnd.h>
61#include <scsi/scsi_device.h>
62#include <scsi/scsi_host.h>
63#include <scsi/scsi_tcq.h>
64
65#include "mptbase.h"
66#include "mptscsih.h"
67
68/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
69#define my_NAME "Fusion MPT FC Host driver"
70#define my_VERSION MPT_LINUX_VERSION_COMMON
71#define MYNAM "mptfc"
72
73MODULE_AUTHOR(MODULEAUTHOR);
74MODULE_DESCRIPTION(my_NAME);
75MODULE_LICENSE("GPL");
76
77/* Command line args */
78static int mpt_pq_filter = 0;
79module_param(mpt_pq_filter, int, 0);
80MODULE_PARM_DESC(mpt_pq_filter, " Enable peripheral qualifier filter: enable=1 (default=0)");
81
82static int mptfcDoneCtx = -1;
83static int mptfcTaskCtx = -1;
84static int mptfcInternalCtx = -1; /* Used only for internal commands */
85
Moore, Eric Dean 2496af32005-04-22 18:02:41 -040086static struct scsi_host_template mptfc_driver_template = {
87 .proc_name = "mptfc",
88 .proc_info = mptscsih_proc_info,
89 .name = "MPT FC Host",
90 .info = mptscsih_info,
91 .queuecommand = mptscsih_qcmd,
92 .slave_alloc = mptscsih_slave_alloc,
93 .slave_configure = mptscsih_slave_configure,
94 .slave_destroy = mptscsih_slave_destroy,
Moore, Eric Dean6e3815b2005-06-24 12:18:57 -060095 .change_queue_depth = mptscsih_change_queue_depth,
Moore, Eric Dean 2496af32005-04-22 18:02:41 -040096 .eh_abort_handler = mptscsih_abort,
97 .eh_device_reset_handler = mptscsih_dev_reset,
98 .eh_bus_reset_handler = mptscsih_bus_reset,
99 .eh_host_reset_handler = mptscsih_host_reset,
100 .bios_param = mptscsih_bios_param,
101 .can_queue = MPT_FC_CAN_QUEUE,
102 .this_id = -1,
103 .sg_tablesize = MPT_SCSI_SG_DEPTH,
104 .max_sectors = 8192,
105 .cmd_per_lun = 7,
106 .use_clustering = ENABLE_CLUSTERING,
Moore, Eric Dean 2496af32005-04-22 18:02:41 -0400107};
108
109/****************************************************************************
110 * Supported hardware
111 */
112
113static struct pci_device_id mptfc_pci_table[] = {
114 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_FC909,
115 PCI_ANY_ID, PCI_ANY_ID },
116 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_FC919,
117 PCI_ANY_ID, PCI_ANY_ID },
118 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_FC929,
119 PCI_ANY_ID, PCI_ANY_ID },
120 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_FC919X,
121 PCI_ANY_ID, PCI_ANY_ID },
122 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_FC929X,
123 PCI_ANY_ID, PCI_ANY_ID },
Moore, Eric Dean 3fadc592005-05-11 17:46:52 -0600124 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_FC939X,
125 PCI_ANY_ID, PCI_ANY_ID },
126 { PCI_VENDOR_ID_LSI_LOGIC, PCI_DEVICE_ID_LSI_FC949X,
127 PCI_ANY_ID, PCI_ANY_ID },
Moore, Eric Dean 2496af32005-04-22 18:02:41 -0400128 {0} /* Terminating entry */
129};
130MODULE_DEVICE_TABLE(pci, mptfc_pci_table);
131
132/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
133/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
134/*
135 * mptfc_probe - Installs scsi devices per bus.
136 * @pdev: Pointer to pci_dev structure
137 *
138 * Returns 0 for success, non-zero for failure.
139 *
140 */
141static int
142mptfc_probe(struct pci_dev *pdev, const struct pci_device_id *id)
143{
144 struct Scsi_Host *sh;
145 MPT_SCSI_HOST *hd;
146 MPT_ADAPTER *ioc;
147 unsigned long flags;
148 int sz, ii;
149 int numSGE = 0;
150 int scale;
151 int ioc_cap;
152 u8 *mem;
153 int error=0;
154 int r;
155
156 if ((r = mpt_attach(pdev,id)) != 0)
157 return r;
158
159 ioc = pci_get_drvdata(pdev);
Moore, Eric Dean d335cc32005-04-30 17:09:38 -0500160 ioc->DoneCtx = mptfcDoneCtx;
161 ioc->TaskCtx = mptfcTaskCtx;
162 ioc->InternalCtx = mptfcInternalCtx;
Moore, Eric Dean 2496af32005-04-22 18:02:41 -0400163
164 /* Added sanity check on readiness of the MPT adapter.
165 */
166 if (ioc->last_state != MPI_IOC_STATE_OPERATIONAL) {
167 printk(MYIOC_s_WARN_FMT
168 "Skipping because it's not operational!\n",
169 ioc->name);
170 return -ENODEV;
171 }
172
173 if (!ioc->active) {
174 printk(MYIOC_s_WARN_FMT "Skipping because it's disabled!\n",
175 ioc->name);
176 return -ENODEV;
177 }
178
179 /* Sanity check - ensure at least 1 port is INITIATOR capable
180 */
181 ioc_cap = 0;
182 for (ii=0; ii < ioc->facts.NumberOfPorts; ii++) {
183 if (ioc->pfacts[ii].ProtocolFlags &
184 MPI_PORTFACTS_PROTOCOL_INITIATOR)
185 ioc_cap ++;
186 }
187
188 if (!ioc_cap) {
189 printk(MYIOC_s_WARN_FMT
190 "Skipping ioc=%p because SCSI Initiator mode is NOT enabled!\n",
191 ioc->name, ioc);
192 return -ENODEV;
193 }
194
195 sh = scsi_host_alloc(&mptfc_driver_template, sizeof(MPT_SCSI_HOST));
196
197 if (!sh) {
198 printk(MYIOC_s_WARN_FMT
199 "Unable to register controller with SCSI subsystem\n",
200 ioc->name);
201 return -1;
202 }
203
204 spin_lock_irqsave(&ioc->FreeQlock, flags);
205
206 /* Attach the SCSI Host to the IOC structure
207 */
208 ioc->sh = sh;
209
210 sh->io_port = 0;
211 sh->n_io_port = 0;
212 sh->irq = 0;
213
214 /* set 16 byte cdb's */
215 sh->max_cmd_len = 16;
216
217 sh->max_id = MPT_MAX_FC_DEVICES<256 ? MPT_MAX_FC_DEVICES : 255;
218
219 sh->max_lun = MPT_LAST_LUN + 1;
220 sh->max_channel = 0;
221 sh->this_id = ioc->pfacts[0].PortSCSIID;
222
223 /* Required entry.
224 */
225 sh->unique_id = ioc->id;
226
227 /* Verify that we won't exceed the maximum
228 * number of chain buffers
229 * We can optimize: ZZ = req_sz/sizeof(SGE)
230 * For 32bit SGE's:
231 * numSGE = 1 + (ZZ-1)*(maxChain -1) + ZZ
232 * + (req_sz - 64)/sizeof(SGE)
233 * A slightly different algorithm is required for
234 * 64bit SGEs.
235 */
236 scale = ioc->req_sz/(sizeof(dma_addr_t) + sizeof(u32));
237 if (sizeof(dma_addr_t) == sizeof(u64)) {
238 numSGE = (scale - 1) *
239 (ioc->facts.MaxChainDepth-1) + scale +
240 (ioc->req_sz - 60) / (sizeof(dma_addr_t) +
241 sizeof(u32));
242 } else {
243 numSGE = 1 + (scale - 1) *
244 (ioc->facts.MaxChainDepth-1) + scale +
245 (ioc->req_sz - 64) / (sizeof(dma_addr_t) +
246 sizeof(u32));
247 }
248
249 if (numSGE < sh->sg_tablesize) {
250 /* Reset this value */
251 dprintk((MYIOC_s_INFO_FMT
252 "Resetting sg_tablesize to %d from %d\n",
253 ioc->name, numSGE, sh->sg_tablesize));
254 sh->sg_tablesize = numSGE;
255 }
256
Moore, Eric Dean 2496af32005-04-22 18:02:41 -0400257 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
258
259 hd = (MPT_SCSI_HOST *) sh->hostdata;
260 hd->ioc = ioc;
261
262 /* SCSI needs scsi_cmnd lookup table!
263 * (with size equal to req_depth*PtrSz!)
264 */
265 sz = ioc->req_depth * sizeof(void *);
266 mem = kmalloc(sz, GFP_ATOMIC);
267 if (mem == NULL) {
268 error = -ENOMEM;
269 goto mptfc_probe_failed;
270 }
271
272 memset(mem, 0, sz);
273 hd->ScsiLookup = (struct scsi_cmnd **) mem;
274
275 dprintk((MYIOC_s_INFO_FMT "ScsiLookup @ %p, sz=%d\n",
276 ioc->name, hd->ScsiLookup, sz));
277
278 /* Allocate memory for the device structures.
279 * A non-Null pointer at an offset
280 * indicates a device exists.
281 * max_id = 1 + maximum id (hosts.h)
282 */
283 sz = sh->max_id * sizeof(void *);
284 mem = kmalloc(sz, GFP_ATOMIC);
285 if (mem == NULL) {
286 error = -ENOMEM;
287 goto mptfc_probe_failed;
288 }
289
290 memset(mem, 0, sz);
291 hd->Targets = (VirtDevice **) mem;
292
293 dprintk((KERN_INFO
294 " Targets @ %p, sz=%d\n", hd->Targets, sz));
295
296 /* Clear the TM flags
297 */
298 hd->tmPending = 0;
299 hd->tmState = TM_STATE_NONE;
300 hd->resetPending = 0;
301 hd->abortSCpnt = NULL;
302
303 /* Clear the pointer used to store
304 * single-threaded commands, i.e., those
305 * issued during a bus scan, dv and
306 * configuration pages.
307 */
308 hd->cmdPtr = NULL;
309
310 /* Initialize this SCSI Hosts' timers
311 * To use, set the timer expires field
312 * and add_timer
313 */
314 init_timer(&hd->timer);
315 hd->timer.data = (unsigned long) hd;
316 hd->timer.function = mptscsih_timer_expired;
317
Moore, Eric Dean 2496af32005-04-22 18:02:41 -0400318 hd->mpt_pq_filter = mpt_pq_filter;
319
320 ddvprintk((MYIOC_s_INFO_FMT
321 "mpt_pq_filter %x\n",
322 ioc->name,
323 mpt_pq_filter));
324
325 init_waitqueue_head(&hd->scandv_waitq);
326 hd->scandv_wait_done = 0;
327 hd->last_queue_full = 0;
328
329 error = scsi_add_host (sh, &ioc->pcidev->dev);
330 if(error) {
331 dprintk((KERN_ERR MYNAM
332 "scsi_add_host failed\n"));
333 goto mptfc_probe_failed;
334 }
335
336 scsi_scan_host(sh);
337 return 0;
338
339mptfc_probe_failed:
340
341 mptscsih_remove(pdev);
342 return error;
343}
344
345static struct pci_driver mptfc_driver = {
346 .name = "mptfc",
347 .id_table = mptfc_pci_table,
348 .probe = mptfc_probe,
349 .remove = __devexit_p(mptscsih_remove),
350 .driver = {
351 .shutdown = mptscsih_shutdown,
352 },
353#ifdef CONFIG_PM
354 .suspend = mptscsih_suspend,
355 .resume = mptscsih_resume,
356#endif
357};
358
359/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
360/**
361 * mptfc_init - Register MPT adapter(s) as SCSI host(s) with
362 * linux scsi mid-layer.
363 *
364 * Returns 0 for success, non-zero for failure.
365 */
366static int __init
367mptfc_init(void)
368{
369
370 show_mptmod_ver(my_NAME, my_VERSION);
371
372 mptfcDoneCtx = mpt_register(mptscsih_io_done, MPTFC_DRIVER);
373 mptfcTaskCtx = mpt_register(mptscsih_taskmgmt_complete, MPTFC_DRIVER);
374 mptfcInternalCtx = mpt_register(mptscsih_scandv_complete, MPTFC_DRIVER);
375
376 if (mpt_event_register(mptfcDoneCtx, mptscsih_event_process) == 0) {
377 devtprintk((KERN_INFO MYNAM
378 ": Registered for IOC event notifications\n"));
379 }
380
381 if (mpt_reset_register(mptfcDoneCtx, mptscsih_ioc_reset) == 0) {
382 dprintk((KERN_INFO MYNAM
383 ": Registered for IOC reset notifications\n"));
384 }
385
386 return pci_register_driver(&mptfc_driver);
387}
388
389/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
390/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
391/**
392 * mptfc_exit - Unregisters MPT adapter(s)
393 *
394 */
395static void __exit
396mptfc_exit(void)
397{
398 pci_unregister_driver(&mptfc_driver);
399
400 mpt_reset_deregister(mptfcDoneCtx);
401 dprintk((KERN_INFO MYNAM
402 ": Deregistered for IOC reset notifications\n"));
403
404 mpt_event_deregister(mptfcDoneCtx);
405 dprintk((KERN_INFO MYNAM
406 ": Deregistered for IOC event notifications\n"));
407
408 mpt_deregister(mptfcInternalCtx);
409 mpt_deregister(mptfcTaskCtx);
410 mpt_deregister(mptfcDoneCtx);
411}
412
413module_init(mptfc_init);
414module_exit(mptfc_exit);