2 * linux/drivers/message/fusion/mptspi.c
3 * For use with LSI Logic PCI chip/adapter(s)
4 * running LSI Logic Fusion MPT (Message Passing Technology) firmware.
6 * Copyright (c) 1999-2007 LSI Logic Corporation
7 * (mailto:mpt_linux_developer@lsil.com)
10 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
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.
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.
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.
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
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
45 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
47 #include "linux_compat.h" /* linux-2.6 tweaks */
48 #include <linux/module.h>
49 #include <linux/kernel.h>
50 #include <linux/init.h>
51 #include <linux/errno.h>
52 #include <linux/kdev_t.h>
53 #include <linux/blkdev.h>
54 #include <linux/delay.h> /* for mdelay */
55 #include <linux/interrupt.h> /* needed for in_interrupt() proto */
56 #include <linux/reboot.h> /* notifier code */
57 #include <linux/sched.h>
58 #include <linux/workqueue.h>
59 #include <linux/raid_class.h>
61 #include <scsi/scsi.h>
62 #include <scsi/scsi_cmnd.h>
63 #include <scsi/scsi_device.h>
64 #include <scsi/scsi_host.h>
65 #include <scsi/scsi_tcq.h>
66 #include <scsi/scsi_transport.h>
67 #include <scsi/scsi_transport_spi.h>
72 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
73 #define my_NAME "Fusion MPT SPI Host driver"
74 #define my_VERSION MPT_LINUX_VERSION_COMMON
75 #define MYNAM "mptspi"
77 MODULE_AUTHOR(MODULEAUTHOR);
78 MODULE_DESCRIPTION(my_NAME);
79 MODULE_LICENSE("GPL");
80 MODULE_VERSION(my_VERSION);
82 /* Command line args */
83 static int mpt_saf_te = MPTSCSIH_SAF_TE;
84 module_param(mpt_saf_te, int, 0);
85 MODULE_PARM_DESC(mpt_saf_te, " Force enabling SEP Processor: enable=1 (default=MPTSCSIH_SAF_TE=0)");
87 static void mptspi_write_offset(struct scsi_target *, int);
88 static void mptspi_write_width(struct scsi_target *, int);
89 static int mptspi_write_spi_device_pg1(struct scsi_target *,
90 struct _CONFIG_PAGE_SCSI_DEVICE_1 *);
92 static struct scsi_transport_template *mptspi_transport_template = NULL;
94 static int mptspiDoneCtx = -1;
95 static int mptspiTaskCtx = -1;
96 static int mptspiInternalCtx = -1; /* Used only for internal commands */
98 static int mptspi_target_alloc(struct scsi_target *starget)
100 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
101 struct _MPT_SCSI_HOST *hd = (struct _MPT_SCSI_HOST *)shost->hostdata;
107 ret = mptscsih_target_alloc(starget);
111 /* if we're a device on virtual channel 1 and we're not part
112 * of an array, just return here (otherwise the setup below
113 * may actually affect a real physical device on channel 0 */
114 if (starget->channel == 1 &&
115 mptscsih_raid_id_to_num(hd, starget->id) < 0)
118 if (hd->ioc->spi_data.nvram &&
119 hd->ioc->spi_data.nvram[starget->id] != MPT_HOST_NVRAM_INVALID) {
120 u32 nvram = hd->ioc->spi_data.nvram[starget->id];
121 spi_min_period(starget) = (nvram & MPT_NVRAM_SYNC_MASK) >> MPT_NVRAM_SYNC_SHIFT;
122 spi_max_width(starget) = nvram & MPT_NVRAM_WIDE_DISABLE ? 0 : 1;
124 spi_min_period(starget) = hd->ioc->spi_data.minSyncFactor;
125 spi_max_width(starget) = hd->ioc->spi_data.maxBusWidth;
127 spi_max_offset(starget) = hd->ioc->spi_data.maxSyncOffset;
129 spi_offset(starget) = 0;
130 mptspi_write_width(starget, 0);
135 static int mptspi_read_spi_device_pg0(struct scsi_target *starget,
136 struct _CONFIG_PAGE_SCSI_DEVICE_0 *pass_pg0)
138 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
139 struct _MPT_SCSI_HOST *hd = (struct _MPT_SCSI_HOST *)shost->hostdata;
140 struct _MPT_ADAPTER *ioc = hd->ioc;
141 struct _CONFIG_PAGE_SCSI_DEVICE_0 *pg0;
144 struct _x_config_parms cfg;
145 struct _CONFIG_PAGE_HEADER hdr;
148 /* No SPI parameters for RAID devices */
149 if (starget->channel == 0 &&
150 (hd->ioc->raid_data.isRaid & (1 << starget->id)))
153 size = ioc->spi_data.sdp0length * 4;
155 if (ioc->spi_data.sdp0length & 1)
160 pg0 = dma_alloc_coherent(&ioc->pcidev->dev, size, &pg0_dma, GFP_KERNEL);
162 starget_printk(KERN_ERR, starget, "dma_alloc_coherent for parameters failed\n");
166 memset(&hdr, 0, sizeof(hdr));
168 hdr.PageVersion = ioc->spi_data.sdp0version;
169 hdr.PageLength = ioc->spi_data.sdp0length;
171 hdr.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE;
173 memset(&cfg, 0, sizeof(cfg));
175 cfg.cfghdr.hdr = &hdr;
176 cfg.physAddr = pg0_dma;
177 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
179 cfg.pageAddr = starget->id;
181 if (mpt_config(ioc, &cfg)) {
182 starget_printk(KERN_ERR, starget, "mpt_config failed\n");
186 memcpy(pass_pg0, pg0, size);
189 dma_free_coherent(&ioc->pcidev->dev, size, pg0, pg0_dma);
193 static u32 mptspi_getRP(struct scsi_target *starget)
197 nego |= spi_iu(starget) ? MPI_SCSIDEVPAGE1_RP_IU : 0;
198 nego |= spi_dt(starget) ? MPI_SCSIDEVPAGE1_RP_DT : 0;
199 nego |= spi_qas(starget) ? MPI_SCSIDEVPAGE1_RP_QAS : 0;
200 nego |= spi_hold_mcs(starget) ? MPI_SCSIDEVPAGE1_RP_HOLD_MCS : 0;
201 nego |= spi_wr_flow(starget) ? MPI_SCSIDEVPAGE1_RP_WR_FLOW : 0;
202 nego |= spi_rd_strm(starget) ? MPI_SCSIDEVPAGE1_RP_RD_STRM : 0;
203 nego |= spi_rti(starget) ? MPI_SCSIDEVPAGE1_RP_RTI : 0;
204 nego |= spi_pcomp_en(starget) ? MPI_SCSIDEVPAGE1_RP_PCOMP_EN : 0;
206 nego |= (spi_period(starget) << MPI_SCSIDEVPAGE1_RP_SHIFT_MIN_SYNC_PERIOD) & MPI_SCSIDEVPAGE1_RP_MIN_SYNC_PERIOD_MASK;
207 nego |= (spi_offset(starget) << MPI_SCSIDEVPAGE1_RP_SHIFT_MAX_SYNC_OFFSET) & MPI_SCSIDEVPAGE1_RP_MAX_SYNC_OFFSET_MASK;
208 nego |= spi_width(starget) ? MPI_SCSIDEVPAGE1_RP_WIDE : 0;
213 static void mptspi_read_parameters(struct scsi_target *starget)
216 struct _CONFIG_PAGE_SCSI_DEVICE_0 pg0;
218 mptspi_read_spi_device_pg0(starget, &pg0);
220 nego = le32_to_cpu(pg0.NegotiatedParameters);
222 spi_iu(starget) = (nego & MPI_SCSIDEVPAGE0_NP_IU) ? 1 : 0;
223 spi_dt(starget) = (nego & MPI_SCSIDEVPAGE0_NP_DT) ? 1 : 0;
224 spi_qas(starget) = (nego & MPI_SCSIDEVPAGE0_NP_QAS) ? 1 : 0;
225 spi_wr_flow(starget) = (nego & MPI_SCSIDEVPAGE0_NP_WR_FLOW) ? 1 : 0;
226 spi_rd_strm(starget) = (nego & MPI_SCSIDEVPAGE0_NP_RD_STRM) ? 1 : 0;
227 spi_rti(starget) = (nego & MPI_SCSIDEVPAGE0_NP_RTI) ? 1 : 0;
228 spi_pcomp_en(starget) = (nego & MPI_SCSIDEVPAGE0_NP_PCOMP_EN) ? 1 : 0;
229 spi_hold_mcs(starget) = (nego & MPI_SCSIDEVPAGE0_NP_HOLD_MCS) ? 1 : 0;
230 spi_period(starget) = (nego & MPI_SCSIDEVPAGE0_NP_NEG_SYNC_PERIOD_MASK) >> MPI_SCSIDEVPAGE0_NP_SHIFT_SYNC_PERIOD;
231 spi_offset(starget) = (nego & MPI_SCSIDEVPAGE0_NP_NEG_SYNC_OFFSET_MASK) >> MPI_SCSIDEVPAGE0_NP_SHIFT_SYNC_OFFSET;
232 spi_width(starget) = (nego & MPI_SCSIDEVPAGE0_NP_WIDE) ? 1 : 0;
236 mptscsih_quiesce_raid(MPT_SCSI_HOST *hd, int quiesce, int disk)
238 MpiRaidActionRequest_t *pReq;
241 /* Get and Populate a free Frame
243 if ((mf = mpt_get_msg_frame(hd->ioc->InternalCtx, hd->ioc)) == NULL) {
244 ddvprintk((MYIOC_s_WARN_FMT "_do_raid: no msg frames!\n",
248 pReq = (MpiRaidActionRequest_t *)mf;
250 pReq->Action = MPI_RAID_ACTION_QUIESCE_PHYS_IO;
252 pReq->Action = MPI_RAID_ACTION_ENABLE_PHYS_IO;
254 pReq->ChainOffset = 0;
255 pReq->Function = MPI_FUNCTION_RAID_ACTION;
256 pReq->VolumeID = disk;
258 pReq->PhysDiskNum = 0;
261 pReq->ActionDataWord = 0; /* Reserved for this action */
263 mpt_add_sge((char *)&pReq->ActionDataSGE,
264 MPT_SGE_FLAGS_SSIMPLE_READ | 0, (dma_addr_t) -1);
266 ddvprintk((MYIOC_s_INFO_FMT "RAID Volume action %x id %d\n",
267 hd->ioc->name, action, io->id));
270 hd->timer.expires = jiffies + HZ*10; /* 10 second timeout */
271 hd->scandv_wait_done = 0;
273 /* Save cmd pointer, for resource free if timeout or
278 add_timer(&hd->timer);
279 mpt_put_msg_frame(hd->ioc->InternalCtx, hd->ioc, mf);
280 wait_event(hd->scandv_waitq, hd->scandv_wait_done);
282 if ((hd->pLocal == NULL) || (hd->pLocal->completion != 0))
288 static void mptspi_dv_device(struct _MPT_SCSI_HOST *hd,
289 struct scsi_device *sdev)
291 VirtTarget *vtarget = scsi_target(sdev)->hostdata;
293 /* no DV on RAID devices */
294 if (sdev->channel == 0 &&
295 (hd->ioc->raid_data.isRaid & (1 << sdev->id)))
298 /* If this is a piece of a RAID, then quiesce first */
299 if (sdev->channel == 1 &&
300 mptscsih_quiesce_raid(hd, 1, vtarget->target_id) < 0) {
301 starget_printk(KERN_ERR, scsi_target(sdev),
302 "Integrated RAID quiesce failed\n");
308 if (sdev->channel == 1 &&
309 mptscsih_quiesce_raid(hd, 0, vtarget->target_id) < 0)
310 starget_printk(KERN_ERR, scsi_target(sdev),
311 "Integrated RAID resume failed\n");
313 mptspi_read_parameters(sdev->sdev_target);
314 spi_display_xfer_agreement(sdev->sdev_target);
315 mptspi_read_parameters(sdev->sdev_target);
318 static int mptspi_slave_alloc(struct scsi_device *sdev)
321 MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)sdev->host->hostdata;
322 /* gcc doesn't see that all uses of this variable occur within
323 * the if() statements, so stop it from whining */
326 if (sdev->channel == 1) {
327 physdisknum = mptscsih_raid_id_to_num(hd, sdev->id);
333 ret = mptscsih_slave_alloc(sdev);
338 if (sdev->channel == 1) {
339 VirtDevice *vdev = sdev->hostdata;
340 sdev->no_uld_attach = 1;
341 vdev->vtarget->tflags |= MPT_TARGET_FLAGS_RAID_COMPONENT;
342 /* The real channel for this device is zero */
343 vdev->vtarget->bus_id = 0;
344 /* The actual physdisknum (for RAID passthrough) */
345 vdev->vtarget->target_id = physdisknum;
351 static int mptspi_slave_configure(struct scsi_device *sdev)
353 int ret = mptscsih_slave_configure(sdev);
354 struct _MPT_SCSI_HOST *hd =
355 (struct _MPT_SCSI_HOST *)sdev->host->hostdata;
360 if ((sdev->channel == 1 ||
361 !(hd->ioc->raid_data.isRaid & (1 << sdev->id))) &&
362 !spi_initial_dv(sdev->sdev_target))
363 mptspi_dv_device(hd, sdev);
368 static void mptspi_slave_destroy(struct scsi_device *sdev)
370 struct scsi_target *starget = scsi_target(sdev);
371 VirtTarget *vtarget = starget->hostdata;
372 VirtDevice *vdevice = sdev->hostdata;
374 /* Will this be the last lun on a non-raid device? */
375 if (vtarget->num_luns == 1 && vdevice->configured_lun) {
376 struct _CONFIG_PAGE_SCSI_DEVICE_1 pg1;
379 pg1.RequestedParameters = 0;
381 pg1.Configuration = 0;
383 mptspi_write_spi_device_pg1(starget, &pg1);
386 mptscsih_slave_destroy(sdev);
389 static struct scsi_host_template mptspi_driver_template = {
390 .module = THIS_MODULE,
391 .proc_name = "mptspi",
392 .proc_info = mptscsih_proc_info,
393 .name = "MPT SPI Host",
394 .info = mptscsih_info,
395 .queuecommand = mptscsih_qcmd,
396 .target_alloc = mptspi_target_alloc,
397 .slave_alloc = mptspi_slave_alloc,
398 .slave_configure = mptspi_slave_configure,
399 .target_destroy = mptscsih_target_destroy,
400 .slave_destroy = mptspi_slave_destroy,
401 .change_queue_depth = mptscsih_change_queue_depth,
402 .eh_abort_handler = mptscsih_abort,
403 .eh_device_reset_handler = mptscsih_dev_reset,
404 .eh_bus_reset_handler = mptscsih_bus_reset,
405 .eh_host_reset_handler = mptscsih_host_reset,
406 .bios_param = mptscsih_bios_param,
407 .can_queue = MPT_SCSI_CAN_QUEUE,
409 .sg_tablesize = MPT_SCSI_SG_DEPTH,
412 .use_clustering = ENABLE_CLUSTERING,
415 static int mptspi_write_spi_device_pg1(struct scsi_target *starget,
416 struct _CONFIG_PAGE_SCSI_DEVICE_1 *pass_pg1)
418 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
419 struct _MPT_SCSI_HOST *hd = (struct _MPT_SCSI_HOST *)shost->hostdata;
420 struct _MPT_ADAPTER *ioc = hd->ioc;
421 struct _CONFIG_PAGE_SCSI_DEVICE_1 *pg1;
424 struct _x_config_parms cfg;
425 struct _CONFIG_PAGE_HEADER hdr;
428 /* don't allow updating nego parameters on RAID devices */
429 if (starget->channel == 0 &&
430 (hd->ioc->raid_data.isRaid & (1 << starget->id)))
433 size = ioc->spi_data.sdp1length * 4;
435 pg1 = dma_alloc_coherent(&ioc->pcidev->dev, size, &pg1_dma, GFP_KERNEL);
437 starget_printk(KERN_ERR, starget, "dma_alloc_coherent for parameters failed\n");
441 memset(&hdr, 0, sizeof(hdr));
443 hdr.PageVersion = ioc->spi_data.sdp1version;
444 hdr.PageLength = ioc->spi_data.sdp1length;
446 hdr.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE;
448 memset(&cfg, 0, sizeof(cfg));
450 cfg.cfghdr.hdr = &hdr;
451 cfg.physAddr = pg1_dma;
452 cfg.action = MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT;
454 cfg.pageAddr = starget->id;
456 memcpy(pg1, pass_pg1, size);
458 pg1->Header.PageVersion = hdr.PageVersion;
459 pg1->Header.PageLength = hdr.PageLength;
460 pg1->Header.PageNumber = hdr.PageNumber;
461 pg1->Header.PageType = hdr.PageType;
463 if (mpt_config(ioc, &cfg)) {
464 starget_printk(KERN_ERR, starget, "mpt_config failed\n");
470 dma_free_coherent(&ioc->pcidev->dev, size, pg1, pg1_dma);
474 static void mptspi_write_offset(struct scsi_target *starget, int offset)
476 struct _CONFIG_PAGE_SCSI_DEVICE_1 pg1;
485 if (spi_offset(starget) == -1)
486 mptspi_read_parameters(starget);
488 spi_offset(starget) = offset;
490 nego = mptspi_getRP(starget);
492 pg1.RequestedParameters = cpu_to_le32(nego);
494 pg1.Configuration = 0;
496 mptspi_write_spi_device_pg1(starget, &pg1);
499 static void mptspi_write_period(struct scsi_target *starget, int period)
501 struct _CONFIG_PAGE_SCSI_DEVICE_1 pg1;
510 if (spi_period(starget) == -1)
511 mptspi_read_parameters(starget);
516 } else if (period == 9) {
520 spi_period(starget) = period;
522 nego = mptspi_getRP(starget);
524 pg1.RequestedParameters = cpu_to_le32(nego);
526 pg1.Configuration = 0;
528 mptspi_write_spi_device_pg1(starget, &pg1);
531 static void mptspi_write_dt(struct scsi_target *starget, int dt)
533 struct _CONFIG_PAGE_SCSI_DEVICE_1 pg1;
536 if (spi_period(starget) == -1)
537 mptspi_read_parameters(starget);
539 if (!dt && spi_period(starget) < 10)
540 spi_period(starget) = 10;
542 spi_dt(starget) = dt;
544 nego = mptspi_getRP(starget);
547 pg1.RequestedParameters = cpu_to_le32(nego);
549 pg1.Configuration = 0;
551 mptspi_write_spi_device_pg1(starget, &pg1);
554 static void mptspi_write_iu(struct scsi_target *starget, int iu)
556 struct _CONFIG_PAGE_SCSI_DEVICE_1 pg1;
559 if (spi_period(starget) == -1)
560 mptspi_read_parameters(starget);
562 if (!iu && spi_period(starget) < 9)
563 spi_period(starget) = 9;
565 spi_iu(starget) = iu;
567 nego = mptspi_getRP(starget);
569 pg1.RequestedParameters = cpu_to_le32(nego);
571 pg1.Configuration = 0;
573 mptspi_write_spi_device_pg1(starget, &pg1);
576 #define MPTSPI_SIMPLE_TRANSPORT_PARM(parm) \
577 static void mptspi_write_##parm(struct scsi_target *starget, int parm)\
579 struct _CONFIG_PAGE_SCSI_DEVICE_1 pg1; \
582 spi_##parm(starget) = parm; \
584 nego = mptspi_getRP(starget); \
586 pg1.RequestedParameters = cpu_to_le32(nego); \
588 pg1.Configuration = 0; \
590 mptspi_write_spi_device_pg1(starget, &pg1); \
593 MPTSPI_SIMPLE_TRANSPORT_PARM(rd_strm)
594 MPTSPI_SIMPLE_TRANSPORT_PARM(wr_flow)
595 MPTSPI_SIMPLE_TRANSPORT_PARM(rti)
596 MPTSPI_SIMPLE_TRANSPORT_PARM(hold_mcs)
597 MPTSPI_SIMPLE_TRANSPORT_PARM(pcomp_en)
599 static void mptspi_write_qas(struct scsi_target *starget, int qas)
601 struct _CONFIG_PAGE_SCSI_DEVICE_1 pg1;
602 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
603 struct _MPT_SCSI_HOST *hd = (struct _MPT_SCSI_HOST *)shost->hostdata;
604 VirtTarget *vtarget = starget->hostdata;
607 if ((vtarget->negoFlags & MPT_TARGET_NO_NEGO_QAS) ||
608 hd->ioc->spi_data.noQas)
609 spi_qas(starget) = 0;
611 spi_qas(starget) = qas;
613 nego = mptspi_getRP(starget);
615 pg1.RequestedParameters = cpu_to_le32(nego);
617 pg1.Configuration = 0;
619 mptspi_write_spi_device_pg1(starget, &pg1);
622 static void mptspi_write_width(struct scsi_target *starget, int width)
624 struct _CONFIG_PAGE_SCSI_DEVICE_1 pg1;
629 if (spi_period(starget) < 10)
630 spi_period(starget) = 10;
633 spi_width(starget) = width;
635 nego = mptspi_getRP(starget);
637 pg1.RequestedParameters = cpu_to_le32(nego);
639 pg1.Configuration = 0;
641 mptspi_write_spi_device_pg1(starget, &pg1);
644 struct work_queue_wrapper {
645 struct work_struct work;
646 struct _MPT_SCSI_HOST *hd;
650 static void mpt_work_wrapper(struct work_struct *work)
652 struct work_queue_wrapper *wqw =
653 container_of(work, struct work_queue_wrapper, work);
654 struct _MPT_SCSI_HOST *hd = wqw->hd;
655 struct Scsi_Host *shost = hd->ioc->sh;
656 struct scsi_device *sdev;
657 int disk = wqw->disk;
658 struct _CONFIG_PAGE_IOC_3 *pg3;
662 mpt_findImVolumes(hd->ioc);
663 pg3 = hd->ioc->raid_data.pIocPg3;
667 shost_for_each_device(sdev,shost) {
668 struct scsi_target *starget = scsi_target(sdev);
669 VirtTarget *vtarget = starget->hostdata;
671 /* only want to search RAID components */
672 if (sdev->channel != 1)
675 /* The target_id is the raid PhysDiskNum, even if
676 * starget->id is the actual target address */
677 if(vtarget->target_id != disk)
680 starget_printk(KERN_INFO, vtarget->starget,
681 "Integrated RAID requests DV of new device\n");
682 mptspi_dv_device(hd, sdev);
684 shost_printk(KERN_INFO, shost,
685 "Integrated RAID detects new device %d\n", disk);
686 scsi_scan_target(&hd->ioc->sh->shost_gendev, 1, disk, 0, 1);
690 static void mpt_dv_raid(struct _MPT_SCSI_HOST *hd, int disk)
692 struct work_queue_wrapper *wqw = kmalloc(sizeof(*wqw), GFP_ATOMIC);
695 shost_printk(KERN_ERR, hd->ioc->sh,
696 "Failed to act on RAID event for physical disk %d\n",
700 INIT_WORK(&wqw->work, mpt_work_wrapper);
704 schedule_work(&wqw->work);
708 mptspi_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *pEvReply)
710 u8 event = le32_to_cpu(pEvReply->Event) & 0xFF;
711 struct _MPT_SCSI_HOST *hd = (struct _MPT_SCSI_HOST *)ioc->sh->hostdata;
713 if (hd && event == MPI_EVENT_INTEGRATED_RAID) {
715 = (le32_to_cpu(pEvReply->Data[0]) & 0x00FF0000) >> 16;
717 if (reason == MPI_EVENT_RAID_RC_DOMAIN_VAL_NEEDED) {
718 int disk = (le32_to_cpu(pEvReply->Data[0]) & 0xFF000000) >> 24;
719 mpt_dv_raid(hd, disk);
722 return mptscsih_event_process(ioc, pEvReply);
726 mptspi_deny_binding(struct scsi_target *starget)
728 struct _MPT_SCSI_HOST *hd =
729 (struct _MPT_SCSI_HOST *)dev_to_shost(starget->dev.parent)->hostdata;
730 return ((hd->ioc->raid_data.isRaid & (1 << starget->id)) &&
731 starget->channel == 0) ? 1 : 0;
734 static struct spi_function_template mptspi_transport_functions = {
735 .get_offset = mptspi_read_parameters,
736 .set_offset = mptspi_write_offset,
738 .get_period = mptspi_read_parameters,
739 .set_period = mptspi_write_period,
741 .get_width = mptspi_read_parameters,
742 .set_width = mptspi_write_width,
744 .get_iu = mptspi_read_parameters,
745 .set_iu = mptspi_write_iu,
747 .get_dt = mptspi_read_parameters,
748 .set_dt = mptspi_write_dt,
750 .get_qas = mptspi_read_parameters,
751 .set_qas = mptspi_write_qas,
753 .get_wr_flow = mptspi_read_parameters,
754 .set_wr_flow = mptspi_write_wr_flow,
756 .get_rd_strm = mptspi_read_parameters,
757 .set_rd_strm = mptspi_write_rd_strm,
759 .get_rti = mptspi_read_parameters,
760 .set_rti = mptspi_write_rti,
762 .get_pcomp_en = mptspi_read_parameters,
763 .set_pcomp_en = mptspi_write_pcomp_en,
765 .get_hold_mcs = mptspi_read_parameters,
766 .set_hold_mcs = mptspi_write_hold_mcs,
768 .deny_binding = mptspi_deny_binding,
771 /****************************************************************************
775 static struct pci_device_id mptspi_pci_table[] = {
776 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_53C1030,
777 PCI_ANY_ID, PCI_ANY_ID },
778 { PCI_VENDOR_ID_LSI_LOGIC, MPI_MANUFACTPAGE_DEVID_53C1035,
779 PCI_ANY_ID, PCI_ANY_ID },
780 {0} /* Terminating entry */
782 MODULE_DEVICE_TABLE(pci, mptspi_pci_table);
786 * renegotiate for a given target
789 mptspi_dv_renegotiate_work(struct work_struct *work)
791 struct work_queue_wrapper *wqw =
792 container_of(work, struct work_queue_wrapper, work);
793 struct _MPT_SCSI_HOST *hd = wqw->hd;
794 struct scsi_device *sdev;
798 shost_for_each_device(sdev, hd->ioc->sh)
799 mptspi_dv_device(hd, sdev);
803 mptspi_dv_renegotiate(struct _MPT_SCSI_HOST *hd)
805 struct work_queue_wrapper *wqw = kmalloc(sizeof(*wqw), GFP_ATOMIC);
810 INIT_WORK(&wqw->work, mptspi_dv_renegotiate_work);
813 schedule_work(&wqw->work);
817 * spi module reset handler
820 mptspi_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)
822 struct _MPT_SCSI_HOST *hd = (struct _MPT_SCSI_HOST *)ioc->sh->hostdata;
825 rc = mptscsih_ioc_reset(ioc, reset_phase);
827 if (reset_phase == MPT_IOC_POST_RESET)
828 mptspi_dv_renegotiate(hd);
835 * spi module resume handler
838 mptspi_resume(struct pci_dev *pdev)
840 MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
841 struct _MPT_SCSI_HOST *hd = (struct _MPT_SCSI_HOST *)ioc->sh->hostdata;
844 rc = mptscsih_resume(pdev);
845 mptspi_dv_renegotiate(hd);
851 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
852 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
854 * mptspi_probe - Installs scsi devices per bus.
855 * @pdev: Pointer to pci_dev structure
857 * Returns 0 for success, non-zero for failure.
861 mptspi_probe(struct pci_dev *pdev, const struct pci_device_id *id)
863 struct Scsi_Host *sh;
874 if ((r = mpt_attach(pdev,id)) != 0)
877 ioc = pci_get_drvdata(pdev);
878 ioc->DoneCtx = mptspiDoneCtx;
879 ioc->TaskCtx = mptspiTaskCtx;
880 ioc->InternalCtx = mptspiInternalCtx;
882 /* Added sanity check on readiness of the MPT adapter.
884 if (ioc->last_state != MPI_IOC_STATE_OPERATIONAL) {
885 printk(MYIOC_s_WARN_FMT
886 "Skipping because it's not operational!\n",
889 goto out_mptspi_probe;
893 printk(MYIOC_s_WARN_FMT "Skipping because it's disabled!\n",
896 goto out_mptspi_probe;
899 /* Sanity check - ensure at least 1 port is INITIATOR capable
902 for (ii=0; ii < ioc->facts.NumberOfPorts; ii++) {
903 if (ioc->pfacts[ii].ProtocolFlags &
904 MPI_PORTFACTS_PROTOCOL_INITIATOR)
909 printk(MYIOC_s_WARN_FMT
910 "Skipping ioc=%p because SCSI Initiator mode is NOT enabled!\n",
915 sh = scsi_host_alloc(&mptspi_driver_template, sizeof(MPT_SCSI_HOST));
918 printk(MYIOC_s_WARN_FMT
919 "Unable to register controller with SCSI subsystem\n",
922 goto out_mptspi_probe;
925 spin_lock_irqsave(&ioc->FreeQlock, flags);
927 /* Attach the SCSI Host to the IOC structure
935 /* set 16 byte cdb's */
936 sh->max_cmd_len = 16;
938 /* Yikes! This is important!
939 * Otherwise, by default, linux
940 * only scans target IDs 0-7!
941 * pfactsN->MaxDevices unreliable
942 * (not supported in early
943 * versions of the FW).
944 * max_id = 1 + actual max id,
945 * max_lun = 1 + actual last lun,
948 sh->max_id = MPT_MAX_SCSI_DEVICES;
950 sh->max_lun = MPT_LAST_LUN + 1;
952 * If RAID Firmware Detected, setup virtual channel
954 if ((ioc->facts.ProductID & MPI_FW_HEADER_PID_PROD_MASK)
955 > MPI_FW_HEADER_PID_PROD_TARGET_SCSI)
959 sh->this_id = ioc->pfacts[0].PortSCSIID;
963 sh->unique_id = ioc->id;
965 /* Verify that we won't exceed the maximum
966 * number of chain buffers
967 * We can optimize: ZZ = req_sz/sizeof(SGE)
969 * numSGE = 1 + (ZZ-1)*(maxChain -1) + ZZ
970 * + (req_sz - 64)/sizeof(SGE)
971 * A slightly different algorithm is required for
974 scale = ioc->req_sz/(sizeof(dma_addr_t) + sizeof(u32));
975 if (sizeof(dma_addr_t) == sizeof(u64)) {
976 numSGE = (scale - 1) *
977 (ioc->facts.MaxChainDepth-1) + scale +
978 (ioc->req_sz - 60) / (sizeof(dma_addr_t) +
981 numSGE = 1 + (scale - 1) *
982 (ioc->facts.MaxChainDepth-1) + scale +
983 (ioc->req_sz - 64) / (sizeof(dma_addr_t) +
987 if (numSGE < sh->sg_tablesize) {
988 /* Reset this value */
989 dprintk((MYIOC_s_INFO_FMT
990 "Resetting sg_tablesize to %d from %d\n",
991 ioc->name, numSGE, sh->sg_tablesize));
992 sh->sg_tablesize = numSGE;
995 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
997 hd = (MPT_SCSI_HOST *) sh->hostdata;
1000 /* SCSI needs scsi_cmnd lookup table!
1001 * (with size equal to req_depth*PtrSz!)
1003 hd->ScsiLookup = kcalloc(ioc->req_depth, sizeof(void *), GFP_ATOMIC);
1004 if (!hd->ScsiLookup) {
1006 goto out_mptspi_probe;
1009 dprintk((MYIOC_s_INFO_FMT "ScsiLookup @ %p\n",
1010 ioc->name, hd->ScsiLookup));
1012 /* Allocate memory for the device structures.
1013 * A non-Null pointer at an offset
1014 * indicates a device exists.
1015 * max_id = 1 + maximum id (hosts.h)
1017 hd->Targets = kcalloc(sh->max_id * (sh->max_channel + 1),
1018 sizeof(void *), GFP_ATOMIC);
1021 goto out_mptspi_probe;
1024 dprintk((KERN_INFO " vdev @ %p\n", hd->Targets));
1026 /* Clear the TM flags
1029 hd->tmState = TM_STATE_NONE;
1030 hd->resetPending = 0;
1031 hd->abortSCpnt = NULL;
1033 /* Clear the pointer used to store
1034 * single-threaded commands, i.e., those
1035 * issued during a bus scan, dv and
1036 * configuration pages.
1040 /* Initialize this SCSI Hosts' timers
1041 * To use, set the timer expires field
1044 init_timer(&hd->timer);
1045 hd->timer.data = (unsigned long) hd;
1046 hd->timer.function = mptscsih_timer_expired;
1048 ioc->spi_data.Saf_Te = mpt_saf_te;
1050 hd->negoNvram = MPT_SCSICFG_USE_NVRAM;
1051 ddvprintk((MYIOC_s_INFO_FMT
1055 ioc->spi_data.noQas = 0;
1057 init_waitqueue_head(&hd->scandv_waitq);
1058 hd->scandv_wait_done = 0;
1059 hd->last_queue_full = 0;
1061 /* Some versions of the firmware don't support page 0; without
1062 * that we can't get the parameters */
1063 if (hd->ioc->spi_data.sdp0length != 0)
1064 sh->transportt = mptspi_transport_template;
1066 error = scsi_add_host (sh, &ioc->pcidev->dev);
1068 dprintk((KERN_ERR MYNAM
1069 "scsi_add_host failed\n"));
1070 goto out_mptspi_probe;
1074 * issue internal bus reset
1076 if (ioc->spi_data.bus_reset)
1077 mptscsih_TMHandler(hd,
1078 MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS,
1086 mptscsih_remove(pdev);
1090 static struct pci_driver mptspi_driver = {
1092 .id_table = mptspi_pci_table,
1093 .probe = mptspi_probe,
1094 .remove = __devexit_p(mptscsih_remove),
1095 .shutdown = mptscsih_shutdown,
1097 .suspend = mptscsih_suspend,
1098 .resume = mptspi_resume,
1102 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1104 * mptspi_init - Register MPT adapter(s) as SCSI host(s) with SCSI mid-layer.
1106 * Returns 0 for success, non-zero for failure.
1111 show_mptmod_ver(my_NAME, my_VERSION);
1113 mptspi_transport_template = spi_attach_transport(&mptspi_transport_functions);
1114 if (!mptspi_transport_template)
1117 mptspiDoneCtx = mpt_register(mptscsih_io_done, MPTSPI_DRIVER);
1118 mptspiTaskCtx = mpt_register(mptscsih_taskmgmt_complete, MPTSPI_DRIVER);
1119 mptspiInternalCtx = mpt_register(mptscsih_scandv_complete, MPTSPI_DRIVER);
1121 if (mpt_event_register(mptspiDoneCtx, mptspi_event_process) == 0) {
1122 devtverboseprintk((KERN_INFO MYNAM
1123 ": Registered for IOC event notifications\n"));
1126 if (mpt_reset_register(mptspiDoneCtx, mptspi_ioc_reset) == 0) {
1127 dprintk((KERN_INFO MYNAM
1128 ": Registered for IOC reset notifications\n"));
1131 return pci_register_driver(&mptspi_driver);
1134 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1135 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1137 * mptspi_exit - Unregisters MPT adapter(s)
1142 pci_unregister_driver(&mptspi_driver);
1144 mpt_reset_deregister(mptspiDoneCtx);
1145 dprintk((KERN_INFO MYNAM
1146 ": Deregistered for IOC reset notifications\n"));
1148 mpt_event_deregister(mptspiDoneCtx);
1149 dprintk((KERN_INFO MYNAM
1150 ": Deregistered for IOC event notifications\n"));
1152 mpt_deregister(mptspiInternalCtx);
1153 mpt_deregister(mptspiTaskCtx);
1154 mpt_deregister(mptspiDoneCtx);
1155 spi_release_transport(mptspi_transport_template);
1158 module_init(mptspi_init);
1159 module_exit(mptspi_exit);