/* * linux/drivers/message/fusion/mptfc.c * For use with LSI PCI chip/adapter(s) * running LSI Fusion MPT (Message Passing Technology) firmware. * * Copyright (c) 1999-2008 LSI Corporation * (mailto:[email protected]) * */ /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ /* This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. NO WARRANTY THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely responsible for determining the appropriateness of using and distributing the Program and assumes all risks associated with its exercise of rights under this Agreement, including but not limited to the risks and costs of program errors, damage to or loss of data, programs or equipment, and unavailability or interruption of operations. DISCLAIMER OF LIABILITY NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ #include <linux/module.h> #include <linux/kernel.h> #include <linux/init.h> #include <linux/errno.h> #include <linux/kdev_t.h> #include <linux/blkdev.h> #include <linux/delay.h> /* for mdelay */ #include <linux/interrupt.h> #include <linux/reboot.h> /* notifier code */ #include <linux/workqueue.h> #include <linux/sort.h> #include <linux/slab.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 <scsi/scsi_transport_fc.h> #include "mptbase.h" #include "mptscsih.h" /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ #define my_NAME … #define my_VERSION … #define MYNAM … MODULE_AUTHOR(…); MODULE_DESCRIPTION(…); MODULE_LICENSE(…) …; MODULE_VERSION(…); /* Command line args */ #define MPTFC_DEV_LOSS_TMO … static int mptfc_dev_loss_tmo = …; /* reasonable default */ module_param(mptfc_dev_loss_tmo, int, 0); MODULE_PARM_DESC(…) …; /* scsi-mid layer global parmeter is max_report_luns, which is 511 */ #define MPTFC_MAX_LUN … static int max_lun = …; module_param(max_lun, int, 0); MODULE_PARM_DESC(…) …; static u8 mptfcDoneCtx = …; static u8 mptfcTaskCtx = …; static u8 mptfcInternalCtx = …; static int mptfc_target_alloc(struct scsi_target *starget); static int mptfc_slave_alloc(struct scsi_device *sdev); static int mptfc_qcmd(struct Scsi_Host *shost, struct scsi_cmnd *SCpnt); static void mptfc_target_destroy(struct scsi_target *starget); static void mptfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout); static void mptfc_remove(struct pci_dev *pdev); static int mptfc_abort(struct scsi_cmnd *SCpnt); static int mptfc_dev_reset(struct scsi_cmnd *SCpnt); static int mptfc_bus_reset(struct scsi_cmnd *SCpnt); static const struct scsi_host_template mptfc_driver_template = …; /**************************************************************************** * Supported hardware */ static struct pci_device_id mptfc_pci_table[] = …; MODULE_DEVICE_TABLE(pci, mptfc_pci_table); static struct scsi_transport_template *mptfc_transport_template = …; static struct fc_function_template mptfc_transport_functions = …; static int mptfc_block_error_handler(struct fc_rport *rport) { … } static int mptfc_abort(struct scsi_cmnd *SCpnt) { … } static int mptfc_dev_reset(struct scsi_cmnd *SCpnt) { … } static int mptfc_bus_reset(struct scsi_cmnd *SCpnt) { … } static void mptfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout) { … } static int mptfc_FcDevPage0_cmp_func(const void *a, const void *b) { … } static int mptfc_GetFcDevPage0(MPT_ADAPTER *ioc, int ioc_port, void(*func)(MPT_ADAPTER *ioc,int channel, FCDevicePage0_t *arg)) { … } static int mptfc_generate_rport_ids(FCDevicePage0_t *pg0, struct fc_rport_identifiers *rid) { … } static void mptfc_register_dev(MPT_ADAPTER *ioc, int channel, FCDevicePage0_t *pg0) { … } /* * OS entry point to allow for host driver to free allocated memory * Called if no device present or device being unloaded */ static void mptfc_target_destroy(struct scsi_target *starget) { … } /* * OS entry point to allow host driver to alloc memory * for each scsi target. Called once per device the bus scan. * Return non-zero if allocation fails. */ static int mptfc_target_alloc(struct scsi_target *starget) { … } /* * mptfc_dump_lun_info * @ioc * @rport * @sdev * */ static void mptfc_dump_lun_info(MPT_ADAPTER *ioc, struct fc_rport *rport, struct scsi_device *sdev, VirtTarget *vtarget) { … } /* * OS entry point to allow host driver to alloc memory * for each scsi device. Called once per device the bus scan. * Return non-zero if allocation fails. * Init memory once per LUN. */ static int mptfc_slave_alloc(struct scsi_device *sdev) { … } static int mptfc_qcmd(struct Scsi_Host *shost, struct scsi_cmnd *SCpnt) { … } /* * mptfc_display_port_link_speed - displaying link speed * @ioc: Pointer to MPT_ADAPTER structure * @portnum: IOC Port number * @pp0dest: port page0 data payload * */ static void mptfc_display_port_link_speed(MPT_ADAPTER *ioc, int portnum, FCPortPage0_t *pp0dest) { … } /* * mptfc_GetFcPortPage0 - Fetch FCPort config Page0. * @ioc: Pointer to MPT_ADAPTER structure * @portnum: IOC Port number * * Return: 0 for success * -ENOMEM if no memory available * -EPERM if not allowed due to ISR context * -EAGAIN if no msg frames currently available * -EFAULT for non-successful reply or no reply (timeout) * -EINVAL portnum arg out of range (hardwired to two elements) */ static int mptfc_GetFcPortPage0(MPT_ADAPTER *ioc, int portnum) { … } static int mptfc_WriteFcPortPage1(MPT_ADAPTER *ioc, int portnum) { … } static int mptfc_GetFcPortPage1(MPT_ADAPTER *ioc, int portnum) { … } static void mptfc_SetFcPortPage1_defaults(MPT_ADAPTER *ioc) { … } static void mptfc_init_host_attr(MPT_ADAPTER *ioc,int portnum) { … } static void mptfc_link_status_change(struct work_struct *work) { … } static void mptfc_setup_reset(struct work_struct *work) { … } static void mptfc_rescan_devices(struct work_struct *work) { … } static int mptfc_probe(struct pci_dev *pdev, const struct pci_device_id *id) { … } static struct pci_driver mptfc_driver = …; static int mptfc_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *pEvReply) { … } static int mptfc_ioc_reset(MPT_ADAPTER *ioc, int reset_phase) { … } /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ /** * mptfc_init - Register MPT adapter(s) as SCSI host(s) with SCSI mid-layer. * * Returns 0 for success, non-zero for failure. */ static int __init mptfc_init(void) { … } /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ /** * mptfc_remove - Remove fc infrastructure for devices * @pdev: Pointer to pci_dev structure * */ static void mptfc_remove(struct pci_dev *pdev) { … } /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ /** * mptfc_exit - Unregisters MPT adapter(s) * */ static void __exit mptfc_exit(void) { … } module_init(…) …; module_exit(mptfc_exit);