drivers/scsi/megaraid.c
Source file repositories/reference/linux-study-clean/drivers/scsi/megaraid.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/scsi/megaraid.c- Extension
.c- Size
- 107209 bytes
- Lines
- 4630
- Domain
- Driver Families
- Bucket
- drivers/scsi
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/mm.hlinux/fs.hlinux/blkdev.hlinux/uaccess.hasm/io.hlinux/completion.hlinux/delay.hlinux/proc_fs.hlinux/seq_file.hlinux/reboot.hlinux/module.hlinux/list.hlinux/interrupt.hlinux/pci.hlinux/init.hlinux/dma-mapping.hlinux/mutex.hlinux/slab.hscsi/scsi.hscsi/scsi_cmnd.hscsi/scsi_device.hscsi/scsi_eh.hscsi/scsi_host.hscsi/scsi_tcq.hscsi/scsicam.hmegaraid.h
Detected Declarations
function mega_setup_mailboxfunction mega_query_adapterfunction mega_runpendqfunction megaraid_queuefunction DEF_SCSI_QCMDfunction mega_get_ldrv_numfunction mega_build_cmdfunction mega_prepare_passthrufunction mega_prepare_extpassthrufunction __mega_runpendqfunction issue_scbfunction mega_busywait_mboxfunction issue_scb_blockfunction megaraid_isr_iomappedfunction megaraid_isr_memmappedfunction mega_cmd_donefunction mega_runpendqfunction mega_free_scbfunction __mega_busywait_mboxfunction mega_build_sglistfunction scsi_for_each_sgfunction mega_8_to_40ldfunction mega_free_sglfunction megaraid_infofunction megaraid_abortfunction megaraid_resetfunction megaraid_abort_and_resetfunction list_for_each_safefunction make_local_pdevfunction free_local_pdevfunction mega_allocate_inquiryfunction mega_free_inquiryfunction proc_show_configfunction proc_show_statfunction proc_show_mboxfunction proc_show_rebuild_ratefunction proc_show_batteryfunction mega_print_inquiryfunction proc_show_pdrvfunction proc_show_pdrv_ch0function proc_show_pdrv_ch1function proc_show_pdrv_ch2function proc_show_pdrv_ch3function proc_show_rdrvfunction proc_show_rdrv_10function proc_show_rdrv_20function proc_show_rdrv_30function proc_show_rdrv_40
Annotated Snippet
static const struct file_operations megadev_fops = {
.owner = THIS_MODULE,
.unlocked_ioctl = megadev_unlocked_ioctl,
.open = megadev_open,
.llseek = noop_llseek,
};
/*
* Array to structures for storing the information about the controllers. This
* information is sent to the user level applications, when they do an ioctl
* for this information.
*/
static struct mcontroller mcontroller[MAX_CONTROLLERS];
/* The current driver version */
static u32 driver_ver = 0x02000000;
/* major number used by the device for character interface */
static int major;
#define IS_RAID_CH(hba, ch) (((hba)->mega_ch_class >> (ch)) & 0x01)
/*
* Debug variable to print some diagnostic messages
*/
static int trace_level;
/**
* mega_setup_mailbox()
* @adapter: pointer to our soft state
*
* Allocates a 8 byte aligned memory for the handshake mailbox.
*/
static int
mega_setup_mailbox(adapter_t *adapter)
{
unsigned long align;
adapter->una_mbox64 = dma_alloc_coherent(&adapter->dev->dev,
sizeof(mbox64_t),
&adapter->una_mbox64_dma,
GFP_KERNEL);
if( !adapter->una_mbox64 ) return -1;
adapter->mbox = &adapter->una_mbox64->mbox;
adapter->mbox = (mbox_t *)((((unsigned long) adapter->mbox) + 15) &
(~0UL ^ 0xFUL));
adapter->mbox64 = (mbox64_t *)(((unsigned long)adapter->mbox) - 8);
align = ((void *)adapter->mbox) - ((void *)&adapter->una_mbox64->mbox);
adapter->mbox_dma = adapter->una_mbox64_dma + 8 + align;
/*
* Register the mailbox if the controller is an io-mapped controller
*/
if( adapter->flag & BOARD_IOMAP ) {
outb(adapter->mbox_dma & 0xFF,
adapter->host->io_port + MBOX_PORT0);
outb((adapter->mbox_dma >> 8) & 0xFF,
adapter->host->io_port + MBOX_PORT1);
outb((adapter->mbox_dma >> 16) & 0xFF,
adapter->host->io_port + MBOX_PORT2);
outb((adapter->mbox_dma >> 24) & 0xFF,
adapter->host->io_port + MBOX_PORT3);
outb(ENABLE_MBOX_BYTE,
adapter->host->io_port + ENABLE_MBOX_REGION);
irq_ack(adapter);
irq_enable(adapter);
}
return 0;
}
/*
* mega_query_adapter()
* @adapter - pointer to our soft state
*
Annotation
- Immediate include surface: `linux/mm.h`, `linux/fs.h`, `linux/blkdev.h`, `linux/uaccess.h`, `asm/io.h`, `linux/completion.h`, `linux/delay.h`, `linux/proc_fs.h`.
- Detected declarations: `function mega_setup_mailbox`, `function mega_query_adapter`, `function mega_runpendq`, `function megaraid_queue`, `function DEF_SCSI_QCMD`, `function mega_get_ldrv_num`, `function mega_build_cmd`, `function mega_prepare_passthru`, `function mega_prepare_extpassthru`, `function __mega_runpendq`.
- Atlas domain: Driver Families / drivers/scsi.
- Implementation status: pattern implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.