1f92363d1SSreekanth Reddy /* 2f92363d1SSreekanth Reddy * This module provides common API to set Diagnostic trigger for MPT 3f92363d1SSreekanth Reddy * (Message Passing Technology) based controllers 4f92363d1SSreekanth Reddy * 5f92363d1SSreekanth Reddy * This code is based on drivers/scsi/mpt3sas/mpt3sas_trigger_diag.c 6a4ffce0dSSreekanth Reddy * Copyright (C) 2012-2014 LSI Corporation 7a03bd153SSreekanth Reddy * Copyright (C) 2013-2014 Avago Technologies 8a03bd153SSreekanth Reddy * (mailto: MPT-FusionLinux.pdl@avagotech.com) 9f92363d1SSreekanth Reddy * 10f92363d1SSreekanth Reddy * This program is free software; you can redistribute it and/or 11f92363d1SSreekanth Reddy * modify it under the terms of the GNU General Public License 12f92363d1SSreekanth Reddy * as published by the Free Software Foundation; either version 2 13f92363d1SSreekanth Reddy * of the License, or (at your option) any later version. 14f92363d1SSreekanth Reddy * 15f92363d1SSreekanth Reddy * This program is distributed in the hope that it will be useful, 16f92363d1SSreekanth Reddy * but WITHOUT ANY WARRANTY; without even the implied warranty of 17f92363d1SSreekanth Reddy * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18f92363d1SSreekanth Reddy * GNU General Public License for more details. 19f92363d1SSreekanth Reddy * 20f92363d1SSreekanth Reddy * NO WARRANTY 21f92363d1SSreekanth Reddy * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR 22f92363d1SSreekanth Reddy * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT 23f92363d1SSreekanth Reddy * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, 24f92363d1SSreekanth Reddy * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is 25f92363d1SSreekanth Reddy * solely responsible for determining the appropriateness of using and 26f92363d1SSreekanth Reddy * distributing the Program and assumes all risks associated with its 27f92363d1SSreekanth Reddy * exercise of rights under this Agreement, including but not limited to 28f92363d1SSreekanth Reddy * the risks and costs of program errors, damage to or loss of data, 29f92363d1SSreekanth Reddy * programs or equipment, and unavailability or interruption of operations. 30f92363d1SSreekanth Reddy 31f92363d1SSreekanth Reddy * DISCLAIMER OF LIABILITY 32f92363d1SSreekanth Reddy * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY 33f92363d1SSreekanth Reddy * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 34f92363d1SSreekanth Reddy * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND 35f92363d1SSreekanth Reddy * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 36f92363d1SSreekanth Reddy * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 37f92363d1SSreekanth Reddy * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED 38f92363d1SSreekanth Reddy * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES 39f92363d1SSreekanth Reddy 40f92363d1SSreekanth Reddy * You should have received a copy of the GNU General Public License 41f92363d1SSreekanth Reddy * along with this program; if not, write to the Free Software 42f92363d1SSreekanth Reddy * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 43f92363d1SSreekanth Reddy * USA. 44f92363d1SSreekanth Reddy */ 45f92363d1SSreekanth Reddy 46f92363d1SSreekanth Reddy #include <linux/kernel.h> 47f92363d1SSreekanth Reddy #include <linux/module.h> 48f92363d1SSreekanth Reddy #include <linux/errno.h> 49f92363d1SSreekanth Reddy #include <linux/init.h> 50f92363d1SSreekanth Reddy #include <linux/slab.h> 51f92363d1SSreekanth Reddy #include <linux/types.h> 52f92363d1SSreekanth Reddy #include <linux/pci.h> 53f92363d1SSreekanth Reddy #include <linux/delay.h> 54f92363d1SSreekanth Reddy #include <linux/compat.h> 55f92363d1SSreekanth Reddy #include <linux/poll.h> 56f92363d1SSreekanth Reddy 57f92363d1SSreekanth Reddy #include <linux/io.h> 58f92363d1SSreekanth Reddy #include <linux/uaccess.h> 59f92363d1SSreekanth Reddy 60f92363d1SSreekanth Reddy #include "mpt3sas_base.h" 61f92363d1SSreekanth Reddy 62f92363d1SSreekanth Reddy /** 63f92363d1SSreekanth Reddy * _mpt3sas_raise_sigio - notifiy app 64f92363d1SSreekanth Reddy * @ioc: per adapter object 654beb4867SBart Van Assche * @event_data: ? 66f92363d1SSreekanth Reddy */ 67f92363d1SSreekanth Reddy static void 68f92363d1SSreekanth Reddy _mpt3sas_raise_sigio(struct MPT3SAS_ADAPTER *ioc, 69f92363d1SSreekanth Reddy struct SL_WH_TRIGGERS_EVENT_DATA_T *event_data) 70f92363d1SSreekanth Reddy { 71f92363d1SSreekanth Reddy Mpi2EventNotificationReply_t *mpi_reply; 72f92363d1SSreekanth Reddy u16 sz, event_data_sz; 73f92363d1SSreekanth Reddy unsigned long flags; 74f92363d1SSreekanth Reddy 75919d8a3fSJoe Perches dTriggerDiagPrintk(ioc, ioc_info(ioc, "%s: enter\n", __func__)); 76f92363d1SSreekanth Reddy 77f92363d1SSreekanth Reddy sz = offsetof(Mpi2EventNotificationReply_t, EventData) + 78f92363d1SSreekanth Reddy sizeof(struct SL_WH_TRIGGERS_EVENT_DATA_T) + 4; 79f92363d1SSreekanth Reddy mpi_reply = kzalloc(sz, GFP_KERNEL); 80f92363d1SSreekanth Reddy if (!mpi_reply) 81f92363d1SSreekanth Reddy goto out; 82f92363d1SSreekanth Reddy mpi_reply->Event = cpu_to_le16(MPI3_EVENT_DIAGNOSTIC_TRIGGER_FIRED); 83f92363d1SSreekanth Reddy event_data_sz = (sizeof(struct SL_WH_TRIGGERS_EVENT_DATA_T) + 4) / 4; 84f92363d1SSreekanth Reddy mpi_reply->EventDataLength = cpu_to_le16(event_data_sz); 85f92363d1SSreekanth Reddy memcpy(&mpi_reply->EventData, event_data, 86f92363d1SSreekanth Reddy sizeof(struct SL_WH_TRIGGERS_EVENT_DATA_T)); 87919d8a3fSJoe Perches dTriggerDiagPrintk(ioc, 88919d8a3fSJoe Perches ioc_info(ioc, "%s: add to driver event log\n", 89919d8a3fSJoe Perches __func__)); 90f92363d1SSreekanth Reddy mpt3sas_ctl_add_to_event_log(ioc, mpi_reply); 91f92363d1SSreekanth Reddy kfree(mpi_reply); 92f92363d1SSreekanth Reddy out: 93f92363d1SSreekanth Reddy 94f92363d1SSreekanth Reddy /* clearing the diag_trigger_active flag */ 95f92363d1SSreekanth Reddy spin_lock_irqsave(&ioc->diag_trigger_lock, flags); 96919d8a3fSJoe Perches dTriggerDiagPrintk(ioc, 97919d8a3fSJoe Perches ioc_info(ioc, "%s: clearing diag_trigger_active flag\n", 98919d8a3fSJoe Perches __func__)); 99f92363d1SSreekanth Reddy ioc->diag_trigger_active = 0; 100f92363d1SSreekanth Reddy spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags); 101f92363d1SSreekanth Reddy 102919d8a3fSJoe Perches dTriggerDiagPrintk(ioc, ioc_info(ioc, "%s: exit\n", 103f92363d1SSreekanth Reddy __func__)); 104f92363d1SSreekanth Reddy } 105f92363d1SSreekanth Reddy 106f92363d1SSreekanth Reddy /** 107f92363d1SSreekanth Reddy * mpt3sas_process_trigger_data - process the event data for the trigger 108f92363d1SSreekanth Reddy * @ioc: per adapter object 1094beb4867SBart Van Assche * @event_data: ? 110f92363d1SSreekanth Reddy */ 111f92363d1SSreekanth Reddy void 112f92363d1SSreekanth Reddy mpt3sas_process_trigger_data(struct MPT3SAS_ADAPTER *ioc, 113f92363d1SSreekanth Reddy struct SL_WH_TRIGGERS_EVENT_DATA_T *event_data) 114f92363d1SSreekanth Reddy { 115f92363d1SSreekanth Reddy u8 issue_reset = 0; 116*4bc50dc1SSreekanth Reddy u32 *trig_data = (u32 *)&event_data->u.master; 117f92363d1SSreekanth Reddy 118919d8a3fSJoe Perches dTriggerDiagPrintk(ioc, ioc_info(ioc, "%s: enter\n", __func__)); 119f92363d1SSreekanth Reddy 120f92363d1SSreekanth Reddy /* release the diag buffer trace */ 121f92363d1SSreekanth Reddy if ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] & 122f92363d1SSreekanth Reddy MPT3_DIAG_BUFFER_IS_RELEASED) == 0) { 123*4bc50dc1SSreekanth Reddy /* 124*4bc50dc1SSreekanth Reddy * add a log message so that user knows which event caused 125*4bc50dc1SSreekanth Reddy * the release 126*4bc50dc1SSreekanth Reddy */ 127*4bc50dc1SSreekanth Reddy ioc_info(ioc, 128*4bc50dc1SSreekanth Reddy "%s: Releasing the trace buffer. Trigger_Type 0x%08x, Data[0] 0x%08x, Data[1] 0x%08x\n", 129*4bc50dc1SSreekanth Reddy __func__, event_data->trigger_type, 130*4bc50dc1SSreekanth Reddy trig_data[0], trig_data[1]); 131f92363d1SSreekanth Reddy mpt3sas_send_diag_release(ioc, MPI2_DIAG_BUF_TYPE_TRACE, 132f92363d1SSreekanth Reddy &issue_reset); 133f92363d1SSreekanth Reddy } 134f92363d1SSreekanth Reddy 135f92363d1SSreekanth Reddy _mpt3sas_raise_sigio(ioc, event_data); 136f92363d1SSreekanth Reddy 137919d8a3fSJoe Perches dTriggerDiagPrintk(ioc, ioc_info(ioc, "%s: exit\n", 138f92363d1SSreekanth Reddy __func__)); 139f92363d1SSreekanth Reddy } 140f92363d1SSreekanth Reddy 141f92363d1SSreekanth Reddy /** 142f92363d1SSreekanth Reddy * mpt3sas_trigger_master - Master trigger handler 143f92363d1SSreekanth Reddy * @ioc: per adapter object 144f92363d1SSreekanth Reddy * @trigger_bitmask: 145f92363d1SSreekanth Reddy * 146f92363d1SSreekanth Reddy */ 147f92363d1SSreekanth Reddy void 148f92363d1SSreekanth Reddy mpt3sas_trigger_master(struct MPT3SAS_ADAPTER *ioc, u32 trigger_bitmask) 149f92363d1SSreekanth Reddy { 150f92363d1SSreekanth Reddy struct SL_WH_TRIGGERS_EVENT_DATA_T event_data; 151f92363d1SSreekanth Reddy unsigned long flags; 152f92363d1SSreekanth Reddy u8 found_match = 0; 153f92363d1SSreekanth Reddy 154f92363d1SSreekanth Reddy spin_lock_irqsave(&ioc->diag_trigger_lock, flags); 155f92363d1SSreekanth Reddy 156f92363d1SSreekanth Reddy if (trigger_bitmask & MASTER_TRIGGER_FW_FAULT || 157f92363d1SSreekanth Reddy trigger_bitmask & MASTER_TRIGGER_ADAPTER_RESET) 158f92363d1SSreekanth Reddy goto by_pass_checks; 159f92363d1SSreekanth Reddy 160f92363d1SSreekanth Reddy /* check to see if trace buffers are currently registered */ 161f92363d1SSreekanth Reddy if ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] & 162f92363d1SSreekanth Reddy MPT3_DIAG_BUFFER_IS_REGISTERED) == 0) { 163f92363d1SSreekanth Reddy spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags); 164f92363d1SSreekanth Reddy return; 165f92363d1SSreekanth Reddy } 166f92363d1SSreekanth Reddy 167f92363d1SSreekanth Reddy /* check to see if trace buffers are currently released */ 168f92363d1SSreekanth Reddy if (ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] & 169f92363d1SSreekanth Reddy MPT3_DIAG_BUFFER_IS_RELEASED) { 170f92363d1SSreekanth Reddy spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags); 171f92363d1SSreekanth Reddy return; 172f92363d1SSreekanth Reddy } 173f92363d1SSreekanth Reddy 174f92363d1SSreekanth Reddy by_pass_checks: 175f92363d1SSreekanth Reddy 176919d8a3fSJoe Perches dTriggerDiagPrintk(ioc, 177919d8a3fSJoe Perches ioc_info(ioc, "%s: enter - trigger_bitmask = 0x%08x\n", 178919d8a3fSJoe Perches __func__, trigger_bitmask)); 179f92363d1SSreekanth Reddy 180f92363d1SSreekanth Reddy /* don't send trigger if an trigger is currently active */ 181f92363d1SSreekanth Reddy if (ioc->diag_trigger_active) { 182f92363d1SSreekanth Reddy spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags); 183f92363d1SSreekanth Reddy goto out; 184f92363d1SSreekanth Reddy } 185f92363d1SSreekanth Reddy 186f92363d1SSreekanth Reddy /* check for the trigger condition */ 187f92363d1SSreekanth Reddy if (ioc->diag_trigger_master.MasterData & trigger_bitmask) { 188f92363d1SSreekanth Reddy found_match = 1; 189f92363d1SSreekanth Reddy ioc->diag_trigger_active = 1; 190919d8a3fSJoe Perches dTriggerDiagPrintk(ioc, 191919d8a3fSJoe Perches ioc_info(ioc, "%s: setting diag_trigger_active flag\n", 192919d8a3fSJoe Perches __func__)); 193f92363d1SSreekanth Reddy } 194f92363d1SSreekanth Reddy spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags); 195f92363d1SSreekanth Reddy 196f92363d1SSreekanth Reddy if (!found_match) 197f92363d1SSreekanth Reddy goto out; 198f92363d1SSreekanth Reddy 199f92363d1SSreekanth Reddy memset(&event_data, 0, sizeof(struct SL_WH_TRIGGERS_EVENT_DATA_T)); 200f92363d1SSreekanth Reddy event_data.trigger_type = MPT3SAS_TRIGGER_MASTER; 201f92363d1SSreekanth Reddy event_data.u.master.MasterData = trigger_bitmask; 202f92363d1SSreekanth Reddy 203f92363d1SSreekanth Reddy if (trigger_bitmask & MASTER_TRIGGER_FW_FAULT || 204f92363d1SSreekanth Reddy trigger_bitmask & MASTER_TRIGGER_ADAPTER_RESET) 205f92363d1SSreekanth Reddy _mpt3sas_raise_sigio(ioc, &event_data); 206f92363d1SSreekanth Reddy else 207f92363d1SSreekanth Reddy mpt3sas_send_trigger_data_event(ioc, &event_data); 208f92363d1SSreekanth Reddy 209f92363d1SSreekanth Reddy out: 210919d8a3fSJoe Perches dTriggerDiagPrintk(ioc, ioc_info(ioc, "%s: exit\n", 211f92363d1SSreekanth Reddy __func__)); 212f92363d1SSreekanth Reddy } 213f92363d1SSreekanth Reddy 214f92363d1SSreekanth Reddy /** 215f92363d1SSreekanth Reddy * mpt3sas_trigger_event - Event trigger handler 216f92363d1SSreekanth Reddy * @ioc: per adapter object 2174beb4867SBart Van Assche * @event: ? 2184beb4867SBart Van Assche * @log_entry_qualifier: ? 219f92363d1SSreekanth Reddy * 220f92363d1SSreekanth Reddy */ 221f92363d1SSreekanth Reddy void 222f92363d1SSreekanth Reddy mpt3sas_trigger_event(struct MPT3SAS_ADAPTER *ioc, u16 event, 223f92363d1SSreekanth Reddy u16 log_entry_qualifier) 224f92363d1SSreekanth Reddy { 225f92363d1SSreekanth Reddy struct SL_WH_TRIGGERS_EVENT_DATA_T event_data; 226f92363d1SSreekanth Reddy struct SL_WH_EVENT_TRIGGER_T *event_trigger; 227f92363d1SSreekanth Reddy int i; 228f92363d1SSreekanth Reddy unsigned long flags; 229f92363d1SSreekanth Reddy u8 found_match; 230f92363d1SSreekanth Reddy 231f92363d1SSreekanth Reddy spin_lock_irqsave(&ioc->diag_trigger_lock, flags); 232f92363d1SSreekanth Reddy 233f92363d1SSreekanth Reddy /* check to see if trace buffers are currently registered */ 234f92363d1SSreekanth Reddy if ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] & 235f92363d1SSreekanth Reddy MPT3_DIAG_BUFFER_IS_REGISTERED) == 0) { 236f92363d1SSreekanth Reddy spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags); 237f92363d1SSreekanth Reddy return; 238f92363d1SSreekanth Reddy } 239f92363d1SSreekanth Reddy 240f92363d1SSreekanth Reddy /* check to see if trace buffers are currently released */ 241f92363d1SSreekanth Reddy if (ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] & 242f92363d1SSreekanth Reddy MPT3_DIAG_BUFFER_IS_RELEASED) { 243f92363d1SSreekanth Reddy spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags); 244f92363d1SSreekanth Reddy return; 245f92363d1SSreekanth Reddy } 246f92363d1SSreekanth Reddy 247919d8a3fSJoe Perches dTriggerDiagPrintk(ioc, 248919d8a3fSJoe Perches ioc_info(ioc, "%s: enter - event = 0x%04x, log_entry_qualifier = 0x%04x\n", 249919d8a3fSJoe Perches __func__, event, log_entry_qualifier)); 250f92363d1SSreekanth Reddy 251f92363d1SSreekanth Reddy /* don't send trigger if an trigger is currently active */ 252f92363d1SSreekanth Reddy if (ioc->diag_trigger_active) { 253f92363d1SSreekanth Reddy spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags); 254f92363d1SSreekanth Reddy goto out; 255f92363d1SSreekanth Reddy } 256f92363d1SSreekanth Reddy 257f92363d1SSreekanth Reddy /* check for the trigger condition */ 258f92363d1SSreekanth Reddy event_trigger = ioc->diag_trigger_event.EventTriggerEntry; 259f92363d1SSreekanth Reddy for (i = 0 , found_match = 0; i < ioc->diag_trigger_event.ValidEntries 260f92363d1SSreekanth Reddy && !found_match; i++, event_trigger++) { 261f92363d1SSreekanth Reddy if (event_trigger->EventValue != event) 262f92363d1SSreekanth Reddy continue; 263f92363d1SSreekanth Reddy if (event == MPI2_EVENT_LOG_ENTRY_ADDED) { 264f92363d1SSreekanth Reddy if (event_trigger->LogEntryQualifier == 265f92363d1SSreekanth Reddy log_entry_qualifier) 266f92363d1SSreekanth Reddy found_match = 1; 267f92363d1SSreekanth Reddy continue; 268f92363d1SSreekanth Reddy } 269f92363d1SSreekanth Reddy found_match = 1; 270f92363d1SSreekanth Reddy ioc->diag_trigger_active = 1; 271919d8a3fSJoe Perches dTriggerDiagPrintk(ioc, 272919d8a3fSJoe Perches ioc_info(ioc, "%s: setting diag_trigger_active flag\n", 273919d8a3fSJoe Perches __func__)); 274f92363d1SSreekanth Reddy } 275f92363d1SSreekanth Reddy spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags); 276f92363d1SSreekanth Reddy 277f92363d1SSreekanth Reddy if (!found_match) 278f92363d1SSreekanth Reddy goto out; 279f92363d1SSreekanth Reddy 280919d8a3fSJoe Perches dTriggerDiagPrintk(ioc, 281919d8a3fSJoe Perches ioc_info(ioc, "%s: setting diag_trigger_active flag\n", 282919d8a3fSJoe Perches __func__)); 283f92363d1SSreekanth Reddy memset(&event_data, 0, sizeof(struct SL_WH_TRIGGERS_EVENT_DATA_T)); 284f92363d1SSreekanth Reddy event_data.trigger_type = MPT3SAS_TRIGGER_EVENT; 285f92363d1SSreekanth Reddy event_data.u.event.EventValue = event; 286f92363d1SSreekanth Reddy event_data.u.event.LogEntryQualifier = log_entry_qualifier; 287f92363d1SSreekanth Reddy mpt3sas_send_trigger_data_event(ioc, &event_data); 288f92363d1SSreekanth Reddy out: 289919d8a3fSJoe Perches dTriggerDiagPrintk(ioc, ioc_info(ioc, "%s: exit\n", 290f92363d1SSreekanth Reddy __func__)); 291f92363d1SSreekanth Reddy } 292f92363d1SSreekanth Reddy 293f92363d1SSreekanth Reddy /** 294f92363d1SSreekanth Reddy * mpt3sas_trigger_scsi - SCSI trigger handler 295f92363d1SSreekanth Reddy * @ioc: per adapter object 2964beb4867SBart Van Assche * @sense_key: ? 2974beb4867SBart Van Assche * @asc: ? 2984beb4867SBart Van Assche * @ascq: ? 299f92363d1SSreekanth Reddy * 300f92363d1SSreekanth Reddy */ 301f92363d1SSreekanth Reddy void 302f92363d1SSreekanth Reddy mpt3sas_trigger_scsi(struct MPT3SAS_ADAPTER *ioc, u8 sense_key, u8 asc, 303f92363d1SSreekanth Reddy u8 ascq) 304f92363d1SSreekanth Reddy { 305f92363d1SSreekanth Reddy struct SL_WH_TRIGGERS_EVENT_DATA_T event_data; 306f92363d1SSreekanth Reddy struct SL_WH_SCSI_TRIGGER_T *scsi_trigger; 307f92363d1SSreekanth Reddy int i; 308f92363d1SSreekanth Reddy unsigned long flags; 309f92363d1SSreekanth Reddy u8 found_match; 310f92363d1SSreekanth Reddy 311f92363d1SSreekanth Reddy spin_lock_irqsave(&ioc->diag_trigger_lock, flags); 312f92363d1SSreekanth Reddy 313f92363d1SSreekanth Reddy /* check to see if trace buffers are currently registered */ 314f92363d1SSreekanth Reddy if ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] & 315f92363d1SSreekanth Reddy MPT3_DIAG_BUFFER_IS_REGISTERED) == 0) { 316f92363d1SSreekanth Reddy spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags); 317f92363d1SSreekanth Reddy return; 318f92363d1SSreekanth Reddy } 319f92363d1SSreekanth Reddy 320f92363d1SSreekanth Reddy /* check to see if trace buffers are currently released */ 321f92363d1SSreekanth Reddy if (ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] & 322f92363d1SSreekanth Reddy MPT3_DIAG_BUFFER_IS_RELEASED) { 323f92363d1SSreekanth Reddy spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags); 324f92363d1SSreekanth Reddy return; 325f92363d1SSreekanth Reddy } 326f92363d1SSreekanth Reddy 327919d8a3fSJoe Perches dTriggerDiagPrintk(ioc, 328919d8a3fSJoe Perches ioc_info(ioc, "%s: enter - sense_key = 0x%02x, asc = 0x%02x, ascq = 0x%02x\n", 329919d8a3fSJoe Perches __func__, sense_key, asc, ascq)); 330f92363d1SSreekanth Reddy 331f92363d1SSreekanth Reddy /* don't send trigger if an trigger is currently active */ 332f92363d1SSreekanth Reddy if (ioc->diag_trigger_active) { 333f92363d1SSreekanth Reddy spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags); 334f92363d1SSreekanth Reddy goto out; 335f92363d1SSreekanth Reddy } 336f92363d1SSreekanth Reddy 337f92363d1SSreekanth Reddy /* check for the trigger condition */ 338f92363d1SSreekanth Reddy scsi_trigger = ioc->diag_trigger_scsi.SCSITriggerEntry; 339f92363d1SSreekanth Reddy for (i = 0 , found_match = 0; i < ioc->diag_trigger_scsi.ValidEntries 340f92363d1SSreekanth Reddy && !found_match; i++, scsi_trigger++) { 341f92363d1SSreekanth Reddy if (scsi_trigger->SenseKey != sense_key) 342f92363d1SSreekanth Reddy continue; 343f92363d1SSreekanth Reddy if (!(scsi_trigger->ASC == 0xFF || scsi_trigger->ASC == asc)) 344f92363d1SSreekanth Reddy continue; 345f92363d1SSreekanth Reddy if (!(scsi_trigger->ASCQ == 0xFF || scsi_trigger->ASCQ == ascq)) 346f92363d1SSreekanth Reddy continue; 347f92363d1SSreekanth Reddy found_match = 1; 348f92363d1SSreekanth Reddy ioc->diag_trigger_active = 1; 349f92363d1SSreekanth Reddy } 350f92363d1SSreekanth Reddy spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags); 351f92363d1SSreekanth Reddy 352f92363d1SSreekanth Reddy if (!found_match) 353f92363d1SSreekanth Reddy goto out; 354f92363d1SSreekanth Reddy 355919d8a3fSJoe Perches dTriggerDiagPrintk(ioc, 356919d8a3fSJoe Perches ioc_info(ioc, "%s: setting diag_trigger_active flag\n", 357919d8a3fSJoe Perches __func__)); 358f92363d1SSreekanth Reddy memset(&event_data, 0, sizeof(struct SL_WH_TRIGGERS_EVENT_DATA_T)); 359f92363d1SSreekanth Reddy event_data.trigger_type = MPT3SAS_TRIGGER_SCSI; 360f92363d1SSreekanth Reddy event_data.u.scsi.SenseKey = sense_key; 361f92363d1SSreekanth Reddy event_data.u.scsi.ASC = asc; 362f92363d1SSreekanth Reddy event_data.u.scsi.ASCQ = ascq; 363f92363d1SSreekanth Reddy mpt3sas_send_trigger_data_event(ioc, &event_data); 364f92363d1SSreekanth Reddy out: 365919d8a3fSJoe Perches dTriggerDiagPrintk(ioc, ioc_info(ioc, "%s: exit\n", 366f92363d1SSreekanth Reddy __func__)); 367f92363d1SSreekanth Reddy } 368f92363d1SSreekanth Reddy 369f92363d1SSreekanth Reddy /** 370f92363d1SSreekanth Reddy * mpt3sas_trigger_mpi - MPI trigger handler 371f92363d1SSreekanth Reddy * @ioc: per adapter object 3724beb4867SBart Van Assche * @ioc_status: ? 3734beb4867SBart Van Assche * @loginfo: ? 374f92363d1SSreekanth Reddy * 375f92363d1SSreekanth Reddy */ 376f92363d1SSreekanth Reddy void 377f92363d1SSreekanth Reddy mpt3sas_trigger_mpi(struct MPT3SAS_ADAPTER *ioc, u16 ioc_status, u32 loginfo) 378f92363d1SSreekanth Reddy { 379f92363d1SSreekanth Reddy struct SL_WH_TRIGGERS_EVENT_DATA_T event_data; 380f92363d1SSreekanth Reddy struct SL_WH_MPI_TRIGGER_T *mpi_trigger; 381f92363d1SSreekanth Reddy int i; 382f92363d1SSreekanth Reddy unsigned long flags; 383f92363d1SSreekanth Reddy u8 found_match; 384f92363d1SSreekanth Reddy 385f92363d1SSreekanth Reddy spin_lock_irqsave(&ioc->diag_trigger_lock, flags); 386f92363d1SSreekanth Reddy 387f92363d1SSreekanth Reddy /* check to see if trace buffers are currently registered */ 388f92363d1SSreekanth Reddy if ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] & 389f92363d1SSreekanth Reddy MPT3_DIAG_BUFFER_IS_REGISTERED) == 0) { 390f92363d1SSreekanth Reddy spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags); 391f92363d1SSreekanth Reddy return; 392f92363d1SSreekanth Reddy } 393f92363d1SSreekanth Reddy 394f92363d1SSreekanth Reddy /* check to see if trace buffers are currently released */ 395f92363d1SSreekanth Reddy if (ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] & 396f92363d1SSreekanth Reddy MPT3_DIAG_BUFFER_IS_RELEASED) { 397f92363d1SSreekanth Reddy spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags); 398f92363d1SSreekanth Reddy return; 399f92363d1SSreekanth Reddy } 400f92363d1SSreekanth Reddy 401919d8a3fSJoe Perches dTriggerDiagPrintk(ioc, 402919d8a3fSJoe Perches ioc_info(ioc, "%s: enter - ioc_status = 0x%04x, loginfo = 0x%08x\n", 403919d8a3fSJoe Perches __func__, ioc_status, loginfo)); 404f92363d1SSreekanth Reddy 405f92363d1SSreekanth Reddy /* don't send trigger if an trigger is currently active */ 406f92363d1SSreekanth Reddy if (ioc->diag_trigger_active) { 407f92363d1SSreekanth Reddy spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags); 408f92363d1SSreekanth Reddy goto out; 409f92363d1SSreekanth Reddy } 410f92363d1SSreekanth Reddy 411f92363d1SSreekanth Reddy /* check for the trigger condition */ 412f92363d1SSreekanth Reddy mpi_trigger = ioc->diag_trigger_mpi.MPITriggerEntry; 413f92363d1SSreekanth Reddy for (i = 0 , found_match = 0; i < ioc->diag_trigger_mpi.ValidEntries 414f92363d1SSreekanth Reddy && !found_match; i++, mpi_trigger++) { 415f92363d1SSreekanth Reddy if (mpi_trigger->IOCStatus != ioc_status) 416f92363d1SSreekanth Reddy continue; 417f92363d1SSreekanth Reddy if (!(mpi_trigger->IocLogInfo == 0xFFFFFFFF || 418f92363d1SSreekanth Reddy mpi_trigger->IocLogInfo == loginfo)) 419f92363d1SSreekanth Reddy continue; 420f92363d1SSreekanth Reddy found_match = 1; 421f92363d1SSreekanth Reddy ioc->diag_trigger_active = 1; 422f92363d1SSreekanth Reddy } 423f92363d1SSreekanth Reddy spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags); 424f92363d1SSreekanth Reddy 425f92363d1SSreekanth Reddy if (!found_match) 426f92363d1SSreekanth Reddy goto out; 427f92363d1SSreekanth Reddy 428919d8a3fSJoe Perches dTriggerDiagPrintk(ioc, 429919d8a3fSJoe Perches ioc_info(ioc, "%s: setting diag_trigger_active flag\n", 430919d8a3fSJoe Perches __func__)); 431f92363d1SSreekanth Reddy memset(&event_data, 0, sizeof(struct SL_WH_TRIGGERS_EVENT_DATA_T)); 432f92363d1SSreekanth Reddy event_data.trigger_type = MPT3SAS_TRIGGER_MPI; 433f92363d1SSreekanth Reddy event_data.u.mpi.IOCStatus = ioc_status; 434f92363d1SSreekanth Reddy event_data.u.mpi.IocLogInfo = loginfo; 435f92363d1SSreekanth Reddy mpt3sas_send_trigger_data_event(ioc, &event_data); 436f92363d1SSreekanth Reddy out: 437919d8a3fSJoe Perches dTriggerDiagPrintk(ioc, ioc_info(ioc, "%s: exit\n", 438f92363d1SSreekanth Reddy __func__)); 439f92363d1SSreekanth Reddy } 440