// SPDX-License-Identifier: GPL-2.0-only /* Linux Driver for BusLogic MultiMaster and FlashPoint SCSI Host Adapters Copyright 1995-1998 by Leonard N. Zubkoff <lnz@dandelion.com> The author respectfully requests that any modifications to this software be sent directly to him for evaluation and testing. Special thanks to Wayne Yen, Jin-Lon Hon, and Alex Win of BusLogic, whose advice has been invaluable, to David Gentzel, for writing the original Linux BusLogic driver, and to Paul Gortmaker, for being such a dedicated test site. Finally, special thanks to Mylex/BusLogic for making the FlashPoint SCCB Manager available as freely redistributable source code. */ #define blogic_drvr_version "2.1.17"#define blogic_drvr_date "12 September 2013" #include <linux/module.h>#include <linux/init.h>#include <linux/interrupt.h>#include <linux/types.h>#include <linux/blkdev.h>#include <linux/delay.h>#include <linux/ioport.h>#include <linux/mm.h>#include <linux/stat.h>#include <linux/pci.h>#include <linux/spinlock.h>#include <linux/jiffies.h>#include <linux/dma-mapping.h>#include <linux/slab.h>#include <linux/msdos_partition.h>#include <scsi/scsicam.h> #include <asm/dma.h>#include <asm/io.h> #include <scsi/scsi.h>#include <scsi/scsi_cmnd.h>#include <scsi/scsi_device.h>#include <scsi/scsi_host.h>#include <scsi/scsi_tcq.h>#include "BusLogic.h"#include "FlashPoint.c" #ifndef FAILURE#define FAILURE (-1)#endif static const struct scsi_host_template blogic_template; /* blogic_drvr_options_count is a count of the number of BusLogic Driver Options specifications provided via the Linux Kernel Command Line or via the Loadable Kernel Module Installation Facility.*/ static int blogic_drvr_options_count; /* blogic_drvr_options is an array of Driver Options structures representing BusLogic Driver Options specifications provided via the Linux Kernel Command Line or via the Loadable Kernel Module Installation Facility.*/ static struct blogic_drvr_options blogic_drvr_options[BLOGIC_MAX_ADAPTERS]; /* BusLogic can be assigned a string by insmod.*/ MODULE_DESCRIPTION("BusLogic MultiMaster and FlashPoint SCSI Host Adapter driver");MODULE_LICENSE("GPL");#ifdef MODULEstatic char *BusLogic;module_param(BusLogic, charp, 0);#endif /* blogic_probe_options is a set of Probe Options to be applied across all BusLogic Host Adapters.*/ static struct blogic_probe_options blogic_probe_options; /* blogic_global_options is a set of Global Options to be applied across all BusLogic Host Adapters.*/ static struct blogic_global_options blogic_global_options; static LIST_HEAD(blogic_host_list); /* blogic_probeinfo_count is the number of entries in blogic_probeinfo_list.*/ static int blogic_probeinfo_count; /* blogic_probeinfo_list is the list of I/O Addresses and Bus Probe Information to be checked for potential BusLogic Host Adapters. It is initialized by interrogating the PCI Configuration Space on PCI machines as well as from the list of standard BusLogic I/O Addresses.*/ static struct blogic_probeinfo *blogic_probeinfo_list; /* blogic_cmd_failure_reason holds a string identifying the reason why a call to blogic_cmd failed. It is only non-NULL when blogic_cmd returns a failure code.*/ static char *blogic_cmd_failure_reason; /* blogic_announce_drvr announces the Driver Version and Date, Author's Name, Copyright Notice, and Electronic Mail Address.*/ static void blogic_announce_drvr(struct blogic_adapter *adapter){ blogic_announce("***** BusLogic SCSI Driver Version " blogic_drvr_version " of " blogic_drvr_date " *****\n", adapter); blogic_announce("Copyright 1995-1998 by Leonard N. Zubkoff <lnz@dandelion.com>\n", adapter);} /* blogic_drvr_info returns the Host Adapter Name to identify this SCSI Driver and Host Adapter.*/ static const char *blogic_drvr_info(struct Scsi_Host *host){ struct blogic_adapter *adapter = (struct blogic_adapter *) host->hostdata; return adapter->full_model;} /* blogic_init_ccbs initializes a group of Command Control Blocks (CCBs) for Host Adapter from the blk_size bytes located at blk_pointer. The newly created CCBs are added to Host Adapter's free list.*/ static void blogic_init_ccbs(struct blogic_adapter *adapter, void *blk_pointer, int blk_size, dma_addr_t blkp){ struct blogic_ccb *ccb = (struct blogic_ccb *) blk_pointer; unsigned int offset = 0; memset(blk_pointer, 0, blk_size); ccb->allocgrp_head = blkp; ccb->allocgrp_size = blk_size; while ((blk_size -= sizeof(struct blogic_ccb)) >= 0) { ccb->status = BLOGIC_CCB_FREE; ccb->adapter = adapter; ccb->dma_handle = (u32) blkp + offset; if (blogic_flashpoint_type(adapter)) { ccb->callback = blogic_qcompleted_ccb; ccb->base_addr = adapter->fpinfo.base_addr; } ccb->next = adapter->free_ccbs; ccb->next_all = adapter->all_ccbs; adapter->free_ccbs = ccb; adapter->all_ccbs = ccb; adapter->alloc_ccbs++; ccb++; offset += sizeof(struct blogic_ccb); }} /* blogic_create_initccbs allocates the initial CCBs for Host Adapter.*/ static bool __init blogic_create_initccbs(struct blogic_adapter *adapter){ int blk_size = BLOGIC_CCB_GRP_ALLOCSIZE * sizeof(struct blogic_ccb); void *blk_pointer; dma_addr_t blkp; while (adapter->alloc_ccbs < adapter->initccbs) { blk_pointer = dma_alloc_coherent(&adapter->pci_device->dev, blk_size, &blkp, GFP_KERNEL); if (blk_pointer == NULL) { blogic_err("UNABLE TO ALLOCATE CCB GROUP - DETACHING\n", adapter); return false; } blogic_init_ccbs(adapter, blk_pointer, blk_size, blkp); } return true;} /* blogic_destroy_ccbs deallocates the CCBs for Host Adapter.*/ static void blogic_destroy_ccbs(struct blogic_adapter *adapter){ struct blogic_ccb *next_ccb = adapter->all_ccbs, *ccb, *lastccb = NULL; adapter->all_ccbs = NULL; adapter->free_ccbs = NULL; while ((ccb = next_ccb) != NULL) { next_ccb = ccb->next_all; if (ccb->allocgrp_head) { if (lastccb) dma_free_coherent(&adapter->pci_device->dev, lastccb->allocgrp_size, lastccb, lastccb->allocgrp_head); lastccb = ccb; } } if (lastccb) dma_free_coherent(&adapter->pci_device->dev, lastccb->allocgrp_size, lastccb, lastccb->allocgrp_head);} /* blogic_create_addlccbs allocates Additional CCBs for Host Adapter. If allocation fails and there are no remaining CCBs available, the Driver Queue Depth is decreased to a known safe value to avoid potential deadlocks when multiple host adapters share the same IRQ Channel.*/ static void blogic_create_addlccbs(struct blogic_adapter *adapter, int addl_ccbs, bool print_success){ int blk_size = BLOGIC_CCB_GRP_ALLOCSIZE * sizeof(struct blogic_ccb); int prev_alloc = adapter->alloc_ccbs; void *blk_pointer; dma_addr_t blkp; if (addl_ccbs <= 0) return; while (adapter->alloc_ccbs - prev_alloc < addl_ccbs) { blk_pointer = dma_alloc_coherent(&adapter->pci_device->dev, blk_size, &blkp, GFP_KERNEL); if (blk_pointer == NULL) break; blogic_init_ccbs(adapter, blk_pointer, blk_size, blkp); } if (adapter->alloc_ccbs > prev_alloc) { if (print_success) blogic_notice("Allocated %d additional CCBs (total now %d)\n", adapter, adapter->alloc_ccbs - prev_alloc, adapter->alloc_ccbs); return; } blogic_notice("Failed to allocate additional CCBs\n", adapter); if (adapter->drvr_qdepth > adapter->alloc_ccbs - adapter->tgt_count) { adapter->drvr_qdepth = adapter->alloc_ccbs - adapter->tgt_count; adapter->scsi_host->can_queue = adapter->drvr_qdepth; }} /* blogic_alloc_ccb allocates a CCB from Host Adapter's free list, allocating more memory from the Kernel if necessary. The Host Adapter's Lock should already have been acquired by the caller.*/ static struct blogic_ccb *blogic_alloc_ccb(struct blogic_adapter *adapter){ static unsigned long serial; struct blogic_ccb *ccb; ccb = adapter->free_ccbs; if (ccb != NULL) { ccb->serial = ++serial; adapter->free_ccbs = ccb->next; ccb->next = NULL; if (adapter->free_ccbs == NULL) blogic_create_addlccbs(adapter, adapter->inc_ccbs, true); return ccb; } blogic_create_addlccbs(adapter, adapter->inc_ccbs, true); ccb = adapter->free_ccbs; if (ccb == NULL) return NULL; ccb->serial = ++serial; adapter->free_ccbs = ccb->next; ccb->next = NULL; return ccb;} /* blogic_dealloc_ccb deallocates a CCB, returning it to the Host Adapter's free list. The Host Adapter's Lock should already have been acquired by the caller.*/ static void blogic_dealloc_ccb(struct blogic_ccb *ccb, int dma_unmap){ struct blogic_adapter *adapter = ccb->adapter; if (ccb->command != NULL) scsi_dma_unmap(ccb->command); if (dma_unmap) dma_unmap_single(&adapter->pci_device->dev, ccb->sensedata, ccb->sense_datalen, DMA_FROM_DEVICE); ccb->command = NULL; ccb->status = BLOGIC_CCB_FREE; ccb->next = adapter->free_ccbs; adapter->free_ccbs = ccb;} /* blogic_cmd sends the command opcode to adapter, optionally providing paramlen bytes of param and receiving at most replylen bytes of reply; any excess reply data is received but discarded. On success, this function returns the number of reply bytes read from the Host Adapter (including any discarded data); on failure, it returns -1 if the command was invalid, or -2 if a timeout occurred. blogic_cmd is called exclusively during host adapter detection and initialization, so performance and latency are not critical, and exclusive access to the Host Adapter hardware is assumed. Once the host adapter and driver are initialized, the only Host Adapter command that is issued is the single byte Execute Mailbox Command operation code, which does not require waiting for the Host Adapter Ready bit to be set in the Status Register.*/ static int blogic_cmd(struct blogic_adapter *adapter, enum blogic_opcode opcode, void *param, int paramlen, void *reply, int replylen){ unsigned char *param_p = (unsigned char *) param; unsigned char *reply_p = (unsigned char *) reply; union blogic_stat_reg statusreg; union blogic_int_reg intreg; unsigned long processor_flag = 0; int reply_b = 0, result; long timeout; /* Clear out the Reply Data if provided. */ if (replylen > 0) memset(reply, 0, replylen); /* If the IRQ Channel has not yet been acquired, then interrupts must be disabled while issuing host adapter commands since a Command Complete interrupt could occur if the IRQ Channel was previously enabled by another BusLogic Host Adapter or another driver sharing the same IRQ Channel. */ if (!adapter->irq_acquired) local_irq_save(processor_flag); /* Wait for the Host Adapter Ready bit to be set and the Command/Parameter Register Busy bit to be reset in the Status Register. */ timeout = 10000; while (--timeout >= 0) { statusreg.all = blogic_rdstatus(adapter); if (statusreg.sr.adapter_ready && !statusreg.sr.cmd_param_busy) break; udelay(100); } if (timeout < 0) { blogic_cmd_failure_reason = "Timeout waiting for Host Adapter Ready"; result = -2; goto done; } /* Write the opcode to the Command/Parameter Register. */ adapter->adapter_cmd_complete = false; blogic_setcmdparam(adapter, opcode); /* Write any additional Parameter Bytes. */ timeout = 10000; while (paramlen > 0 && --timeout >= 0) { /* Wait 100 microseconds to give the Host Adapter enough time to determine whether the last value written to the Command/Parameter Register was valid or not. If the Command Complete bit is set in the Interrupt Register, then the Command Invalid bit in the Status Register will be reset if the Operation Code or Parameter was valid and the command has completed, or set if the Operation Code or Parameter was invalid. If the Data In Register Ready bit is set in the Status Register, then the Operation Code was valid, and data is waiting to be read back from the Host Adapter. Otherwise, wait for the Command/Parameter Register Busy bit in the Status Register to be reset. */ udelay(100); intreg.all = blogic_rdint(adapter); statusreg.all = blogic_rdstatus(adapter); if (intreg.ir.cmd_complete) break; if (adapter->adapter_cmd_complete) break; if (statusreg.sr.datain_ready) break; if (statusreg.sr.cmd_param_busy) continue; blogic_setcmdparam(adapter, *param_p++); paramlen--; } if (timeout < 0) { blogic_cmd_failure_reason = "Timeout waiting for Parameter Acceptance"; result = -2; goto done; } /* The Modify I/O Address command does not cause a Command Complete Interrupt. */ if (opcode == BLOGIC_MOD_IOADDR) { statusreg.all = blogic_rdstatus(adapter); if (statusreg.sr.cmd_invalid) { blogic_cmd_failure_reason = "Modify I/O Address Invalid"; result = -1; goto done; } if (blogic_global_options.trace_config) blogic_notice("blogic_cmd(%02X) Status = %02X: (Modify I/O Address)\n", adapter, opcode, statusreg.all); result = 0; goto done; } /* Select an appropriate timeout value for awaiting command completion. */ switch (opcode) { case BLOGIC_INQ_DEV0TO7: case BLOGIC_INQ_DEV8TO15: case BLOGIC_INQ_DEV: /* Approximately 60 seconds. */ timeout = 60 * 10000; break; default: /* Approximately 1 second. */ timeout = 10000; break; } /* Receive any Reply Bytes, waiting for either the Command Complete bit to be set in the Interrupt Register, or for the Interrupt Handler to set the Host Adapter Command Completed bit in the Host Adapter structure. */ while (--timeout >= 0) { intreg.all = blogic_rdint(adapter); statusreg.all = blogic_rdstatus(adapter); if (intreg.ir.cmd_complete) break; if (adapter->adapter_cmd_complete) break; if (statusreg.sr.datain_ready) { if (++reply_b <= replylen) *reply_p++ = blogic_rddatain(adapter); else blogic_rddatain(adapter); } if (opcode == BLOGIC_FETCH_LOCALRAM && statusreg.sr.adapter_ready) break; udelay(100); } if (timeout < 0) { blogic_cmd_failure_reason = "Timeout waiting for Command Complete"; result = -2; goto done; } /* Clear any pending Command Complete Interrupt. */ blogic_intreset(adapter); /* Provide tracing information if requested. */Lines 1–500 of 3737. Load more
// SPDX-License-Identifier: GPL-2.0-only /* Linux Driver for BusLogic MultiMaster and FlashPoint SCSI Host Adapters Copyright 1995-1998 by Leonard N. Zubkoff <lnz@dandelion.com> The author respectfully requests that any modifications to this software be sent directly to him for evaluation and testing. Special thanks to Wayne Yen, Jin-Lon Hon, and Alex Win of BusLogic, whose advice has been invaluable, to David Gentzel, for writing the original Linux BusLogic driver, and to Paul Gortmaker, for being such a dedicated test site. Finally, special thanks to Mylex/BusLogic for making the FlashPoint SCCB Manager available as freely redistributable source code. */ #define blogic_drvr_version "2.1.17" #define blogic_drvr_date "12 September 2013" #include <linux/module.h> #include <linux/init.h> #include <linux/interrupt.h> #include <linux/types.h> #include <linux/blkdev.h> #include <linux/delay.h> #include <linux/ioport.h> #include <linux/mm.h> #include <linux/stat.h> #include <linux/pci.h> #include <linux/spinlock.h> #include <linux/jiffies.h> #include <linux/dma-mapping.h> #include <linux/slab.h> #include <linux/msdos_partition.h> #include <scsi/scsicam.h> #include <asm/dma.h> #include <asm/io.h> #include <scsi/scsi.h> #include <scsi/scsi_cmnd.h> #include <scsi/scsi_device.h> #include <scsi/scsi_host.h> #include <scsi/scsi_tcq.h> #include "BusLogic.h" #include "FlashPoint.c" #ifndef FAILURE #define FAILURE (-1) #endif static const struct scsi_host_template blogic_template; /* blogic_drvr_options_count is a count of the number of BusLogic Driver Options specifications provided via the Linux Kernel Command Line or via the Loadable Kernel Module Installation Facility. */ static int blogic_drvr_options_count; /* blogic_drvr_options is an array of Driver Options structures representing BusLogic Driver Options specifications provided via the Linux Kernel Command Line or via the Loadable Kernel Module Installation Facility. */ static struct blogic_drvr_options blogic_drvr_options[BLOGIC_MAX_ADAPTERS]; /* BusLogic can be assigned a string by insmod. */ MODULE_DESCRIPTION("BusLogic MultiMaster and FlashPoint SCSI Host Adapter driver"); MODULE_LICENSE("GPL"); #ifdef MODULE static char *BusLogic; module_param(BusLogic, charp, 0); #endif /* blogic_probe_options is a set of Probe Options to be applied across all BusLogic Host Adapters. */ static struct blogic_probe_options blogic_probe_options; /* blogic_global_options is a set of Global Options to be applied across all BusLogic Host Adapters. */ static struct blogic_global_options blogic_global_options; static LIST_HEAD(blogic_host_list); /* blogic_probeinfo_count is the number of entries in blogic_probeinfo_list. */ static int blogic_probeinfo_count; /* blogic_probeinfo_list is the list of I/O Addresses and Bus Probe Information to be checked for potential BusLogic Host Adapters. It is initialized by interrogating the PCI Configuration Space on PCI machines as well as from the list of standard BusLogic I/O Addresses. */ static struct blogic_probeinfo *blogic_probeinfo_list; /* blogic_cmd_failure_reason holds a string identifying the reason why a call to blogic_cmd failed. It is only non-NULL when blogic_cmd returns a failure code. */ static char *blogic_cmd_failure_reason; /* blogic_announce_drvr announces the Driver Version and Date, Author's Name, Copyright Notice, and Electronic Mail Address. */ static void blogic_announce_drvr(struct blogic_adapter *adapter) { blogic_announce("***** BusLogic SCSI Driver Version " blogic_drvr_version " of " blogic_drvr_date " *****\n", adapter); blogic_announce("Copyright 1995-1998 by Leonard N. Zubkoff <lnz@dandelion.com>\n", adapter); } /* blogic_drvr_info returns the Host Adapter Name to identify this SCSI Driver and Host Adapter. */ static const char *blogic_drvr_info(struct Scsi_Host *host) { struct blogic_adapter *adapter = (struct blogic_adapter *) host->hostdata; return adapter->full_model; } /* blogic_init_ccbs initializes a group of Command Control Blocks (CCBs) for Host Adapter from the blk_size bytes located at blk_pointer. The newly created CCBs are added to Host Adapter's free list. */ static void blogic_init_ccbs(struct blogic_adapter *adapter, void *blk_pointer, int blk_size, dma_addr_t blkp) { struct blogic_ccb *ccb = (struct blogic_ccb *) blk_pointer; unsigned int offset = 0; memset(blk_pointer, 0, blk_size); ccb->allocgrp_head = blkp; ccb->allocgrp_size = blk_size; while ((blk_size -= sizeof(struct blogic_ccb)) >= 0) { ccb->status = BLOGIC_CCB_FREE; ccb->adapter = adapter; ccb->dma_handle = (u32) blkp + offset; if (blogic_flashpoint_type(adapter)) { ccb->callback = blogic_qcompleted_ccb; ccb->base_addr = adapter->fpinfo.base_addr; } ccb->next = adapter->free_ccbs; ccb->next_all = adapter->all_ccbs; adapter->free_ccbs = ccb; adapter->all_ccbs = ccb; adapter->alloc_ccbs++; ccb++; offset += sizeof(struct blogic_ccb); } } /* blogic_create_initccbs allocates the initial CCBs for Host Adapter. */ static bool __init blogic_create_initccbs(struct blogic_adapter *adapter) { int blk_size = BLOGIC_CCB_GRP_ALLOCSIZE * sizeof(struct blogic_ccb); void *blk_pointer; dma_addr_t blkp; while (adapter->alloc_ccbs < adapter->initccbs) { blk_pointer = dma_alloc_coherent(&adapter->pci_device->dev, blk_size, &blkp, GFP_KERNEL); if (blk_pointer == NULL) { blogic_err("UNABLE TO ALLOCATE CCB GROUP - DETACHING\n", adapter); return false; } blogic_init_ccbs(adapter, blk_pointer, blk_size, blkp); } return true; } /* blogic_destroy_ccbs deallocates the CCBs for Host Adapter. */ static void blogic_destroy_ccbs(struct blogic_adapter *adapter) { struct blogic_ccb *next_ccb = adapter->all_ccbs, *ccb, *lastccb = NULL; adapter->all_ccbs = NULL; adapter->free_ccbs = NULL; while ((ccb = next_ccb) != NULL) { next_ccb = ccb->next_all; if (ccb->allocgrp_head) { if (lastccb) dma_free_coherent(&adapter->pci_device->dev, lastccb->allocgrp_size, lastccb, lastccb->allocgrp_head); lastccb = ccb; } } if (lastccb) dma_free_coherent(&adapter->pci_device->dev, lastccb->allocgrp_size, lastccb, lastccb->allocgrp_head); } /* blogic_create_addlccbs allocates Additional CCBs for Host Adapter. If allocation fails and there are no remaining CCBs available, the Driver Queue Depth is decreased to a known safe value to avoid potential deadlocks when multiple host adapters share the same IRQ Channel. */ static void blogic_create_addlccbs(struct blogic_adapter *adapter, int addl_ccbs, bool print_success) { int blk_size = BLOGIC_CCB_GRP_ALLOCSIZE * sizeof(struct blogic_ccb); int prev_alloc = adapter->alloc_ccbs; void *blk_pointer; dma_addr_t blkp; if (addl_ccbs <= 0) return; while (adapter->alloc_ccbs - prev_alloc < addl_ccbs) { blk_pointer = dma_alloc_coherent(&adapter->pci_device->dev, blk_size, &blkp, GFP_KERNEL); if (blk_pointer == NULL) break; blogic_init_ccbs(adapter, blk_pointer, blk_size, blkp); } if (adapter->alloc_ccbs > prev_alloc) { if (print_success) blogic_notice("Allocated %d additional CCBs (total now %d)\n", adapter, adapter->alloc_ccbs - prev_alloc, adapter->alloc_ccbs); return; } blogic_notice("Failed to allocate additional CCBs\n", adapter); if (adapter->drvr_qdepth > adapter->alloc_ccbs - adapter->tgt_count) { adapter->drvr_qdepth = adapter->alloc_ccbs - adapter->tgt_count; adapter->scsi_host->can_queue = adapter->drvr_qdepth; } } /* blogic_alloc_ccb allocates a CCB from Host Adapter's free list, allocating more memory from the Kernel if necessary. The Host Adapter's Lock should already have been acquired by the caller. */ static struct blogic_ccb *blogic_alloc_ccb(struct blogic_adapter *adapter) { static unsigned long serial; struct blogic_ccb *ccb; ccb = adapter->free_ccbs; if (ccb != NULL) { ccb->serial = ++serial; adapter->free_ccbs = ccb->next; ccb->next = NULL; if (adapter->free_ccbs == NULL) blogic_create_addlccbs(adapter, adapter->inc_ccbs, true); return ccb; } blogic_create_addlccbs(adapter, adapter->inc_ccbs, true); ccb = adapter->free_ccbs; if (ccb == NULL) return NULL; ccb->serial = ++serial; adapter->free_ccbs = ccb->next; ccb->next = NULL; return ccb; } /* blogic_dealloc_ccb deallocates a CCB, returning it to the Host Adapter's free list. The Host Adapter's Lock should already have been acquired by the caller. */ static void blogic_dealloc_ccb(struct blogic_ccb *ccb, int dma_unmap) { struct blogic_adapter *adapter = ccb->adapter; if (ccb->command != NULL) scsi_dma_unmap(ccb->command); if (dma_unmap) dma_unmap_single(&adapter->pci_device->dev, ccb->sensedata, ccb->sense_datalen, DMA_FROM_DEVICE); ccb->command = NULL; ccb->status = BLOGIC_CCB_FREE; ccb->next = adapter->free_ccbs; adapter->free_ccbs = ccb; } /* blogic_cmd sends the command opcode to adapter, optionally providing paramlen bytes of param and receiving at most replylen bytes of reply; any excess reply data is received but discarded. On success, this function returns the number of reply bytes read from the Host Adapter (including any discarded data); on failure, it returns -1 if the command was invalid, or -2 if a timeout occurred. blogic_cmd is called exclusively during host adapter detection and initialization, so performance and latency are not critical, and exclusive access to the Host Adapter hardware is assumed. Once the host adapter and driver are initialized, the only Host Adapter command that is issued is the single byte Execute Mailbox Command operation code, which does not require waiting for the Host Adapter Ready bit to be set in the Status Register. */ static int blogic_cmd(struct blogic_adapter *adapter, enum blogic_opcode opcode, void *param, int paramlen, void *reply, int replylen) { unsigned char *param_p = (unsigned char *) param; unsigned char *reply_p = (unsigned char *) reply; union blogic_stat_reg statusreg; union blogic_int_reg intreg; unsigned long processor_flag = 0; int reply_b = 0, result; long timeout; /* Clear out the Reply Data if provided. */ if (replylen > 0) memset(reply, 0, replylen); /* If the IRQ Channel has not yet been acquired, then interrupts must be disabled while issuing host adapter commands since a Command Complete interrupt could occur if the IRQ Channel was previously enabled by another BusLogic Host Adapter or another driver sharing the same IRQ Channel. */ if (!adapter->irq_acquired) local_irq_save(processor_flag); /* Wait for the Host Adapter Ready bit to be set and the Command/Parameter Register Busy bit to be reset in the Status Register. */ timeout = 10000; while (--timeout >= 0) { statusreg.all = blogic_rdstatus(adapter); if (statusreg.sr.adapter_ready && !statusreg.sr.cmd_param_busy) break; udelay(100); } if (timeout < 0) { blogic_cmd_failure_reason = "Timeout waiting for Host Adapter Ready"; result = -2; goto done; } /* Write the opcode to the Command/Parameter Register. */ adapter->adapter_cmd_complete = false; blogic_setcmdparam(adapter, opcode); /* Write any additional Parameter Bytes. */ timeout = 10000; while (paramlen > 0 && --timeout >= 0) { /* Wait 100 microseconds to give the Host Adapter enough time to determine whether the last value written to the Command/Parameter Register was valid or not. If the Command Complete bit is set in the Interrupt Register, then the Command Invalid bit in the Status Register will be reset if the Operation Code or Parameter was valid and the command has completed, or set if the Operation Code or Parameter was invalid. If the Data In Register Ready bit is set in the Status Register, then the Operation Code was valid, and data is waiting to be read back from the Host Adapter. Otherwise, wait for the Command/Parameter Register Busy bit in the Status Register to be reset. */ udelay(100); intreg.all = blogic_rdint(adapter); statusreg.all = blogic_rdstatus(adapter); if (intreg.ir.cmd_complete) break; if (adapter->adapter_cmd_complete) break; if (statusreg.sr.datain_ready) break; if (statusreg.sr.cmd_param_busy) continue; blogic_setcmdparam(adapter, *param_p++); paramlen--; } if (timeout < 0) { blogic_cmd_failure_reason = "Timeout waiting for Parameter Acceptance"; result = -2; goto done; } /* The Modify I/O Address command does not cause a Command Complete Interrupt. */ if (opcode == BLOGIC_MOD_IOADDR) { statusreg.all = blogic_rdstatus(adapter); if (statusreg.sr.cmd_invalid) { blogic_cmd_failure_reason = "Modify I/O Address Invalid"; result = -1; goto done; } if (blogic_global_options.trace_config) blogic_notice("blogic_cmd(%02X) Status = %02X: (Modify I/O Address)\n", adapter, opcode, statusreg.all); result = 0; goto done; } /* Select an appropriate timeout value for awaiting command completion. */ switch (opcode) { case BLOGIC_INQ_DEV0TO7: case BLOGIC_INQ_DEV8TO15: case BLOGIC_INQ_DEV: /* Approximately 60 seconds. */ timeout = 60 * 10000; break; default: /* Approximately 1 second. */ timeout = 10000; break; } /* Receive any Reply Bytes, waiting for either the Command Complete bit to be set in the Interrupt Register, or for the Interrupt Handler to set the Host Adapter Command Completed bit in the Host Adapter structure. */ while (--timeout >= 0) { intreg.all = blogic_rdint(adapter); statusreg.all = blogic_rdstatus(adapter); if (intreg.ir.cmd_complete) break; if (adapter->adapter_cmd_complete) break; if (statusreg.sr.datain_ready) { if (++reply_b <= replylen) *reply_p++ = blogic_rddatain(adapter); else blogic_rddatain(adapter); } if (opcode == BLOGIC_FETCH_LOCALRAM && statusreg.sr.adapter_ready) break; udelay(100); } if (timeout < 0) { blogic_cmd_failure_reason = "Timeout waiting for Command Complete"; result = -2; goto done; } /* Clear any pending Command Complete Interrupt. */ blogic_intreset(adapter); /* Provide tracing information if requested. */