3 * Linux MegaRAID device driver
5 * Copyright (c) 2003-2004 LSI Logic Corporation.
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
12 * FILE : megaraid_mbox.c
13 * Version : v2.20.5.1 (Nov 16 2006)
16 * Atul Mukker <Atul.Mukker@lsi.com>
17 * Sreenivas Bagalkote <Sreenivas.Bagalkote@lsi.com>
18 * Manoj Jose <Manoj.Jose@lsi.com>
21 * List of supported controllers
23 * OEM Product Name VID DID SSVID SSID
24 * --- ------------ --- --- ---- ----
25 * Dell PERC3/QC 101E 1960 1028 0471
26 * Dell PERC3/DC 101E 1960 1028 0493
27 * Dell PERC3/SC 101E 1960 1028 0475
28 * Dell PERC3/Di 1028 1960 1028 0123
29 * Dell PERC4/SC 1000 1960 1028 0520
30 * Dell PERC4/DC 1000 1960 1028 0518
31 * Dell PERC4/QC 1000 0407 1028 0531
32 * Dell PERC4/Di 1028 000F 1028 014A
33 * Dell PERC 4e/Si 1028 0013 1028 016c
34 * Dell PERC 4e/Di 1028 0013 1028 016d
35 * Dell PERC 4e/Di 1028 0013 1028 016e
36 * Dell PERC 4e/Di 1028 0013 1028 016f
37 * Dell PERC 4e/Di 1028 0013 1028 0170
38 * Dell PERC 4e/DC 1000 0408 1028 0002
39 * Dell PERC 4e/SC 1000 0408 1028 0001
42 * LSI MegaRAID SCSI 320-0 1000 1960 1000 A520
43 * LSI MegaRAID SCSI 320-1 1000 1960 1000 0520
44 * LSI MegaRAID SCSI 320-2 1000 1960 1000 0518
45 * LSI MegaRAID SCSI 320-0X 1000 0407 1000 0530
46 * LSI MegaRAID SCSI 320-2X 1000 0407 1000 0532
47 * LSI MegaRAID SCSI 320-4X 1000 0407 1000 0531
48 * LSI MegaRAID SCSI 320-1E 1000 0408 1000 0001
49 * LSI MegaRAID SCSI 320-2E 1000 0408 1000 0002
50 * LSI MegaRAID SATA 150-4 1000 1960 1000 4523
51 * LSI MegaRAID SATA 150-6 1000 1960 1000 0523
52 * LSI MegaRAID SATA 300-4X 1000 0409 1000 3004
53 * LSI MegaRAID SATA 300-8X 1000 0409 1000 3008
55 * INTEL RAID Controller SRCU42X 1000 0407 8086 0532
56 * INTEL RAID Controller SRCS16 1000 1960 8086 0523
57 * INTEL RAID Controller SRCU42E 1000 0408 8086 0002
58 * INTEL RAID Controller SRCZCRX 1000 0407 8086 0530
59 * INTEL RAID Controller SRCS28X 1000 0409 8086 3008
60 * INTEL RAID Controller SROMBU42E 1000 0408 8086 3431
61 * INTEL RAID Controller SROMBU42E 1000 0408 8086 3499
62 * INTEL RAID Controller SRCU51L 1000 1960 8086 0520
64 * FSC MegaRAID PCI Express ROMB 1000 0408 1734 1065
66 * ACER MegaRAID ROMB-2E 1000 0408 1025 004D
68 * NEC MegaRAID PCI Express ROMB 1000 0408 1033 8287
70 * For history of changes, see Documentation/ChangeLog.megaraid
73 #include "megaraid_mbox.h"
75 static int megaraid_init(void);
76 static void megaraid_exit(void);
78 static int megaraid_probe_one(struct pci_dev
*, const struct pci_device_id
*);
79 static void megaraid_detach_one(struct pci_dev
*);
80 static void megaraid_mbox_shutdown(struct pci_dev
*);
82 static int megaraid_io_attach(adapter_t
*);
83 static void megaraid_io_detach(adapter_t
*);
85 static int megaraid_init_mbox(adapter_t
*);
86 static void megaraid_fini_mbox(adapter_t
*);
88 static int megaraid_alloc_cmd_packets(adapter_t
*);
89 static void megaraid_free_cmd_packets(adapter_t
*);
91 static int megaraid_mbox_setup_dma_pools(adapter_t
*);
92 static void megaraid_mbox_teardown_dma_pools(adapter_t
*);
94 static int megaraid_sysfs_alloc_resources(adapter_t
*);
95 static void megaraid_sysfs_free_resources(adapter_t
*);
97 static int megaraid_abort_handler(struct scsi_cmnd
*);
98 static int megaraid_reset_handler(struct scsi_cmnd
*);
100 static int mbox_post_sync_cmd(adapter_t
*, uint8_t []);
101 static int mbox_post_sync_cmd_fast(adapter_t
*, uint8_t []);
102 static int megaraid_busywait_mbox(mraid_device_t
*);
103 static int megaraid_mbox_product_info(adapter_t
*);
104 static int megaraid_mbox_extended_cdb(adapter_t
*);
105 static int megaraid_mbox_support_ha(adapter_t
*, uint16_t *);
106 static int megaraid_mbox_support_random_del(adapter_t
*);
107 static int megaraid_mbox_get_max_sg(adapter_t
*);
108 static void megaraid_mbox_enum_raid_scsi(adapter_t
*);
109 static void megaraid_mbox_flush_cache(adapter_t
*);
110 static int megaraid_mbox_fire_sync_cmd(adapter_t
*);
112 static void megaraid_mbox_display_scb(adapter_t
*, scb_t
*);
113 static void megaraid_mbox_setup_device_map(adapter_t
*);
115 static int megaraid_queue_command(struct scsi_cmnd
*,
116 void (*)(struct scsi_cmnd
*));
117 static scb_t
*megaraid_mbox_build_cmd(adapter_t
*, struct scsi_cmnd
*, int *);
118 static void megaraid_mbox_runpendq(adapter_t
*, scb_t
*);
119 static void megaraid_mbox_prepare_pthru(adapter_t
*, scb_t
*,
121 static void megaraid_mbox_prepare_epthru(adapter_t
*, scb_t
*,
124 static irqreturn_t
megaraid_isr(int, void *);
126 static void megaraid_mbox_dpc(unsigned long);
128 static ssize_t
megaraid_sysfs_show_app_hndl(struct class_device
*, char *);
129 static ssize_t
megaraid_sysfs_show_ldnum(struct device
*, struct device_attribute
*attr
, char *);
131 static int megaraid_cmm_register(adapter_t
*);
132 static int megaraid_cmm_unregister(adapter_t
*);
133 static int megaraid_mbox_mm_handler(unsigned long, uioc_t
*, uint32_t);
134 static int megaraid_mbox_mm_command(adapter_t
*, uioc_t
*);
135 static void megaraid_mbox_mm_done(adapter_t
*, scb_t
*);
136 static int gather_hbainfo(adapter_t
*, mraid_hba_info_t
*);
137 static int wait_till_fw_empty(adapter_t
*);
141 MODULE_AUTHOR("megaraidlinux@lsi.com");
142 MODULE_DESCRIPTION("LSI Logic MegaRAID Mailbox Driver");
143 MODULE_LICENSE("GPL");
144 MODULE_VERSION(MEGARAID_VERSION
);
147 * ### modules parameters for driver ###
151 * Set to enable driver to expose unconfigured disk to kernel
153 static int megaraid_expose_unconf_disks
= 0;
154 module_param_named(unconf_disks
, megaraid_expose_unconf_disks
, int, 0);
155 MODULE_PARM_DESC(unconf_disks
,
156 "Set to expose unconfigured disks to kernel (default=0)");
159 * driver wait time if the adapter's mailbox is busy
161 static unsigned int max_mbox_busy_wait
= MBOX_BUSY_WAIT
;
162 module_param_named(busy_wait
, max_mbox_busy_wait
, int, 0);
163 MODULE_PARM_DESC(busy_wait
,
164 "Max wait for mailbox in microseconds if busy (default=10)");
167 * number of sectors per IO command
169 static unsigned int megaraid_max_sectors
= MBOX_MAX_SECTORS
;
170 module_param_named(max_sectors
, megaraid_max_sectors
, int, 0);
171 MODULE_PARM_DESC(max_sectors
,
172 "Maximum number of sectors per IO command (default=128)");
175 * number of commands per logical unit
177 static unsigned int megaraid_cmd_per_lun
= MBOX_DEF_CMD_PER_LUN
;
178 module_param_named(cmd_per_lun
, megaraid_cmd_per_lun
, int, 0);
179 MODULE_PARM_DESC(cmd_per_lun
,
180 "Maximum number of commands per logical unit (default=64)");
184 * Fast driver load option, skip scanning for physical devices during load.
185 * This would result in non-disk devices being skipped during driver load
186 * time. These can be later added though, using /proc/scsi/scsi
188 static unsigned int megaraid_fast_load
= 0;
189 module_param_named(fast_load
, megaraid_fast_load
, int, 0);
190 MODULE_PARM_DESC(fast_load
,
191 "Faster loading of the driver, skips physical devices! (default=0)");
195 * mraid_debug level - threshold for amount of information to be displayed by
196 * the driver. This level can be changed through modules parameters, ioctl or
197 * sysfs/proc interface. By default, print the announcement messages only.
199 int mraid_debug_level
= CL_ANN
;
200 module_param_named(debug_level
, mraid_debug_level
, int, 0);
201 MODULE_PARM_DESC(debug_level
, "Debug level for driver (default=0)");
204 * ### global data ###
206 static uint8_t megaraid_mbox_version
[8] =
207 { 0x02, 0x20, 0x04, 0x06, 3, 7, 20, 5 };
211 * PCI table for all supported controllers.
213 static struct pci_device_id pci_id_table_g
[] = {
216 PCI_DEVICE_ID_PERC4_DI_DISCOVERY
,
218 PCI_SUBSYS_ID_PERC4_DI_DISCOVERY
,
221 PCI_VENDOR_ID_LSI_LOGIC
,
222 PCI_DEVICE_ID_PERC4_SC
,
224 PCI_SUBSYS_ID_PERC4_SC
,
227 PCI_VENDOR_ID_LSI_LOGIC
,
228 PCI_DEVICE_ID_PERC4_DC
,
230 PCI_SUBSYS_ID_PERC4_DC
,
233 PCI_VENDOR_ID_LSI_LOGIC
,
240 PCI_DEVICE_ID_PERC4_DI_EVERGLADES
,
242 PCI_SUBSYS_ID_PERC4_DI_EVERGLADES
,
246 PCI_DEVICE_ID_PERC4E_SI_BIGBEND
,
248 PCI_SUBSYS_ID_PERC4E_SI_BIGBEND
,
252 PCI_DEVICE_ID_PERC4E_DI_KOBUK
,
254 PCI_SUBSYS_ID_PERC4E_DI_KOBUK
,
258 PCI_DEVICE_ID_PERC4E_DI_CORVETTE
,
260 PCI_SUBSYS_ID_PERC4E_DI_CORVETTE
,
264 PCI_DEVICE_ID_PERC4E_DI_EXPEDITION
,
266 PCI_SUBSYS_ID_PERC4E_DI_EXPEDITION
,
270 PCI_DEVICE_ID_PERC4E_DI_GUADALUPE
,
272 PCI_SUBSYS_ID_PERC4E_DI_GUADALUPE
,
275 PCI_VENDOR_ID_LSI_LOGIC
,
276 PCI_DEVICE_ID_DOBSON
,
282 PCI_DEVICE_ID_AMI_MEGARAID3
,
287 PCI_VENDOR_ID_LSI_LOGIC
,
288 PCI_DEVICE_ID_AMI_MEGARAID3
,
293 PCI_VENDOR_ID_LSI_LOGIC
,
294 PCI_DEVICE_ID_LINDSAY
,
298 {0} /* Terminating entry */
300 MODULE_DEVICE_TABLE(pci
, pci_id_table_g
);
303 static struct pci_driver megaraid_pci_driver_g
= {
305 .id_table
= pci_id_table_g
,
306 .probe
= megaraid_probe_one
,
307 .remove
= __devexit_p(megaraid_detach_one
),
308 .shutdown
= megaraid_mbox_shutdown
,
313 // definitions for the device attributes for exporting logical drive number
314 // for a scsi address (Host, Channel, Id, Lun)
316 CLASS_DEVICE_ATTR(megaraid_mbox_app_hndl
, S_IRUSR
, megaraid_sysfs_show_app_hndl
,
319 // Host template initializer for megaraid mbox sysfs device attributes
320 static struct class_device_attribute
*megaraid_shost_attrs
[] = {
321 &class_device_attr_megaraid_mbox_app_hndl
,
326 DEVICE_ATTR(megaraid_mbox_ld
, S_IRUSR
, megaraid_sysfs_show_ldnum
, NULL
);
328 // Host template initializer for megaraid mbox sysfs device attributes
329 static struct device_attribute
*megaraid_sdev_attrs
[] = {
330 &dev_attr_megaraid_mbox_ld
,
335 * megaraid_change_queue_depth - Change the device's queue depth
336 * @sdev: scsi device struct
337 * @qdepth: depth to set
342 static int megaraid_change_queue_depth(struct scsi_device
*sdev
, int qdepth
)
344 if (qdepth
> MBOX_MAX_SCSI_CMDS
)
345 qdepth
= MBOX_MAX_SCSI_CMDS
;
346 scsi_adjust_queue_depth(sdev
, 0, qdepth
);
347 return sdev
->queue_depth
;
351 * Scsi host template for megaraid unified driver
353 static struct scsi_host_template megaraid_template_g
= {
354 .module
= THIS_MODULE
,
355 .name
= "LSI Logic MegaRAID driver",
356 .proc_name
= "megaraid",
357 .queuecommand
= megaraid_queue_command
,
358 .eh_abort_handler
= megaraid_abort_handler
,
359 .eh_device_reset_handler
= megaraid_reset_handler
,
360 .eh_bus_reset_handler
= megaraid_reset_handler
,
361 .eh_host_reset_handler
= megaraid_reset_handler
,
362 .change_queue_depth
= megaraid_change_queue_depth
,
363 .use_clustering
= ENABLE_CLUSTERING
,
364 .sdev_attrs
= megaraid_sdev_attrs
,
365 .shost_attrs
= megaraid_shost_attrs
,
370 * megaraid_init - module load hook
372 * We register ourselves as hotplug enabled module and let PCI subsystem
373 * discover our adapters.
380 // Announce the driver version
381 con_log(CL_ANN
, (KERN_INFO
"megaraid: %s %s\n", MEGARAID_VERSION
,
382 MEGARAID_EXT_VERSION
));
384 // check validity of module parameters
385 if (megaraid_cmd_per_lun
> MBOX_MAX_SCSI_CMDS
) {
387 con_log(CL_ANN
, (KERN_WARNING
388 "megaraid mailbox: max commands per lun reset to %d\n",
389 MBOX_MAX_SCSI_CMDS
));
391 megaraid_cmd_per_lun
= MBOX_MAX_SCSI_CMDS
;
395 // register as a PCI hot-plug driver module
396 rval
= pci_register_driver(&megaraid_pci_driver_g
);
398 con_log(CL_ANN
, (KERN_WARNING
399 "megaraid: could not register hotplug support.\n"));
407 * megaraid_exit - driver unload entry point
409 * We simply unwrap the megaraid_init routine here.
414 con_log(CL_DLEVEL1
, (KERN_NOTICE
"megaraid: unloading framework\n"));
416 // unregister as PCI hotplug driver
417 pci_unregister_driver(&megaraid_pci_driver_g
);
424 * megaraid_probe_one - PCI hotplug entry point
425 * @pdev : handle to this controller's PCI configuration space
426 * @id : pci device id of the class of controllers
428 * This routine should be called whenever a new adapter is detected by the
429 * PCI hotplug susbsytem.
432 megaraid_probe_one(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
437 // detected a new controller
438 con_log(CL_ANN
, (KERN_INFO
439 "megaraid: probe new device %#4.04x:%#4.04x:%#4.04x:%#4.04x: ",
440 pdev
->vendor
, pdev
->device
, pdev
->subsystem_vendor
,
441 pdev
->subsystem_device
));
443 con_log(CL_ANN
, ("bus %d:slot %d:func %d\n", pdev
->bus
->number
,
444 PCI_SLOT(pdev
->devfn
), PCI_FUNC(pdev
->devfn
)));
446 if (pci_enable_device(pdev
)) {
447 con_log(CL_ANN
, (KERN_WARNING
448 "megaraid: pci_enable_device failed\n"));
453 // Enable bus-mastering on this controller
454 pci_set_master(pdev
);
456 // Allocate the per driver initialization structure
457 adapter
= kzalloc(sizeof(adapter_t
), GFP_KERNEL
);
459 if (adapter
== NULL
) {
460 con_log(CL_ANN
, (KERN_WARNING
461 "megaraid: out of memory, %s %d.\n", __FUNCTION__
, __LINE__
));
467 // set up PCI related soft state and other pre-known parameters
468 adapter
->unique_id
= pdev
->bus
->number
<< 8 | pdev
->devfn
;
469 adapter
->irq
= pdev
->irq
;
470 adapter
->pdev
= pdev
;
472 atomic_set(&adapter
->being_detached
, 0);
474 // Setup the default DMA mask. This would be changed later on
475 // depending on hardware capabilities
476 if (pci_set_dma_mask(adapter
->pdev
, DMA_32BIT_MASK
) != 0) {
478 con_log(CL_ANN
, (KERN_WARNING
479 "megaraid: pci_set_dma_mask failed:%d\n", __LINE__
));
481 goto out_free_adapter
;
485 // Initialize the synchronization lock for kernel and LLD
486 spin_lock_init(&adapter
->lock
);
488 // Initialize the command queues: the list of free SCBs and the list
490 INIT_LIST_HEAD(&adapter
->kscb_pool
);
491 spin_lock_init(SCSI_FREE_LIST_LOCK(adapter
));
493 INIT_LIST_HEAD(&adapter
->pend_list
);
494 spin_lock_init(PENDING_LIST_LOCK(adapter
));
496 INIT_LIST_HEAD(&adapter
->completed_list
);
497 spin_lock_init(COMPLETED_LIST_LOCK(adapter
));
500 // Start the mailbox based controller
501 if (megaraid_init_mbox(adapter
) != 0) {
502 con_log(CL_ANN
, (KERN_WARNING
503 "megaraid: maibox adapter did not initialize\n"));
505 goto out_free_adapter
;
508 // Register with LSI Common Management Module
509 if (megaraid_cmm_register(adapter
) != 0) {
511 con_log(CL_ANN
, (KERN_WARNING
512 "megaraid: could not register with management module\n"));
517 // setup adapter handle in PCI soft state
518 pci_set_drvdata(pdev
, adapter
);
520 // attach with scsi mid-layer
521 if (megaraid_io_attach(adapter
) != 0) {
523 con_log(CL_ANN
, (KERN_WARNING
"megaraid: io attach failed\n"));
531 pci_set_drvdata(pdev
, NULL
);
532 megaraid_cmm_unregister(adapter
);
534 megaraid_fini_mbox(adapter
);
538 pci_disable_device(pdev
);
545 * megaraid_detach_one - release framework resources and call LLD release routine
546 * @pdev : handle for our PCI cofiguration space
548 * This routine is called during driver unload. We free all the allocated
549 * resources and call the corresponding LLD so that it can also release all
552 * This routine is also called from the PCI hotplug system.
555 megaraid_detach_one(struct pci_dev
*pdev
)
558 struct Scsi_Host
*host
;
561 // Start a rollback on this adapter
562 adapter
= pci_get_drvdata(pdev
);
565 con_log(CL_ANN
, (KERN_CRIT
566 "megaraid: Invalid detach on %#4.04x:%#4.04x:%#4.04x:%#4.04x\n",
567 pdev
->vendor
, pdev
->device
, pdev
->subsystem_vendor
,
568 pdev
->subsystem_device
));
573 con_log(CL_ANN
, (KERN_NOTICE
574 "megaraid: detaching device %#4.04x:%#4.04x:%#4.04x:%#4.04x\n",
575 pdev
->vendor
, pdev
->device
, pdev
->subsystem_vendor
,
576 pdev
->subsystem_device
));
580 host
= adapter
->host
;
582 // do not allow any more requests from the management module for this
584 // FIXME: How do we account for the request which might still be
586 atomic_set(&adapter
->being_detached
, 1);
588 // detach from the IO sub-system
589 megaraid_io_detach(adapter
);
591 // reset the device state in the PCI structure. We check this
592 // condition when we enter here. If the device state is NULL,
593 // that would mean the device has already been removed
594 pci_set_drvdata(pdev
, NULL
);
596 // Unregister from common management module
598 // FIXME: this must return success or failure for conditions if there
599 // is a command pending with LLD or not.
600 megaraid_cmm_unregister(adapter
);
602 // finalize the mailbox based controller and release all resources
603 megaraid_fini_mbox(adapter
);
609 pci_disable_device(pdev
);
616 * megaraid_mbox_shutdown - PCI shutdown for megaraid HBA
617 * @pdev : generic driver model device
619 * Shutdown notification, perform flush cache.
622 megaraid_mbox_shutdown(struct pci_dev
*pdev
)
624 adapter_t
*adapter
= pci_get_drvdata(pdev
);
628 con_log(CL_ANN
, (KERN_WARNING
629 "megaraid: null device in shutdown\n"));
634 con_log(CL_ANN
, (KERN_INFO
"megaraid: flushing adapter %d...",
637 megaraid_mbox_flush_cache(adapter
);
639 con_log(CL_ANN
, ("done\n"));
644 * megaraid_io_attach - attach a device with the IO subsystem
645 * @adapter : controller's soft state
647 * Attach this device with the IO subsystem.
650 megaraid_io_attach(adapter_t
*adapter
)
652 struct Scsi_Host
*host
;
654 // Initialize SCSI Host structure
655 host
= scsi_host_alloc(&megaraid_template_g
, 8);
657 con_log(CL_ANN
, (KERN_WARNING
658 "megaraid mbox: scsi_register failed\n"));
663 SCSIHOST2ADAP(host
) = (caddr_t
)adapter
;
664 adapter
->host
= host
;
666 host
->irq
= adapter
->irq
;
667 host
->unique_id
= adapter
->unique_id
;
668 host
->can_queue
= adapter
->max_cmds
;
669 host
->this_id
= adapter
->init_id
;
670 host
->sg_tablesize
= adapter
->sglen
;
671 host
->max_sectors
= adapter
->max_sectors
;
672 host
->cmd_per_lun
= adapter
->cmd_per_lun
;
673 host
->max_channel
= adapter
->max_channel
;
674 host
->max_id
= adapter
->max_target
;
675 host
->max_lun
= adapter
->max_lun
;
678 // notify mid-layer about the new controller
679 if (scsi_add_host(host
, &adapter
->pdev
->dev
)) {
681 con_log(CL_ANN
, (KERN_WARNING
682 "megaraid mbox: scsi_add_host failed\n"));
689 scsi_scan_host(host
);
696 * megaraid_io_detach - detach a device from the IO subsystem
697 * @adapter : controller's soft state
699 * Detach this device from the IO subsystem.
702 megaraid_io_detach(adapter_t
*adapter
)
704 struct Scsi_Host
*host
;
706 con_log(CL_DLEVEL1
, (KERN_INFO
"megaraid: io detach\n"));
708 host
= adapter
->host
;
710 scsi_remove_host(host
);
717 * START: Mailbox Low Level Driver
719 * This is section specific to the single mailbox based controllers
723 * megaraid_init_mbox - initialize controller
724 * @adapter : our soft state
726 * - Allocate 16-byte aligned mailbox memory for firmware handshake
727 * - Allocate controller's memory resources
728 * - Find out all initialization data
729 * - Allocate memory required for all the commands
730 * - Use internal library of FW routines, build up complete soft state
733 megaraid_init_mbox(adapter_t
*adapter
)
735 struct pci_dev
*pdev
;
736 mraid_device_t
*raid_dev
;
741 adapter
->ito
= MBOX_TIMEOUT
;
742 pdev
= adapter
->pdev
;
745 * Allocate and initialize the init data structure for mailbox
748 raid_dev
= kzalloc(sizeof(mraid_device_t
), GFP_KERNEL
);
749 if (raid_dev
== NULL
) return -1;
753 * Attach the adapter soft state to raid device soft state
755 adapter
->raid_device
= (caddr_t
)raid_dev
;
756 raid_dev
->fast_load
= megaraid_fast_load
;
760 raid_dev
->baseport
= pci_resource_start(pdev
, 0);
762 if (pci_request_regions(pdev
, "MegaRAID: LSI Logic Corporation") != 0) {
764 con_log(CL_ANN
, (KERN_WARNING
765 "megaraid: mem region busy\n"));
767 goto out_free_raid_dev
;
770 raid_dev
->baseaddr
= ioremap_nocache(raid_dev
->baseport
, 128);
772 if (!raid_dev
->baseaddr
) {
774 con_log(CL_ANN
, (KERN_WARNING
775 "megaraid: could not map hba memory\n") );
777 goto out_release_regions
;
780 /* initialize the mutual exclusion lock for the mailbox */
781 spin_lock_init(&raid_dev
->mailbox_lock
);
783 /* allocate memory required for commands */
784 if (megaraid_alloc_cmd_packets(adapter
) != 0)
788 * Issue SYNC cmd to flush the pending cmds in the adapter
789 * and initialize its internal state
792 if (megaraid_mbox_fire_sync_cmd(adapter
))
793 con_log(CL_ANN
, ("megaraid: sync cmd failed\n"));
796 * Setup the rest of the soft state using the library of
800 /* request IRQ and register the interrupt service routine */
801 if (request_irq(adapter
->irq
, megaraid_isr
, IRQF_SHARED
, "megaraid",
804 con_log(CL_ANN
, (KERN_WARNING
805 "megaraid: Couldn't register IRQ %d!\n", adapter
->irq
));
811 if (megaraid_mbox_product_info(adapter
) != 0)
814 // Do we support extended CDBs
815 adapter
->max_cdb_sz
= 10;
816 if (megaraid_mbox_extended_cdb(adapter
) == 0) {
817 adapter
->max_cdb_sz
= 16;
821 * Do we support cluster environment, if we do, what is the initiator
823 * NOTE: In a non-cluster aware firmware environment, the LLD should
824 * return 7 as initiator id.
827 adapter
->init_id
= -1;
828 if (megaraid_mbox_support_ha(adapter
, &adapter
->init_id
) == 0) {
833 * Prepare the device ids array to have the mapping between the kernel
834 * device address and megaraid device address.
835 * We export the physical devices on their actual addresses. The
836 * logical drives are exported on a virtual SCSI channel
838 megaraid_mbox_setup_device_map(adapter
);
840 // If the firmware supports random deletion, update the device id map
841 if (megaraid_mbox_support_random_del(adapter
)) {
843 // Change the logical drives numbers in device_ids array one
844 // slot in device_ids is reserved for target id, that's why
846 for (i
= 0; i
<= MAX_LOGICAL_DRIVES_40LD
; i
++) {
847 adapter
->device_ids
[adapter
->max_channel
][i
] += 0x80;
849 adapter
->device_ids
[adapter
->max_channel
][adapter
->init_id
] =
852 raid_dev
->random_del_supported
= 1;
856 * find out the maximum number of scatter-gather elements supported by
859 adapter
->sglen
= megaraid_mbox_get_max_sg(adapter
);
861 // enumerate RAID and SCSI channels so that all devices on SCSI
862 // channels can later be exported, including disk devices
863 megaraid_mbox_enum_raid_scsi(adapter
);
866 * Other parameters required by upper layer
868 * maximum number of sectors per IO command
870 adapter
->max_sectors
= megaraid_max_sectors
;
873 * number of queued commands per LUN.
875 adapter
->cmd_per_lun
= megaraid_cmd_per_lun
;
878 * Allocate resources required to issue FW calls, when sysfs is
881 if (megaraid_sysfs_alloc_resources(adapter
) != 0)
884 // Set the DMA mask to 64-bit. All supported controllers as capable of
886 pci_read_config_dword(adapter
->pdev
, PCI_CONF_AMISIG64
, &magic64
);
888 if (((magic64
== HBA_SIGNATURE_64_BIT
) &&
889 ((adapter
->pdev
->subsystem_device
!=
890 PCI_SUBSYS_ID_MEGARAID_SATA_150_6
) &&
891 (adapter
->pdev
->subsystem_device
!=
892 PCI_SUBSYS_ID_MEGARAID_SATA_150_4
))) ||
893 (adapter
->pdev
->vendor
== PCI_VENDOR_ID_LSI_LOGIC
&&
894 adapter
->pdev
->device
== PCI_DEVICE_ID_VERDE
) ||
895 (adapter
->pdev
->vendor
== PCI_VENDOR_ID_LSI_LOGIC
&&
896 adapter
->pdev
->device
== PCI_DEVICE_ID_DOBSON
) ||
897 (adapter
->pdev
->vendor
== PCI_VENDOR_ID_LSI_LOGIC
&&
898 adapter
->pdev
->device
== PCI_DEVICE_ID_LINDSAY
) ||
899 (adapter
->pdev
->vendor
== PCI_VENDOR_ID_DELL
&&
900 adapter
->pdev
->device
== PCI_DEVICE_ID_PERC4_DI_EVERGLADES
) ||
901 (adapter
->pdev
->vendor
== PCI_VENDOR_ID_DELL
&&
902 adapter
->pdev
->device
== PCI_DEVICE_ID_PERC4E_DI_KOBUK
)) {
903 if (pci_set_dma_mask(adapter
->pdev
, DMA_64BIT_MASK
)) {
904 con_log(CL_ANN
, (KERN_WARNING
905 "megaraid: DMA mask for 64-bit failed\n"));
907 if (pci_set_dma_mask (adapter
->pdev
, DMA_32BIT_MASK
)) {
908 con_log(CL_ANN
, (KERN_WARNING
909 "megaraid: 32-bit DMA mask failed\n"));
910 goto out_free_sysfs_res
;
915 // setup tasklet for DPC
916 tasklet_init(&adapter
->dpc_h
, megaraid_mbox_dpc
,
917 (unsigned long)adapter
);
919 con_log(CL_DLEVEL1
, (KERN_INFO
920 "megaraid mbox hba successfully initialized\n"));
925 megaraid_sysfs_free_resources(adapter
);
927 free_irq(adapter
->irq
, adapter
);
929 megaraid_free_cmd_packets(adapter
);
931 iounmap(raid_dev
->baseaddr
);
933 pci_release_regions(pdev
);
942 * megaraid_fini_mbox - undo controller initialization
943 * @adapter : our soft state
946 megaraid_fini_mbox(adapter_t
*adapter
)
948 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
951 megaraid_mbox_flush_cache(adapter
);
953 tasklet_kill(&adapter
->dpc_h
);
955 megaraid_sysfs_free_resources(adapter
);
957 megaraid_free_cmd_packets(adapter
);
959 free_irq(adapter
->irq
, adapter
);
961 iounmap(raid_dev
->baseaddr
);
963 pci_release_regions(adapter
->pdev
);
972 * megaraid_alloc_cmd_packets - allocate shared mailbox
973 * @adapter : soft state of the raid controller
975 * Allocate and align the shared mailbox. This maibox is used to issue
976 * all the commands. For IO based controllers, the mailbox is also regsitered
977 * with the FW. Allocate memory for all commands as well.
978 * This is our big allocator.
981 megaraid_alloc_cmd_packets(adapter_t
*adapter
)
983 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
984 struct pci_dev
*pdev
;
988 struct mraid_pci_blk
*epthru_pci_blk
;
989 struct mraid_pci_blk
*sg_pci_blk
;
990 struct mraid_pci_blk
*mbox_pci_blk
;
993 pdev
= adapter
->pdev
;
997 * Allocate the common 16-byte aligned memory for the handshake
1000 raid_dev
->una_mbox64
= pci_alloc_consistent(adapter
->pdev
,
1001 sizeof(mbox64_t
), &raid_dev
->una_mbox64_dma
);
1003 if (!raid_dev
->una_mbox64
) {
1004 con_log(CL_ANN
, (KERN_WARNING
1005 "megaraid: out of memory, %s %d\n", __FUNCTION__
,
1009 memset(raid_dev
->una_mbox64
, 0, sizeof(mbox64_t
));
1012 * Align the mailbox at 16-byte boundary
1014 raid_dev
->mbox
= &raid_dev
->una_mbox64
->mbox32
;
1016 raid_dev
->mbox
= (mbox_t
*)((((unsigned long)raid_dev
->mbox
) + 15) &
1019 raid_dev
->mbox64
= (mbox64_t
*)(((unsigned long)raid_dev
->mbox
) - 8);
1021 align
= ((void *)raid_dev
->mbox
-
1022 ((void *)&raid_dev
->una_mbox64
->mbox32
));
1024 raid_dev
->mbox_dma
= (unsigned long)raid_dev
->una_mbox64_dma
+ 8 +
1027 // Allocate memory for commands issued internally
1028 adapter
->ibuf
= pci_alloc_consistent(pdev
, MBOX_IBUF_SIZE
,
1029 &adapter
->ibuf_dma_h
);
1030 if (!adapter
->ibuf
) {
1032 con_log(CL_ANN
, (KERN_WARNING
1033 "megaraid: out of memory, %s %d\n", __FUNCTION__
,
1036 goto out_free_common_mbox
;
1038 memset(adapter
->ibuf
, 0, MBOX_IBUF_SIZE
);
1040 // Allocate memory for our SCSI Command Blocks and their associated
1044 * Allocate memory for the base list of scb. Later allocate memory for
1045 * CCBs and embedded components of each CCB and point the pointers in
1046 * scb to the allocated components
1047 * NOTE: The code to allocate SCB will be duplicated in all the LLD
1048 * since the calling routine does not yet know the number of available
1051 adapter
->kscb_list
= kcalloc(MBOX_MAX_SCSI_CMDS
, sizeof(scb_t
), GFP_KERNEL
);
1053 if (adapter
->kscb_list
== NULL
) {
1054 con_log(CL_ANN
, (KERN_WARNING
1055 "megaraid: out of memory, %s %d\n", __FUNCTION__
,
1060 // memory allocation for our command packets
1061 if (megaraid_mbox_setup_dma_pools(adapter
) != 0) {
1062 con_log(CL_ANN
, (KERN_WARNING
1063 "megaraid: out of memory, %s %d\n", __FUNCTION__
,
1065 goto out_free_scb_list
;
1068 // Adjust the scb pointers and link in the free pool
1069 epthru_pci_blk
= raid_dev
->epthru_pool
;
1070 sg_pci_blk
= raid_dev
->sg_pool
;
1071 mbox_pci_blk
= raid_dev
->mbox_pool
;
1073 for (i
= 0; i
< MBOX_MAX_SCSI_CMDS
; i
++) {
1074 scb
= adapter
->kscb_list
+ i
;
1075 ccb
= raid_dev
->ccb_list
+ i
;
1077 ccb
->mbox
= (mbox_t
*)(mbox_pci_blk
[i
].vaddr
+ 16);
1078 ccb
->raw_mbox
= (uint8_t *)ccb
->mbox
;
1079 ccb
->mbox64
= (mbox64_t
*)(mbox_pci_blk
[i
].vaddr
+ 8);
1080 ccb
->mbox_dma_h
= (unsigned long)mbox_pci_blk
[i
].dma_addr
+ 16;
1082 // make sure the mailbox is aligned properly
1083 if (ccb
->mbox_dma_h
& 0x0F) {
1084 con_log(CL_ANN
, (KERN_CRIT
1085 "megaraid mbox: not aligned on 16-bytes\n"));
1087 goto out_teardown_dma_pools
;
1090 ccb
->epthru
= (mraid_epassthru_t
*)
1091 epthru_pci_blk
[i
].vaddr
;
1092 ccb
->epthru_dma_h
= epthru_pci_blk
[i
].dma_addr
;
1093 ccb
->pthru
= (mraid_passthru_t
*)ccb
->epthru
;
1094 ccb
->pthru_dma_h
= ccb
->epthru_dma_h
;
1097 ccb
->sgl64
= (mbox_sgl64
*)sg_pci_blk
[i
].vaddr
;
1098 ccb
->sgl_dma_h
= sg_pci_blk
[i
].dma_addr
;
1099 ccb
->sgl32
= (mbox_sgl32
*)ccb
->sgl64
;
1101 scb
->ccb
= (caddr_t
)ccb
;
1104 scb
->sno
= i
; // command index
1107 scb
->state
= SCB_FREE
;
1108 scb
->dma_direction
= PCI_DMA_NONE
;
1109 scb
->dma_type
= MRAID_DMA_NONE
;
1110 scb
->dev_channel
= -1;
1111 scb
->dev_target
= -1;
1113 // put scb in the free pool
1114 list_add_tail(&scb
->list
, &adapter
->kscb_pool
);
1119 out_teardown_dma_pools
:
1120 megaraid_mbox_teardown_dma_pools(adapter
);
1122 kfree(adapter
->kscb_list
);
1124 pci_free_consistent(pdev
, MBOX_IBUF_SIZE
, (void *)adapter
->ibuf
,
1125 adapter
->ibuf_dma_h
);
1126 out_free_common_mbox
:
1127 pci_free_consistent(adapter
->pdev
, sizeof(mbox64_t
),
1128 (caddr_t
)raid_dev
->una_mbox64
, raid_dev
->una_mbox64_dma
);
1135 * megaraid_free_cmd_packets - free memory
1136 * @adapter : soft state of the raid controller
1138 * Release memory resources allocated for commands.
1141 megaraid_free_cmd_packets(adapter_t
*adapter
)
1143 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
1145 megaraid_mbox_teardown_dma_pools(adapter
);
1147 kfree(adapter
->kscb_list
);
1149 pci_free_consistent(adapter
->pdev
, MBOX_IBUF_SIZE
,
1150 (void *)adapter
->ibuf
, adapter
->ibuf_dma_h
);
1152 pci_free_consistent(adapter
->pdev
, sizeof(mbox64_t
),
1153 (caddr_t
)raid_dev
->una_mbox64
, raid_dev
->una_mbox64_dma
);
1159 * megaraid_mbox_setup_dma_pools - setup dma pool for command packets
1160 * @adapter : HBA soft state
1162 * Setup the dma pools for mailbox, passthru and extended passthru structures,
1163 * and scatter-gather lists.
1166 megaraid_mbox_setup_dma_pools(adapter_t
*adapter
)
1168 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
1169 struct mraid_pci_blk
*epthru_pci_blk
;
1170 struct mraid_pci_blk
*sg_pci_blk
;
1171 struct mraid_pci_blk
*mbox_pci_blk
;
1176 // Allocate memory for 16-bytes aligned mailboxes
1177 raid_dev
->mbox_pool_handle
= pci_pool_create("megaraid mbox pool",
1179 sizeof(mbox64_t
) + 16,
1182 if (raid_dev
->mbox_pool_handle
== NULL
) {
1183 goto fail_setup_dma_pool
;
1186 mbox_pci_blk
= raid_dev
->mbox_pool
;
1187 for (i
= 0; i
< MBOX_MAX_SCSI_CMDS
; i
++) {
1188 mbox_pci_blk
[i
].vaddr
= pci_pool_alloc(
1189 raid_dev
->mbox_pool_handle
,
1191 &mbox_pci_blk
[i
].dma_addr
);
1192 if (!mbox_pci_blk
[i
].vaddr
) {
1193 goto fail_setup_dma_pool
;
1198 * Allocate memory for each embedded passthru strucuture pointer
1199 * Request for a 128 bytes aligned structure for each passthru command
1201 * Since passthru and extended passthru commands are exclusive, they
1202 * share common memory pool. Passthru structures piggyback on memory
1203 * allocted to extended passthru since passthru is smaller of the two
1205 raid_dev
->epthru_pool_handle
= pci_pool_create("megaraid mbox pthru",
1206 adapter
->pdev
, sizeof(mraid_epassthru_t
), 128, 0);
1208 if (raid_dev
->epthru_pool_handle
== NULL
) {
1209 goto fail_setup_dma_pool
;
1212 epthru_pci_blk
= raid_dev
->epthru_pool
;
1213 for (i
= 0; i
< MBOX_MAX_SCSI_CMDS
; i
++) {
1214 epthru_pci_blk
[i
].vaddr
= pci_pool_alloc(
1215 raid_dev
->epthru_pool_handle
,
1217 &epthru_pci_blk
[i
].dma_addr
);
1218 if (!epthru_pci_blk
[i
].vaddr
) {
1219 goto fail_setup_dma_pool
;
1224 // Allocate memory for each scatter-gather list. Request for 512 bytes
1225 // alignment for each sg list
1226 raid_dev
->sg_pool_handle
= pci_pool_create("megaraid mbox sg",
1228 sizeof(mbox_sgl64
) * MBOX_MAX_SG_SIZE
,
1231 if (raid_dev
->sg_pool_handle
== NULL
) {
1232 goto fail_setup_dma_pool
;
1235 sg_pci_blk
= raid_dev
->sg_pool
;
1236 for (i
= 0; i
< MBOX_MAX_SCSI_CMDS
; i
++) {
1237 sg_pci_blk
[i
].vaddr
= pci_pool_alloc(
1238 raid_dev
->sg_pool_handle
,
1240 &sg_pci_blk
[i
].dma_addr
);
1241 if (!sg_pci_blk
[i
].vaddr
) {
1242 goto fail_setup_dma_pool
;
1248 fail_setup_dma_pool
:
1249 megaraid_mbox_teardown_dma_pools(adapter
);
1255 * megaraid_mbox_teardown_dma_pools - teardown dma pools for command packets
1256 * @adapter : HBA soft state
1258 * Teardown the dma pool for mailbox, passthru and extended passthru
1259 * structures, and scatter-gather lists.
1262 megaraid_mbox_teardown_dma_pools(adapter_t
*adapter
)
1264 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
1265 struct mraid_pci_blk
*epthru_pci_blk
;
1266 struct mraid_pci_blk
*sg_pci_blk
;
1267 struct mraid_pci_blk
*mbox_pci_blk
;
1271 sg_pci_blk
= raid_dev
->sg_pool
;
1272 for (i
= 0; i
< MBOX_MAX_SCSI_CMDS
&& sg_pci_blk
[i
].vaddr
; i
++) {
1273 pci_pool_free(raid_dev
->sg_pool_handle
, sg_pci_blk
[i
].vaddr
,
1274 sg_pci_blk
[i
].dma_addr
);
1276 if (raid_dev
->sg_pool_handle
)
1277 pci_pool_destroy(raid_dev
->sg_pool_handle
);
1280 epthru_pci_blk
= raid_dev
->epthru_pool
;
1281 for (i
= 0; i
< MBOX_MAX_SCSI_CMDS
&& epthru_pci_blk
[i
].vaddr
; i
++) {
1282 pci_pool_free(raid_dev
->epthru_pool_handle
,
1283 epthru_pci_blk
[i
].vaddr
, epthru_pci_blk
[i
].dma_addr
);
1285 if (raid_dev
->epthru_pool_handle
)
1286 pci_pool_destroy(raid_dev
->epthru_pool_handle
);
1289 mbox_pci_blk
= raid_dev
->mbox_pool
;
1290 for (i
= 0; i
< MBOX_MAX_SCSI_CMDS
&& mbox_pci_blk
[i
].vaddr
; i
++) {
1291 pci_pool_free(raid_dev
->mbox_pool_handle
,
1292 mbox_pci_blk
[i
].vaddr
, mbox_pci_blk
[i
].dma_addr
);
1294 if (raid_dev
->mbox_pool_handle
)
1295 pci_pool_destroy(raid_dev
->mbox_pool_handle
);
1302 * megaraid_alloc_scb - detach and return a scb from the free list
1303 * @adapter : controller's soft state
1304 * @scp : pointer to the scsi command to be executed
1306 * Return the scb from the head of the free list. %NULL if there are none
1310 megaraid_alloc_scb(adapter_t
*adapter
, struct scsi_cmnd
*scp
)
1312 struct list_head
*head
= &adapter
->kscb_pool
;
1314 unsigned long flags
;
1316 // detach scb from free pool
1317 spin_lock_irqsave(SCSI_FREE_LIST_LOCK(adapter
), flags
);
1319 if (list_empty(head
)) {
1320 spin_unlock_irqrestore(SCSI_FREE_LIST_LOCK(adapter
), flags
);
1324 scb
= list_entry(head
->next
, scb_t
, list
);
1325 list_del_init(&scb
->list
);
1327 spin_unlock_irqrestore(SCSI_FREE_LIST_LOCK(adapter
), flags
);
1329 scb
->state
= SCB_ACTIVE
;
1331 scb
->dma_type
= MRAID_DMA_NONE
;
1338 * megaraid_dealloc_scb - return the scb to the free pool
1339 * @adapter : controller's soft state
1340 * @scb : scb to be freed
1342 * Return the scb back to the free list of scbs. The caller must 'flush' the
1343 * SCB before calling us. E.g., performing pci_unamp and/or pci_sync etc.
1344 * NOTE NOTE: Make sure the scb is not on any list before calling this
1348 megaraid_dealloc_scb(adapter_t
*adapter
, scb_t
*scb
)
1350 unsigned long flags
;
1352 // put scb in the free pool
1353 scb
->state
= SCB_FREE
;
1355 spin_lock_irqsave(SCSI_FREE_LIST_LOCK(adapter
), flags
);
1357 list_add(&scb
->list
, &adapter
->kscb_pool
);
1359 spin_unlock_irqrestore(SCSI_FREE_LIST_LOCK(adapter
), flags
);
1366 * megaraid_mbox_mksgl - make the scatter-gather list
1367 * @adapter : controller's soft state
1368 * @scb : scsi control block
1370 * Prepare the scatter-gather list.
1373 megaraid_mbox_mksgl(adapter_t
*adapter
, scb_t
*scb
)
1375 struct scatterlist
*sgl
;
1377 struct scsi_cmnd
*scp
;
1383 ccb
= (mbox_ccb_t
*)scb
->ccb
;
1385 sgcnt
= scsi_dma_map(scp
);
1386 BUG_ON(sgcnt
< 0 || sgcnt
> adapter
->sglen
);
1388 // no mapping required if no data to be transferred
1392 scb
->dma_type
= MRAID_DMA_WSG
;
1394 scsi_for_each_sg(scp
, sgl
, sgcnt
, i
) {
1395 ccb
->sgl64
[i
].address
= sg_dma_address(sgl
);
1396 ccb
->sgl64
[i
].length
= sg_dma_len(sgl
);
1399 // Return count of SG nodes
1405 * mbox_post_cmd - issue a mailbox command
1406 * @adapter : controller's soft state
1407 * @scb : command to be issued
1409 * Post the command to the controller if mailbox is available.
1412 mbox_post_cmd(adapter_t
*adapter
, scb_t
*scb
)
1414 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
1418 unsigned long flags
;
1422 ccb
= (mbox_ccb_t
*)scb
->ccb
;
1423 mbox
= raid_dev
->mbox
;
1424 mbox64
= raid_dev
->mbox64
;
1427 * Check for busy mailbox. If it is, return failure - the caller
1428 * should retry later.
1430 spin_lock_irqsave(MAILBOX_LOCK(raid_dev
), flags
);
1432 if (unlikely(mbox
->busy
)) {
1437 } while(mbox
->busy
&& (i
< max_mbox_busy_wait
));
1441 spin_unlock_irqrestore(MAILBOX_LOCK(raid_dev
), flags
);
1448 // Copy this command's mailbox data into "adapter's" mailbox
1449 memcpy((caddr_t
)mbox64
, (caddr_t
)ccb
->mbox64
, 22);
1450 mbox
->cmdid
= scb
->sno
;
1452 adapter
->outstanding_cmds
++;
1454 if (scb
->dma_direction
== PCI_DMA_TODEVICE
)
1455 pci_dma_sync_sg_for_device(adapter
->pdev
,
1456 scsi_sglist(scb
->scp
),
1457 scsi_sg_count(scb
->scp
),
1460 mbox
->busy
= 1; // Set busy
1465 WRINDOOR(raid_dev
, raid_dev
->mbox_dma
| 0x1);
1467 spin_unlock_irqrestore(MAILBOX_LOCK(raid_dev
), flags
);
1474 * megaraid_queue_command - generic queue entry point for all LLDs
1475 * @scp : pointer to the scsi command to be executed
1476 * @done : callback routine to be called after the cmd has be completed
1478 * Queue entry point for mailbox based controllers.
1481 megaraid_queue_command(struct scsi_cmnd
*scp
, void (*done
)(struct scsi_cmnd
*))
1487 adapter
= SCP2ADAPTER(scp
);
1488 scp
->scsi_done
= done
;
1492 * Allocate and build a SCB request
1493 * if_busy flag will be set if megaraid_mbox_build_cmd() command could
1494 * not allocate scb. We will return non-zero status in that case.
1495 * NOTE: scb can be null even though certain commands completed
1496 * successfully, e.g., MODE_SENSE and TEST_UNIT_READY, it would
1497 * return 0 in that case, and we would do the callback right away.
1500 scb
= megaraid_mbox_build_cmd(adapter
, scp
, &if_busy
);
1501 if (!scb
) { // command already completed
1506 megaraid_mbox_runpendq(adapter
, scb
);
1511 * megaraid_mbox_build_cmd - transform the mid-layer scsi commands
1512 * @adapter : controller's soft state
1513 * @scp : mid-layer scsi command pointer
1514 * @busy : set if request could not be completed because of lack of
1517 * Transform the mid-layer scsi command to megaraid firmware lingua.
1518 * Convert the command issued by mid-layer to format understood by megaraid
1519 * firmware. We also complete certain commands without sending them to firmware.
1522 megaraid_mbox_build_cmd(adapter_t
*adapter
, struct scsi_cmnd
*scp
, int *busy
)
1524 mraid_device_t
*rdev
= ADAP2RAIDDEV(adapter
);
1529 mraid_passthru_t
*pthru
;
1533 char skip
[] = "skipping";
1534 char scan
[] = "scanning";
1539 * Get the appropriate device map for the device this command is
1542 MRAID_GET_DEVICE_MAP(adapter
, scp
, channel
, target
, islogical
);
1545 * Logical drive commands
1548 switch (scp
->cmnd
[0]) {
1549 case TEST_UNIT_READY
:
1551 * Do we support clustering and is the support enabled
1552 * If no, return success always
1555 scp
->result
= (DID_OK
<< 16);
1559 if (!(scb
= megaraid_alloc_scb(adapter
, scp
))) {
1560 scp
->result
= (DID_ERROR
<< 16);
1565 scb
->dma_direction
= scp
->sc_data_direction
;
1566 scb
->dev_channel
= 0xFF;
1567 scb
->dev_target
= target
;
1568 ccb
= (mbox_ccb_t
*)scb
->ccb
;
1571 * The command id will be provided by the command
1574 ccb
->raw_mbox
[0] = CLUSTER_CMD
;
1575 ccb
->raw_mbox
[2] = RESERVATION_STATUS
;
1576 ccb
->raw_mbox
[3] = target
;
1582 struct scatterlist
*sgl
;
1585 sgl
= scsi_sglist(scp
);
1588 (page_address((&sgl
[0])->page
)
1589 + (&sgl
[0])->offset
);
1591 memset(vaddr
, 0, scp
->cmnd
[4]);
1594 con_log(CL_ANN
, (KERN_WARNING
1595 "megaraid mailbox: invalid sg:%d\n",
1599 scp
->result
= (DID_OK
<< 16);
1604 * Display the channel scan for logical drives
1605 * Do not display scan for a channel if already done.
1607 if (!(rdev
->last_disp
& (1L << SCP2CHANNEL(scp
)))) {
1609 con_log(CL_ANN
, (KERN_INFO
1610 "scsi[%d]: scanning scsi channel %d",
1611 adapter
->host
->host_no
,
1615 " [virtual] for logical drives\n"));
1617 rdev
->last_disp
|= (1L << SCP2CHANNEL(scp
));
1620 if (scp
->cmnd
[1] & MEGA_SCSI_INQ_EVPD
) {
1621 scp
->sense_buffer
[0] = 0x70;
1622 scp
->sense_buffer
[2] = ILLEGAL_REQUEST
;
1623 scp
->sense_buffer
[12] = MEGA_INVALID_FIELD_IN_CDB
;
1624 scp
->result
= CHECK_CONDITION
<< 1;
1632 * Do not allow LUN > 0 for logical drives and
1633 * requests for more than 40 logical drives
1636 scp
->result
= (DID_BAD_TARGET
<< 16);
1639 if ((target
% 0x80) >= MAX_LOGICAL_DRIVES_40LD
) {
1640 scp
->result
= (DID_BAD_TARGET
<< 16);
1645 /* Allocate a SCB and initialize passthru */
1646 if (!(scb
= megaraid_alloc_scb(adapter
, scp
))) {
1647 scp
->result
= (DID_ERROR
<< 16);
1652 ccb
= (mbox_ccb_t
*)scb
->ccb
;
1653 scb
->dev_channel
= 0xFF;
1654 scb
->dev_target
= target
;
1657 mbox64
= ccb
->mbox64
;
1661 pthru
->reqsenselen
= 14;
1662 pthru
->islogical
= 1;
1663 pthru
->logdrv
= target
;
1664 pthru
->cdblen
= scp
->cmd_len
;
1665 memcpy(pthru
->cdb
, scp
->cmnd
, scp
->cmd_len
);
1667 mbox
->cmd
= MBOXCMD_PASSTHRU64
;
1668 scb
->dma_direction
= scp
->sc_data_direction
;
1670 pthru
->dataxferlen
= scsi_bufflen(scp
);
1671 pthru
->dataxferaddr
= ccb
->sgl_dma_h
;
1672 pthru
->numsge
= megaraid_mbox_mksgl(adapter
,
1675 mbox
->xferaddr
= 0xFFFFFFFF;
1676 mbox64
->xferaddr_lo
= (uint32_t )ccb
->pthru_dma_h
;
1677 mbox64
->xferaddr_hi
= 0;
1689 * Allocate a SCB and initialize mailbox
1691 if (!(scb
= megaraid_alloc_scb(adapter
, scp
))) {
1692 scp
->result
= (DID_ERROR
<< 16);
1696 ccb
= (mbox_ccb_t
*)scb
->ccb
;
1697 scb
->dev_channel
= 0xFF;
1698 scb
->dev_target
= target
;
1700 mbox64
= ccb
->mbox64
;
1701 mbox
->logdrv
= target
;
1704 * A little HACK: 2nd bit is zero for all scsi read
1705 * commands and is set for all scsi write commands
1707 mbox
->cmd
= (scp
->cmnd
[0] & 0x02) ? MBOXCMD_LWRITE64
:
1711 * 6-byte READ(0x08) or WRITE(0x0A) cdb
1713 if (scp
->cmd_len
== 6) {
1714 mbox
->numsectors
= (uint32_t)scp
->cmnd
[4];
1716 ((uint32_t)scp
->cmnd
[1] << 16) |
1717 ((uint32_t)scp
->cmnd
[2] << 8) |
1718 (uint32_t)scp
->cmnd
[3];
1720 mbox
->lba
&= 0x1FFFFF;
1724 * 10-byte READ(0x28) or WRITE(0x2A) cdb
1726 else if (scp
->cmd_len
== 10) {
1728 (uint32_t)scp
->cmnd
[8] |
1729 ((uint32_t)scp
->cmnd
[7] << 8);
1731 ((uint32_t)scp
->cmnd
[2] << 24) |
1732 ((uint32_t)scp
->cmnd
[3] << 16) |
1733 ((uint32_t)scp
->cmnd
[4] << 8) |
1734 (uint32_t)scp
->cmnd
[5];
1738 * 12-byte READ(0xA8) or WRITE(0xAA) cdb
1740 else if (scp
->cmd_len
== 12) {
1742 ((uint32_t)scp
->cmnd
[2] << 24) |
1743 ((uint32_t)scp
->cmnd
[3] << 16) |
1744 ((uint32_t)scp
->cmnd
[4] << 8) |
1745 (uint32_t)scp
->cmnd
[5];
1748 ((uint32_t)scp
->cmnd
[6] << 24) |
1749 ((uint32_t)scp
->cmnd
[7] << 16) |
1750 ((uint32_t)scp
->cmnd
[8] << 8) |
1751 (uint32_t)scp
->cmnd
[9];
1754 con_log(CL_ANN
, (KERN_WARNING
1755 "megaraid: unsupported CDB length\n"));
1757 megaraid_dealloc_scb(adapter
, scb
);
1759 scp
->result
= (DID_ERROR
<< 16);
1763 scb
->dma_direction
= scp
->sc_data_direction
;
1765 // Calculate Scatter-Gather info
1766 mbox64
->xferaddr_lo
= (uint32_t )ccb
->sgl_dma_h
;
1767 mbox
->numsge
= megaraid_mbox_mksgl(adapter
,
1769 mbox
->xferaddr
= 0xFFFFFFFF;
1770 mbox64
->xferaddr_hi
= 0;
1777 * Do we support clustering and is the support enabled
1780 scp
->result
= (DID_BAD_TARGET
<< 16);
1785 * Allocate a SCB and initialize mailbox
1787 if (!(scb
= megaraid_alloc_scb(adapter
, scp
))) {
1788 scp
->result
= (DID_ERROR
<< 16);
1793 ccb
= (mbox_ccb_t
*)scb
->ccb
;
1794 scb
->dev_channel
= 0xFF;
1795 scb
->dev_target
= target
;
1796 ccb
->raw_mbox
[0] = CLUSTER_CMD
;
1797 ccb
->raw_mbox
[2] = (scp
->cmnd
[0] == RESERVE
) ?
1798 RESERVE_LD
: RELEASE_LD
;
1800 ccb
->raw_mbox
[3] = target
;
1801 scb
->dma_direction
= scp
->sc_data_direction
;
1806 scp
->result
= (DID_BAD_TARGET
<< 16);
1810 else { // Passthru device commands
1812 // Do not allow access to target id > 15 or LUN > 7
1813 if (target
> 15 || SCP2LUN(scp
) > 7) {
1814 scp
->result
= (DID_BAD_TARGET
<< 16);
1818 // if fast load option was set and scan for last device is
1819 // over, reset the fast_load flag so that during a possible
1820 // next scan, devices can be made available
1821 if (rdev
->fast_load
&& (target
== 15) &&
1822 (SCP2CHANNEL(scp
) == adapter
->max_channel
-1)) {
1824 con_log(CL_ANN
, (KERN_INFO
1825 "megaraid[%d]: physical device scan re-enabled\n",
1826 adapter
->host
->host_no
));
1827 rdev
->fast_load
= 0;
1831 * Display the channel scan for physical devices
1833 if (!(rdev
->last_disp
& (1L << SCP2CHANNEL(scp
)))) {
1835 ss
= rdev
->fast_load
? skip
: scan
;
1837 con_log(CL_ANN
, (KERN_INFO
1838 "scsi[%d]: %s scsi channel %d [Phy %d]",
1839 adapter
->host
->host_no
, ss
, SCP2CHANNEL(scp
),
1843 " for non-raid devices\n"));
1845 rdev
->last_disp
|= (1L << SCP2CHANNEL(scp
));
1848 // disable channel sweep if fast load option given
1849 if (rdev
->fast_load
) {
1850 scp
->result
= (DID_BAD_TARGET
<< 16);
1854 // Allocate a SCB and initialize passthru
1855 if (!(scb
= megaraid_alloc_scb(adapter
, scp
))) {
1856 scp
->result
= (DID_ERROR
<< 16);
1861 ccb
= (mbox_ccb_t
*)scb
->ccb
;
1862 scb
->dev_channel
= channel
;
1863 scb
->dev_target
= target
;
1864 scb
->dma_direction
= scp
->sc_data_direction
;
1866 mbox64
= ccb
->mbox64
;
1868 // Does this firmware support extended CDBs
1869 if (adapter
->max_cdb_sz
== 16) {
1870 mbox
->cmd
= MBOXCMD_EXTPTHRU
;
1872 megaraid_mbox_prepare_epthru(adapter
, scb
, scp
);
1874 mbox64
->xferaddr_lo
= (uint32_t)ccb
->epthru_dma_h
;
1875 mbox64
->xferaddr_hi
= 0;
1876 mbox
->xferaddr
= 0xFFFFFFFF;
1879 mbox
->cmd
= MBOXCMD_PASSTHRU64
;
1881 megaraid_mbox_prepare_pthru(adapter
, scb
, scp
);
1883 mbox64
->xferaddr_lo
= (uint32_t)ccb
->pthru_dma_h
;
1884 mbox64
->xferaddr_hi
= 0;
1885 mbox
->xferaddr
= 0xFFFFFFFF;
1895 * megaraid_mbox_runpendq - execute commands queued in the pending queue
1896 * @adapter : controller's soft state
1897 * @scb_q : SCB to be queued in the pending list
1899 * Scan the pending list for commands which are not yet issued and try to
1900 * post to the controller. The SCB can be a null pointer, which would indicate
1901 * no SCB to be queue, just try to execute the ones in the pending list.
1903 * NOTE: We do not actually traverse the pending list. The SCBs are plucked
1904 * out from the head of the pending list. If it is successfully issued, the
1905 * next SCB is at the head now.
1908 megaraid_mbox_runpendq(adapter_t
*adapter
, scb_t
*scb_q
)
1911 unsigned long flags
;
1913 spin_lock_irqsave(PENDING_LIST_LOCK(adapter
), flags
);
1916 scb_q
->state
= SCB_PENDQ
;
1917 list_add_tail(&scb_q
->list
, &adapter
->pend_list
);
1920 // if the adapter in not in quiescent mode, post the commands to FW
1921 if (adapter
->quiescent
) {
1922 spin_unlock_irqrestore(PENDING_LIST_LOCK(adapter
), flags
);
1926 while (!list_empty(&adapter
->pend_list
)) {
1928 assert_spin_locked(PENDING_LIST_LOCK(adapter
));
1930 scb
= list_entry(adapter
->pend_list
.next
, scb_t
, list
);
1932 // remove the scb from the pending list and try to
1933 // issue. If we are unable to issue it, put back in
1934 // the pending list and return
1936 list_del_init(&scb
->list
);
1938 spin_unlock_irqrestore(PENDING_LIST_LOCK(adapter
), flags
);
1940 // if mailbox was busy, return SCB back to pending
1941 // list. Make sure to add at the head, since that's
1942 // where it would have been removed from
1944 scb
->state
= SCB_ISSUED
;
1946 if (mbox_post_cmd(adapter
, scb
) != 0) {
1948 spin_lock_irqsave(PENDING_LIST_LOCK(adapter
), flags
);
1950 scb
->state
= SCB_PENDQ
;
1952 list_add(&scb
->list
, &adapter
->pend_list
);
1954 spin_unlock_irqrestore(PENDING_LIST_LOCK(adapter
),
1960 spin_lock_irqsave(PENDING_LIST_LOCK(adapter
), flags
);
1963 spin_unlock_irqrestore(PENDING_LIST_LOCK(adapter
), flags
);
1971 * megaraid_mbox_prepare_pthru - prepare a command for physical devices
1972 * @adapter : pointer to controller's soft state
1973 * @scb : scsi control block
1974 * @scp : scsi command from the mid-layer
1976 * Prepare a command for the scsi physical devices.
1979 megaraid_mbox_prepare_pthru(adapter_t
*adapter
, scb_t
*scb
,
1980 struct scsi_cmnd
*scp
)
1983 mraid_passthru_t
*pthru
;
1987 ccb
= (mbox_ccb_t
*)scb
->ccb
;
1989 channel
= scb
->dev_channel
;
1990 target
= scb
->dev_target
;
1992 // 0=6sec, 1=60sec, 2=10min, 3=3hrs, 4=NO timeout
1995 pthru
->islogical
= 0;
1997 pthru
->target
= (channel
<< 4) | target
;
1998 pthru
->logdrv
= SCP2LUN(scp
);
1999 pthru
->reqsenselen
= 14;
2000 pthru
->cdblen
= scp
->cmd_len
;
2002 memcpy(pthru
->cdb
, scp
->cmnd
, scp
->cmd_len
);
2004 if (scsi_bufflen(scp
)) {
2005 pthru
->dataxferlen
= scsi_bufflen(scp
);
2006 pthru
->dataxferaddr
= ccb
->sgl_dma_h
;
2007 pthru
->numsge
= megaraid_mbox_mksgl(adapter
, scb
);
2010 pthru
->dataxferaddr
= 0;
2011 pthru
->dataxferlen
= 0;
2019 * megaraid_mbox_prepare_epthru - prepare a command for physical devices
2020 * @adapter : pointer to controller's soft state
2021 * @scb : scsi control block
2022 * @scp : scsi command from the mid-layer
2024 * Prepare a command for the scsi physical devices. This rountine prepares
2025 * commands for devices which can take extended CDBs (>10 bytes).
2028 megaraid_mbox_prepare_epthru(adapter_t
*adapter
, scb_t
*scb
,
2029 struct scsi_cmnd
*scp
)
2032 mraid_epassthru_t
*epthru
;
2036 ccb
= (mbox_ccb_t
*)scb
->ccb
;
2037 epthru
= ccb
->epthru
;
2038 channel
= scb
->dev_channel
;
2039 target
= scb
->dev_target
;
2041 // 0=6sec, 1=60sec, 2=10min, 3=3hrs, 4=NO timeout
2042 epthru
->timeout
= 4;
2044 epthru
->islogical
= 0;
2045 epthru
->channel
= 0;
2046 epthru
->target
= (channel
<< 4) | target
;
2047 epthru
->logdrv
= SCP2LUN(scp
);
2048 epthru
->reqsenselen
= 14;
2049 epthru
->cdblen
= scp
->cmd_len
;
2051 memcpy(epthru
->cdb
, scp
->cmnd
, scp
->cmd_len
);
2053 if (scsi_bufflen(scp
)) {
2054 epthru
->dataxferlen
= scsi_bufflen(scp
);
2055 epthru
->dataxferaddr
= ccb
->sgl_dma_h
;
2056 epthru
->numsge
= megaraid_mbox_mksgl(adapter
, scb
);
2059 epthru
->dataxferaddr
= 0;
2060 epthru
->dataxferlen
= 0;
2068 * megaraid_ack_sequence - interrupt ack sequence for memory mapped HBAs
2069 * @adapter : controller's soft state
2071 * Interrupt acknowledgement sequence for memory mapped HBAs. Find out the
2072 * completed command and put them on the completed list for later processing.
2074 * Returns: 1 if the interrupt is valid, 0 otherwise
2077 megaraid_ack_sequence(adapter_t
*adapter
)
2079 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
2083 uint8_t completed
[MBOX_MAX_FIRMWARE_STATUS
];
2084 struct list_head clist
;
2087 unsigned long flags
;
2091 mbox
= raid_dev
->mbox
;
2093 // move the SCBs from the firmware completed array to our local list
2094 INIT_LIST_HEAD(&clist
);
2096 // loop till F/W has more commands for us to complete
2098 spin_lock_irqsave(MAILBOX_LOCK(raid_dev
), flags
);
2101 * Check if a valid interrupt is pending. If found, force the
2102 * interrupt line low.
2104 dword
= RDOUTDOOR(raid_dev
);
2105 if (dword
!= 0x10001234) break;
2109 WROUTDOOR(raid_dev
, 0x10001234);
2112 // wait for valid numstatus to post
2113 for (i
= 0; i
< 0xFFFFF; i
++) {
2114 if (mbox
->numstatus
!= 0xFF) {
2115 nstatus
= mbox
->numstatus
;
2120 mbox
->numstatus
= 0xFF;
2122 adapter
->outstanding_cmds
-= nstatus
;
2124 for (i
= 0; i
< nstatus
; i
++) {
2126 // wait for valid command index to post
2127 for (j
= 0; j
< 0xFFFFF; j
++) {
2128 if (mbox
->completed
[i
] != 0xFF) break;
2131 completed
[i
] = mbox
->completed
[i
];
2132 mbox
->completed
[i
] = 0xFF;
2134 if (completed
[i
] == 0xFF) {
2135 con_log(CL_ANN
, (KERN_CRIT
2136 "megaraid: command posting timed out\n"));
2142 // Get SCB associated with this command id
2143 if (completed
[i
] >= MBOX_MAX_SCSI_CMDS
) {
2145 scb
= adapter
->uscb_list
+ (completed
[i
] -
2146 MBOX_MAX_SCSI_CMDS
);
2150 scb
= adapter
->kscb_list
+ completed
[i
];
2153 scb
->status
= mbox
->status
;
2154 list_add_tail(&scb
->list
, &clist
);
2157 // Acknowledge interrupt
2158 WRINDOOR(raid_dev
, 0x02);
2162 spin_unlock_irqrestore(MAILBOX_LOCK(raid_dev
), flags
);
2165 // put the completed commands in the completed list. DPC would
2166 // complete these commands later
2167 spin_lock_irqsave(COMPLETED_LIST_LOCK(adapter
), flags
);
2169 list_splice(&clist
, &adapter
->completed_list
);
2171 spin_unlock_irqrestore(COMPLETED_LIST_LOCK(adapter
), flags
);
2174 // schedule the DPC if there is some work for it
2176 tasklet_schedule(&adapter
->dpc_h
);
2183 * megaraid_isr - isr for memory based mailbox based controllers
2185 * @devp : pointer to our soft state
2187 * Interrupt service routine for memory-mapped mailbox controllers.
2190 megaraid_isr(int irq
, void *devp
)
2192 adapter_t
*adapter
= devp
;
2195 handled
= megaraid_ack_sequence(adapter
);
2197 /* Loop through any pending requests */
2198 if (!adapter
->quiescent
) {
2199 megaraid_mbox_runpendq(adapter
, NULL
);
2202 return IRQ_RETVAL(handled
);
2207 * megaraid_mbox_sync_scb - sync kernel buffers
2208 * @adapter : controller's soft state
2209 * @scb : pointer to the resource packet
2211 * DMA sync if required.
2214 megaraid_mbox_sync_scb(adapter_t
*adapter
, scb_t
*scb
)
2218 ccb
= (mbox_ccb_t
*)scb
->ccb
;
2220 if (scb
->dma_direction
== PCI_DMA_FROMDEVICE
)
2221 pci_dma_sync_sg_for_cpu(adapter
->pdev
,
2222 scsi_sglist(scb
->scp
),
2223 scsi_sg_count(scb
->scp
),
2224 PCI_DMA_FROMDEVICE
);
2226 scsi_dma_unmap(scb
->scp
);
2232 * megaraid_mbox_dpc - the tasklet to complete the commands from completed list
2233 * @devp : pointer to HBA soft state
2235 * Pick up the commands from the completed list and send back to the owners.
2236 * This is a reentrant function and does not assume any locks are held while
2237 * it is being called.
2240 megaraid_mbox_dpc(unsigned long devp
)
2242 adapter_t
*adapter
= (adapter_t
*)devp
;
2243 mraid_device_t
*raid_dev
;
2244 struct list_head clist
;
2245 struct scatterlist
*sgl
;
2248 struct scsi_cmnd
*scp
;
2249 mraid_passthru_t
*pthru
;
2250 mraid_epassthru_t
*epthru
;
2256 unsigned long flags
;
2262 if (!adapter
) return;
2264 raid_dev
= ADAP2RAIDDEV(adapter
);
2266 // move the SCBs from the completed list to our local list
2267 INIT_LIST_HEAD(&clist
);
2269 spin_lock_irqsave(COMPLETED_LIST_LOCK(adapter
), flags
);
2271 list_splice_init(&adapter
->completed_list
, &clist
);
2273 spin_unlock_irqrestore(COMPLETED_LIST_LOCK(adapter
), flags
);
2276 list_for_each_entry_safe(scb
, tmp
, &clist
, list
) {
2278 status
= scb
->status
;
2280 ccb
= (mbox_ccb_t
*)scb
->ccb
;
2282 epthru
= ccb
->epthru
;
2285 // Make sure f/w has completed a valid command
2286 if (scb
->state
!= SCB_ISSUED
) {
2287 con_log(CL_ANN
, (KERN_CRIT
2288 "megaraid critical err: invalid command %d:%d:%p\n",
2289 scb
->sno
, scb
->state
, scp
));
2291 continue; // Must never happen!
2294 // check for the management command and complete it right away
2295 if (scb
->sno
>= MBOX_MAX_SCSI_CMDS
) {
2296 scb
->state
= SCB_FREE
;
2297 scb
->status
= status
;
2299 // remove from local clist
2300 list_del_init(&scb
->list
);
2302 kioc
= (uioc_t
*)scb
->gp
;
2305 megaraid_mbox_mm_done(adapter
, scb
);
2310 // Was an abort issued for this command earlier
2311 if (scb
->state
& SCB_ABORT
) {
2312 con_log(CL_ANN
, (KERN_NOTICE
2313 "megaraid: aborted cmd %lx[%x] completed\n",
2314 scp
->serial_number
, scb
->sno
));
2318 * If the inquiry came of a disk drive which is not part of
2319 * any RAID array, expose it to the kernel. For this to be
2320 * enabled, user must set the "megaraid_expose_unconf_disks"
2321 * flag to 1 by specifying it on module parameter list.
2322 * This would enable data migration off drives from other
2325 islogical
= MRAID_IS_LOGICAL(adapter
, scp
);
2326 if (scp
->cmnd
[0] == INQUIRY
&& status
== 0 && islogical
== 0
2327 && IS_RAID_CH(raid_dev
, scb
->dev_channel
)) {
2329 sgl
= scsi_sglist(scp
);
2331 c
= *(unsigned char *)
2332 (page_address((&sgl
[0])->page
) +
2335 con_log(CL_ANN
, (KERN_WARNING
2336 "megaraid mailbox: invalid sg:%d\n",
2341 if ((c
& 0x1F ) == TYPE_DISK
) {
2342 pdev_index
= (scb
->dev_channel
* 16) +
2345 raid_dev
->pdrv_state
[pdev_index
] & 0x0F;
2347 if (pdev_state
== PDRV_ONLINE
||
2348 pdev_state
== PDRV_FAILED
||
2349 pdev_state
== PDRV_RBLD
||
2350 pdev_state
== PDRV_HOTSPARE
||
2351 megaraid_expose_unconf_disks
== 0) {
2358 // Convert MegaRAID status to Linux error code
2363 scp
->result
= (DID_OK
<< 16);
2368 /* set sense_buffer and result fields */
2369 if (mbox
->cmd
== MBOXCMD_PASSTHRU
||
2370 mbox
->cmd
== MBOXCMD_PASSTHRU64
) {
2372 memcpy(scp
->sense_buffer
, pthru
->reqsensearea
,
2375 scp
->result
= DRIVER_SENSE
<< 24 |
2376 DID_OK
<< 16 | CHECK_CONDITION
<< 1;
2379 if (mbox
->cmd
== MBOXCMD_EXTPTHRU
) {
2381 memcpy(scp
->sense_buffer
,
2382 epthru
->reqsensearea
, 14);
2384 scp
->result
= DRIVER_SENSE
<< 24 |
2386 CHECK_CONDITION
<< 1;
2388 scp
->sense_buffer
[0] = 0x70;
2389 scp
->sense_buffer
[2] = ABORTED_COMMAND
;
2390 scp
->result
= CHECK_CONDITION
<< 1;
2397 scp
->result
= DID_BUS_BUSY
<< 16 | status
;
2403 * If TEST_UNIT_READY fails, we know RESERVATION_STATUS
2406 if (scp
->cmnd
[0] == TEST_UNIT_READY
) {
2407 scp
->result
= DID_ERROR
<< 16 |
2408 RESERVATION_CONFLICT
<< 1;
2412 * Error code returned is 1 if Reserve or Release
2413 * failed or the input parameter is invalid
2415 if (status
== 1 && (scp
->cmnd
[0] == RESERVE
||
2416 scp
->cmnd
[0] == RELEASE
)) {
2418 scp
->result
= DID_ERROR
<< 16 |
2419 RESERVATION_CONFLICT
<< 1;
2422 scp
->result
= DID_BAD_TARGET
<< 16 | status
;
2426 // print a debug message for all failed commands
2428 megaraid_mbox_display_scb(adapter
, scb
);
2431 // Free our internal resources and call the mid-layer callback
2433 megaraid_mbox_sync_scb(adapter
, scb
);
2435 // remove from local clist
2436 list_del_init(&scb
->list
);
2438 // put back in free list
2439 megaraid_dealloc_scb(adapter
, scb
);
2441 // send the scsi packet back to kernel
2442 scp
->scsi_done(scp
);
2450 * megaraid_abort_handler - abort the scsi command
2451 * @scp : command to be aborted
2453 * Abort a previous SCSI request. Only commands on the pending list can be
2454 * aborted. All the commands issued to the F/W must complete.
2457 megaraid_abort_handler(struct scsi_cmnd
*scp
)
2460 mraid_device_t
*raid_dev
;
2464 unsigned long flags
;
2468 adapter
= SCP2ADAPTER(scp
);
2469 raid_dev
= ADAP2RAIDDEV(adapter
);
2471 con_log(CL_ANN
, (KERN_WARNING
2472 "megaraid: aborting-%ld cmd=%x <c=%d t=%d l=%d>\n",
2473 scp
->serial_number
, scp
->cmnd
[0], SCP2CHANNEL(scp
),
2474 SCP2TARGET(scp
), SCP2LUN(scp
)));
2476 // If FW has stopped responding, simply return failure
2477 if (raid_dev
->hw_error
) {
2478 con_log(CL_ANN
, (KERN_NOTICE
2479 "megaraid: hw error, not aborting\n"));
2483 // There might a race here, where the command was completed by the
2484 // firmware and now it is on the completed list. Before we could
2485 // complete the command to the kernel in dpc, the abort came.
2486 // Find out if this is the case to avoid the race.
2488 spin_lock_irqsave(COMPLETED_LIST_LOCK(adapter
), flags
);
2489 list_for_each_entry_safe(scb
, tmp
, &adapter
->completed_list
, list
) {
2491 if (scb
->scp
== scp
) { // Found command
2493 list_del_init(&scb
->list
); // from completed list
2495 con_log(CL_ANN
, (KERN_WARNING
2496 "megaraid: %ld:%d[%d:%d], abort from completed list\n",
2497 scp
->serial_number
, scb
->sno
,
2498 scb
->dev_channel
, scb
->dev_target
));
2500 scp
->result
= (DID_ABORT
<< 16);
2501 scp
->scsi_done(scp
);
2503 megaraid_dealloc_scb(adapter
, scb
);
2505 spin_unlock_irqrestore(COMPLETED_LIST_LOCK(adapter
),
2511 spin_unlock_irqrestore(COMPLETED_LIST_LOCK(adapter
), flags
);
2514 // Find out if this command is still on the pending list. If it is and
2515 // was never issued, abort and return success. If the command is owned
2516 // by the firmware, we must wait for it to complete by the FW.
2517 spin_lock_irqsave(PENDING_LIST_LOCK(adapter
), flags
);
2518 list_for_each_entry_safe(scb
, tmp
, &adapter
->pend_list
, list
) {
2520 if (scb
->scp
== scp
) { // Found command
2522 list_del_init(&scb
->list
); // from pending list
2524 ASSERT(!(scb
->state
& SCB_ISSUED
));
2526 con_log(CL_ANN
, (KERN_WARNING
2527 "megaraid abort: %ld[%d:%d], driver owner\n",
2528 scp
->serial_number
, scb
->dev_channel
,
2531 scp
->result
= (DID_ABORT
<< 16);
2532 scp
->scsi_done(scp
);
2534 megaraid_dealloc_scb(adapter
, scb
);
2536 spin_unlock_irqrestore(PENDING_LIST_LOCK(adapter
),
2542 spin_unlock_irqrestore(PENDING_LIST_LOCK(adapter
), flags
);
2545 // Check do we even own this command, in which case this would be
2546 // owned by the firmware. The only way to locate the FW scb is to
2547 // traverse through the list of all SCB, since driver does not
2548 // maintain these SCBs on any list
2550 spin_lock_irq(&adapter
->lock
);
2551 for (i
= 0; i
< MBOX_MAX_SCSI_CMDS
; i
++) {
2552 scb
= adapter
->kscb_list
+ i
;
2554 if (scb
->scp
== scp
) {
2558 if (!(scb
->state
& SCB_ISSUED
)) {
2559 con_log(CL_ANN
, (KERN_WARNING
2560 "megaraid abort: %ld%d[%d:%d], invalid state\n",
2561 scp
->serial_number
, scb
->sno
, scb
->dev_channel
,
2566 con_log(CL_ANN
, (KERN_WARNING
2567 "megaraid abort: %ld:%d[%d:%d], fw owner\n",
2568 scp
->serial_number
, scb
->sno
, scb
->dev_channel
,
2573 spin_unlock_irq(&adapter
->lock
);
2576 con_log(CL_ANN
, (KERN_WARNING
2577 "megaraid abort: scsi cmd:%ld, do now own\n",
2578 scp
->serial_number
));
2580 // FIXME: Should there be a callback for this command?
2584 // We cannot actually abort a command owned by firmware, return
2585 // failure and wait for reset. In host reset handler, we will find out
2586 // if the HBA is still live
2591 * megaraid_reset_handler - device reset hadler for mailbox based driver
2592 * @scp : reference command
2594 * Reset handler for the mailbox based controller. First try to find out if
2595 * the FW is still live, in which case the outstanding commands counter mut go
2596 * down to 0. If that happens, also issue the reservation reset command to
2597 * relinquish (possible) reservations on the logical drives connected to this
2601 megaraid_reset_handler(struct scsi_cmnd
*scp
)
2606 mraid_device_t
*raid_dev
;
2607 unsigned long flags
;
2608 uint8_t raw_mbox
[sizeof(mbox_t
)];
2610 int recovery_window
;
2615 adapter
= SCP2ADAPTER(scp
);
2616 raid_dev
= ADAP2RAIDDEV(adapter
);
2618 // return failure if adapter is not responding
2619 if (raid_dev
->hw_error
) {
2620 con_log(CL_ANN
, (KERN_NOTICE
2621 "megaraid: hw error, cannot reset\n"));
2626 // Under exceptional conditions, FW can take up to 3 minutes to
2627 // complete command processing. Wait for additional 2 minutes for the
2628 // pending commands counter to go down to 0. If it doesn't, let the
2629 // controller be marked offline
2630 // Also, reset all the commands currently owned by the driver
2631 spin_lock_irqsave(PENDING_LIST_LOCK(adapter
), flags
);
2632 list_for_each_entry_safe(scb
, tmp
, &adapter
->pend_list
, list
) {
2633 list_del_init(&scb
->list
); // from pending list
2635 if (scb
->sno
>= MBOX_MAX_SCSI_CMDS
) {
2636 con_log(CL_ANN
, (KERN_WARNING
2637 "megaraid: IOCTL packet with %d[%d:%d] being reset\n",
2638 scb
->sno
, scb
->dev_channel
, scb
->dev_target
));
2642 kioc
= (uioc_t
*)scb
->gp
;
2643 kioc
->status
= -EFAULT
;
2645 megaraid_mbox_mm_done(adapter
, scb
);
2647 if (scb
->scp
== scp
) { // Found command
2648 con_log(CL_ANN
, (KERN_WARNING
2649 "megaraid: %ld:%d[%d:%d], reset from pending list\n",
2650 scp
->serial_number
, scb
->sno
,
2651 scb
->dev_channel
, scb
->dev_target
));
2653 con_log(CL_ANN
, (KERN_WARNING
2654 "megaraid: IO packet with %d[%d:%d] being reset\n",
2655 scb
->sno
, scb
->dev_channel
, scb
->dev_target
));
2658 scb
->scp
->result
= (DID_RESET
<< 16);
2659 scb
->scp
->scsi_done(scb
->scp
);
2661 megaraid_dealloc_scb(adapter
, scb
);
2664 spin_unlock_irqrestore(PENDING_LIST_LOCK(adapter
), flags
);
2666 if (adapter
->outstanding_cmds
) {
2667 con_log(CL_ANN
, (KERN_NOTICE
2668 "megaraid: %d outstanding commands. Max wait %d sec\n",
2669 adapter
->outstanding_cmds
,
2670 (MBOX_RESET_WAIT
+ MBOX_RESET_EXT_WAIT
)));
2673 recovery_window
= MBOX_RESET_WAIT
+ MBOX_RESET_EXT_WAIT
;
2675 recovering
= adapter
->outstanding_cmds
;
2677 for (i
= 0; i
< recovery_window
; i
++) {
2679 megaraid_ack_sequence(adapter
);
2681 // print a message once every 5 seconds only
2684 "megaraid mbox: Wait for %d commands to complete:%d\n",
2685 adapter
->outstanding_cmds
,
2686 (MBOX_RESET_WAIT
+ MBOX_RESET_EXT_WAIT
) - i
));
2689 // bailout if no recovery happended in reset time
2690 if (adapter
->outstanding_cmds
== 0) {
2697 spin_lock(&adapter
->lock
);
2699 // If still outstanding commands, bail out
2700 if (adapter
->outstanding_cmds
) {
2701 con_log(CL_ANN
, (KERN_WARNING
2702 "megaraid mbox: critical hardware error!\n"));
2704 raid_dev
->hw_error
= 1;
2710 con_log(CL_ANN
, (KERN_NOTICE
2711 "megaraid mbox: reset sequence completed sucessfully\n"));
2715 // If the controller supports clustering, reset reservations
2721 // clear reservations if any
2722 raw_mbox
[0] = CLUSTER_CMD
;
2723 raw_mbox
[2] = RESET_RESERVATIONS
;
2726 if (mbox_post_sync_cmd_fast(adapter
, raw_mbox
) == 0) {
2728 (KERN_INFO
"megaraid: reservation reset\n"));
2732 con_log(CL_ANN
, (KERN_WARNING
2733 "megaraid: reservation reset failed\n"));
2737 spin_unlock_irq(&adapter
->lock
);
2742 * START: internal commands library
2744 * This section of the driver has the common routine used by the driver and
2745 * also has all the FW routines
2749 * mbox_post_sync_cmd() - blocking command to the mailbox based controllers
2750 * @adapter : controller's soft state
2751 * @raw_mbox : the mailbox
2753 * Issue a scb in synchronous and non-interrupt mode for mailbox based
2757 mbox_post_sync_cmd(adapter_t
*adapter
, uint8_t raw_mbox
[])
2759 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
2766 mbox64
= raid_dev
->mbox64
;
2767 mbox
= raid_dev
->mbox
;
2770 * Wait until mailbox is free
2772 if (megaraid_busywait_mbox(raid_dev
) != 0)
2773 goto blocked_mailbox
;
2776 * Copy mailbox data into host structure
2778 memcpy((caddr_t
)mbox
, (caddr_t
)raw_mbox
, 16);
2783 mbox
->numstatus
= 0xFF;
2784 mbox
->status
= 0xFF;
2787 WRINDOOR(raid_dev
, raid_dev
->mbox_dma
| 0x1);
2789 // wait for maximum 1 second for status to post. If the status is not
2790 // available within 1 second, assume FW is initializing and wait
2791 // for an extended amount of time
2792 if (mbox
->numstatus
== 0xFF) { // status not yet available
2795 for (i
= 0; mbox
->numstatus
== 0xFF && i
< 1000; i
++) {
2802 con_log(CL_ANN
, (KERN_NOTICE
2803 "megaraid mailbox: wait for FW to boot "));
2805 for (i
= 0; (mbox
->numstatus
== 0xFF) &&
2806 (i
< MBOX_RESET_WAIT
); i
++) {
2808 con_log(CL_ANN
, ("\b\b\b\b\b[%03d]",
2809 MBOX_RESET_WAIT
- i
));
2813 if (i
== MBOX_RESET_WAIT
) {
2816 "\nmegaraid mailbox: status not available\n"));
2820 con_log(CL_ANN
, ("\b\b\b\b\b[ok] \n"));
2824 // wait for maximum 1 second for poll semaphore
2825 if (mbox
->poll
!= 0x77) {
2828 for (i
= 0; (mbox
->poll
!= 0x77) && (i
< 1000); i
++) {
2834 con_log(CL_ANN
, (KERN_WARNING
2835 "megaraid mailbox: could not get poll semaphore\n"));
2840 WRINDOOR(raid_dev
, raid_dev
->mbox_dma
| 0x2);
2843 // wait for maximum 1 second for acknowledgement
2844 if (RDINDOOR(raid_dev
) & 0x2) {
2847 for (i
= 0; (RDINDOOR(raid_dev
) & 0x2) && (i
< 1000); i
++) {
2853 con_log(CL_ANN
, (KERN_WARNING
2854 "megaraid mailbox: could not acknowledge\n"));
2861 status
= mbox
->status
;
2863 // invalidate the completed command id array. After command
2864 // completion, firmware would write the valid id.
2865 mbox
->numstatus
= 0xFF;
2866 mbox
->status
= 0xFF;
2867 for (i
= 0; i
< MBOX_MAX_FIRMWARE_STATUS
; i
++) {
2868 mbox
->completed
[i
] = 0xFF;
2875 con_log(CL_ANN
, (KERN_WARNING
"megaraid: blocked mailbox\n") );
2881 * mbox_post_sync_cmd_fast - blocking command to the mailbox based controllers
2882 * @adapter : controller's soft state
2883 * @raw_mbox : the mailbox
2885 * Issue a scb in synchronous and non-interrupt mode for mailbox based
2886 * controllers. This is a faster version of the synchronous command and
2887 * therefore can be called in interrupt-context as well.
2890 mbox_post_sync_cmd_fast(adapter_t
*adapter
, uint8_t raw_mbox
[])
2892 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
2897 mbox
= raid_dev
->mbox
;
2899 // return immediately if the mailbox is busy
2900 if (mbox
->busy
) return -1;
2902 // Copy mailbox data into host structure
2903 memcpy((caddr_t
)mbox
, (caddr_t
)raw_mbox
, 14);
2908 mbox
->numstatus
= 0xFF;
2909 mbox
->status
= 0xFF;
2912 WRINDOOR(raid_dev
, raid_dev
->mbox_dma
| 0x1);
2914 for (i
= 0; i
< MBOX_SYNC_WAIT_CNT
; i
++) {
2915 if (mbox
->numstatus
!= 0xFF) break;
2917 udelay(MBOX_SYNC_DELAY_200
);
2920 if (i
== MBOX_SYNC_WAIT_CNT
) {
2921 // We may need to re-calibrate the counter
2922 con_log(CL_ANN
, (KERN_CRIT
2923 "megaraid: fast sync command timed out\n"));
2926 WRINDOOR(raid_dev
, raid_dev
->mbox_dma
| 0x2);
2929 return mbox
->status
;
2934 * megaraid_busywait_mbox() - Wait until the controller's mailbox is available
2935 * @raid_dev : RAID device (HBA) soft state
2937 * Wait until the controller's mailbox is available to accept more commands.
2938 * Wait for at most 1 second.
2941 megaraid_busywait_mbox(mraid_device_t
*raid_dev
)
2943 mbox_t
*mbox
= raid_dev
->mbox
;
2948 for (i
= 0; mbox
->busy
&& i
< 1000; i
++)
2952 if (i
< 1000) return 0;
2958 * megaraid_mbox_product_info - some static information about the controller
2959 * @adapter : our soft state
2961 * Issue commands to the controller to grab some parameters required by our
2965 megaraid_mbox_product_info(adapter_t
*adapter
)
2967 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
2969 uint8_t raw_mbox
[sizeof(mbox_t
)];
2970 mraid_pinfo_t
*pinfo
;
2971 dma_addr_t pinfo_dma_h
;
2972 mraid_inquiry3_t
*mraid_inq3
;
2976 memset((caddr_t
)raw_mbox
, 0, sizeof(raw_mbox
));
2977 mbox
= (mbox_t
*)raw_mbox
;
2980 * Issue an ENQUIRY3 command to find out certain adapter parameters,
2981 * e.g., max channels, max commands etc.
2983 pinfo
= pci_alloc_consistent(adapter
->pdev
, sizeof(mraid_pinfo_t
),
2986 if (pinfo
== NULL
) {
2987 con_log(CL_ANN
, (KERN_WARNING
2988 "megaraid: out of memory, %s %d\n", __FUNCTION__
,
2993 memset(pinfo
, 0, sizeof(mraid_pinfo_t
));
2995 mbox
->xferaddr
= (uint32_t)adapter
->ibuf_dma_h
;
2996 memset((void *)adapter
->ibuf
, 0, MBOX_IBUF_SIZE
);
2998 raw_mbox
[0] = FC_NEW_CONFIG
;
2999 raw_mbox
[2] = NC_SUBOP_ENQUIRY3
;
3000 raw_mbox
[3] = ENQ3_GET_SOLICITED_FULL
;
3002 // Issue the command
3003 if (mbox_post_sync_cmd(adapter
, raw_mbox
) != 0) {
3005 con_log(CL_ANN
, (KERN_WARNING
"megaraid: Inquiry3 failed\n"));
3007 pci_free_consistent(adapter
->pdev
, sizeof(mraid_pinfo_t
),
3008 pinfo
, pinfo_dma_h
);
3014 * Collect information about state of each physical drive
3015 * attached to the controller. We will expose all the disks
3016 * which are not part of RAID
3018 mraid_inq3
= (mraid_inquiry3_t
*)adapter
->ibuf
;
3019 for (i
= 0; i
< MBOX_MAX_PHYSICAL_DRIVES
; i
++) {
3020 raid_dev
->pdrv_state
[i
] = mraid_inq3
->pdrv_state
[i
];
3024 * Get product info for information like number of channels,
3025 * maximum commands supported.
3027 memset((caddr_t
)raw_mbox
, 0, sizeof(raw_mbox
));
3028 mbox
->xferaddr
= (uint32_t)pinfo_dma_h
;
3030 raw_mbox
[0] = FC_NEW_CONFIG
;
3031 raw_mbox
[2] = NC_SUBOP_PRODUCT_INFO
;
3033 if (mbox_post_sync_cmd(adapter
, raw_mbox
) != 0) {
3035 con_log(CL_ANN
, (KERN_WARNING
3036 "megaraid: product info failed\n"));
3038 pci_free_consistent(adapter
->pdev
, sizeof(mraid_pinfo_t
),
3039 pinfo
, pinfo_dma_h
);
3045 * Setup some parameters for host, as required by our caller
3047 adapter
->max_channel
= pinfo
->nchannels
;
3050 * we will export all the logical drives on a single channel.
3051 * Add 1 since inquires do not come for inititor ID
3053 adapter
->max_target
= MAX_LOGICAL_DRIVES_40LD
+ 1;
3054 adapter
->max_lun
= 8; // up to 8 LUNs for non-disk devices
3057 * These are the maximum outstanding commands for the scsi-layer
3059 adapter
->max_cmds
= MBOX_MAX_SCSI_CMDS
;
3061 memset(adapter
->fw_version
, 0, VERSION_SIZE
);
3062 memset(adapter
->bios_version
, 0, VERSION_SIZE
);
3064 memcpy(adapter
->fw_version
, pinfo
->fw_version
, 4);
3065 adapter
->fw_version
[4] = 0;
3067 memcpy(adapter
->bios_version
, pinfo
->bios_version
, 4);
3068 adapter
->bios_version
[4] = 0;
3070 con_log(CL_ANN
, (KERN_NOTICE
3071 "megaraid: fw version:[%s] bios version:[%s]\n",
3072 adapter
->fw_version
, adapter
->bios_version
));
3074 pci_free_consistent(adapter
->pdev
, sizeof(mraid_pinfo_t
), pinfo
,
3083 * megaraid_mbox_extended_cdb - check for support for extended CDBs
3084 * @adapter : soft state for the controller
3086 * This routine check whether the controller in question supports extended
3087 * ( > 10 bytes ) CDBs.
3090 megaraid_mbox_extended_cdb(adapter_t
*adapter
)
3093 uint8_t raw_mbox
[sizeof(mbox_t
)];
3096 mbox
= (mbox_t
*)raw_mbox
;
3098 memset((caddr_t
)raw_mbox
, 0, sizeof(raw_mbox
));
3099 mbox
->xferaddr
= (uint32_t)adapter
->ibuf_dma_h
;
3101 memset((void *)adapter
->ibuf
, 0, MBOX_IBUF_SIZE
);
3103 raw_mbox
[0] = MAIN_MISC_OPCODE
;
3104 raw_mbox
[2] = SUPPORT_EXT_CDB
;
3110 if (mbox_post_sync_cmd(adapter
, raw_mbox
) != 0) {
3119 * megaraid_mbox_support_ha - Do we support clustering
3120 * @adapter : soft state for the controller
3121 * @init_id : ID of the initiator
3123 * Determine if the firmware supports clustering and the ID of the initiator.
3126 megaraid_mbox_support_ha(adapter_t
*adapter
, uint16_t *init_id
)
3129 uint8_t raw_mbox
[sizeof(mbox_t
)];
3133 mbox
= (mbox_t
*)raw_mbox
;
3135 memset((caddr_t
)raw_mbox
, 0, sizeof(raw_mbox
));
3137 mbox
->xferaddr
= (uint32_t)adapter
->ibuf_dma_h
;
3139 memset((void *)adapter
->ibuf
, 0, MBOX_IBUF_SIZE
);
3141 raw_mbox
[0] = GET_TARGET_ID
;
3143 // Issue the command
3146 if (mbox_post_sync_cmd(adapter
, raw_mbox
) == 0) {
3148 *init_id
= *(uint8_t *)adapter
->ibuf
;
3150 con_log(CL_ANN
, (KERN_INFO
3151 "megaraid: cluster firmware, initiator ID: %d\n",
3162 * megaraid_mbox_support_random_del - Do we support random deletion
3163 * @adapter : soft state for the controller
3165 * Determine if the firmware supports random deletion.
3166 * Return: 1 is operation supported, 0 otherwise
3169 megaraid_mbox_support_random_del(adapter_t
*adapter
)
3172 uint8_t raw_mbox
[sizeof(mbox_t
)];
3176 mbox
= (mbox_t
*)raw_mbox
;
3178 memset((caddr_t
)raw_mbox
, 0, sizeof(mbox_t
));
3180 raw_mbox
[0] = FC_DEL_LOGDRV
;
3181 raw_mbox
[2] = OP_SUP_DEL_LOGDRV
;
3183 // Issue the command
3185 if (mbox_post_sync_cmd(adapter
, raw_mbox
) == 0) {
3187 con_log(CL_DLEVEL1
, ("megaraid: supports random deletion\n"));
3197 * megaraid_mbox_get_max_sg - maximum sg elements supported by the firmware
3198 * @adapter : soft state for the controller
3200 * Find out the maximum number of scatter-gather elements supported by the
3204 megaraid_mbox_get_max_sg(adapter_t
*adapter
)
3207 uint8_t raw_mbox
[sizeof(mbox_t
)];
3211 mbox
= (mbox_t
*)raw_mbox
;
3213 memset((caddr_t
)raw_mbox
, 0, sizeof(mbox_t
));
3215 mbox
->xferaddr
= (uint32_t)adapter
->ibuf_dma_h
;
3217 memset((void *)adapter
->ibuf
, 0, MBOX_IBUF_SIZE
);
3219 raw_mbox
[0] = MAIN_MISC_OPCODE
;
3220 raw_mbox
[2] = GET_MAX_SG_SUPPORT
;
3222 // Issue the command
3223 if (mbox_post_sync_cmd(adapter
, raw_mbox
) == 0) {
3224 nsg
= *(uint8_t *)adapter
->ibuf
;
3227 nsg
= MBOX_DEFAULT_SG_SIZE
;
3230 if (nsg
> MBOX_MAX_SG_SIZE
) nsg
= MBOX_MAX_SG_SIZE
;
3237 * megaraid_mbox_enum_raid_scsi - enumerate the RAID and SCSI channels
3238 * @adapter : soft state for the controller
3240 * Enumerate the RAID and SCSI channels for ROMB platforms so that channels
3241 * can be exported as regular SCSI channels.
3244 megaraid_mbox_enum_raid_scsi(adapter_t
*adapter
)
3246 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
3248 uint8_t raw_mbox
[sizeof(mbox_t
)];
3251 mbox
= (mbox_t
*)raw_mbox
;
3253 memset((caddr_t
)raw_mbox
, 0, sizeof(mbox_t
));
3255 mbox
->xferaddr
= (uint32_t)adapter
->ibuf_dma_h
;
3257 memset((void *)adapter
->ibuf
, 0, MBOX_IBUF_SIZE
);
3259 raw_mbox
[0] = CHNL_CLASS
;
3260 raw_mbox
[2] = GET_CHNL_CLASS
;
3262 // Issue the command. If the command fails, all channels are RAID
3264 raid_dev
->channel_class
= 0xFF;
3265 if (mbox_post_sync_cmd(adapter
, raw_mbox
) == 0) {
3266 raid_dev
->channel_class
= *(uint8_t *)adapter
->ibuf
;
3274 * megaraid_mbox_flush_cache - flush adapter and disks cache
3275 * @adapter : soft state for the controller
3277 * Flush adapter cache followed by disks cache.
3280 megaraid_mbox_flush_cache(adapter_t
*adapter
)
3283 uint8_t raw_mbox
[sizeof(mbox_t
)];
3286 mbox
= (mbox_t
*)raw_mbox
;
3288 memset((caddr_t
)raw_mbox
, 0, sizeof(mbox_t
));
3290 raw_mbox
[0] = FLUSH_ADAPTER
;
3292 if (mbox_post_sync_cmd(adapter
, raw_mbox
) != 0) {
3293 con_log(CL_ANN
, ("megaraid: flush adapter failed\n"));
3296 raw_mbox
[0] = FLUSH_SYSTEM
;
3298 if (mbox_post_sync_cmd(adapter
, raw_mbox
) != 0) {
3299 con_log(CL_ANN
, ("megaraid: flush disks cache failed\n"));
3307 * megaraid_mbox_fire_sync_cmd - fire the sync cmd
3308 * @adapter : soft state for the controller
3310 * Clears the pending cmds in FW and reinits its RAID structs.
3313 megaraid_mbox_fire_sync_cmd(adapter_t
*adapter
)
3316 uint8_t raw_mbox
[sizeof(mbox_t
)];
3317 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
3323 mbox
= (mbox_t
*)raw_mbox
;
3325 memset((caddr_t
)raw_mbox
, 0, sizeof(mbox_t
));
3329 mbox64
= raid_dev
->mbox64
;
3330 mbox
= raid_dev
->mbox
;
3332 /* Wait until mailbox is free */
3333 if (megaraid_busywait_mbox(raid_dev
) != 0) {
3335 goto blocked_mailbox
;
3338 /* Copy mailbox data into host structure */
3339 memcpy((caddr_t
)mbox
, (caddr_t
)raw_mbox
, 16);
3344 mbox
->numstatus
= 0;
3348 WRINDOOR(raid_dev
, raid_dev
->mbox_dma
| 0x1);
3350 /* Wait for maximum 1 min for status to post.
3351 * If the Firmware SUPPORTS the ABOVE COMMAND,
3352 * mbox->cmd will be set to 0
3354 * the firmware will reject the command with
3355 * mbox->numstatus set to 1
3360 while (!mbox
->numstatus
&& mbox
->cmd
== 0xFF) {
3364 if (i
> 1000 * 60) {
3369 if (mbox
->numstatus
== 1)
3370 status
= 1; /*cmd not supported*/
3372 /* Check for interrupt line */
3373 dword
= RDOUTDOOR(raid_dev
);
3374 WROUTDOOR(raid_dev
, dword
);
3375 WRINDOOR(raid_dev
,2);
3380 con_log(CL_ANN
, (KERN_WARNING
"megaraid: blocked mailbox\n"));
3385 * megaraid_mbox_display_scb - display SCB information, mostly debug purposes
3386 * @adapter : controller's soft state
3387 * @scb : SCB to be displayed
3388 * @level : debug level for console print
3390 * Diplay information about the given SCB iff the current debug level is
3394 megaraid_mbox_display_scb(adapter_t
*adapter
, scb_t
*scb
)
3397 struct scsi_cmnd
*scp
;
3403 ccb
= (mbox_ccb_t
*)scb
->ccb
;
3409 con_log(level
, (KERN_NOTICE
3410 "megaraid mailbox: status:%#x cmd:%#x id:%#x ", scb
->status
,
3411 mbox
->cmd
, scb
->sno
));
3413 con_log(level
, ("sec:%#x lba:%#x addr:%#x ld:%d sg:%d\n",
3414 mbox
->numsectors
, mbox
->lba
, mbox
->xferaddr
, mbox
->logdrv
,
3419 con_log(level
, (KERN_NOTICE
"scsi cmnd: "));
3421 for (i
= 0; i
< scp
->cmd_len
; i
++) {
3422 con_log(level
, ("%#2.02x ", scp
->cmnd
[i
]));
3425 con_log(level
, ("\n"));
3432 * megaraid_mbox_setup_device_map - manage device ids
3433 * @adapter : Driver's soft state
3435 * Manange the device ids to have an appropraite mapping between the kernel
3436 * scsi addresses and megaraid scsi and logical drive addresses. We export
3437 * scsi devices on their actual addresses, whereas the logical drives are
3438 * exported on a virtual scsi channel.
3441 megaraid_mbox_setup_device_map(adapter_t
*adapter
)
3447 * First fill the values on the logical drive channel
3449 for (t
= 0; t
< LSI_MAX_LOGICAL_DRIVES_64LD
; t
++)
3450 adapter
->device_ids
[adapter
->max_channel
][t
] =
3451 (t
< adapter
->init_id
) ? t
: t
- 1;
3453 adapter
->device_ids
[adapter
->max_channel
][adapter
->init_id
] = 0xFF;
3456 * Fill the values on the physical devices channels
3458 for (c
= 0; c
< adapter
->max_channel
; c
++)
3459 for (t
= 0; t
< LSI_MAX_LOGICAL_DRIVES_64LD
; t
++)
3460 adapter
->device_ids
[c
][t
] = (c
<< 8) | t
;
3465 * END: internal commands library
3469 * START: Interface for the common management module
3471 * This is the module, which interfaces with the common mangement module to
3472 * provide support for ioctl and sysfs
3476 * megaraid_cmm_register - register with the mangement module
3477 * @adapter : HBA soft state
3479 * Register with the management module, which allows applications to issue
3480 * ioctl calls to the drivers. This interface is used by the management module
3481 * to setup sysfs support as well.
3484 megaraid_cmm_register(adapter_t
*adapter
)
3486 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
3493 // Allocate memory for the base list of scb for management module.
3494 adapter
->uscb_list
= kcalloc(MBOX_MAX_USER_CMDS
, sizeof(scb_t
), GFP_KERNEL
);
3496 if (adapter
->uscb_list
== NULL
) {
3497 con_log(CL_ANN
, (KERN_WARNING
3498 "megaraid: out of memory, %s %d\n", __FUNCTION__
,
3504 // Initialize the synchronization parameters for resources for
3505 // commands for management module
3506 INIT_LIST_HEAD(&adapter
->uscb_pool
);
3508 spin_lock_init(USER_FREE_LIST_LOCK(adapter
));
3512 // link all the packets. Note, CCB for commands, coming from the
3513 // commom management module, mailbox physical address are already
3514 // setup by it. We just need placeholder for that in our local command
3516 for (i
= 0; i
< MBOX_MAX_USER_CMDS
; i
++) {
3518 scb
= adapter
->uscb_list
+ i
;
3519 ccb
= raid_dev
->uccb_list
+ i
;
3521 scb
->ccb
= (caddr_t
)ccb
;
3522 ccb
->mbox64
= raid_dev
->umbox64
+ i
;
3523 ccb
->mbox
= &ccb
->mbox64
->mbox32
;
3524 ccb
->raw_mbox
= (uint8_t *)ccb
->mbox
;
3528 // COMMAND ID 0 - (MBOX_MAX_SCSI_CMDS-1) ARE RESERVED FOR
3529 // COMMANDS COMING FROM IO SUBSYSTEM (MID-LAYER)
3530 scb
->sno
= i
+ MBOX_MAX_SCSI_CMDS
;
3533 scb
->state
= SCB_FREE
;
3534 scb
->dma_direction
= PCI_DMA_NONE
;
3535 scb
->dma_type
= MRAID_DMA_NONE
;
3536 scb
->dev_channel
= -1;
3537 scb
->dev_target
= -1;
3539 // put scb in the free pool
3540 list_add_tail(&scb
->list
, &adapter
->uscb_pool
);
3543 adp
.unique_id
= adapter
->unique_id
;
3544 adp
.drvr_type
= DRVRTYPE_MBOX
;
3545 adp
.drvr_data
= (unsigned long)adapter
;
3546 adp
.pdev
= adapter
->pdev
;
3547 adp
.issue_uioc
= megaraid_mbox_mm_handler
;
3548 adp
.timeout
= MBOX_RESET_WAIT
+ MBOX_RESET_EXT_WAIT
;
3549 adp
.max_kioc
= MBOX_MAX_USER_CMDS
;
3551 if ((rval
= mraid_mm_register_adp(&adp
)) != 0) {
3553 con_log(CL_ANN
, (KERN_WARNING
3554 "megaraid mbox: did not register with CMM\n"));
3556 kfree(adapter
->uscb_list
);
3564 * megaraid_cmm_unregister - un-register with the mangement module
3565 * @adapter : HBA soft state
3567 * Un-register with the management module.
3568 * FIXME: mgmt module must return failure for unregister if it has pending
3572 megaraid_cmm_unregister(adapter_t
*adapter
)
3574 kfree(adapter
->uscb_list
);
3575 mraid_mm_unregister_adp(adapter
->unique_id
);
3581 * megaraid_mbox_mm_handler - interface for CMM to issue commands to LLD
3582 * @drvr_data : LLD specific data
3583 * @kioc : CMM interface packet
3584 * @action : command action
3586 * This routine is invoked whenever the Common Mangement Module (CMM) has a
3587 * command for us. The 'action' parameter specifies if this is a new command
3591 megaraid_mbox_mm_handler(unsigned long drvr_data
, uioc_t
*kioc
, uint32_t action
)
3595 if (action
!= IOCTL_ISSUE
) {
3596 con_log(CL_ANN
, (KERN_WARNING
3597 "megaraid: unsupported management action:%#2x\n",
3602 adapter
= (adapter_t
*)drvr_data
;
3604 // make sure this adapter is not being detached right now.
3605 if (atomic_read(&adapter
->being_detached
)) {
3606 con_log(CL_ANN
, (KERN_WARNING
3607 "megaraid: reject management request, detaching\n"));
3611 switch (kioc
->opcode
) {
3615 kioc
->status
= gather_hbainfo(adapter
, (mraid_hba_info_t
*)
3616 (unsigned long)kioc
->buf_vaddr
);
3620 return kioc
->status
;
3624 return megaraid_mbox_mm_command(adapter
, kioc
);
3627 kioc
->status
= (-EINVAL
);
3632 return 0; // not reached
3636 * megaraid_mbox_mm_command - issues commands routed through CMM
3637 * @adapter : HBA soft state
3638 * @kioc : management command packet
3640 * Issues commands, which are routed through the management module.
3643 megaraid_mbox_mm_command(adapter_t
*adapter
, uioc_t
*kioc
)
3645 struct list_head
*head
= &adapter
->uscb_pool
;
3650 unsigned long flags
;
3652 // detach one scb from free pool
3653 spin_lock_irqsave(USER_FREE_LIST_LOCK(adapter
), flags
);
3655 if (list_empty(head
)) { // should never happen because of CMM
3657 con_log(CL_ANN
, (KERN_WARNING
3658 "megaraid mbox: bug in cmm handler, lost resources\n"));
3660 spin_unlock_irqrestore(USER_FREE_LIST_LOCK(adapter
), flags
);
3665 scb
= list_entry(head
->next
, scb_t
, list
);
3666 list_del_init(&scb
->list
);
3668 spin_unlock_irqrestore(USER_FREE_LIST_LOCK(adapter
), flags
);
3670 scb
->state
= SCB_ACTIVE
;
3671 scb
->dma_type
= MRAID_DMA_NONE
;
3672 scb
->dma_direction
= PCI_DMA_NONE
;
3674 ccb
= (mbox_ccb_t
*)scb
->ccb
;
3675 mbox64
= (mbox64_t
*)(unsigned long)kioc
->cmdbuf
;
3676 raw_mbox
= (uint8_t *)&mbox64
->mbox32
;
3678 memcpy(ccb
->mbox64
, mbox64
, sizeof(mbox64_t
));
3680 scb
->gp
= (unsigned long)kioc
;
3683 * If it is a logdrv random delete operation, we have to wait till
3684 * there are no outstanding cmds at the fw and then issue it directly
3686 if (raw_mbox
[0] == FC_DEL_LOGDRV
&& raw_mbox
[2] == OP_DEL_LOGDRV
) {
3688 if (wait_till_fw_empty(adapter
)) {
3689 con_log(CL_ANN
, (KERN_NOTICE
3690 "megaraid mbox: LD delete, timed out\n"));
3692 kioc
->status
= -ETIME
;
3696 megaraid_mbox_mm_done(adapter
, scb
);
3701 INIT_LIST_HEAD(&scb
->list
);
3703 scb
->state
= SCB_ISSUED
;
3704 if (mbox_post_cmd(adapter
, scb
) != 0) {
3706 con_log(CL_ANN
, (KERN_NOTICE
3707 "megaraid mbox: LD delete, mailbox busy\n"));
3709 kioc
->status
= -EBUSY
;
3713 megaraid_mbox_mm_done(adapter
, scb
);
3721 // put the command on the pending list and execute
3722 megaraid_mbox_runpendq(adapter
, scb
);
3729 wait_till_fw_empty(adapter_t
*adapter
)
3731 unsigned long flags
= 0;
3736 * Set the quiescent flag to stop issuing cmds to FW.
3738 spin_lock_irqsave(&adapter
->lock
, flags
);
3739 adapter
->quiescent
++;
3740 spin_unlock_irqrestore(&adapter
->lock
, flags
);
3743 * Wait till there are no more cmds outstanding at FW. Try for at most
3746 for (i
= 0; i
< 60 && adapter
->outstanding_cmds
; i
++) {
3747 con_log(CL_DLEVEL1
, (KERN_INFO
3748 "megaraid: FW has %d pending commands\n",
3749 adapter
->outstanding_cmds
));
3754 return adapter
->outstanding_cmds
;
3759 * megaraid_mbox_mm_done - callback for CMM commands
3760 * @adapter : HBA soft state
3761 * @scb : completed command
3763 * Callback routine for internal commands originated from the management
3767 megaraid_mbox_mm_done(adapter_t
*adapter
, scb_t
*scb
)
3772 unsigned long flags
;
3774 kioc
= (uioc_t
*)scb
->gp
;
3775 mbox64
= (mbox64_t
*)(unsigned long)kioc
->cmdbuf
;
3776 mbox64
->mbox32
.status
= scb
->status
;
3777 raw_mbox
= (uint8_t *)&mbox64
->mbox32
;
3780 // put scb in the free pool
3781 scb
->state
= SCB_FREE
;
3784 spin_lock_irqsave(USER_FREE_LIST_LOCK(adapter
), flags
);
3786 list_add(&scb
->list
, &adapter
->uscb_pool
);
3788 spin_unlock_irqrestore(USER_FREE_LIST_LOCK(adapter
), flags
);
3790 // if a delete logical drive operation succeeded, restart the
3792 if (raw_mbox
[0] == FC_DEL_LOGDRV
&& raw_mbox
[2] == OP_DEL_LOGDRV
) {
3794 adapter
->quiescent
--;
3796 megaraid_mbox_runpendq(adapter
, NULL
);
3806 * gather_hbainfo - HBA characteristics for the applications
3807 * @adapter : HBA soft state
3808 * @hinfo : pointer to the caller's host info strucuture
3811 gather_hbainfo(adapter_t
*adapter
, mraid_hba_info_t
*hinfo
)
3815 dmajor
= megaraid_mbox_version
[0];
3817 hinfo
->pci_vendor_id
= adapter
->pdev
->vendor
;
3818 hinfo
->pci_device_id
= adapter
->pdev
->device
;
3819 hinfo
->subsys_vendor_id
= adapter
->pdev
->subsystem_vendor
;
3820 hinfo
->subsys_device_id
= adapter
->pdev
->subsystem_device
;
3822 hinfo
->pci_bus
= adapter
->pdev
->bus
->number
;
3823 hinfo
->pci_dev_fn
= adapter
->pdev
->devfn
;
3824 hinfo
->pci_slot
= PCI_SLOT(adapter
->pdev
->devfn
);
3825 hinfo
->irq
= adapter
->host
->irq
;
3826 hinfo
->baseport
= ADAP2RAIDDEV(adapter
)->baseport
;
3828 hinfo
->unique_id
= (hinfo
->pci_bus
<< 8) | adapter
->pdev
->devfn
;
3829 hinfo
->host_no
= adapter
->host
->host_no
;
3835 * END: Interface for the common management module
3841 * megaraid_sysfs_alloc_resources - allocate sysfs related resources
3842 * @adapter : controller's soft state
3844 * Allocate packets required to issue FW calls whenever the sysfs attributes
3845 * are read. These attributes would require up-to-date information from the
3846 * FW. Also set up resources for mutual exclusion to share these resources and
3849 * Return 0 on success.
3850 * Return -ERROR_CODE on failure.
3853 megaraid_sysfs_alloc_resources(adapter_t
*adapter
)
3855 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
3858 raid_dev
->sysfs_uioc
= kmalloc(sizeof(uioc_t
), GFP_KERNEL
);
3860 raid_dev
->sysfs_mbox64
= kmalloc(sizeof(mbox64_t
), GFP_KERNEL
);
3862 raid_dev
->sysfs_buffer
= pci_alloc_consistent(adapter
->pdev
,
3863 PAGE_SIZE
, &raid_dev
->sysfs_buffer_dma
);
3865 if (!raid_dev
->sysfs_uioc
|| !raid_dev
->sysfs_mbox64
||
3866 !raid_dev
->sysfs_buffer
) {
3868 con_log(CL_ANN
, (KERN_WARNING
3869 "megaraid: out of memory, %s %d\n", __FUNCTION__
,
3874 megaraid_sysfs_free_resources(adapter
);
3877 mutex_init(&raid_dev
->sysfs_mtx
);
3879 init_waitqueue_head(&raid_dev
->sysfs_wait_q
);
3886 * megaraid_sysfs_free_resources - free sysfs related resources
3887 * @adapter : controller's soft state
3889 * Free packets allocated for sysfs FW commands
3892 megaraid_sysfs_free_resources(adapter_t
*adapter
)
3894 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
3896 kfree(raid_dev
->sysfs_uioc
);
3897 kfree(raid_dev
->sysfs_mbox64
);
3899 if (raid_dev
->sysfs_buffer
) {
3900 pci_free_consistent(adapter
->pdev
, PAGE_SIZE
,
3901 raid_dev
->sysfs_buffer
, raid_dev
->sysfs_buffer_dma
);
3907 * megaraid_sysfs_get_ldmap_done - callback for get ldmap
3908 * @uioc : completed packet
3910 * Callback routine called in the ISR/tasklet context for get ldmap call
3913 megaraid_sysfs_get_ldmap_done(uioc_t
*uioc
)
3915 adapter_t
*adapter
= (adapter_t
*)uioc
->buf_vaddr
;
3916 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
3920 wake_up(&raid_dev
->sysfs_wait_q
);
3925 * megaraid_sysfs_get_ldmap_timeout - timeout handling for get ldmap
3926 * @data : timed out packet
3928 * Timeout routine to recover and return to application, in case the adapter
3929 * has stopped responding. A timeout of 60 seconds for this command seems like
3933 megaraid_sysfs_get_ldmap_timeout(unsigned long data
)
3935 uioc_t
*uioc
= (uioc_t
*)data
;
3936 adapter_t
*adapter
= (adapter_t
*)uioc
->buf_vaddr
;
3937 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
3939 uioc
->status
= -ETIME
;
3941 wake_up(&raid_dev
->sysfs_wait_q
);
3946 * megaraid_sysfs_get_ldmap - get update logical drive map
3947 * @adapter : controller's soft state
3949 * This routine will be called whenever user reads the logical drive
3950 * attributes, go get the current logical drive mapping table from the
3951 * firmware. We use the managment API's to issue commands to the controller.
3953 * NOTE: The commands issuance functionality is not generalized and
3954 * implemented in context of "get ld map" command only. If required, the
3955 * command issuance logical can be trivially pulled out and implemented as a
3956 * standalone libary. For now, this should suffice since there is no other
3957 * user of this interface.
3959 * Return 0 on success.
3960 * Return -1 on failure.
3963 megaraid_sysfs_get_ldmap(adapter_t
*adapter
)
3965 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
3970 struct timer_list sysfs_timer
;
3971 struct timer_list
*timerp
;
3976 * Allow only one read at a time to go through the sysfs attributes
3978 mutex_lock(&raid_dev
->sysfs_mtx
);
3980 uioc
= raid_dev
->sysfs_uioc
;
3981 mbox64
= raid_dev
->sysfs_mbox64
;
3982 ldmap
= raid_dev
->sysfs_buffer
;
3984 memset(uioc
, 0, sizeof(uioc_t
));
3985 memset(mbox64
, 0, sizeof(mbox64_t
));
3986 memset(ldmap
, 0, sizeof(raid_dev
->curr_ldmap
));
3988 mbox
= &mbox64
->mbox32
;
3989 raw_mbox
= (char *)mbox
;
3990 uioc
->cmdbuf
= (uint64_t)(unsigned long)mbox64
;
3991 uioc
->buf_vaddr
= (caddr_t
)adapter
;
3992 uioc
->status
= -ENODATA
;
3993 uioc
->done
= megaraid_sysfs_get_ldmap_done
;
3996 * Prepare the mailbox packet to get the current logical drive mapping
3999 mbox
->xferaddr
= (uint32_t)raid_dev
->sysfs_buffer_dma
;
4001 raw_mbox
[0] = FC_DEL_LOGDRV
;
4002 raw_mbox
[2] = OP_GET_LDID_MAP
;
4005 * Setup a timer to recover from a non-responding controller
4007 timerp
= &sysfs_timer
;
4010 timerp
->function
= megaraid_sysfs_get_ldmap_timeout
;
4011 timerp
->data
= (unsigned long)uioc
;
4012 timerp
->expires
= jiffies
+ 60 * HZ
;
4017 * Send the command to the firmware
4019 rval
= megaraid_mbox_mm_command(adapter
, uioc
);
4021 if (rval
== 0) { // command successfully issued
4022 wait_event(raid_dev
->sysfs_wait_q
, (uioc
->status
!= -ENODATA
));
4025 * Check if the command timed out
4027 if (uioc
->status
== -ETIME
) {
4028 con_log(CL_ANN
, (KERN_NOTICE
4029 "megaraid: sysfs get ld map timed out\n"));
4034 rval
= mbox
->status
;
4038 memcpy(raid_dev
->curr_ldmap
, ldmap
,
4039 sizeof(raid_dev
->curr_ldmap
));
4042 con_log(CL_ANN
, (KERN_NOTICE
4043 "megaraid: get ld map failed with %x\n", rval
));
4047 con_log(CL_ANN
, (KERN_NOTICE
4048 "megaraid: could not issue ldmap command:%x\n", rval
));
4052 del_timer_sync(timerp
);
4054 mutex_unlock(&raid_dev
->sysfs_mtx
);
4061 * megaraid_sysfs_show_app_hndl - display application handle for this adapter
4062 * @cdev : class device object representation for the host
4063 * @buf : buffer to send data to
4065 * Display the handle used by the applications while executing management
4066 * tasks on the adapter. We invoke a management module API to get the adapter
4067 * handle, since we do not interface with applications directly.
4070 megaraid_sysfs_show_app_hndl(struct class_device
*cdev
, char *buf
)
4072 struct Scsi_Host
*shost
= class_to_shost(cdev
);
4073 adapter_t
*adapter
= (adapter_t
*)SCSIHOST2ADAP(shost
);
4076 app_hndl
= mraid_mm_adapter_app_handle(adapter
->unique_id
);
4078 return snprintf(buf
, 8, "%u\n", app_hndl
);
4083 * megaraid_sysfs_show_ldnum - display the logical drive number for this device
4084 * @dev : device object representation for the scsi device
4085 * @attr : device attribute to show
4086 * @buf : buffer to send data to
4088 * Display the logical drive number for the device in question, if it a valid
4089 * logical drive. For physical devices, "-1" is returned.
4091 * The logical drive number is displayed in following format:
4093 * <SCSI ID> <LD NUM> <LD STICKY ID> <APP ADAPTER HANDLE>
4095 * <int> <int> <int> <int>
4098 megaraid_sysfs_show_ldnum(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
4100 struct scsi_device
*sdev
= to_scsi_device(dev
);
4101 adapter_t
*adapter
= (adapter_t
*)SCSIHOST2ADAP(sdev
->host
);
4102 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
4104 int logical_drv
= -1;
4106 uint32_t app_hndl
= 0;
4111 if (raid_dev
->random_del_supported
&&
4112 MRAID_IS_LOGICAL_SDEV(adapter
, sdev
)) {
4114 rval
= megaraid_sysfs_get_ldmap(adapter
);
4117 for (i
= 0; i
< MAX_LOGICAL_DRIVES_40LD
; i
++) {
4119 mapped_sdev_id
= sdev
->id
;
4121 if (sdev
->id
> adapter
->init_id
) {
4122 mapped_sdev_id
-= 1;
4125 if (raid_dev
->curr_ldmap
[i
] == mapped_sdev_id
) {
4131 ldid_map
= raid_dev
->curr_ldmap
[i
];
4133 app_hndl
= mraid_mm_adapter_app_handle(
4134 adapter
->unique_id
);
4141 con_log(CL_ANN
, (KERN_NOTICE
4142 "megaraid: sysfs get ld map failed: %x\n",
4147 return snprintf(buf
, 36, "%d %d %d %d\n", scsi_id
, logical_drv
,
4148 ldid_map
, app_hndl
);
4153 * END: Mailbox Low Level Driver
4155 module_init(megaraid_init
);
4156 module_exit(megaraid_exit
);
4158 /* vim: set ts=8 sw=8 tw=78 ai si: */