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/scsi/ChangeLog.megaraid
73 #include <linux/slab.h>
74 #include <linux/module.h>
75 #include "megaraid_mbox.h"
77 static int megaraid_init(void);
78 static void megaraid_exit(void);
80 static int megaraid_probe_one(struct pci_dev
*, const struct pci_device_id
*);
81 static void megaraid_detach_one(struct pci_dev
*);
82 static void megaraid_mbox_shutdown(struct pci_dev
*);
84 static int megaraid_io_attach(adapter_t
*);
85 static void megaraid_io_detach(adapter_t
*);
87 static int megaraid_init_mbox(adapter_t
*);
88 static void megaraid_fini_mbox(adapter_t
*);
90 static int megaraid_alloc_cmd_packets(adapter_t
*);
91 static void megaraid_free_cmd_packets(adapter_t
*);
93 static int megaraid_mbox_setup_dma_pools(adapter_t
*);
94 static void megaraid_mbox_teardown_dma_pools(adapter_t
*);
96 static int megaraid_sysfs_alloc_resources(adapter_t
*);
97 static void megaraid_sysfs_free_resources(adapter_t
*);
99 static int megaraid_abort_handler(struct scsi_cmnd
*);
100 static int megaraid_reset_handler(struct scsi_cmnd
*);
102 static int mbox_post_sync_cmd(adapter_t
*, uint8_t []);
103 static int mbox_post_sync_cmd_fast(adapter_t
*, uint8_t []);
104 static int megaraid_busywait_mbox(mraid_device_t
*);
105 static int megaraid_mbox_product_info(adapter_t
*);
106 static int megaraid_mbox_extended_cdb(adapter_t
*);
107 static int megaraid_mbox_support_ha(adapter_t
*, uint16_t *);
108 static int megaraid_mbox_support_random_del(adapter_t
*);
109 static int megaraid_mbox_get_max_sg(adapter_t
*);
110 static void megaraid_mbox_enum_raid_scsi(adapter_t
*);
111 static void megaraid_mbox_flush_cache(adapter_t
*);
112 static int megaraid_mbox_fire_sync_cmd(adapter_t
*);
114 static void megaraid_mbox_display_scb(adapter_t
*, scb_t
*);
115 static void megaraid_mbox_setup_device_map(adapter_t
*);
117 static int megaraid_queue_command(struct Scsi_Host
*, struct scsi_cmnd
*);
118 static scb_t
*megaraid_mbox_build_cmd(adapter_t
*, struct scsi_cmnd
*, int *);
119 static void megaraid_mbox_runpendq(adapter_t
*, scb_t
*);
120 static void megaraid_mbox_prepare_pthru(adapter_t
*, scb_t
*,
122 static void megaraid_mbox_prepare_epthru(adapter_t
*, scb_t
*,
125 static irqreturn_t
megaraid_isr(int, void *);
127 static void megaraid_mbox_dpc(unsigned long);
129 static ssize_t
megaraid_sysfs_show_app_hndl(struct device
*, struct device_attribute
*attr
, char *);
130 static ssize_t
megaraid_sysfs_show_ldnum(struct device
*, struct device_attribute
*attr
, char *);
132 static int megaraid_cmm_register(adapter_t
*);
133 static int megaraid_cmm_unregister(adapter_t
*);
134 static int megaraid_mbox_mm_handler(unsigned long, uioc_t
*, uint32_t);
135 static int megaraid_mbox_mm_command(adapter_t
*, uioc_t
*);
136 static void megaraid_mbox_mm_done(adapter_t
*, scb_t
*);
137 static int gather_hbainfo(adapter_t
*, mraid_hba_info_t
*);
138 static int wait_till_fw_empty(adapter_t
*);
142 MODULE_AUTHOR("megaraidlinux@lsi.com");
143 MODULE_DESCRIPTION("LSI Logic MegaRAID Mailbox Driver");
144 MODULE_LICENSE("GPL");
145 MODULE_VERSION(MEGARAID_VERSION
);
148 * ### modules parameters for driver ###
152 * Set to enable driver to expose unconfigured disk to kernel
154 static int megaraid_expose_unconf_disks
= 0;
155 module_param_named(unconf_disks
, megaraid_expose_unconf_disks
, int, 0);
156 MODULE_PARM_DESC(unconf_disks
,
157 "Set to expose unconfigured disks to kernel (default=0)");
160 * driver wait time if the adapter's mailbox is busy
162 static unsigned int max_mbox_busy_wait
= MBOX_BUSY_WAIT
;
163 module_param_named(busy_wait
, max_mbox_busy_wait
, int, 0);
164 MODULE_PARM_DESC(busy_wait
,
165 "Max wait for mailbox in microseconds if busy (default=10)");
168 * number of sectors per IO command
170 static unsigned int megaraid_max_sectors
= MBOX_MAX_SECTORS
;
171 module_param_named(max_sectors
, megaraid_max_sectors
, int, 0);
172 MODULE_PARM_DESC(max_sectors
,
173 "Maximum number of sectors per IO command (default=128)");
176 * number of commands per logical unit
178 static unsigned int megaraid_cmd_per_lun
= MBOX_DEF_CMD_PER_LUN
;
179 module_param_named(cmd_per_lun
, megaraid_cmd_per_lun
, int, 0);
180 MODULE_PARM_DESC(cmd_per_lun
,
181 "Maximum number of commands per logical unit (default=64)");
185 * Fast driver load option, skip scanning for physical devices during load.
186 * This would result in non-disk devices being skipped during driver load
187 * time. These can be later added though, using /proc/scsi/scsi
189 static unsigned int megaraid_fast_load
= 0;
190 module_param_named(fast_load
, megaraid_fast_load
, int, 0);
191 MODULE_PARM_DESC(fast_load
,
192 "Faster loading of the driver, skips physical devices! (default=0)");
196 * mraid_debug level - threshold for amount of information to be displayed by
197 * the driver. This level can be changed through modules parameters, ioctl or
198 * sysfs/proc interface. By default, print the announcement messages only.
200 int mraid_debug_level
= CL_ANN
;
201 module_param_named(debug_level
, mraid_debug_level
, int, 0);
202 MODULE_PARM_DESC(debug_level
, "Debug level for driver (default=0)");
205 * PCI table for all supported controllers.
207 static struct pci_device_id pci_id_table_g
[] = {
210 PCI_DEVICE_ID_PERC4_DI_DISCOVERY
,
212 PCI_SUBSYS_ID_PERC4_DI_DISCOVERY
,
215 PCI_VENDOR_ID_LSI_LOGIC
,
216 PCI_DEVICE_ID_PERC4_SC
,
218 PCI_SUBSYS_ID_PERC4_SC
,
221 PCI_VENDOR_ID_LSI_LOGIC
,
222 PCI_DEVICE_ID_PERC4_DC
,
224 PCI_SUBSYS_ID_PERC4_DC
,
227 PCI_VENDOR_ID_LSI_LOGIC
,
234 PCI_DEVICE_ID_PERC4_DI_EVERGLADES
,
236 PCI_SUBSYS_ID_PERC4_DI_EVERGLADES
,
240 PCI_DEVICE_ID_PERC4E_SI_BIGBEND
,
242 PCI_SUBSYS_ID_PERC4E_SI_BIGBEND
,
246 PCI_DEVICE_ID_PERC4E_DI_KOBUK
,
248 PCI_SUBSYS_ID_PERC4E_DI_KOBUK
,
252 PCI_DEVICE_ID_PERC4E_DI_CORVETTE
,
254 PCI_SUBSYS_ID_PERC4E_DI_CORVETTE
,
258 PCI_DEVICE_ID_PERC4E_DI_EXPEDITION
,
260 PCI_SUBSYS_ID_PERC4E_DI_EXPEDITION
,
264 PCI_DEVICE_ID_PERC4E_DI_GUADALUPE
,
266 PCI_SUBSYS_ID_PERC4E_DI_GUADALUPE
,
269 PCI_VENDOR_ID_LSI_LOGIC
,
270 PCI_DEVICE_ID_DOBSON
,
276 PCI_DEVICE_ID_AMI_MEGARAID3
,
281 PCI_VENDOR_ID_LSI_LOGIC
,
282 PCI_DEVICE_ID_AMI_MEGARAID3
,
287 PCI_VENDOR_ID_LSI_LOGIC
,
288 PCI_DEVICE_ID_LINDSAY
,
292 {0} /* Terminating entry */
294 MODULE_DEVICE_TABLE(pci
, pci_id_table_g
);
297 static struct pci_driver megaraid_pci_driver
= {
299 .id_table
= pci_id_table_g
,
300 .probe
= megaraid_probe_one
,
301 .remove
= megaraid_detach_one
,
302 .shutdown
= megaraid_mbox_shutdown
,
307 // definitions for the device attributes for exporting logical drive number
308 // for a scsi address (Host, Channel, Id, Lun)
310 DEVICE_ATTR(megaraid_mbox_app_hndl
, S_IRUSR
, megaraid_sysfs_show_app_hndl
,
313 // Host template initializer for megaraid mbox sysfs device attributes
314 static struct device_attribute
*megaraid_shost_attrs
[] = {
315 &dev_attr_megaraid_mbox_app_hndl
,
320 DEVICE_ATTR(megaraid_mbox_ld
, S_IRUSR
, megaraid_sysfs_show_ldnum
, NULL
);
322 // Host template initializer for megaraid mbox sysfs device attributes
323 static struct device_attribute
*megaraid_sdev_attrs
[] = {
324 &dev_attr_megaraid_mbox_ld
,
329 * Scsi host template for megaraid unified driver
331 static struct scsi_host_template megaraid_template_g
= {
332 .module
= THIS_MODULE
,
333 .name
= "LSI Logic MegaRAID driver",
334 .proc_name
= "megaraid",
335 .queuecommand
= megaraid_queue_command
,
336 .eh_abort_handler
= megaraid_abort_handler
,
337 .eh_host_reset_handler
= megaraid_reset_handler
,
338 .change_queue_depth
= scsi_change_queue_depth
,
339 .use_clustering
= ENABLE_CLUSTERING
,
341 .sdev_attrs
= megaraid_sdev_attrs
,
342 .shost_attrs
= megaraid_shost_attrs
,
347 * megaraid_init - module load hook
349 * We register ourselves as hotplug enabled module and let PCI subsystem
350 * discover our adapters.
357 // Announce the driver version
358 con_log(CL_ANN
, (KERN_INFO
"megaraid: %s %s\n", MEGARAID_VERSION
,
359 MEGARAID_EXT_VERSION
));
361 // check validity of module parameters
362 if (megaraid_cmd_per_lun
> MBOX_MAX_SCSI_CMDS
) {
364 con_log(CL_ANN
, (KERN_WARNING
365 "megaraid mailbox: max commands per lun reset to %d\n",
366 MBOX_MAX_SCSI_CMDS
));
368 megaraid_cmd_per_lun
= MBOX_MAX_SCSI_CMDS
;
372 // register as a PCI hot-plug driver module
373 rval
= pci_register_driver(&megaraid_pci_driver
);
375 con_log(CL_ANN
, (KERN_WARNING
376 "megaraid: could not register hotplug support.\n"));
384 * megaraid_exit - driver unload entry point
386 * We simply unwrap the megaraid_init routine here.
391 con_log(CL_DLEVEL1
, (KERN_NOTICE
"megaraid: unloading framework\n"));
393 // unregister as PCI hotplug driver
394 pci_unregister_driver(&megaraid_pci_driver
);
401 * megaraid_probe_one - PCI hotplug entry point
402 * @pdev : handle to this controller's PCI configuration space
403 * @id : pci device id of the class of controllers
405 * This routine should be called whenever a new adapter is detected by the
406 * PCI hotplug susbsystem.
409 megaraid_probe_one(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
414 // detected a new controller
415 con_log(CL_ANN
, (KERN_INFO
416 "megaraid: probe new device %#4.04x:%#4.04x:%#4.04x:%#4.04x: ",
417 pdev
->vendor
, pdev
->device
, pdev
->subsystem_vendor
,
418 pdev
->subsystem_device
));
420 con_log(CL_ANN
, ("bus %d:slot %d:func %d\n", pdev
->bus
->number
,
421 PCI_SLOT(pdev
->devfn
), PCI_FUNC(pdev
->devfn
)));
423 if (pci_enable_device(pdev
)) {
424 con_log(CL_ANN
, (KERN_WARNING
425 "megaraid: pci_enable_device failed\n"));
430 // Enable bus-mastering on this controller
431 pci_set_master(pdev
);
433 // Allocate the per driver initialization structure
434 adapter
= kzalloc(sizeof(adapter_t
), GFP_KERNEL
);
436 if (adapter
== NULL
) {
437 con_log(CL_ANN
, (KERN_WARNING
438 "megaraid: out of memory, %s %d.\n", __func__
, __LINE__
));
444 // set up PCI related soft state and other pre-known parameters
445 adapter
->unique_id
= pdev
->bus
->number
<< 8 | pdev
->devfn
;
446 adapter
->irq
= pdev
->irq
;
447 adapter
->pdev
= pdev
;
449 atomic_set(&adapter
->being_detached
, 0);
451 // Setup the default DMA mask. This would be changed later on
452 // depending on hardware capabilities
453 if (dma_set_mask(&adapter
->pdev
->dev
, DMA_BIT_MASK(32))) {
454 con_log(CL_ANN
, (KERN_WARNING
455 "megaraid: dma_set_mask failed:%d\n", __LINE__
));
457 goto out_free_adapter
;
461 // Initialize the synchronization lock for kernel and LLD
462 spin_lock_init(&adapter
->lock
);
464 // Initialize the command queues: the list of free SCBs and the list
466 INIT_LIST_HEAD(&adapter
->kscb_pool
);
467 spin_lock_init(SCSI_FREE_LIST_LOCK(adapter
));
469 INIT_LIST_HEAD(&adapter
->pend_list
);
470 spin_lock_init(PENDING_LIST_LOCK(adapter
));
472 INIT_LIST_HEAD(&adapter
->completed_list
);
473 spin_lock_init(COMPLETED_LIST_LOCK(adapter
));
476 // Start the mailbox based controller
477 if (megaraid_init_mbox(adapter
) != 0) {
478 con_log(CL_ANN
, (KERN_WARNING
479 "megaraid: mailbox adapter did not initialize\n"));
481 goto out_free_adapter
;
484 // Register with LSI Common Management Module
485 if (megaraid_cmm_register(adapter
) != 0) {
487 con_log(CL_ANN
, (KERN_WARNING
488 "megaraid: could not register with management module\n"));
493 // setup adapter handle in PCI soft state
494 pci_set_drvdata(pdev
, adapter
);
496 // attach with scsi mid-layer
497 if (megaraid_io_attach(adapter
) != 0) {
499 con_log(CL_ANN
, (KERN_WARNING
"megaraid: io attach failed\n"));
507 megaraid_cmm_unregister(adapter
);
509 megaraid_fini_mbox(adapter
);
513 pci_disable_device(pdev
);
520 * megaraid_detach_one - release framework resources and call LLD release routine
521 * @pdev : handle for our PCI configuration space
523 * This routine is called during driver unload. We free all the allocated
524 * resources and call the corresponding LLD so that it can also release all
527 * This routine is also called from the PCI hotplug system.
530 megaraid_detach_one(struct pci_dev
*pdev
)
533 struct Scsi_Host
*host
;
536 // Start a rollback on this adapter
537 adapter
= pci_get_drvdata(pdev
);
540 con_log(CL_ANN
, (KERN_CRIT
541 "megaraid: Invalid detach on %#4.04x:%#4.04x:%#4.04x:%#4.04x\n",
542 pdev
->vendor
, pdev
->device
, pdev
->subsystem_vendor
,
543 pdev
->subsystem_device
));
548 con_log(CL_ANN
, (KERN_NOTICE
549 "megaraid: detaching device %#4.04x:%#4.04x:%#4.04x:%#4.04x\n",
550 pdev
->vendor
, pdev
->device
, pdev
->subsystem_vendor
,
551 pdev
->subsystem_device
));
555 host
= adapter
->host
;
557 // do not allow any more requests from the management module for this
559 // FIXME: How do we account for the request which might still be
561 atomic_set(&adapter
->being_detached
, 1);
563 // detach from the IO sub-system
564 megaraid_io_detach(adapter
);
566 // Unregister from common management module
568 // FIXME: this must return success or failure for conditions if there
569 // is a command pending with LLD or not.
570 megaraid_cmm_unregister(adapter
);
572 // finalize the mailbox based controller and release all resources
573 megaraid_fini_mbox(adapter
);
579 pci_disable_device(pdev
);
586 * megaraid_mbox_shutdown - PCI shutdown for megaraid HBA
587 * @pdev : generic driver model device
589 * Shutdown notification, perform flush cache.
592 megaraid_mbox_shutdown(struct pci_dev
*pdev
)
594 adapter_t
*adapter
= pci_get_drvdata(pdev
);
598 con_log(CL_ANN
, (KERN_WARNING
599 "megaraid: null device in shutdown\n"));
604 con_log(CL_ANN
, (KERN_INFO
"megaraid: flushing adapter %d...",
607 megaraid_mbox_flush_cache(adapter
);
609 con_log(CL_ANN
, ("done\n"));
614 * megaraid_io_attach - attach a device with the IO subsystem
615 * @adapter : controller's soft state
617 * Attach this device with the IO subsystem.
620 megaraid_io_attach(adapter_t
*adapter
)
622 struct Scsi_Host
*host
;
624 // Initialize SCSI Host structure
625 host
= scsi_host_alloc(&megaraid_template_g
, 8);
627 con_log(CL_ANN
, (KERN_WARNING
628 "megaraid mbox: scsi_register failed\n"));
633 SCSIHOST2ADAP(host
) = (caddr_t
)adapter
;
634 adapter
->host
= host
;
636 host
->irq
= adapter
->irq
;
637 host
->unique_id
= adapter
->unique_id
;
638 host
->can_queue
= adapter
->max_cmds
;
639 host
->this_id
= adapter
->init_id
;
640 host
->sg_tablesize
= adapter
->sglen
;
641 host
->max_sectors
= adapter
->max_sectors
;
642 host
->cmd_per_lun
= adapter
->cmd_per_lun
;
643 host
->max_channel
= adapter
->max_channel
;
644 host
->max_id
= adapter
->max_target
;
645 host
->max_lun
= adapter
->max_lun
;
648 // notify mid-layer about the new controller
649 if (scsi_add_host(host
, &adapter
->pdev
->dev
)) {
651 con_log(CL_ANN
, (KERN_WARNING
652 "megaraid mbox: scsi_add_host failed\n"));
659 scsi_scan_host(host
);
666 * megaraid_io_detach - detach a device from the IO subsystem
667 * @adapter : controller's soft state
669 * Detach this device from the IO subsystem.
672 megaraid_io_detach(adapter_t
*adapter
)
674 struct Scsi_Host
*host
;
676 con_log(CL_DLEVEL1
, (KERN_INFO
"megaraid: io detach\n"));
678 host
= adapter
->host
;
680 scsi_remove_host(host
);
687 * START: Mailbox Low Level Driver
689 * This is section specific to the single mailbox based controllers
693 * megaraid_init_mbox - initialize controller
694 * @adapter : our soft state
696 * - Allocate 16-byte aligned mailbox memory for firmware handshake
697 * - Allocate controller's memory resources
698 * - Find out all initialization data
699 * - Allocate memory required for all the commands
700 * - Use internal library of FW routines, build up complete soft state
703 megaraid_init_mbox(adapter_t
*adapter
)
705 struct pci_dev
*pdev
;
706 mraid_device_t
*raid_dev
;
711 adapter
->ito
= MBOX_TIMEOUT
;
712 pdev
= adapter
->pdev
;
715 * Allocate and initialize the init data structure for mailbox
718 raid_dev
= kzalloc(sizeof(mraid_device_t
), GFP_KERNEL
);
719 if (raid_dev
== NULL
) return -1;
723 * Attach the adapter soft state to raid device soft state
725 adapter
->raid_device
= (caddr_t
)raid_dev
;
726 raid_dev
->fast_load
= megaraid_fast_load
;
730 raid_dev
->baseport
= pci_resource_start(pdev
, 0);
732 if (pci_request_regions(pdev
, "MegaRAID: LSI Logic Corporation") != 0) {
734 con_log(CL_ANN
, (KERN_WARNING
735 "megaraid: mem region busy\n"));
737 goto out_free_raid_dev
;
740 raid_dev
->baseaddr
= ioremap_nocache(raid_dev
->baseport
, 128);
742 if (!raid_dev
->baseaddr
) {
744 con_log(CL_ANN
, (KERN_WARNING
745 "megaraid: could not map hba memory\n") );
747 goto out_release_regions
;
750 /* initialize the mutual exclusion lock for the mailbox */
751 spin_lock_init(&raid_dev
->mailbox_lock
);
753 /* allocate memory required for commands */
754 if (megaraid_alloc_cmd_packets(adapter
) != 0)
758 * Issue SYNC cmd to flush the pending cmds in the adapter
759 * and initialize its internal state
762 if (megaraid_mbox_fire_sync_cmd(adapter
))
763 con_log(CL_ANN
, ("megaraid: sync cmd failed\n"));
766 * Setup the rest of the soft state using the library of
770 /* request IRQ and register the interrupt service routine */
771 if (request_irq(adapter
->irq
, megaraid_isr
, IRQF_SHARED
, "megaraid",
774 con_log(CL_ANN
, (KERN_WARNING
775 "megaraid: Couldn't register IRQ %d!\n", adapter
->irq
));
781 if (megaraid_mbox_product_info(adapter
) != 0)
784 // Do we support extended CDBs
785 adapter
->max_cdb_sz
= 10;
786 if (megaraid_mbox_extended_cdb(adapter
) == 0) {
787 adapter
->max_cdb_sz
= 16;
791 * Do we support cluster environment, if we do, what is the initiator
793 * NOTE: In a non-cluster aware firmware environment, the LLD should
794 * return 7 as initiator id.
797 adapter
->init_id
= -1;
798 if (megaraid_mbox_support_ha(adapter
, &adapter
->init_id
) == 0) {
803 * Prepare the device ids array to have the mapping between the kernel
804 * device address and megaraid device address.
805 * We export the physical devices on their actual addresses. The
806 * logical drives are exported on a virtual SCSI channel
808 megaraid_mbox_setup_device_map(adapter
);
810 // If the firmware supports random deletion, update the device id map
811 if (megaraid_mbox_support_random_del(adapter
)) {
813 // Change the logical drives numbers in device_ids array one
814 // slot in device_ids is reserved for target id, that's why
816 for (i
= 0; i
<= MAX_LOGICAL_DRIVES_40LD
; i
++) {
817 adapter
->device_ids
[adapter
->max_channel
][i
] += 0x80;
819 adapter
->device_ids
[adapter
->max_channel
][adapter
->init_id
] =
822 raid_dev
->random_del_supported
= 1;
826 * find out the maximum number of scatter-gather elements supported by
829 adapter
->sglen
= megaraid_mbox_get_max_sg(adapter
);
831 // enumerate RAID and SCSI channels so that all devices on SCSI
832 // channels can later be exported, including disk devices
833 megaraid_mbox_enum_raid_scsi(adapter
);
836 * Other parameters required by upper layer
838 * maximum number of sectors per IO command
840 adapter
->max_sectors
= megaraid_max_sectors
;
843 * number of queued commands per LUN.
845 adapter
->cmd_per_lun
= megaraid_cmd_per_lun
;
848 * Allocate resources required to issue FW calls, when sysfs is
851 if (megaraid_sysfs_alloc_resources(adapter
) != 0)
854 // Set the DMA mask to 64-bit. All supported controllers as capable of
856 pci_read_config_dword(adapter
->pdev
, PCI_CONF_AMISIG64
, &magic64
);
858 if (((magic64
== HBA_SIGNATURE_64_BIT
) &&
859 ((adapter
->pdev
->subsystem_device
!=
860 PCI_SUBSYS_ID_MEGARAID_SATA_150_6
) &&
861 (adapter
->pdev
->subsystem_device
!=
862 PCI_SUBSYS_ID_MEGARAID_SATA_150_4
))) ||
863 (adapter
->pdev
->vendor
== PCI_VENDOR_ID_LSI_LOGIC
&&
864 adapter
->pdev
->device
== PCI_DEVICE_ID_VERDE
) ||
865 (adapter
->pdev
->vendor
== PCI_VENDOR_ID_LSI_LOGIC
&&
866 adapter
->pdev
->device
== PCI_DEVICE_ID_DOBSON
) ||
867 (adapter
->pdev
->vendor
== PCI_VENDOR_ID_LSI_LOGIC
&&
868 adapter
->pdev
->device
== PCI_DEVICE_ID_LINDSAY
) ||
869 (adapter
->pdev
->vendor
== PCI_VENDOR_ID_DELL
&&
870 adapter
->pdev
->device
== PCI_DEVICE_ID_PERC4_DI_EVERGLADES
) ||
871 (adapter
->pdev
->vendor
== PCI_VENDOR_ID_DELL
&&
872 adapter
->pdev
->device
== PCI_DEVICE_ID_PERC4E_DI_KOBUK
)) {
873 if (dma_set_mask(&adapter
->pdev
->dev
, DMA_BIT_MASK(64))) {
874 con_log(CL_ANN
, (KERN_WARNING
875 "megaraid: DMA mask for 64-bit failed\n"));
877 if (dma_set_mask(&adapter
->pdev
->dev
,
879 con_log(CL_ANN
, (KERN_WARNING
880 "megaraid: 32-bit DMA mask failed\n"));
881 goto out_free_sysfs_res
;
886 // setup tasklet for DPC
887 tasklet_init(&adapter
->dpc_h
, megaraid_mbox_dpc
,
888 (unsigned long)adapter
);
890 con_log(CL_DLEVEL1
, (KERN_INFO
891 "megaraid mbox hba successfully initialized\n"));
896 megaraid_sysfs_free_resources(adapter
);
898 free_irq(adapter
->irq
, adapter
);
900 megaraid_free_cmd_packets(adapter
);
902 iounmap(raid_dev
->baseaddr
);
904 pci_release_regions(pdev
);
913 * megaraid_fini_mbox - undo controller initialization
914 * @adapter : our soft state
917 megaraid_fini_mbox(adapter_t
*adapter
)
919 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
922 megaraid_mbox_flush_cache(adapter
);
924 tasklet_kill(&adapter
->dpc_h
);
926 megaraid_sysfs_free_resources(adapter
);
928 megaraid_free_cmd_packets(adapter
);
930 free_irq(adapter
->irq
, adapter
);
932 iounmap(raid_dev
->baseaddr
);
934 pci_release_regions(adapter
->pdev
);
943 * megaraid_alloc_cmd_packets - allocate shared mailbox
944 * @adapter : soft state of the raid controller
946 * Allocate and align the shared mailbox. This mailbox is used to issue
947 * all the commands. For IO based controllers, the mailbox is also registered
948 * with the FW. Allocate memory for all commands as well.
949 * This is our big allocator.
952 megaraid_alloc_cmd_packets(adapter_t
*adapter
)
954 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
955 struct pci_dev
*pdev
;
959 struct mraid_pci_blk
*epthru_pci_blk
;
960 struct mraid_pci_blk
*sg_pci_blk
;
961 struct mraid_pci_blk
*mbox_pci_blk
;
964 pdev
= adapter
->pdev
;
968 * Allocate the common 16-byte aligned memory for the handshake
971 raid_dev
->una_mbox64
= dma_zalloc_coherent(&adapter
->pdev
->dev
,
972 sizeof(mbox64_t
), &raid_dev
->una_mbox64_dma
,
975 if (!raid_dev
->una_mbox64
) {
976 con_log(CL_ANN
, (KERN_WARNING
977 "megaraid: out of memory, %s %d\n", __func__
,
983 * Align the mailbox at 16-byte boundary
985 raid_dev
->mbox
= &raid_dev
->una_mbox64
->mbox32
;
987 raid_dev
->mbox
= (mbox_t
*)((((unsigned long)raid_dev
->mbox
) + 15) &
990 raid_dev
->mbox64
= (mbox64_t
*)(((unsigned long)raid_dev
->mbox
) - 8);
992 align
= ((void *)raid_dev
->mbox
-
993 ((void *)&raid_dev
->una_mbox64
->mbox32
));
995 raid_dev
->mbox_dma
= (unsigned long)raid_dev
->una_mbox64_dma
+ 8 +
998 // Allocate memory for commands issued internally
999 adapter
->ibuf
= dma_zalloc_coherent(&pdev
->dev
, MBOX_IBUF_SIZE
,
1000 &adapter
->ibuf_dma_h
, GFP_KERNEL
);
1001 if (!adapter
->ibuf
) {
1003 con_log(CL_ANN
, (KERN_WARNING
1004 "megaraid: out of memory, %s %d\n", __func__
,
1007 goto out_free_common_mbox
;
1010 // Allocate memory for our SCSI Command Blocks and their associated
1014 * Allocate memory for the base list of scb. Later allocate memory for
1015 * CCBs and embedded components of each CCB and point the pointers in
1016 * scb to the allocated components
1017 * NOTE: The code to allocate SCB will be duplicated in all the LLD
1018 * since the calling routine does not yet know the number of available
1021 adapter
->kscb_list
= kcalloc(MBOX_MAX_SCSI_CMDS
, sizeof(scb_t
), GFP_KERNEL
);
1023 if (adapter
->kscb_list
== NULL
) {
1024 con_log(CL_ANN
, (KERN_WARNING
1025 "megaraid: out of memory, %s %d\n", __func__
,
1030 // memory allocation for our command packets
1031 if (megaraid_mbox_setup_dma_pools(adapter
) != 0) {
1032 con_log(CL_ANN
, (KERN_WARNING
1033 "megaraid: out of memory, %s %d\n", __func__
,
1035 goto out_free_scb_list
;
1038 // Adjust the scb pointers and link in the free pool
1039 epthru_pci_blk
= raid_dev
->epthru_pool
;
1040 sg_pci_blk
= raid_dev
->sg_pool
;
1041 mbox_pci_blk
= raid_dev
->mbox_pool
;
1043 for (i
= 0; i
< MBOX_MAX_SCSI_CMDS
; i
++) {
1044 scb
= adapter
->kscb_list
+ i
;
1045 ccb
= raid_dev
->ccb_list
+ i
;
1047 ccb
->mbox
= (mbox_t
*)(mbox_pci_blk
[i
].vaddr
+ 16);
1048 ccb
->raw_mbox
= (uint8_t *)ccb
->mbox
;
1049 ccb
->mbox64
= (mbox64_t
*)(mbox_pci_blk
[i
].vaddr
+ 8);
1050 ccb
->mbox_dma_h
= (unsigned long)mbox_pci_blk
[i
].dma_addr
+ 16;
1052 // make sure the mailbox is aligned properly
1053 if (ccb
->mbox_dma_h
& 0x0F) {
1054 con_log(CL_ANN
, (KERN_CRIT
1055 "megaraid mbox: not aligned on 16-bytes\n"));
1057 goto out_teardown_dma_pools
;
1060 ccb
->epthru
= (mraid_epassthru_t
*)
1061 epthru_pci_blk
[i
].vaddr
;
1062 ccb
->epthru_dma_h
= epthru_pci_blk
[i
].dma_addr
;
1063 ccb
->pthru
= (mraid_passthru_t
*)ccb
->epthru
;
1064 ccb
->pthru_dma_h
= ccb
->epthru_dma_h
;
1067 ccb
->sgl64
= (mbox_sgl64
*)sg_pci_blk
[i
].vaddr
;
1068 ccb
->sgl_dma_h
= sg_pci_blk
[i
].dma_addr
;
1069 ccb
->sgl32
= (mbox_sgl32
*)ccb
->sgl64
;
1071 scb
->ccb
= (caddr_t
)ccb
;
1074 scb
->sno
= i
; // command index
1077 scb
->state
= SCB_FREE
;
1078 scb
->dma_direction
= DMA_NONE
;
1079 scb
->dma_type
= MRAID_DMA_NONE
;
1080 scb
->dev_channel
= -1;
1081 scb
->dev_target
= -1;
1083 // put scb in the free pool
1084 list_add_tail(&scb
->list
, &adapter
->kscb_pool
);
1089 out_teardown_dma_pools
:
1090 megaraid_mbox_teardown_dma_pools(adapter
);
1092 kfree(adapter
->kscb_list
);
1094 dma_free_coherent(&pdev
->dev
, MBOX_IBUF_SIZE
, (void *)adapter
->ibuf
,
1095 adapter
->ibuf_dma_h
);
1096 out_free_common_mbox
:
1097 dma_free_coherent(&adapter
->pdev
->dev
, sizeof(mbox64_t
),
1098 (caddr_t
)raid_dev
->una_mbox64
, raid_dev
->una_mbox64_dma
);
1105 * megaraid_free_cmd_packets - free memory
1106 * @adapter : soft state of the raid controller
1108 * Release memory resources allocated for commands.
1111 megaraid_free_cmd_packets(adapter_t
*adapter
)
1113 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
1115 megaraid_mbox_teardown_dma_pools(adapter
);
1117 kfree(adapter
->kscb_list
);
1119 dma_free_coherent(&adapter
->pdev
->dev
, MBOX_IBUF_SIZE
,
1120 (void *)adapter
->ibuf
, adapter
->ibuf_dma_h
);
1122 dma_free_coherent(&adapter
->pdev
->dev
, sizeof(mbox64_t
),
1123 (caddr_t
)raid_dev
->una_mbox64
, raid_dev
->una_mbox64_dma
);
1129 * megaraid_mbox_setup_dma_pools - setup dma pool for command packets
1130 * @adapter : HBA soft state
1132 * Setup the dma pools for mailbox, passthru and extended passthru structures,
1133 * and scatter-gather lists.
1136 megaraid_mbox_setup_dma_pools(adapter_t
*adapter
)
1138 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
1139 struct mraid_pci_blk
*epthru_pci_blk
;
1140 struct mraid_pci_blk
*sg_pci_blk
;
1141 struct mraid_pci_blk
*mbox_pci_blk
;
1146 // Allocate memory for 16-bytes aligned mailboxes
1147 raid_dev
->mbox_pool_handle
= dma_pool_create("megaraid mbox pool",
1148 &adapter
->pdev
->dev
,
1149 sizeof(mbox64_t
) + 16,
1152 if (raid_dev
->mbox_pool_handle
== NULL
) {
1153 goto fail_setup_dma_pool
;
1156 mbox_pci_blk
= raid_dev
->mbox_pool
;
1157 for (i
= 0; i
< MBOX_MAX_SCSI_CMDS
; i
++) {
1158 mbox_pci_blk
[i
].vaddr
= dma_pool_alloc(
1159 raid_dev
->mbox_pool_handle
,
1161 &mbox_pci_blk
[i
].dma_addr
);
1162 if (!mbox_pci_blk
[i
].vaddr
) {
1163 goto fail_setup_dma_pool
;
1168 * Allocate memory for each embedded passthru strucuture pointer
1169 * Request for a 128 bytes aligned structure for each passthru command
1171 * Since passthru and extended passthru commands are exclusive, they
1172 * share common memory pool. Passthru structures piggyback on memory
1173 * allocted to extended passthru since passthru is smaller of the two
1175 raid_dev
->epthru_pool_handle
= dma_pool_create("megaraid mbox pthru",
1176 &adapter
->pdev
->dev
, sizeof(mraid_epassthru_t
), 128, 0);
1178 if (raid_dev
->epthru_pool_handle
== NULL
) {
1179 goto fail_setup_dma_pool
;
1182 epthru_pci_blk
= raid_dev
->epthru_pool
;
1183 for (i
= 0; i
< MBOX_MAX_SCSI_CMDS
; i
++) {
1184 epthru_pci_blk
[i
].vaddr
= dma_pool_alloc(
1185 raid_dev
->epthru_pool_handle
,
1187 &epthru_pci_blk
[i
].dma_addr
);
1188 if (!epthru_pci_blk
[i
].vaddr
) {
1189 goto fail_setup_dma_pool
;
1194 // Allocate memory for each scatter-gather list. Request for 512 bytes
1195 // alignment for each sg list
1196 raid_dev
->sg_pool_handle
= dma_pool_create("megaraid mbox sg",
1197 &adapter
->pdev
->dev
,
1198 sizeof(mbox_sgl64
) * MBOX_MAX_SG_SIZE
,
1201 if (raid_dev
->sg_pool_handle
== NULL
) {
1202 goto fail_setup_dma_pool
;
1205 sg_pci_blk
= raid_dev
->sg_pool
;
1206 for (i
= 0; i
< MBOX_MAX_SCSI_CMDS
; i
++) {
1207 sg_pci_blk
[i
].vaddr
= dma_pool_alloc(
1208 raid_dev
->sg_pool_handle
,
1210 &sg_pci_blk
[i
].dma_addr
);
1211 if (!sg_pci_blk
[i
].vaddr
) {
1212 goto fail_setup_dma_pool
;
1218 fail_setup_dma_pool
:
1219 megaraid_mbox_teardown_dma_pools(adapter
);
1225 * megaraid_mbox_teardown_dma_pools - teardown dma pools for command packets
1226 * @adapter : HBA soft state
1228 * Teardown the dma pool for mailbox, passthru and extended passthru
1229 * structures, and scatter-gather lists.
1232 megaraid_mbox_teardown_dma_pools(adapter_t
*adapter
)
1234 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
1235 struct mraid_pci_blk
*epthru_pci_blk
;
1236 struct mraid_pci_blk
*sg_pci_blk
;
1237 struct mraid_pci_blk
*mbox_pci_blk
;
1241 sg_pci_blk
= raid_dev
->sg_pool
;
1242 for (i
= 0; i
< MBOX_MAX_SCSI_CMDS
&& sg_pci_blk
[i
].vaddr
; i
++) {
1243 dma_pool_free(raid_dev
->sg_pool_handle
, sg_pci_blk
[i
].vaddr
,
1244 sg_pci_blk
[i
].dma_addr
);
1246 if (raid_dev
->sg_pool_handle
)
1247 dma_pool_destroy(raid_dev
->sg_pool_handle
);
1250 epthru_pci_blk
= raid_dev
->epthru_pool
;
1251 for (i
= 0; i
< MBOX_MAX_SCSI_CMDS
&& epthru_pci_blk
[i
].vaddr
; i
++) {
1252 dma_pool_free(raid_dev
->epthru_pool_handle
,
1253 epthru_pci_blk
[i
].vaddr
, epthru_pci_blk
[i
].dma_addr
);
1255 if (raid_dev
->epthru_pool_handle
)
1256 dma_pool_destroy(raid_dev
->epthru_pool_handle
);
1259 mbox_pci_blk
= raid_dev
->mbox_pool
;
1260 for (i
= 0; i
< MBOX_MAX_SCSI_CMDS
&& mbox_pci_blk
[i
].vaddr
; i
++) {
1261 dma_pool_free(raid_dev
->mbox_pool_handle
,
1262 mbox_pci_blk
[i
].vaddr
, mbox_pci_blk
[i
].dma_addr
);
1264 if (raid_dev
->mbox_pool_handle
)
1265 dma_pool_destroy(raid_dev
->mbox_pool_handle
);
1272 * megaraid_alloc_scb - detach and return a scb from the free list
1273 * @adapter : controller's soft state
1274 * @scp : pointer to the scsi command to be executed
1276 * Return the scb from the head of the free list. %NULL if there are none
1280 megaraid_alloc_scb(adapter_t
*adapter
, struct scsi_cmnd
*scp
)
1282 struct list_head
*head
= &adapter
->kscb_pool
;
1284 unsigned long flags
;
1286 // detach scb from free pool
1287 spin_lock_irqsave(SCSI_FREE_LIST_LOCK(adapter
), flags
);
1289 if (list_empty(head
)) {
1290 spin_unlock_irqrestore(SCSI_FREE_LIST_LOCK(adapter
), flags
);
1294 scb
= list_entry(head
->next
, scb_t
, list
);
1295 list_del_init(&scb
->list
);
1297 spin_unlock_irqrestore(SCSI_FREE_LIST_LOCK(adapter
), flags
);
1299 scb
->state
= SCB_ACTIVE
;
1301 scb
->dma_type
= MRAID_DMA_NONE
;
1308 * megaraid_dealloc_scb - return the scb to the free pool
1309 * @adapter : controller's soft state
1310 * @scb : scb to be freed
1312 * Return the scb back to the free list of scbs. The caller must 'flush' the
1313 * SCB before calling us. E.g., performing pci_unamp and/or pci_sync etc.
1314 * NOTE NOTE: Make sure the scb is not on any list before calling this
1318 megaraid_dealloc_scb(adapter_t
*adapter
, scb_t
*scb
)
1320 unsigned long flags
;
1322 // put scb in the free pool
1323 scb
->state
= SCB_FREE
;
1325 spin_lock_irqsave(SCSI_FREE_LIST_LOCK(adapter
), flags
);
1327 list_add(&scb
->list
, &adapter
->kscb_pool
);
1329 spin_unlock_irqrestore(SCSI_FREE_LIST_LOCK(adapter
), flags
);
1336 * megaraid_mbox_mksgl - make the scatter-gather list
1337 * @adapter : controller's soft state
1338 * @scb : scsi control block
1340 * Prepare the scatter-gather list.
1343 megaraid_mbox_mksgl(adapter_t
*adapter
, scb_t
*scb
)
1345 struct scatterlist
*sgl
;
1347 struct scsi_cmnd
*scp
;
1353 ccb
= (mbox_ccb_t
*)scb
->ccb
;
1355 sgcnt
= scsi_dma_map(scp
);
1356 BUG_ON(sgcnt
< 0 || sgcnt
> adapter
->sglen
);
1358 // no mapping required if no data to be transferred
1362 scb
->dma_type
= MRAID_DMA_WSG
;
1364 scsi_for_each_sg(scp
, sgl
, sgcnt
, i
) {
1365 ccb
->sgl64
[i
].address
= sg_dma_address(sgl
);
1366 ccb
->sgl64
[i
].length
= sg_dma_len(sgl
);
1369 // Return count of SG nodes
1375 * mbox_post_cmd - issue a mailbox command
1376 * @adapter : controller's soft state
1377 * @scb : command to be issued
1379 * Post the command to the controller if mailbox is available.
1382 mbox_post_cmd(adapter_t
*adapter
, scb_t
*scb
)
1384 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
1388 unsigned long flags
;
1392 ccb
= (mbox_ccb_t
*)scb
->ccb
;
1393 mbox
= raid_dev
->mbox
;
1394 mbox64
= raid_dev
->mbox64
;
1397 * Check for busy mailbox. If it is, return failure - the caller
1398 * should retry later.
1400 spin_lock_irqsave(MAILBOX_LOCK(raid_dev
), flags
);
1402 if (unlikely(mbox
->busy
)) {
1407 } while(mbox
->busy
&& (i
< max_mbox_busy_wait
));
1411 spin_unlock_irqrestore(MAILBOX_LOCK(raid_dev
), flags
);
1418 // Copy this command's mailbox data into "adapter's" mailbox
1419 memcpy((caddr_t
)mbox64
, (caddr_t
)ccb
->mbox64
, 22);
1420 mbox
->cmdid
= scb
->sno
;
1422 adapter
->outstanding_cmds
++;
1424 mbox
->busy
= 1; // Set busy
1429 WRINDOOR(raid_dev
, raid_dev
->mbox_dma
| 0x1);
1431 spin_unlock_irqrestore(MAILBOX_LOCK(raid_dev
), flags
);
1438 * megaraid_queue_command - generic queue entry point for all LLDs
1439 * @scp : pointer to the scsi command to be executed
1440 * @done : callback routine to be called after the cmd has be completed
1442 * Queue entry point for mailbox based controllers.
1445 megaraid_queue_command_lck(struct scsi_cmnd
*scp
, void (*done
)(struct scsi_cmnd
*))
1451 adapter
= SCP2ADAPTER(scp
);
1452 scp
->scsi_done
= done
;
1456 * Allocate and build a SCB request
1457 * if_busy flag will be set if megaraid_mbox_build_cmd() command could
1458 * not allocate scb. We will return non-zero status in that case.
1459 * NOTE: scb can be null even though certain commands completed
1460 * successfully, e.g., MODE_SENSE and TEST_UNIT_READY, it would
1461 * return 0 in that case, and we would do the callback right away.
1464 scb
= megaraid_mbox_build_cmd(adapter
, scp
, &if_busy
);
1465 if (!scb
) { // command already completed
1470 megaraid_mbox_runpendq(adapter
, scb
);
1474 static DEF_SCSI_QCMD(megaraid_queue_command
)
1477 * megaraid_mbox_build_cmd - transform the mid-layer scsi commands
1478 * @adapter : controller's soft state
1479 * @scp : mid-layer scsi command pointer
1480 * @busy : set if request could not be completed because of lack of
1483 * Transform the mid-layer scsi command to megaraid firmware lingua.
1484 * Convert the command issued by mid-layer to format understood by megaraid
1485 * firmware. We also complete certain commands without sending them to firmware.
1488 megaraid_mbox_build_cmd(adapter_t
*adapter
, struct scsi_cmnd
*scp
, int *busy
)
1490 mraid_device_t
*rdev
= ADAP2RAIDDEV(adapter
);
1495 mraid_passthru_t
*pthru
;
1499 char skip
[] = "skipping";
1500 char scan
[] = "scanning";
1505 * Get the appropriate device map for the device this command is
1508 MRAID_GET_DEVICE_MAP(adapter
, scp
, channel
, target
, islogical
);
1511 * Logical drive commands
1514 switch (scp
->cmnd
[0]) {
1515 case TEST_UNIT_READY
:
1517 * Do we support clustering and is the support enabled
1518 * If no, return success always
1521 scp
->result
= (DID_OK
<< 16);
1525 if (!(scb
= megaraid_alloc_scb(adapter
, scp
))) {
1526 scp
->result
= (DID_ERROR
<< 16);
1531 scb
->dma_direction
= scp
->sc_data_direction
;
1532 scb
->dev_channel
= 0xFF;
1533 scb
->dev_target
= target
;
1534 ccb
= (mbox_ccb_t
*)scb
->ccb
;
1537 * The command id will be provided by the command
1540 ccb
->raw_mbox
[0] = CLUSTER_CMD
;
1541 ccb
->raw_mbox
[2] = RESERVATION_STATUS
;
1542 ccb
->raw_mbox
[3] = target
;
1548 struct scatterlist
*sgl
;
1551 sgl
= scsi_sglist(scp
);
1553 vaddr
= (caddr_t
) sg_virt(&sgl
[0]);
1555 memset(vaddr
, 0, scp
->cmnd
[4]);
1558 con_log(CL_ANN
, (KERN_WARNING
1559 "megaraid mailbox: invalid sg:%d\n",
1563 scp
->result
= (DID_OK
<< 16);
1568 * Display the channel scan for logical drives
1569 * Do not display scan for a channel if already done.
1571 if (!(rdev
->last_disp
& (1L << SCP2CHANNEL(scp
)))) {
1573 con_log(CL_ANN
, (KERN_INFO
1574 "scsi[%d]: scanning scsi channel %d",
1575 adapter
->host
->host_no
,
1579 " [virtual] for logical drives\n"));
1581 rdev
->last_disp
|= (1L << SCP2CHANNEL(scp
));
1584 if (scp
->cmnd
[1] & MEGA_SCSI_INQ_EVPD
) {
1585 scp
->sense_buffer
[0] = 0x70;
1586 scp
->sense_buffer
[2] = ILLEGAL_REQUEST
;
1587 scp
->sense_buffer
[12] = MEGA_INVALID_FIELD_IN_CDB
;
1588 scp
->result
= CHECK_CONDITION
<< 1;
1596 * Do not allow LUN > 0 for logical drives and
1597 * requests for more than 40 logical drives
1600 scp
->result
= (DID_BAD_TARGET
<< 16);
1603 if ((target
% 0x80) >= MAX_LOGICAL_DRIVES_40LD
) {
1604 scp
->result
= (DID_BAD_TARGET
<< 16);
1609 /* Allocate a SCB and initialize passthru */
1610 if (!(scb
= megaraid_alloc_scb(adapter
, scp
))) {
1611 scp
->result
= (DID_ERROR
<< 16);
1616 ccb
= (mbox_ccb_t
*)scb
->ccb
;
1617 scb
->dev_channel
= 0xFF;
1618 scb
->dev_target
= target
;
1621 mbox64
= ccb
->mbox64
;
1625 pthru
->reqsenselen
= 14;
1626 pthru
->islogical
= 1;
1627 pthru
->logdrv
= target
;
1628 pthru
->cdblen
= scp
->cmd_len
;
1629 memcpy(pthru
->cdb
, scp
->cmnd
, scp
->cmd_len
);
1631 mbox
->cmd
= MBOXCMD_PASSTHRU64
;
1632 scb
->dma_direction
= scp
->sc_data_direction
;
1634 pthru
->dataxferlen
= scsi_bufflen(scp
);
1635 pthru
->dataxferaddr
= ccb
->sgl_dma_h
;
1636 pthru
->numsge
= megaraid_mbox_mksgl(adapter
,
1639 mbox
->xferaddr
= 0xFFFFFFFF;
1640 mbox64
->xferaddr_lo
= (uint32_t )ccb
->pthru_dma_h
;
1641 mbox64
->xferaddr_hi
= 0;
1653 * Allocate a SCB and initialize mailbox
1655 if (!(scb
= megaraid_alloc_scb(adapter
, scp
))) {
1656 scp
->result
= (DID_ERROR
<< 16);
1660 ccb
= (mbox_ccb_t
*)scb
->ccb
;
1661 scb
->dev_channel
= 0xFF;
1662 scb
->dev_target
= target
;
1664 mbox64
= ccb
->mbox64
;
1665 mbox
->logdrv
= target
;
1668 * A little HACK: 2nd bit is zero for all scsi read
1669 * commands and is set for all scsi write commands
1671 mbox
->cmd
= (scp
->cmnd
[0] & 0x02) ? MBOXCMD_LWRITE64
:
1675 * 6-byte READ(0x08) or WRITE(0x0A) cdb
1677 if (scp
->cmd_len
== 6) {
1678 mbox
->numsectors
= (uint32_t)scp
->cmnd
[4];
1680 ((uint32_t)scp
->cmnd
[1] << 16) |
1681 ((uint32_t)scp
->cmnd
[2] << 8) |
1682 (uint32_t)scp
->cmnd
[3];
1684 mbox
->lba
&= 0x1FFFFF;
1688 * 10-byte READ(0x28) or WRITE(0x2A) cdb
1690 else if (scp
->cmd_len
== 10) {
1692 (uint32_t)scp
->cmnd
[8] |
1693 ((uint32_t)scp
->cmnd
[7] << 8);
1695 ((uint32_t)scp
->cmnd
[2] << 24) |
1696 ((uint32_t)scp
->cmnd
[3] << 16) |
1697 ((uint32_t)scp
->cmnd
[4] << 8) |
1698 (uint32_t)scp
->cmnd
[5];
1702 * 12-byte READ(0xA8) or WRITE(0xAA) cdb
1704 else if (scp
->cmd_len
== 12) {
1706 ((uint32_t)scp
->cmnd
[2] << 24) |
1707 ((uint32_t)scp
->cmnd
[3] << 16) |
1708 ((uint32_t)scp
->cmnd
[4] << 8) |
1709 (uint32_t)scp
->cmnd
[5];
1712 ((uint32_t)scp
->cmnd
[6] << 24) |
1713 ((uint32_t)scp
->cmnd
[7] << 16) |
1714 ((uint32_t)scp
->cmnd
[8] << 8) |
1715 (uint32_t)scp
->cmnd
[9];
1718 con_log(CL_ANN
, (KERN_WARNING
1719 "megaraid: unsupported CDB length\n"));
1721 megaraid_dealloc_scb(adapter
, scb
);
1723 scp
->result
= (DID_ERROR
<< 16);
1727 scb
->dma_direction
= scp
->sc_data_direction
;
1729 // Calculate Scatter-Gather info
1730 mbox64
->xferaddr_lo
= (uint32_t )ccb
->sgl_dma_h
;
1731 mbox
->numsge
= megaraid_mbox_mksgl(adapter
,
1733 mbox
->xferaddr
= 0xFFFFFFFF;
1734 mbox64
->xferaddr_hi
= 0;
1741 * Do we support clustering and is the support enabled
1744 scp
->result
= (DID_BAD_TARGET
<< 16);
1749 * Allocate a SCB and initialize mailbox
1751 if (!(scb
= megaraid_alloc_scb(adapter
, scp
))) {
1752 scp
->result
= (DID_ERROR
<< 16);
1757 ccb
= (mbox_ccb_t
*)scb
->ccb
;
1758 scb
->dev_channel
= 0xFF;
1759 scb
->dev_target
= target
;
1760 ccb
->raw_mbox
[0] = CLUSTER_CMD
;
1761 ccb
->raw_mbox
[2] = (scp
->cmnd
[0] == RESERVE
) ?
1762 RESERVE_LD
: RELEASE_LD
;
1764 ccb
->raw_mbox
[3] = target
;
1765 scb
->dma_direction
= scp
->sc_data_direction
;
1770 scp
->result
= (DID_BAD_TARGET
<< 16);
1774 else { // Passthru device commands
1776 // Do not allow access to target id > 15 or LUN > 7
1777 if (target
> 15 || SCP2LUN(scp
) > 7) {
1778 scp
->result
= (DID_BAD_TARGET
<< 16);
1782 // if fast load option was set and scan for last device is
1783 // over, reset the fast_load flag so that during a possible
1784 // next scan, devices can be made available
1785 if (rdev
->fast_load
&& (target
== 15) &&
1786 (SCP2CHANNEL(scp
) == adapter
->max_channel
-1)) {
1788 con_log(CL_ANN
, (KERN_INFO
1789 "megaraid[%d]: physical device scan re-enabled\n",
1790 adapter
->host
->host_no
));
1791 rdev
->fast_load
= 0;
1795 * Display the channel scan for physical devices
1797 if (!(rdev
->last_disp
& (1L << SCP2CHANNEL(scp
)))) {
1799 ss
= rdev
->fast_load
? skip
: scan
;
1801 con_log(CL_ANN
, (KERN_INFO
1802 "scsi[%d]: %s scsi channel %d [Phy %d]",
1803 adapter
->host
->host_no
, ss
, SCP2CHANNEL(scp
),
1807 " for non-raid devices\n"));
1809 rdev
->last_disp
|= (1L << SCP2CHANNEL(scp
));
1812 // disable channel sweep if fast load option given
1813 if (rdev
->fast_load
) {
1814 scp
->result
= (DID_BAD_TARGET
<< 16);
1818 // Allocate a SCB and initialize passthru
1819 if (!(scb
= megaraid_alloc_scb(adapter
, scp
))) {
1820 scp
->result
= (DID_ERROR
<< 16);
1825 ccb
= (mbox_ccb_t
*)scb
->ccb
;
1826 scb
->dev_channel
= channel
;
1827 scb
->dev_target
= target
;
1828 scb
->dma_direction
= scp
->sc_data_direction
;
1830 mbox64
= ccb
->mbox64
;
1832 // Does this firmware support extended CDBs
1833 if (adapter
->max_cdb_sz
== 16) {
1834 mbox
->cmd
= MBOXCMD_EXTPTHRU
;
1836 megaraid_mbox_prepare_epthru(adapter
, scb
, scp
);
1838 mbox64
->xferaddr_lo
= (uint32_t)ccb
->epthru_dma_h
;
1839 mbox64
->xferaddr_hi
= 0;
1840 mbox
->xferaddr
= 0xFFFFFFFF;
1843 mbox
->cmd
= MBOXCMD_PASSTHRU64
;
1845 megaraid_mbox_prepare_pthru(adapter
, scb
, scp
);
1847 mbox64
->xferaddr_lo
= (uint32_t)ccb
->pthru_dma_h
;
1848 mbox64
->xferaddr_hi
= 0;
1849 mbox
->xferaddr
= 0xFFFFFFFF;
1859 * megaraid_mbox_runpendq - execute commands queued in the pending queue
1860 * @adapter : controller's soft state
1861 * @scb_q : SCB to be queued in the pending list
1863 * Scan the pending list for commands which are not yet issued and try to
1864 * post to the controller. The SCB can be a null pointer, which would indicate
1865 * no SCB to be queue, just try to execute the ones in the pending list.
1867 * NOTE: We do not actually traverse the pending list. The SCBs are plucked
1868 * out from the head of the pending list. If it is successfully issued, the
1869 * next SCB is at the head now.
1872 megaraid_mbox_runpendq(adapter_t
*adapter
, scb_t
*scb_q
)
1875 unsigned long flags
;
1877 spin_lock_irqsave(PENDING_LIST_LOCK(adapter
), flags
);
1880 scb_q
->state
= SCB_PENDQ
;
1881 list_add_tail(&scb_q
->list
, &adapter
->pend_list
);
1884 // if the adapter in not in quiescent mode, post the commands to FW
1885 if (adapter
->quiescent
) {
1886 spin_unlock_irqrestore(PENDING_LIST_LOCK(adapter
), flags
);
1890 while (!list_empty(&adapter
->pend_list
)) {
1892 assert_spin_locked(PENDING_LIST_LOCK(adapter
));
1894 scb
= list_entry(adapter
->pend_list
.next
, scb_t
, list
);
1896 // remove the scb from the pending list and try to
1897 // issue. If we are unable to issue it, put back in
1898 // the pending list and return
1900 list_del_init(&scb
->list
);
1902 spin_unlock_irqrestore(PENDING_LIST_LOCK(adapter
), flags
);
1904 // if mailbox was busy, return SCB back to pending
1905 // list. Make sure to add at the head, since that's
1906 // where it would have been removed from
1908 scb
->state
= SCB_ISSUED
;
1910 if (mbox_post_cmd(adapter
, scb
) != 0) {
1912 spin_lock_irqsave(PENDING_LIST_LOCK(adapter
), flags
);
1914 scb
->state
= SCB_PENDQ
;
1916 list_add(&scb
->list
, &adapter
->pend_list
);
1918 spin_unlock_irqrestore(PENDING_LIST_LOCK(adapter
),
1924 spin_lock_irqsave(PENDING_LIST_LOCK(adapter
), flags
);
1927 spin_unlock_irqrestore(PENDING_LIST_LOCK(adapter
), flags
);
1935 * megaraid_mbox_prepare_pthru - prepare a command for physical devices
1936 * @adapter : pointer to controller's soft state
1937 * @scb : scsi control block
1938 * @scp : scsi command from the mid-layer
1940 * Prepare a command for the scsi physical devices.
1943 megaraid_mbox_prepare_pthru(adapter_t
*adapter
, scb_t
*scb
,
1944 struct scsi_cmnd
*scp
)
1947 mraid_passthru_t
*pthru
;
1951 ccb
= (mbox_ccb_t
*)scb
->ccb
;
1953 channel
= scb
->dev_channel
;
1954 target
= scb
->dev_target
;
1956 // 0=6sec, 1=60sec, 2=10min, 3=3hrs, 4=NO timeout
1959 pthru
->islogical
= 0;
1961 pthru
->target
= (channel
<< 4) | target
;
1962 pthru
->logdrv
= SCP2LUN(scp
);
1963 pthru
->reqsenselen
= 14;
1964 pthru
->cdblen
= scp
->cmd_len
;
1966 memcpy(pthru
->cdb
, scp
->cmnd
, scp
->cmd_len
);
1968 if (scsi_bufflen(scp
)) {
1969 pthru
->dataxferlen
= scsi_bufflen(scp
);
1970 pthru
->dataxferaddr
= ccb
->sgl_dma_h
;
1971 pthru
->numsge
= megaraid_mbox_mksgl(adapter
, scb
);
1974 pthru
->dataxferaddr
= 0;
1975 pthru
->dataxferlen
= 0;
1983 * megaraid_mbox_prepare_epthru - prepare a command for physical devices
1984 * @adapter : pointer to controller's soft state
1985 * @scb : scsi control block
1986 * @scp : scsi command from the mid-layer
1988 * Prepare a command for the scsi physical devices. This routine prepares
1989 * commands for devices which can take extended CDBs (>10 bytes).
1992 megaraid_mbox_prepare_epthru(adapter_t
*adapter
, scb_t
*scb
,
1993 struct scsi_cmnd
*scp
)
1996 mraid_epassthru_t
*epthru
;
2000 ccb
= (mbox_ccb_t
*)scb
->ccb
;
2001 epthru
= ccb
->epthru
;
2002 channel
= scb
->dev_channel
;
2003 target
= scb
->dev_target
;
2005 // 0=6sec, 1=60sec, 2=10min, 3=3hrs, 4=NO timeout
2006 epthru
->timeout
= 4;
2008 epthru
->islogical
= 0;
2009 epthru
->channel
= 0;
2010 epthru
->target
= (channel
<< 4) | target
;
2011 epthru
->logdrv
= SCP2LUN(scp
);
2012 epthru
->reqsenselen
= 14;
2013 epthru
->cdblen
= scp
->cmd_len
;
2015 memcpy(epthru
->cdb
, scp
->cmnd
, scp
->cmd_len
);
2017 if (scsi_bufflen(scp
)) {
2018 epthru
->dataxferlen
= scsi_bufflen(scp
);
2019 epthru
->dataxferaddr
= ccb
->sgl_dma_h
;
2020 epthru
->numsge
= megaraid_mbox_mksgl(adapter
, scb
);
2023 epthru
->dataxferaddr
= 0;
2024 epthru
->dataxferlen
= 0;
2032 * megaraid_ack_sequence - interrupt ack sequence for memory mapped HBAs
2033 * @adapter : controller's soft state
2035 * Interrupt acknowledgement sequence for memory mapped HBAs. Find out the
2036 * completed command and put them on the completed list for later processing.
2038 * Returns: 1 if the interrupt is valid, 0 otherwise
2041 megaraid_ack_sequence(adapter_t
*adapter
)
2043 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
2047 uint8_t completed
[MBOX_MAX_FIRMWARE_STATUS
];
2048 struct list_head clist
;
2051 unsigned long flags
;
2055 mbox
= raid_dev
->mbox
;
2057 // move the SCBs from the firmware completed array to our local list
2058 INIT_LIST_HEAD(&clist
);
2060 // loop till F/W has more commands for us to complete
2062 spin_lock_irqsave(MAILBOX_LOCK(raid_dev
), flags
);
2065 * Check if a valid interrupt is pending. If found, force the
2066 * interrupt line low.
2068 dword
= RDOUTDOOR(raid_dev
);
2069 if (dword
!= 0x10001234) break;
2073 WROUTDOOR(raid_dev
, 0x10001234);
2076 // wait for valid numstatus to post
2077 for (i
= 0; i
< 0xFFFFF; i
++) {
2078 if (mbox
->numstatus
!= 0xFF) {
2079 nstatus
= mbox
->numstatus
;
2084 mbox
->numstatus
= 0xFF;
2086 adapter
->outstanding_cmds
-= nstatus
;
2088 for (i
= 0; i
< nstatus
; i
++) {
2090 // wait for valid command index to post
2091 for (j
= 0; j
< 0xFFFFF; j
++) {
2092 if (mbox
->completed
[i
] != 0xFF) break;
2095 completed
[i
] = mbox
->completed
[i
];
2096 mbox
->completed
[i
] = 0xFF;
2098 if (completed
[i
] == 0xFF) {
2099 con_log(CL_ANN
, (KERN_CRIT
2100 "megaraid: command posting timed out\n"));
2106 // Get SCB associated with this command id
2107 if (completed
[i
] >= MBOX_MAX_SCSI_CMDS
) {
2109 scb
= adapter
->uscb_list
+ (completed
[i
] -
2110 MBOX_MAX_SCSI_CMDS
);
2114 scb
= adapter
->kscb_list
+ completed
[i
];
2117 scb
->status
= mbox
->status
;
2118 list_add_tail(&scb
->list
, &clist
);
2121 // Acknowledge interrupt
2122 WRINDOOR(raid_dev
, 0x02);
2126 spin_unlock_irqrestore(MAILBOX_LOCK(raid_dev
), flags
);
2129 // put the completed commands in the completed list. DPC would
2130 // complete these commands later
2131 spin_lock_irqsave(COMPLETED_LIST_LOCK(adapter
), flags
);
2133 list_splice(&clist
, &adapter
->completed_list
);
2135 spin_unlock_irqrestore(COMPLETED_LIST_LOCK(adapter
), flags
);
2138 // schedule the DPC if there is some work for it
2140 tasklet_schedule(&adapter
->dpc_h
);
2147 * megaraid_isr - isr for memory based mailbox based controllers
2149 * @devp : pointer to our soft state
2151 * Interrupt service routine for memory-mapped mailbox controllers.
2154 megaraid_isr(int irq
, void *devp
)
2156 adapter_t
*adapter
= devp
;
2159 handled
= megaraid_ack_sequence(adapter
);
2161 /* Loop through any pending requests */
2162 if (!adapter
->quiescent
) {
2163 megaraid_mbox_runpendq(adapter
, NULL
);
2166 return IRQ_RETVAL(handled
);
2171 * megaraid_mbox_dpc - the tasklet to complete the commands from completed list
2172 * @devp : pointer to HBA soft state
2174 * Pick up the commands from the completed list and send back to the owners.
2175 * This is a reentrant function and does not assume any locks are held while
2176 * it is being called.
2179 megaraid_mbox_dpc(unsigned long devp
)
2181 adapter_t
*adapter
= (adapter_t
*)devp
;
2182 mraid_device_t
*raid_dev
;
2183 struct list_head clist
;
2184 struct scatterlist
*sgl
;
2187 struct scsi_cmnd
*scp
;
2188 mraid_passthru_t
*pthru
;
2189 mraid_epassthru_t
*epthru
;
2195 unsigned long flags
;
2201 if (!adapter
) return;
2203 raid_dev
= ADAP2RAIDDEV(adapter
);
2205 // move the SCBs from the completed list to our local list
2206 INIT_LIST_HEAD(&clist
);
2208 spin_lock_irqsave(COMPLETED_LIST_LOCK(adapter
), flags
);
2210 list_splice_init(&adapter
->completed_list
, &clist
);
2212 spin_unlock_irqrestore(COMPLETED_LIST_LOCK(adapter
), flags
);
2215 list_for_each_entry_safe(scb
, tmp
, &clist
, list
) {
2217 status
= scb
->status
;
2219 ccb
= (mbox_ccb_t
*)scb
->ccb
;
2221 epthru
= ccb
->epthru
;
2224 // Make sure f/w has completed a valid command
2225 if (scb
->state
!= SCB_ISSUED
) {
2226 con_log(CL_ANN
, (KERN_CRIT
2227 "megaraid critical err: invalid command %d:%d:%p\n",
2228 scb
->sno
, scb
->state
, scp
));
2230 continue; // Must never happen!
2233 // check for the management command and complete it right away
2234 if (scb
->sno
>= MBOX_MAX_SCSI_CMDS
) {
2235 scb
->state
= SCB_FREE
;
2236 scb
->status
= status
;
2238 // remove from local clist
2239 list_del_init(&scb
->list
);
2241 kioc
= (uioc_t
*)scb
->gp
;
2244 megaraid_mbox_mm_done(adapter
, scb
);
2249 // Was an abort issued for this command earlier
2250 if (scb
->state
& SCB_ABORT
) {
2251 con_log(CL_ANN
, (KERN_NOTICE
2252 "megaraid: aborted cmd [%x] completed\n",
2257 * If the inquiry came of a disk drive which is not part of
2258 * any RAID array, expose it to the kernel. For this to be
2259 * enabled, user must set the "megaraid_expose_unconf_disks"
2260 * flag to 1 by specifying it on module parameter list.
2261 * This would enable data migration off drives from other
2264 islogical
= MRAID_IS_LOGICAL(adapter
, scp
);
2265 if (scp
->cmnd
[0] == INQUIRY
&& status
== 0 && islogical
== 0
2266 && IS_RAID_CH(raid_dev
, scb
->dev_channel
)) {
2268 sgl
= scsi_sglist(scp
);
2270 c
= *(unsigned char *) sg_virt(&sgl
[0]);
2272 con_log(CL_ANN
, (KERN_WARNING
2273 "megaraid mailbox: invalid sg:%d\n",
2278 if ((c
& 0x1F ) == TYPE_DISK
) {
2279 pdev_index
= (scb
->dev_channel
* 16) +
2282 raid_dev
->pdrv_state
[pdev_index
] & 0x0F;
2284 if (pdev_state
== PDRV_ONLINE
||
2285 pdev_state
== PDRV_FAILED
||
2286 pdev_state
== PDRV_RBLD
||
2287 pdev_state
== PDRV_HOTSPARE
||
2288 megaraid_expose_unconf_disks
== 0) {
2295 // Convert MegaRAID status to Linux error code
2300 scp
->result
= (DID_OK
<< 16);
2305 /* set sense_buffer and result fields */
2306 if (mbox
->cmd
== MBOXCMD_PASSTHRU
||
2307 mbox
->cmd
== MBOXCMD_PASSTHRU64
) {
2309 memcpy(scp
->sense_buffer
, pthru
->reqsensearea
,
2312 scp
->result
= DRIVER_SENSE
<< 24 |
2313 DID_OK
<< 16 | CHECK_CONDITION
<< 1;
2316 if (mbox
->cmd
== MBOXCMD_EXTPTHRU
) {
2318 memcpy(scp
->sense_buffer
,
2319 epthru
->reqsensearea
, 14);
2321 scp
->result
= DRIVER_SENSE
<< 24 |
2323 CHECK_CONDITION
<< 1;
2325 scp
->sense_buffer
[0] = 0x70;
2326 scp
->sense_buffer
[2] = ABORTED_COMMAND
;
2327 scp
->result
= CHECK_CONDITION
<< 1;
2334 scp
->result
= DID_BUS_BUSY
<< 16 | status
;
2340 * If TEST_UNIT_READY fails, we know RESERVATION_STATUS
2343 if (scp
->cmnd
[0] == TEST_UNIT_READY
) {
2344 scp
->result
= DID_ERROR
<< 16 |
2345 RESERVATION_CONFLICT
<< 1;
2349 * Error code returned is 1 if Reserve or Release
2350 * failed or the input parameter is invalid
2352 if (status
== 1 && (scp
->cmnd
[0] == RESERVE
||
2353 scp
->cmnd
[0] == RELEASE
)) {
2355 scp
->result
= DID_ERROR
<< 16 |
2356 RESERVATION_CONFLICT
<< 1;
2359 scp
->result
= DID_BAD_TARGET
<< 16 | status
;
2363 // print a debug message for all failed commands
2365 megaraid_mbox_display_scb(adapter
, scb
);
2368 scsi_dma_unmap(scp
);
2370 // remove from local clist
2371 list_del_init(&scb
->list
);
2373 // put back in free list
2374 megaraid_dealloc_scb(adapter
, scb
);
2376 // send the scsi packet back to kernel
2377 scp
->scsi_done(scp
);
2385 * megaraid_abort_handler - abort the scsi command
2386 * @scp : command to be aborted
2388 * Abort a previous SCSI request. Only commands on the pending list can be
2389 * aborted. All the commands issued to the F/W must complete.
2392 megaraid_abort_handler(struct scsi_cmnd
*scp
)
2395 mraid_device_t
*raid_dev
;
2399 unsigned long flags
;
2403 adapter
= SCP2ADAPTER(scp
);
2404 raid_dev
= ADAP2RAIDDEV(adapter
);
2406 con_log(CL_ANN
, (KERN_WARNING
2407 "megaraid: aborting cmd=%x <c=%d t=%d l=%d>\n",
2408 scp
->cmnd
[0], SCP2CHANNEL(scp
),
2409 SCP2TARGET(scp
), SCP2LUN(scp
)));
2411 // If FW has stopped responding, simply return failure
2412 if (raid_dev
->hw_error
) {
2413 con_log(CL_ANN
, (KERN_NOTICE
2414 "megaraid: hw error, not aborting\n"));
2418 // There might a race here, where the command was completed by the
2419 // firmware and now it is on the completed list. Before we could
2420 // complete the command to the kernel in dpc, the abort came.
2421 // Find out if this is the case to avoid the race.
2423 spin_lock_irqsave(COMPLETED_LIST_LOCK(adapter
), flags
);
2424 list_for_each_entry_safe(scb
, tmp
, &adapter
->completed_list
, list
) {
2426 if (scb
->scp
== scp
) { // Found command
2428 list_del_init(&scb
->list
); // from completed list
2430 con_log(CL_ANN
, (KERN_WARNING
2431 "megaraid: %d[%d:%d], abort from completed list\n",
2432 scb
->sno
, scb
->dev_channel
, scb
->dev_target
));
2434 scp
->result
= (DID_ABORT
<< 16);
2435 scp
->scsi_done(scp
);
2437 megaraid_dealloc_scb(adapter
, scb
);
2439 spin_unlock_irqrestore(COMPLETED_LIST_LOCK(adapter
),
2445 spin_unlock_irqrestore(COMPLETED_LIST_LOCK(adapter
), flags
);
2448 // Find out if this command is still on the pending list. If it is and
2449 // was never issued, abort and return success. If the command is owned
2450 // by the firmware, we must wait for it to complete by the FW.
2451 spin_lock_irqsave(PENDING_LIST_LOCK(adapter
), flags
);
2452 list_for_each_entry_safe(scb
, tmp
, &adapter
->pend_list
, list
) {
2454 if (scb
->scp
== scp
) { // Found command
2456 list_del_init(&scb
->list
); // from pending list
2458 ASSERT(!(scb
->state
& SCB_ISSUED
));
2460 con_log(CL_ANN
, (KERN_WARNING
2461 "megaraid abort: [%d:%d], driver owner\n",
2462 scb
->dev_channel
, scb
->dev_target
));
2464 scp
->result
= (DID_ABORT
<< 16);
2465 scp
->scsi_done(scp
);
2467 megaraid_dealloc_scb(adapter
, scb
);
2469 spin_unlock_irqrestore(PENDING_LIST_LOCK(adapter
),
2475 spin_unlock_irqrestore(PENDING_LIST_LOCK(adapter
), flags
);
2478 // Check do we even own this command, in which case this would be
2479 // owned by the firmware. The only way to locate the FW scb is to
2480 // traverse through the list of all SCB, since driver does not
2481 // maintain these SCBs on any list
2483 spin_lock_irq(&adapter
->lock
);
2484 for (i
= 0; i
< MBOX_MAX_SCSI_CMDS
; i
++) {
2485 scb
= adapter
->kscb_list
+ i
;
2487 if (scb
->scp
== scp
) {
2491 if (!(scb
->state
& SCB_ISSUED
)) {
2492 con_log(CL_ANN
, (KERN_WARNING
2493 "megaraid abort: %d[%d:%d], invalid state\n",
2494 scb
->sno
, scb
->dev_channel
, scb
->dev_target
));
2498 con_log(CL_ANN
, (KERN_WARNING
2499 "megaraid abort: %d[%d:%d], fw owner\n",
2500 scb
->sno
, scb
->dev_channel
, scb
->dev_target
));
2504 spin_unlock_irq(&adapter
->lock
);
2507 con_log(CL_ANN
, (KERN_WARNING
"megaraid abort: do now own\n"));
2509 // FIXME: Should there be a callback for this command?
2513 // We cannot actually abort a command owned by firmware, return
2514 // failure and wait for reset. In host reset handler, we will find out
2515 // if the HBA is still live
2520 * megaraid_reset_handler - device reset handler for mailbox based driver
2521 * @scp : reference command
2523 * Reset handler for the mailbox based controller. First try to find out if
2524 * the FW is still live, in which case the outstanding commands counter mut go
2525 * down to 0. If that happens, also issue the reservation reset command to
2526 * relinquish (possible) reservations on the logical drives connected to this
2530 megaraid_reset_handler(struct scsi_cmnd
*scp
)
2535 mraid_device_t
*raid_dev
;
2536 unsigned long flags
;
2537 uint8_t raw_mbox
[sizeof(mbox_t
)];
2539 int recovery_window
;
2543 adapter
= SCP2ADAPTER(scp
);
2544 raid_dev
= ADAP2RAIDDEV(adapter
);
2546 // return failure if adapter is not responding
2547 if (raid_dev
->hw_error
) {
2548 con_log(CL_ANN
, (KERN_NOTICE
2549 "megaraid: hw error, cannot reset\n"));
2553 // Under exceptional conditions, FW can take up to 3 minutes to
2554 // complete command processing. Wait for additional 2 minutes for the
2555 // pending commands counter to go down to 0. If it doesn't, let the
2556 // controller be marked offline
2557 // Also, reset all the commands currently owned by the driver
2558 spin_lock_irqsave(PENDING_LIST_LOCK(adapter
), flags
);
2559 list_for_each_entry_safe(scb
, tmp
, &adapter
->pend_list
, list
) {
2560 list_del_init(&scb
->list
); // from pending list
2562 if (scb
->sno
>= MBOX_MAX_SCSI_CMDS
) {
2563 con_log(CL_ANN
, (KERN_WARNING
2564 "megaraid: IOCTL packet with %d[%d:%d] being reset\n",
2565 scb
->sno
, scb
->dev_channel
, scb
->dev_target
));
2569 kioc
= (uioc_t
*)scb
->gp
;
2570 kioc
->status
= -EFAULT
;
2572 megaraid_mbox_mm_done(adapter
, scb
);
2574 if (scb
->scp
== scp
) { // Found command
2575 con_log(CL_ANN
, (KERN_WARNING
2576 "megaraid: %d[%d:%d], reset from pending list\n",
2577 scb
->sno
, scb
->dev_channel
, scb
->dev_target
));
2579 con_log(CL_ANN
, (KERN_WARNING
2580 "megaraid: IO packet with %d[%d:%d] being reset\n",
2581 scb
->sno
, scb
->dev_channel
, scb
->dev_target
));
2584 scb
->scp
->result
= (DID_RESET
<< 16);
2585 scb
->scp
->scsi_done(scb
->scp
);
2587 megaraid_dealloc_scb(adapter
, scb
);
2590 spin_unlock_irqrestore(PENDING_LIST_LOCK(adapter
), flags
);
2592 if (adapter
->outstanding_cmds
) {
2593 con_log(CL_ANN
, (KERN_NOTICE
2594 "megaraid: %d outstanding commands. Max wait %d sec\n",
2595 adapter
->outstanding_cmds
,
2596 (MBOX_RESET_WAIT
+ MBOX_RESET_EXT_WAIT
)));
2599 recovery_window
= MBOX_RESET_WAIT
+ MBOX_RESET_EXT_WAIT
;
2601 for (i
= 0; i
< recovery_window
; i
++) {
2603 megaraid_ack_sequence(adapter
);
2605 // print a message once every 5 seconds only
2608 "megaraid mbox: Wait for %d commands to complete:%d\n",
2609 adapter
->outstanding_cmds
,
2610 (MBOX_RESET_WAIT
+ MBOX_RESET_EXT_WAIT
) - i
));
2613 // bailout if no recovery happened in reset time
2614 if (adapter
->outstanding_cmds
== 0) {
2621 spin_lock(&adapter
->lock
);
2623 // If still outstanding commands, bail out
2624 if (adapter
->outstanding_cmds
) {
2625 con_log(CL_ANN
, (KERN_WARNING
2626 "megaraid mbox: critical hardware error!\n"));
2628 raid_dev
->hw_error
= 1;
2634 con_log(CL_ANN
, (KERN_NOTICE
2635 "megaraid mbox: reset sequence completed successfully\n"));
2639 // If the controller supports clustering, reset reservations
2645 // clear reservations if any
2646 raw_mbox
[0] = CLUSTER_CMD
;
2647 raw_mbox
[2] = RESET_RESERVATIONS
;
2650 if (mbox_post_sync_cmd_fast(adapter
, raw_mbox
) == 0) {
2652 (KERN_INFO
"megaraid: reservation reset\n"));
2656 con_log(CL_ANN
, (KERN_WARNING
2657 "megaraid: reservation reset failed\n"));
2661 spin_unlock(&adapter
->lock
);
2666 * START: internal commands library
2668 * This section of the driver has the common routine used by the driver and
2669 * also has all the FW routines
2673 * mbox_post_sync_cmd() - blocking command to the mailbox based controllers
2674 * @adapter : controller's soft state
2675 * @raw_mbox : the mailbox
2677 * Issue a scb in synchronous and non-interrupt mode for mailbox based
2681 mbox_post_sync_cmd(adapter_t
*adapter
, uint8_t raw_mbox
[])
2683 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
2688 mbox
= raid_dev
->mbox
;
2691 * Wait until mailbox is free
2693 if (megaraid_busywait_mbox(raid_dev
) != 0)
2694 goto blocked_mailbox
;
2697 * Copy mailbox data into host structure
2699 memcpy((caddr_t
)mbox
, (caddr_t
)raw_mbox
, 16);
2704 mbox
->numstatus
= 0xFF;
2705 mbox
->status
= 0xFF;
2708 WRINDOOR(raid_dev
, raid_dev
->mbox_dma
| 0x1);
2710 // wait for maximum 1 second for status to post. If the status is not
2711 // available within 1 second, assume FW is initializing and wait
2712 // for an extended amount of time
2713 if (mbox
->numstatus
== 0xFF) { // status not yet available
2716 for (i
= 0; mbox
->numstatus
== 0xFF && i
< 1000; i
++) {
2723 con_log(CL_ANN
, (KERN_NOTICE
2724 "megaraid mailbox: wait for FW to boot "));
2726 for (i
= 0; (mbox
->numstatus
== 0xFF) &&
2727 (i
< MBOX_RESET_WAIT
); i
++) {
2729 con_log(CL_ANN
, ("\b\b\b\b\b[%03d]",
2730 MBOX_RESET_WAIT
- i
));
2734 if (i
== MBOX_RESET_WAIT
) {
2737 "\nmegaraid mailbox: status not available\n"));
2741 con_log(CL_ANN
, ("\b\b\b\b\b[ok] \n"));
2745 // wait for maximum 1 second for poll semaphore
2746 if (mbox
->poll
!= 0x77) {
2749 for (i
= 0; (mbox
->poll
!= 0x77) && (i
< 1000); i
++) {
2755 con_log(CL_ANN
, (KERN_WARNING
2756 "megaraid mailbox: could not get poll semaphore\n"));
2761 WRINDOOR(raid_dev
, raid_dev
->mbox_dma
| 0x2);
2764 // wait for maximum 1 second for acknowledgement
2765 if (RDINDOOR(raid_dev
) & 0x2) {
2768 for (i
= 0; (RDINDOOR(raid_dev
) & 0x2) && (i
< 1000); i
++) {
2774 con_log(CL_ANN
, (KERN_WARNING
2775 "megaraid mailbox: could not acknowledge\n"));
2782 status
= mbox
->status
;
2784 // invalidate the completed command id array. After command
2785 // completion, firmware would write the valid id.
2786 mbox
->numstatus
= 0xFF;
2787 mbox
->status
= 0xFF;
2788 for (i
= 0; i
< MBOX_MAX_FIRMWARE_STATUS
; i
++) {
2789 mbox
->completed
[i
] = 0xFF;
2796 con_log(CL_ANN
, (KERN_WARNING
"megaraid: blocked mailbox\n") );
2802 * mbox_post_sync_cmd_fast - blocking command to the mailbox based controllers
2803 * @adapter : controller's soft state
2804 * @raw_mbox : the mailbox
2806 * Issue a scb in synchronous and non-interrupt mode for mailbox based
2807 * controllers. This is a faster version of the synchronous command and
2808 * therefore can be called in interrupt-context as well.
2811 mbox_post_sync_cmd_fast(adapter_t
*adapter
, uint8_t raw_mbox
[])
2813 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
2818 mbox
= raid_dev
->mbox
;
2820 // return immediately if the mailbox is busy
2821 if (mbox
->busy
) return -1;
2823 // Copy mailbox data into host structure
2824 memcpy((caddr_t
)mbox
, (caddr_t
)raw_mbox
, 14);
2829 mbox
->numstatus
= 0xFF;
2830 mbox
->status
= 0xFF;
2833 WRINDOOR(raid_dev
, raid_dev
->mbox_dma
| 0x1);
2835 for (i
= 0; i
< MBOX_SYNC_WAIT_CNT
; i
++) {
2836 if (mbox
->numstatus
!= 0xFF) break;
2838 udelay(MBOX_SYNC_DELAY_200
);
2841 if (i
== MBOX_SYNC_WAIT_CNT
) {
2842 // We may need to re-calibrate the counter
2843 con_log(CL_ANN
, (KERN_CRIT
2844 "megaraid: fast sync command timed out\n"));
2847 WRINDOOR(raid_dev
, raid_dev
->mbox_dma
| 0x2);
2850 return mbox
->status
;
2855 * megaraid_busywait_mbox() - Wait until the controller's mailbox is available
2856 * @raid_dev : RAID device (HBA) soft state
2858 * Wait until the controller's mailbox is available to accept more commands.
2859 * Wait for at most 1 second.
2862 megaraid_busywait_mbox(mraid_device_t
*raid_dev
)
2864 mbox_t
*mbox
= raid_dev
->mbox
;
2869 for (i
= 0; mbox
->busy
&& i
< 1000; i
++)
2873 if (i
< 1000) return 0;
2879 * megaraid_mbox_product_info - some static information about the controller
2880 * @adapter : our soft state
2882 * Issue commands to the controller to grab some parameters required by our
2886 megaraid_mbox_product_info(adapter_t
*adapter
)
2888 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
2890 uint8_t raw_mbox
[sizeof(mbox_t
)];
2891 mraid_pinfo_t
*pinfo
;
2892 dma_addr_t pinfo_dma_h
;
2893 mraid_inquiry3_t
*mraid_inq3
;
2897 memset((caddr_t
)raw_mbox
, 0, sizeof(raw_mbox
));
2898 mbox
= (mbox_t
*)raw_mbox
;
2901 * Issue an ENQUIRY3 command to find out certain adapter parameters,
2902 * e.g., max channels, max commands etc.
2904 pinfo
= dma_zalloc_coherent(&adapter
->pdev
->dev
, sizeof(mraid_pinfo_t
),
2905 &pinfo_dma_h
, GFP_KERNEL
);
2906 if (pinfo
== NULL
) {
2907 con_log(CL_ANN
, (KERN_WARNING
2908 "megaraid: out of memory, %s %d\n", __func__
,
2914 mbox
->xferaddr
= (uint32_t)adapter
->ibuf_dma_h
;
2915 memset((void *)adapter
->ibuf
, 0, MBOX_IBUF_SIZE
);
2917 raw_mbox
[0] = FC_NEW_CONFIG
;
2918 raw_mbox
[2] = NC_SUBOP_ENQUIRY3
;
2919 raw_mbox
[3] = ENQ3_GET_SOLICITED_FULL
;
2921 // Issue the command
2922 if (mbox_post_sync_cmd(adapter
, raw_mbox
) != 0) {
2924 con_log(CL_ANN
, (KERN_WARNING
"megaraid: Inquiry3 failed\n"));
2926 dma_free_coherent(&adapter
->pdev
->dev
, sizeof(mraid_pinfo_t
),
2927 pinfo
, pinfo_dma_h
);
2933 * Collect information about state of each physical drive
2934 * attached to the controller. We will expose all the disks
2935 * which are not part of RAID
2937 mraid_inq3
= (mraid_inquiry3_t
*)adapter
->ibuf
;
2938 for (i
= 0; i
< MBOX_MAX_PHYSICAL_DRIVES
; i
++) {
2939 raid_dev
->pdrv_state
[i
] = mraid_inq3
->pdrv_state
[i
];
2943 * Get product info for information like number of channels,
2944 * maximum commands supported.
2946 memset((caddr_t
)raw_mbox
, 0, sizeof(raw_mbox
));
2947 mbox
->xferaddr
= (uint32_t)pinfo_dma_h
;
2949 raw_mbox
[0] = FC_NEW_CONFIG
;
2950 raw_mbox
[2] = NC_SUBOP_PRODUCT_INFO
;
2952 if (mbox_post_sync_cmd(adapter
, raw_mbox
) != 0) {
2954 con_log(CL_ANN
, (KERN_WARNING
2955 "megaraid: product info failed\n"));
2957 dma_free_coherent(&adapter
->pdev
->dev
, sizeof(mraid_pinfo_t
),
2958 pinfo
, pinfo_dma_h
);
2964 * Setup some parameters for host, as required by our caller
2966 adapter
->max_channel
= pinfo
->nchannels
;
2969 * we will export all the logical drives on a single channel.
2970 * Add 1 since inquires do not come for inititor ID
2972 adapter
->max_target
= MAX_LOGICAL_DRIVES_40LD
+ 1;
2973 adapter
->max_lun
= 8; // up to 8 LUNs for non-disk devices
2976 * These are the maximum outstanding commands for the scsi-layer
2978 adapter
->max_cmds
= MBOX_MAX_SCSI_CMDS
;
2980 memset(adapter
->fw_version
, 0, VERSION_SIZE
);
2981 memset(adapter
->bios_version
, 0, VERSION_SIZE
);
2983 memcpy(adapter
->fw_version
, pinfo
->fw_version
, 4);
2984 adapter
->fw_version
[4] = 0;
2986 memcpy(adapter
->bios_version
, pinfo
->bios_version
, 4);
2987 adapter
->bios_version
[4] = 0;
2989 con_log(CL_ANN
, (KERN_NOTICE
2990 "megaraid: fw version:[%s] bios version:[%s]\n",
2991 adapter
->fw_version
, adapter
->bios_version
));
2993 dma_free_coherent(&adapter
->pdev
->dev
, sizeof(mraid_pinfo_t
), pinfo
,
3002 * megaraid_mbox_extended_cdb - check for support for extended CDBs
3003 * @adapter : soft state for the controller
3005 * This routine check whether the controller in question supports extended
3006 * ( > 10 bytes ) CDBs.
3009 megaraid_mbox_extended_cdb(adapter_t
*adapter
)
3012 uint8_t raw_mbox
[sizeof(mbox_t
)];
3015 mbox
= (mbox_t
*)raw_mbox
;
3017 memset((caddr_t
)raw_mbox
, 0, sizeof(raw_mbox
));
3018 mbox
->xferaddr
= (uint32_t)adapter
->ibuf_dma_h
;
3020 memset((void *)adapter
->ibuf
, 0, MBOX_IBUF_SIZE
);
3022 raw_mbox
[0] = MAIN_MISC_OPCODE
;
3023 raw_mbox
[2] = SUPPORT_EXT_CDB
;
3029 if (mbox_post_sync_cmd(adapter
, raw_mbox
) != 0) {
3038 * megaraid_mbox_support_ha - Do we support clustering
3039 * @adapter : soft state for the controller
3040 * @init_id : ID of the initiator
3042 * Determine if the firmware supports clustering and the ID of the initiator.
3045 megaraid_mbox_support_ha(adapter_t
*adapter
, uint16_t *init_id
)
3048 uint8_t raw_mbox
[sizeof(mbox_t
)];
3052 mbox
= (mbox_t
*)raw_mbox
;
3054 memset((caddr_t
)raw_mbox
, 0, sizeof(raw_mbox
));
3056 mbox
->xferaddr
= (uint32_t)adapter
->ibuf_dma_h
;
3058 memset((void *)adapter
->ibuf
, 0, MBOX_IBUF_SIZE
);
3060 raw_mbox
[0] = GET_TARGET_ID
;
3062 // Issue the command
3065 if (mbox_post_sync_cmd(adapter
, raw_mbox
) == 0) {
3067 *init_id
= *(uint8_t *)adapter
->ibuf
;
3069 con_log(CL_ANN
, (KERN_INFO
3070 "megaraid: cluster firmware, initiator ID: %d\n",
3081 * megaraid_mbox_support_random_del - Do we support random deletion
3082 * @adapter : soft state for the controller
3084 * Determine if the firmware supports random deletion.
3085 * Return: 1 is operation supported, 0 otherwise
3088 megaraid_mbox_support_random_del(adapter_t
*adapter
)
3090 uint8_t raw_mbox
[sizeof(mbox_t
)];
3094 * Newer firmware on Dell CERC expect a different
3095 * random deletion handling, so disable it.
3097 if (adapter
->pdev
->vendor
== PCI_VENDOR_ID_AMI
&&
3098 adapter
->pdev
->device
== PCI_DEVICE_ID_AMI_MEGARAID3
&&
3099 adapter
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_DELL
&&
3100 adapter
->pdev
->subsystem_device
== PCI_SUBSYS_ID_CERC_ATA100_4CH
&&
3101 (adapter
->fw_version
[0] > '6' ||
3102 (adapter
->fw_version
[0] == '6' &&
3103 adapter
->fw_version
[2] > '6') ||
3104 (adapter
->fw_version
[0] == '6'
3105 && adapter
->fw_version
[2] == '6'
3106 && adapter
->fw_version
[3] > '1'))) {
3107 con_log(CL_DLEVEL1
, ("megaraid: disable random deletion\n"));
3111 memset((caddr_t
)raw_mbox
, 0, sizeof(mbox_t
));
3113 raw_mbox
[0] = FC_DEL_LOGDRV
;
3114 raw_mbox
[2] = OP_SUP_DEL_LOGDRV
;
3116 // Issue the command
3118 if (mbox_post_sync_cmd(adapter
, raw_mbox
) == 0) {
3120 con_log(CL_DLEVEL1
, ("megaraid: supports random deletion\n"));
3130 * megaraid_mbox_get_max_sg - maximum sg elements supported by the firmware
3131 * @adapter : soft state for the controller
3133 * Find out the maximum number of scatter-gather elements supported by the
3137 megaraid_mbox_get_max_sg(adapter_t
*adapter
)
3140 uint8_t raw_mbox
[sizeof(mbox_t
)];
3144 mbox
= (mbox_t
*)raw_mbox
;
3146 memset((caddr_t
)raw_mbox
, 0, sizeof(mbox_t
));
3148 mbox
->xferaddr
= (uint32_t)adapter
->ibuf_dma_h
;
3150 memset((void *)adapter
->ibuf
, 0, MBOX_IBUF_SIZE
);
3152 raw_mbox
[0] = MAIN_MISC_OPCODE
;
3153 raw_mbox
[2] = GET_MAX_SG_SUPPORT
;
3155 // Issue the command
3156 if (mbox_post_sync_cmd(adapter
, raw_mbox
) == 0) {
3157 nsg
= *(uint8_t *)adapter
->ibuf
;
3160 nsg
= MBOX_DEFAULT_SG_SIZE
;
3163 if (nsg
> MBOX_MAX_SG_SIZE
) nsg
= MBOX_MAX_SG_SIZE
;
3170 * megaraid_mbox_enum_raid_scsi - enumerate the RAID and SCSI channels
3171 * @adapter : soft state for the controller
3173 * Enumerate the RAID and SCSI channels for ROMB platforms so that channels
3174 * can be exported as regular SCSI channels.
3177 megaraid_mbox_enum_raid_scsi(adapter_t
*adapter
)
3179 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
3181 uint8_t raw_mbox
[sizeof(mbox_t
)];
3184 mbox
= (mbox_t
*)raw_mbox
;
3186 memset((caddr_t
)raw_mbox
, 0, sizeof(mbox_t
));
3188 mbox
->xferaddr
= (uint32_t)adapter
->ibuf_dma_h
;
3190 memset((void *)adapter
->ibuf
, 0, MBOX_IBUF_SIZE
);
3192 raw_mbox
[0] = CHNL_CLASS
;
3193 raw_mbox
[2] = GET_CHNL_CLASS
;
3195 // Issue the command. If the command fails, all channels are RAID
3197 raid_dev
->channel_class
= 0xFF;
3198 if (mbox_post_sync_cmd(adapter
, raw_mbox
) == 0) {
3199 raid_dev
->channel_class
= *(uint8_t *)adapter
->ibuf
;
3207 * megaraid_mbox_flush_cache - flush adapter and disks cache
3208 * @adapter : soft state for the controller
3210 * Flush adapter cache followed by disks cache.
3213 megaraid_mbox_flush_cache(adapter_t
*adapter
)
3215 uint8_t raw_mbox
[sizeof(mbox_t
)];
3217 memset((caddr_t
)raw_mbox
, 0, sizeof(mbox_t
));
3219 raw_mbox
[0] = FLUSH_ADAPTER
;
3221 if (mbox_post_sync_cmd(adapter
, raw_mbox
) != 0) {
3222 con_log(CL_ANN
, ("megaraid: flush adapter failed\n"));
3225 raw_mbox
[0] = FLUSH_SYSTEM
;
3227 if (mbox_post_sync_cmd(adapter
, raw_mbox
) != 0) {
3228 con_log(CL_ANN
, ("megaraid: flush disks cache failed\n"));
3236 * megaraid_mbox_fire_sync_cmd - fire the sync cmd
3237 * @adapter : soft state for the controller
3239 * Clears the pending cmds in FW and reinits its RAID structs.
3242 megaraid_mbox_fire_sync_cmd(adapter_t
*adapter
)
3245 uint8_t raw_mbox
[sizeof(mbox_t
)];
3246 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
3251 mbox
= (mbox_t
*)raw_mbox
;
3253 memset((caddr_t
)raw_mbox
, 0, sizeof(mbox_t
));
3257 mbox
= raid_dev
->mbox
;
3259 /* Wait until mailbox is free */
3260 if (megaraid_busywait_mbox(raid_dev
) != 0) {
3262 goto blocked_mailbox
;
3265 /* Copy mailbox data into host structure */
3266 memcpy((caddr_t
)mbox
, (caddr_t
)raw_mbox
, 16);
3271 mbox
->numstatus
= 0;
3275 WRINDOOR(raid_dev
, raid_dev
->mbox_dma
| 0x1);
3277 /* Wait for maximum 1 min for status to post.
3278 * If the Firmware SUPPORTS the ABOVE COMMAND,
3279 * mbox->cmd will be set to 0
3281 * the firmware will reject the command with
3282 * mbox->numstatus set to 1
3287 while (!mbox
->numstatus
&& mbox
->cmd
== 0xFF) {
3291 if (i
> 1000 * 60) {
3296 if (mbox
->numstatus
== 1)
3297 status
= 1; /*cmd not supported*/
3299 /* Check for interrupt line */
3300 dword
= RDOUTDOOR(raid_dev
);
3301 WROUTDOOR(raid_dev
, dword
);
3302 WRINDOOR(raid_dev
,2);
3307 con_log(CL_ANN
, (KERN_WARNING
"megaraid: blocked mailbox\n"));
3312 * megaraid_mbox_display_scb - display SCB information, mostly debug purposes
3313 * @adapter : controller's soft state
3314 * @scb : SCB to be displayed
3315 * @level : debug level for console print
3317 * Diplay information about the given SCB iff the current debug level is
3321 megaraid_mbox_display_scb(adapter_t
*adapter
, scb_t
*scb
)
3324 struct scsi_cmnd
*scp
;
3330 ccb
= (mbox_ccb_t
*)scb
->ccb
;
3336 con_log(level
, (KERN_NOTICE
3337 "megaraid mailbox: status:%#x cmd:%#x id:%#x ", scb
->status
,
3338 mbox
->cmd
, scb
->sno
));
3340 con_log(level
, ("sec:%#x lba:%#x addr:%#x ld:%d sg:%d\n",
3341 mbox
->numsectors
, mbox
->lba
, mbox
->xferaddr
, mbox
->logdrv
,
3346 con_log(level
, (KERN_NOTICE
"scsi cmnd: "));
3348 for (i
= 0; i
< scp
->cmd_len
; i
++) {
3349 con_log(level
, ("%#2.02x ", scp
->cmnd
[i
]));
3352 con_log(level
, ("\n"));
3359 * megaraid_mbox_setup_device_map - manage device ids
3360 * @adapter : Driver's soft state
3362 * Manage the device ids to have an appropriate mapping between the kernel
3363 * scsi addresses and megaraid scsi and logical drive addresses. We export
3364 * scsi devices on their actual addresses, whereas the logical drives are
3365 * exported on a virtual scsi channel.
3368 megaraid_mbox_setup_device_map(adapter_t
*adapter
)
3374 * First fill the values on the logical drive channel
3376 for (t
= 0; t
< LSI_MAX_LOGICAL_DRIVES_64LD
; t
++)
3377 adapter
->device_ids
[adapter
->max_channel
][t
] =
3378 (t
< adapter
->init_id
) ? t
: t
- 1;
3380 adapter
->device_ids
[adapter
->max_channel
][adapter
->init_id
] = 0xFF;
3383 * Fill the values on the physical devices channels
3385 for (c
= 0; c
< adapter
->max_channel
; c
++)
3386 for (t
= 0; t
< LSI_MAX_LOGICAL_DRIVES_64LD
; t
++)
3387 adapter
->device_ids
[c
][t
] = (c
<< 8) | t
;
3392 * END: internal commands library
3396 * START: Interface for the common management module
3398 * This is the module, which interfaces with the common management module to
3399 * provide support for ioctl and sysfs
3403 * megaraid_cmm_register - register with the management module
3404 * @adapter : HBA soft state
3406 * Register with the management module, which allows applications to issue
3407 * ioctl calls to the drivers. This interface is used by the management module
3408 * to setup sysfs support as well.
3411 megaraid_cmm_register(adapter_t
*adapter
)
3413 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
3420 // Allocate memory for the base list of scb for management module.
3421 adapter
->uscb_list
= kcalloc(MBOX_MAX_USER_CMDS
, sizeof(scb_t
), GFP_KERNEL
);
3423 if (adapter
->uscb_list
== NULL
) {
3424 con_log(CL_ANN
, (KERN_WARNING
3425 "megaraid: out of memory, %s %d\n", __func__
,
3431 // Initialize the synchronization parameters for resources for
3432 // commands for management module
3433 INIT_LIST_HEAD(&adapter
->uscb_pool
);
3435 spin_lock_init(USER_FREE_LIST_LOCK(adapter
));
3439 // link all the packets. Note, CCB for commands, coming from the
3440 // commom management module, mailbox physical address are already
3441 // setup by it. We just need placeholder for that in our local command
3443 for (i
= 0; i
< MBOX_MAX_USER_CMDS
; i
++) {
3445 scb
= adapter
->uscb_list
+ i
;
3446 ccb
= raid_dev
->uccb_list
+ i
;
3448 scb
->ccb
= (caddr_t
)ccb
;
3449 ccb
->mbox64
= raid_dev
->umbox64
+ i
;
3450 ccb
->mbox
= &ccb
->mbox64
->mbox32
;
3451 ccb
->raw_mbox
= (uint8_t *)ccb
->mbox
;
3455 // COMMAND ID 0 - (MBOX_MAX_SCSI_CMDS-1) ARE RESERVED FOR
3456 // COMMANDS COMING FROM IO SUBSYSTEM (MID-LAYER)
3457 scb
->sno
= i
+ MBOX_MAX_SCSI_CMDS
;
3460 scb
->state
= SCB_FREE
;
3461 scb
->dma_direction
= DMA_NONE
;
3462 scb
->dma_type
= MRAID_DMA_NONE
;
3463 scb
->dev_channel
= -1;
3464 scb
->dev_target
= -1;
3466 // put scb in the free pool
3467 list_add_tail(&scb
->list
, &adapter
->uscb_pool
);
3470 adp
.unique_id
= adapter
->unique_id
;
3471 adp
.drvr_type
= DRVRTYPE_MBOX
;
3472 adp
.drvr_data
= (unsigned long)adapter
;
3473 adp
.pdev
= adapter
->pdev
;
3474 adp
.issue_uioc
= megaraid_mbox_mm_handler
;
3475 adp
.timeout
= MBOX_RESET_WAIT
+ MBOX_RESET_EXT_WAIT
;
3476 adp
.max_kioc
= MBOX_MAX_USER_CMDS
;
3478 if ((rval
= mraid_mm_register_adp(&adp
)) != 0) {
3480 con_log(CL_ANN
, (KERN_WARNING
3481 "megaraid mbox: did not register with CMM\n"));
3483 kfree(adapter
->uscb_list
);
3491 * megaraid_cmm_unregister - un-register with the management module
3492 * @adapter : HBA soft state
3494 * Un-register with the management module.
3495 * FIXME: mgmt module must return failure for unregister if it has pending
3499 megaraid_cmm_unregister(adapter_t
*adapter
)
3501 kfree(adapter
->uscb_list
);
3502 mraid_mm_unregister_adp(adapter
->unique_id
);
3508 * megaraid_mbox_mm_handler - interface for CMM to issue commands to LLD
3509 * @drvr_data : LLD specific data
3510 * @kioc : CMM interface packet
3511 * @action : command action
3513 * This routine is invoked whenever the Common Management Module (CMM) has a
3514 * command for us. The 'action' parameter specifies if this is a new command
3518 megaraid_mbox_mm_handler(unsigned long drvr_data
, uioc_t
*kioc
, uint32_t action
)
3522 if (action
!= IOCTL_ISSUE
) {
3523 con_log(CL_ANN
, (KERN_WARNING
3524 "megaraid: unsupported management action:%#2x\n",
3529 adapter
= (adapter_t
*)drvr_data
;
3531 // make sure this adapter is not being detached right now.
3532 if (atomic_read(&adapter
->being_detached
)) {
3533 con_log(CL_ANN
, (KERN_WARNING
3534 "megaraid: reject management request, detaching\n"));
3538 switch (kioc
->opcode
) {
3542 kioc
->status
= gather_hbainfo(adapter
, (mraid_hba_info_t
*)
3543 (unsigned long)kioc
->buf_vaddr
);
3547 return kioc
->status
;
3551 return megaraid_mbox_mm_command(adapter
, kioc
);
3554 kioc
->status
= (-EINVAL
);
3559 return 0; // not reached
3563 * megaraid_mbox_mm_command - issues commands routed through CMM
3564 * @adapter : HBA soft state
3565 * @kioc : management command packet
3567 * Issues commands, which are routed through the management module.
3570 megaraid_mbox_mm_command(adapter_t
*adapter
, uioc_t
*kioc
)
3572 struct list_head
*head
= &adapter
->uscb_pool
;
3577 unsigned long flags
;
3579 // detach one scb from free pool
3580 spin_lock_irqsave(USER_FREE_LIST_LOCK(adapter
), flags
);
3582 if (list_empty(head
)) { // should never happen because of CMM
3584 con_log(CL_ANN
, (KERN_WARNING
3585 "megaraid mbox: bug in cmm handler, lost resources\n"));
3587 spin_unlock_irqrestore(USER_FREE_LIST_LOCK(adapter
), flags
);
3592 scb
= list_entry(head
->next
, scb_t
, list
);
3593 list_del_init(&scb
->list
);
3595 spin_unlock_irqrestore(USER_FREE_LIST_LOCK(adapter
), flags
);
3597 scb
->state
= SCB_ACTIVE
;
3598 scb
->dma_type
= MRAID_DMA_NONE
;
3599 scb
->dma_direction
= DMA_NONE
;
3601 ccb
= (mbox_ccb_t
*)scb
->ccb
;
3602 mbox64
= (mbox64_t
*)(unsigned long)kioc
->cmdbuf
;
3603 raw_mbox
= (uint8_t *)&mbox64
->mbox32
;
3605 memcpy(ccb
->mbox64
, mbox64
, sizeof(mbox64_t
));
3607 scb
->gp
= (unsigned long)kioc
;
3610 * If it is a logdrv random delete operation, we have to wait till
3611 * there are no outstanding cmds at the fw and then issue it directly
3613 if (raw_mbox
[0] == FC_DEL_LOGDRV
&& raw_mbox
[2] == OP_DEL_LOGDRV
) {
3615 if (wait_till_fw_empty(adapter
)) {
3616 con_log(CL_ANN
, (KERN_NOTICE
3617 "megaraid mbox: LD delete, timed out\n"));
3619 kioc
->status
= -ETIME
;
3623 megaraid_mbox_mm_done(adapter
, scb
);
3628 INIT_LIST_HEAD(&scb
->list
);
3630 scb
->state
= SCB_ISSUED
;
3631 if (mbox_post_cmd(adapter
, scb
) != 0) {
3633 con_log(CL_ANN
, (KERN_NOTICE
3634 "megaraid mbox: LD delete, mailbox busy\n"));
3636 kioc
->status
= -EBUSY
;
3640 megaraid_mbox_mm_done(adapter
, scb
);
3648 // put the command on the pending list and execute
3649 megaraid_mbox_runpendq(adapter
, scb
);
3656 wait_till_fw_empty(adapter_t
*adapter
)
3658 unsigned long flags
= 0;
3663 * Set the quiescent flag to stop issuing cmds to FW.
3665 spin_lock_irqsave(&adapter
->lock
, flags
);
3666 adapter
->quiescent
++;
3667 spin_unlock_irqrestore(&adapter
->lock
, flags
);
3670 * Wait till there are no more cmds outstanding at FW. Try for at most
3673 for (i
= 0; i
< 60 && adapter
->outstanding_cmds
; i
++) {
3674 con_log(CL_DLEVEL1
, (KERN_INFO
3675 "megaraid: FW has %d pending commands\n",
3676 adapter
->outstanding_cmds
));
3681 return adapter
->outstanding_cmds
;
3686 * megaraid_mbox_mm_done - callback for CMM commands
3687 * @adapter : HBA soft state
3688 * @scb : completed command
3690 * Callback routine for internal commands originated from the management
3694 megaraid_mbox_mm_done(adapter_t
*adapter
, scb_t
*scb
)
3699 unsigned long flags
;
3701 kioc
= (uioc_t
*)scb
->gp
;
3702 mbox64
= (mbox64_t
*)(unsigned long)kioc
->cmdbuf
;
3703 mbox64
->mbox32
.status
= scb
->status
;
3704 raw_mbox
= (uint8_t *)&mbox64
->mbox32
;
3707 // put scb in the free pool
3708 scb
->state
= SCB_FREE
;
3711 spin_lock_irqsave(USER_FREE_LIST_LOCK(adapter
), flags
);
3713 list_add(&scb
->list
, &adapter
->uscb_pool
);
3715 spin_unlock_irqrestore(USER_FREE_LIST_LOCK(adapter
), flags
);
3717 // if a delete logical drive operation succeeded, restart the
3719 if (raw_mbox
[0] == FC_DEL_LOGDRV
&& raw_mbox
[2] == OP_DEL_LOGDRV
) {
3721 adapter
->quiescent
--;
3723 megaraid_mbox_runpendq(adapter
, NULL
);
3733 * gather_hbainfo - HBA characteristics for the applications
3734 * @adapter : HBA soft state
3735 * @hinfo : pointer to the caller's host info strucuture
3738 gather_hbainfo(adapter_t
*adapter
, mraid_hba_info_t
*hinfo
)
3740 hinfo
->pci_vendor_id
= adapter
->pdev
->vendor
;
3741 hinfo
->pci_device_id
= adapter
->pdev
->device
;
3742 hinfo
->subsys_vendor_id
= adapter
->pdev
->subsystem_vendor
;
3743 hinfo
->subsys_device_id
= adapter
->pdev
->subsystem_device
;
3745 hinfo
->pci_bus
= adapter
->pdev
->bus
->number
;
3746 hinfo
->pci_dev_fn
= adapter
->pdev
->devfn
;
3747 hinfo
->pci_slot
= PCI_SLOT(adapter
->pdev
->devfn
);
3748 hinfo
->irq
= adapter
->host
->irq
;
3749 hinfo
->baseport
= ADAP2RAIDDEV(adapter
)->baseport
;
3751 hinfo
->unique_id
= (hinfo
->pci_bus
<< 8) | adapter
->pdev
->devfn
;
3752 hinfo
->host_no
= adapter
->host
->host_no
;
3758 * END: Interface for the common management module
3764 * megaraid_sysfs_alloc_resources - allocate sysfs related resources
3765 * @adapter : controller's soft state
3767 * Allocate packets required to issue FW calls whenever the sysfs attributes
3768 * are read. These attributes would require up-to-date information from the
3769 * FW. Also set up resources for mutual exclusion to share these resources and
3772 * Return 0 on success.
3773 * Return -ERROR_CODE on failure.
3776 megaraid_sysfs_alloc_resources(adapter_t
*adapter
)
3778 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
3781 raid_dev
->sysfs_uioc
= kmalloc(sizeof(uioc_t
), GFP_KERNEL
);
3783 raid_dev
->sysfs_mbox64
= kmalloc(sizeof(mbox64_t
), GFP_KERNEL
);
3785 raid_dev
->sysfs_buffer
= dma_alloc_coherent(&adapter
->pdev
->dev
,
3786 PAGE_SIZE
, &raid_dev
->sysfs_buffer_dma
, GFP_KERNEL
);
3788 if (!raid_dev
->sysfs_uioc
|| !raid_dev
->sysfs_mbox64
||
3789 !raid_dev
->sysfs_buffer
) {
3791 con_log(CL_ANN
, (KERN_WARNING
3792 "megaraid: out of memory, %s %d\n", __func__
,
3797 megaraid_sysfs_free_resources(adapter
);
3800 mutex_init(&raid_dev
->sysfs_mtx
);
3802 init_waitqueue_head(&raid_dev
->sysfs_wait_q
);
3809 * megaraid_sysfs_free_resources - free sysfs related resources
3810 * @adapter : controller's soft state
3812 * Free packets allocated for sysfs FW commands
3815 megaraid_sysfs_free_resources(adapter_t
*adapter
)
3817 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
3819 kfree(raid_dev
->sysfs_uioc
);
3820 kfree(raid_dev
->sysfs_mbox64
);
3822 if (raid_dev
->sysfs_buffer
) {
3823 dma_free_coherent(&adapter
->pdev
->dev
, PAGE_SIZE
,
3824 raid_dev
->sysfs_buffer
, raid_dev
->sysfs_buffer_dma
);
3830 * megaraid_sysfs_get_ldmap_done - callback for get ldmap
3831 * @uioc : completed packet
3833 * Callback routine called in the ISR/tasklet context for get ldmap call
3836 megaraid_sysfs_get_ldmap_done(uioc_t
*uioc
)
3838 adapter_t
*adapter
= (adapter_t
*)uioc
->buf_vaddr
;
3839 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
3843 wake_up(&raid_dev
->sysfs_wait_q
);
3847 * megaraid_sysfs_get_ldmap_timeout - timeout handling for get ldmap
3848 * @t : timed out timer
3850 * Timeout routine to recover and return to application, in case the adapter
3851 * has stopped responding. A timeout of 60 seconds for this command seems like
3855 megaraid_sysfs_get_ldmap_timeout(struct timer_list
*t
)
3857 struct uioc_timeout
*timeout
= from_timer(timeout
, t
, timer
);
3858 uioc_t
*uioc
= timeout
->uioc
;
3859 adapter_t
*adapter
= (adapter_t
*)uioc
->buf_vaddr
;
3860 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
3862 uioc
->status
= -ETIME
;
3864 wake_up(&raid_dev
->sysfs_wait_q
);
3869 * megaraid_sysfs_get_ldmap - get update logical drive map
3870 * @adapter : controller's soft state
3872 * This routine will be called whenever user reads the logical drive
3873 * attributes, go get the current logical drive mapping table from the
3874 * firmware. We use the management API's to issue commands to the controller.
3876 * NOTE: The commands issuance functionality is not generalized and
3877 * implemented in context of "get ld map" command only. If required, the
3878 * command issuance logical can be trivially pulled out and implemented as a
3879 * standalone library. For now, this should suffice since there is no other
3880 * user of this interface.
3882 * Return 0 on success.
3883 * Return -1 on failure.
3886 megaraid_sysfs_get_ldmap(adapter_t
*adapter
)
3888 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
3893 struct uioc_timeout timeout
;
3898 * Allow only one read at a time to go through the sysfs attributes
3900 mutex_lock(&raid_dev
->sysfs_mtx
);
3902 uioc
= raid_dev
->sysfs_uioc
;
3903 mbox64
= raid_dev
->sysfs_mbox64
;
3904 ldmap
= raid_dev
->sysfs_buffer
;
3906 memset(uioc
, 0, sizeof(uioc_t
));
3907 memset(mbox64
, 0, sizeof(mbox64_t
));
3908 memset(ldmap
, 0, sizeof(raid_dev
->curr_ldmap
));
3910 mbox
= &mbox64
->mbox32
;
3911 raw_mbox
= (char *)mbox
;
3912 uioc
->cmdbuf
= (uint64_t)(unsigned long)mbox64
;
3913 uioc
->buf_vaddr
= (caddr_t
)adapter
;
3914 uioc
->status
= -ENODATA
;
3915 uioc
->done
= megaraid_sysfs_get_ldmap_done
;
3918 * Prepare the mailbox packet to get the current logical drive mapping
3921 mbox
->xferaddr
= (uint32_t)raid_dev
->sysfs_buffer_dma
;
3923 raw_mbox
[0] = FC_DEL_LOGDRV
;
3924 raw_mbox
[2] = OP_GET_LDID_MAP
;
3927 * Setup a timer to recover from a non-responding controller
3929 timeout
.uioc
= uioc
;
3930 timer_setup_on_stack(&timeout
.timer
,
3931 megaraid_sysfs_get_ldmap_timeout
, 0);
3933 timeout
.timer
.expires
= jiffies
+ 60 * HZ
;
3934 add_timer(&timeout
.timer
);
3937 * Send the command to the firmware
3939 rval
= megaraid_mbox_mm_command(adapter
, uioc
);
3941 if (rval
== 0) { // command successfully issued
3942 wait_event(raid_dev
->sysfs_wait_q
, (uioc
->status
!= -ENODATA
));
3945 * Check if the command timed out
3947 if (uioc
->status
== -ETIME
) {
3948 con_log(CL_ANN
, (KERN_NOTICE
3949 "megaraid: sysfs get ld map timed out\n"));
3954 rval
= mbox
->status
;
3958 memcpy(raid_dev
->curr_ldmap
, ldmap
,
3959 sizeof(raid_dev
->curr_ldmap
));
3962 con_log(CL_ANN
, (KERN_NOTICE
3963 "megaraid: get ld map failed with %x\n", rval
));
3967 con_log(CL_ANN
, (KERN_NOTICE
3968 "megaraid: could not issue ldmap command:%x\n", rval
));
3972 del_timer_sync(&timeout
.timer
);
3973 destroy_timer_on_stack(&timeout
.timer
);
3975 mutex_unlock(&raid_dev
->sysfs_mtx
);
3982 * megaraid_sysfs_show_app_hndl - display application handle for this adapter
3983 * @cdev : class device object representation for the host
3984 * @buf : buffer to send data to
3986 * Display the handle used by the applications while executing management
3987 * tasks on the adapter. We invoke a management module API to get the adapter
3988 * handle, since we do not interface with applications directly.
3991 megaraid_sysfs_show_app_hndl(struct device
*dev
, struct device_attribute
*attr
,
3994 struct Scsi_Host
*shost
= class_to_shost(dev
);
3995 adapter_t
*adapter
= (adapter_t
*)SCSIHOST2ADAP(shost
);
3998 app_hndl
= mraid_mm_adapter_app_handle(adapter
->unique_id
);
4000 return snprintf(buf
, 8, "%u\n", app_hndl
);
4005 * megaraid_sysfs_show_ldnum - display the logical drive number for this device
4006 * @dev : device object representation for the scsi device
4007 * @attr : device attribute to show
4008 * @buf : buffer to send data to
4010 * Display the logical drive number for the device in question, if it a valid
4011 * logical drive. For physical devices, "-1" is returned.
4013 * The logical drive number is displayed in following format:
4015 * <SCSI ID> <LD NUM> <LD STICKY ID> <APP ADAPTER HANDLE>
4017 * <int> <int> <int> <int>
4020 megaraid_sysfs_show_ldnum(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
4022 struct scsi_device
*sdev
= to_scsi_device(dev
);
4023 adapter_t
*adapter
= (adapter_t
*)SCSIHOST2ADAP(sdev
->host
);
4024 mraid_device_t
*raid_dev
= ADAP2RAIDDEV(adapter
);
4026 int logical_drv
= -1;
4028 uint32_t app_hndl
= 0;
4033 if (raid_dev
->random_del_supported
&&
4034 MRAID_IS_LOGICAL_SDEV(adapter
, sdev
)) {
4036 rval
= megaraid_sysfs_get_ldmap(adapter
);
4039 for (i
= 0; i
< MAX_LOGICAL_DRIVES_40LD
; i
++) {
4041 mapped_sdev_id
= sdev
->id
;
4043 if (sdev
->id
> adapter
->init_id
) {
4044 mapped_sdev_id
-= 1;
4047 if (raid_dev
->curr_ldmap
[i
] == mapped_sdev_id
) {
4053 ldid_map
= raid_dev
->curr_ldmap
[i
];
4055 app_hndl
= mraid_mm_adapter_app_handle(
4056 adapter
->unique_id
);
4063 con_log(CL_ANN
, (KERN_NOTICE
4064 "megaraid: sysfs get ld map failed: %x\n",
4069 return snprintf(buf
, 36, "%d %d %d %d\n", scsi_id
, logical_drv
,
4070 ldid_map
, app_hndl
);
4075 * END: Mailbox Low Level Driver
4077 module_init(megaraid_init
);
4078 module_exit(megaraid_exit
);
4080 /* vim: set ts=8 sw=8 tw=78 ai si: */