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; 1164bc50dc1SSreekanth 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) { 1234bc50dc1SSreekanth Reddy /* 1244bc50dc1SSreekanth Reddy * add a log message so that user knows which event caused 1254bc50dc1SSreekanth Reddy * the release 1264bc50dc1SSreekanth Reddy */ 1274bc50dc1SSreekanth Reddy ioc_info(ioc, 1284bc50dc1SSreekanth Reddy "%s: Releasing the trace buffer. Trigger_Type 0x%08x, Data[0] 0x%08x, Data[1] 0x%08x\n", 1294bc50dc1SSreekanth Reddy __func__, event_data->trigger_type, 1304bc50dc1SSreekanth 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 135*688c1a0aSSuganath Prabu S ioc->htb_rel.buffer_rel_condition = MPT3_DIAG_BUFFER_REL_TRIGGER; 136*688c1a0aSSuganath Prabu S if (event_data) { 137*688c1a0aSSuganath Prabu S ioc->htb_rel.trigger_type = event_data->trigger_type; 138*688c1a0aSSuganath Prabu S switch (event_data->trigger_type) { 139*688c1a0aSSuganath Prabu S case MPT3SAS_TRIGGER_SCSI: 140*688c1a0aSSuganath Prabu S memcpy(&ioc->htb_rel.trigger_info_dwords, 141*688c1a0aSSuganath Prabu S &event_data->u.scsi, 142*688c1a0aSSuganath Prabu S sizeof(struct SL_WH_SCSI_TRIGGER_T)); 143*688c1a0aSSuganath Prabu S break; 144*688c1a0aSSuganath Prabu S case MPT3SAS_TRIGGER_MPI: 145*688c1a0aSSuganath Prabu S memcpy(&ioc->htb_rel.trigger_info_dwords, 146*688c1a0aSSuganath Prabu S &event_data->u.mpi, 147*688c1a0aSSuganath Prabu S sizeof(struct SL_WH_MPI_TRIGGER_T)); 148*688c1a0aSSuganath Prabu S break; 149*688c1a0aSSuganath Prabu S case MPT3SAS_TRIGGER_MASTER: 150*688c1a0aSSuganath Prabu S ioc->htb_rel.trigger_info_dwords[0] = 151*688c1a0aSSuganath Prabu S event_data->u.master.MasterData; 152*688c1a0aSSuganath Prabu S break; 153*688c1a0aSSuganath Prabu S case MPT3SAS_TRIGGER_EVENT: 154*688c1a0aSSuganath Prabu S memcpy(&ioc->htb_rel.trigger_info_dwords, 155*688c1a0aSSuganath Prabu S &event_data->u.event, 156*688c1a0aSSuganath Prabu S sizeof(struct SL_WH_EVENT_TRIGGER_T)); 157*688c1a0aSSuganath Prabu S break; 158*688c1a0aSSuganath Prabu S default: 159*688c1a0aSSuganath Prabu S ioc_err(ioc, "%d - Is not a valid Trigger type\n", 160*688c1a0aSSuganath Prabu S event_data->trigger_type); 161*688c1a0aSSuganath Prabu S break; 162*688c1a0aSSuganath Prabu S } 163*688c1a0aSSuganath Prabu S } 164f92363d1SSreekanth Reddy _mpt3sas_raise_sigio(ioc, event_data); 165f92363d1SSreekanth Reddy 166919d8a3fSJoe Perches dTriggerDiagPrintk(ioc, ioc_info(ioc, "%s: exit\n", 167f92363d1SSreekanth Reddy __func__)); 168f92363d1SSreekanth Reddy } 169f92363d1SSreekanth Reddy 170f92363d1SSreekanth Reddy /** 171f92363d1SSreekanth Reddy * mpt3sas_trigger_master - Master trigger handler 172f92363d1SSreekanth Reddy * @ioc: per adapter object 173f92363d1SSreekanth Reddy * @trigger_bitmask: 174f92363d1SSreekanth Reddy * 175f92363d1SSreekanth Reddy */ 176f92363d1SSreekanth Reddy void 177f92363d1SSreekanth Reddy mpt3sas_trigger_master(struct MPT3SAS_ADAPTER *ioc, u32 trigger_bitmask) 178f92363d1SSreekanth Reddy { 179f92363d1SSreekanth Reddy struct SL_WH_TRIGGERS_EVENT_DATA_T event_data; 180f92363d1SSreekanth Reddy unsigned long flags; 181f92363d1SSreekanth Reddy u8 found_match = 0; 182f92363d1SSreekanth Reddy 183f92363d1SSreekanth Reddy spin_lock_irqsave(&ioc->diag_trigger_lock, flags); 184f92363d1SSreekanth Reddy 185f92363d1SSreekanth Reddy if (trigger_bitmask & MASTER_TRIGGER_FW_FAULT || 186f92363d1SSreekanth Reddy trigger_bitmask & MASTER_TRIGGER_ADAPTER_RESET) 187f92363d1SSreekanth Reddy goto by_pass_checks; 188f92363d1SSreekanth Reddy 189f92363d1SSreekanth Reddy /* check to see if trace buffers are currently registered */ 190f92363d1SSreekanth Reddy if ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] & 191f92363d1SSreekanth Reddy MPT3_DIAG_BUFFER_IS_REGISTERED) == 0) { 192f92363d1SSreekanth Reddy spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags); 193f92363d1SSreekanth Reddy return; 194f92363d1SSreekanth Reddy } 195f92363d1SSreekanth Reddy 196f92363d1SSreekanth Reddy /* check to see if trace buffers are currently released */ 197f92363d1SSreekanth Reddy if (ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] & 198f92363d1SSreekanth Reddy MPT3_DIAG_BUFFER_IS_RELEASED) { 199f92363d1SSreekanth Reddy spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags); 200f92363d1SSreekanth Reddy return; 201f92363d1SSreekanth Reddy } 202f92363d1SSreekanth Reddy 203f92363d1SSreekanth Reddy by_pass_checks: 204f92363d1SSreekanth Reddy 205919d8a3fSJoe Perches dTriggerDiagPrintk(ioc, 206919d8a3fSJoe Perches ioc_info(ioc, "%s: enter - trigger_bitmask = 0x%08x\n", 207919d8a3fSJoe Perches __func__, trigger_bitmask)); 208f92363d1SSreekanth Reddy 209f92363d1SSreekanth Reddy /* don't send trigger if an trigger is currently active */ 210f92363d1SSreekanth Reddy if (ioc->diag_trigger_active) { 211f92363d1SSreekanth Reddy spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags); 212f92363d1SSreekanth Reddy goto out; 213f92363d1SSreekanth Reddy } 214f92363d1SSreekanth Reddy 215f92363d1SSreekanth Reddy /* check for the trigger condition */ 216f92363d1SSreekanth Reddy if (ioc->diag_trigger_master.MasterData & trigger_bitmask) { 217f92363d1SSreekanth Reddy found_match = 1; 218f92363d1SSreekanth Reddy ioc->diag_trigger_active = 1; 219919d8a3fSJoe Perches dTriggerDiagPrintk(ioc, 220919d8a3fSJoe Perches ioc_info(ioc, "%s: setting diag_trigger_active flag\n", 221919d8a3fSJoe Perches __func__)); 222f92363d1SSreekanth Reddy } 223f92363d1SSreekanth Reddy spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags); 224f92363d1SSreekanth Reddy 225f92363d1SSreekanth Reddy if (!found_match) 226f92363d1SSreekanth Reddy goto out; 227f92363d1SSreekanth Reddy 228f92363d1SSreekanth Reddy memset(&event_data, 0, sizeof(struct SL_WH_TRIGGERS_EVENT_DATA_T)); 229f92363d1SSreekanth Reddy event_data.trigger_type = MPT3SAS_TRIGGER_MASTER; 230f92363d1SSreekanth Reddy event_data.u.master.MasterData = trigger_bitmask; 231f92363d1SSreekanth Reddy 232f92363d1SSreekanth Reddy if (trigger_bitmask & MASTER_TRIGGER_FW_FAULT || 233*688c1a0aSSuganath Prabu S trigger_bitmask & MASTER_TRIGGER_ADAPTER_RESET) { 234*688c1a0aSSuganath Prabu S ioc->htb_rel.trigger_type = MPT3SAS_TRIGGER_MASTER; 235*688c1a0aSSuganath Prabu S ioc->htb_rel.trigger_info_dwords[0] = trigger_bitmask; 236*688c1a0aSSuganath Prabu S if (ioc->reset_from_user) 237*688c1a0aSSuganath Prabu S ioc->htb_rel.trigger_info_dwords[1] = 238*688c1a0aSSuganath Prabu S MPT_DIAG_RESET_ISSUED_BY_USER; 239f92363d1SSreekanth Reddy _mpt3sas_raise_sigio(ioc, &event_data); 240*688c1a0aSSuganath Prabu S } else 241f92363d1SSreekanth Reddy mpt3sas_send_trigger_data_event(ioc, &event_data); 242f92363d1SSreekanth Reddy 243f92363d1SSreekanth Reddy out: 244919d8a3fSJoe Perches dTriggerDiagPrintk(ioc, ioc_info(ioc, "%s: exit\n", 245f92363d1SSreekanth Reddy __func__)); 246f92363d1SSreekanth Reddy } 247f92363d1SSreekanth Reddy 248f92363d1SSreekanth Reddy /** 249f92363d1SSreekanth Reddy * mpt3sas_trigger_event - Event trigger handler 250f92363d1SSreekanth Reddy * @ioc: per adapter object 2514beb4867SBart Van Assche * @event: ? 2524beb4867SBart Van Assche * @log_entry_qualifier: ? 253f92363d1SSreekanth Reddy * 254f92363d1SSreekanth Reddy */ 255f92363d1SSreekanth Reddy void 256f92363d1SSreekanth Reddy mpt3sas_trigger_event(struct MPT3SAS_ADAPTER *ioc, u16 event, 257f92363d1SSreekanth Reddy u16 log_entry_qualifier) 258f92363d1SSreekanth Reddy { 259f92363d1SSreekanth Reddy struct SL_WH_TRIGGERS_EVENT_DATA_T event_data; 260f92363d1SSreekanth Reddy struct SL_WH_EVENT_TRIGGER_T *event_trigger; 261f92363d1SSreekanth Reddy int i; 262f92363d1SSreekanth Reddy unsigned long flags; 263f92363d1SSreekanth Reddy u8 found_match; 264f92363d1SSreekanth Reddy 265f92363d1SSreekanth Reddy spin_lock_irqsave(&ioc->diag_trigger_lock, flags); 266f92363d1SSreekanth Reddy 267f92363d1SSreekanth Reddy /* check to see if trace buffers are currently registered */ 268f92363d1SSreekanth Reddy if ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] & 269f92363d1SSreekanth Reddy MPT3_DIAG_BUFFER_IS_REGISTERED) == 0) { 270f92363d1SSreekanth Reddy spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags); 271f92363d1SSreekanth Reddy return; 272f92363d1SSreekanth Reddy } 273f92363d1SSreekanth Reddy 274f92363d1SSreekanth Reddy /* check to see if trace buffers are currently released */ 275f92363d1SSreekanth Reddy if (ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] & 276f92363d1SSreekanth Reddy MPT3_DIAG_BUFFER_IS_RELEASED) { 277f92363d1SSreekanth Reddy spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags); 278f92363d1SSreekanth Reddy return; 279f92363d1SSreekanth Reddy } 280f92363d1SSreekanth Reddy 281919d8a3fSJoe Perches dTriggerDiagPrintk(ioc, 282919d8a3fSJoe Perches ioc_info(ioc, "%s: enter - event = 0x%04x, log_entry_qualifier = 0x%04x\n", 283919d8a3fSJoe Perches __func__, event, log_entry_qualifier)); 284f92363d1SSreekanth Reddy 285f92363d1SSreekanth Reddy /* don't send trigger if an trigger is currently active */ 286f92363d1SSreekanth Reddy if (ioc->diag_trigger_active) { 287f92363d1SSreekanth Reddy spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags); 288f92363d1SSreekanth Reddy goto out; 289f92363d1SSreekanth Reddy } 290f92363d1SSreekanth Reddy 291f92363d1SSreekanth Reddy /* check for the trigger condition */ 292f92363d1SSreekanth Reddy event_trigger = ioc->diag_trigger_event.EventTriggerEntry; 293f92363d1SSreekanth Reddy for (i = 0 , found_match = 0; i < ioc->diag_trigger_event.ValidEntries 294f92363d1SSreekanth Reddy && !found_match; i++, event_trigger++) { 295f92363d1SSreekanth Reddy if (event_trigger->EventValue != event) 296f92363d1SSreekanth Reddy continue; 297f92363d1SSreekanth Reddy if (event == MPI2_EVENT_LOG_ENTRY_ADDED) { 298f92363d1SSreekanth Reddy if (event_trigger->LogEntryQualifier == 299f92363d1SSreekanth Reddy log_entry_qualifier) 300f92363d1SSreekanth Reddy found_match = 1; 301f92363d1SSreekanth Reddy continue; 302f92363d1SSreekanth Reddy } 303f92363d1SSreekanth Reddy found_match = 1; 304f92363d1SSreekanth Reddy ioc->diag_trigger_active = 1; 305919d8a3fSJoe Perches dTriggerDiagPrintk(ioc, 306919d8a3fSJoe Perches ioc_info(ioc, "%s: setting diag_trigger_active flag\n", 307919d8a3fSJoe Perches __func__)); 308f92363d1SSreekanth Reddy } 309f92363d1SSreekanth Reddy spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags); 310f92363d1SSreekanth Reddy 311f92363d1SSreekanth Reddy if (!found_match) 312f92363d1SSreekanth Reddy goto out; 313f92363d1SSreekanth Reddy 314919d8a3fSJoe Perches dTriggerDiagPrintk(ioc, 315919d8a3fSJoe Perches ioc_info(ioc, "%s: setting diag_trigger_active flag\n", 316919d8a3fSJoe Perches __func__)); 317f92363d1SSreekanth Reddy memset(&event_data, 0, sizeof(struct SL_WH_TRIGGERS_EVENT_DATA_T)); 318f92363d1SSreekanth Reddy event_data.trigger_type = MPT3SAS_TRIGGER_EVENT; 319f92363d1SSreekanth Reddy event_data.u.event.EventValue = event; 320f92363d1SSreekanth Reddy event_data.u.event.LogEntryQualifier = log_entry_qualifier; 321f92363d1SSreekanth Reddy mpt3sas_send_trigger_data_event(ioc, &event_data); 322f92363d1SSreekanth Reddy out: 323919d8a3fSJoe Perches dTriggerDiagPrintk(ioc, ioc_info(ioc, "%s: exit\n", 324f92363d1SSreekanth Reddy __func__)); 325f92363d1SSreekanth Reddy } 326f92363d1SSreekanth Reddy 327f92363d1SSreekanth Reddy /** 328f92363d1SSreekanth Reddy * mpt3sas_trigger_scsi - SCSI trigger handler 329f92363d1SSreekanth Reddy * @ioc: per adapter object 3304beb4867SBart Van Assche * @sense_key: ? 3314beb4867SBart Van Assche * @asc: ? 3324beb4867SBart Van Assche * @ascq: ? 333f92363d1SSreekanth Reddy * 334f92363d1SSreekanth Reddy */ 335f92363d1SSreekanth Reddy void 336f92363d1SSreekanth Reddy mpt3sas_trigger_scsi(struct MPT3SAS_ADAPTER *ioc, u8 sense_key, u8 asc, 337f92363d1SSreekanth Reddy u8 ascq) 338f92363d1SSreekanth Reddy { 339f92363d1SSreekanth Reddy struct SL_WH_TRIGGERS_EVENT_DATA_T event_data; 340f92363d1SSreekanth Reddy struct SL_WH_SCSI_TRIGGER_T *scsi_trigger; 341f92363d1SSreekanth Reddy int i; 342f92363d1SSreekanth Reddy unsigned long flags; 343f92363d1SSreekanth Reddy u8 found_match; 344f92363d1SSreekanth Reddy 345f92363d1SSreekanth Reddy spin_lock_irqsave(&ioc->diag_trigger_lock, flags); 346f92363d1SSreekanth Reddy 347f92363d1SSreekanth Reddy /* check to see if trace buffers are currently registered */ 348f92363d1SSreekanth Reddy if ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] & 349f92363d1SSreekanth Reddy MPT3_DIAG_BUFFER_IS_REGISTERED) == 0) { 350f92363d1SSreekanth Reddy spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags); 351f92363d1SSreekanth Reddy return; 352f92363d1SSreekanth Reddy } 353f92363d1SSreekanth Reddy 354f92363d1SSreekanth Reddy /* check to see if trace buffers are currently released */ 355f92363d1SSreekanth Reddy if (ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] & 356f92363d1SSreekanth Reddy MPT3_DIAG_BUFFER_IS_RELEASED) { 357f92363d1SSreekanth Reddy spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags); 358f92363d1SSreekanth Reddy return; 359f92363d1SSreekanth Reddy } 360f92363d1SSreekanth Reddy 361919d8a3fSJoe Perches dTriggerDiagPrintk(ioc, 362919d8a3fSJoe Perches ioc_info(ioc, "%s: enter - sense_key = 0x%02x, asc = 0x%02x, ascq = 0x%02x\n", 363919d8a3fSJoe Perches __func__, sense_key, asc, ascq)); 364f92363d1SSreekanth Reddy 365f92363d1SSreekanth Reddy /* don't send trigger if an trigger is currently active */ 366f92363d1SSreekanth Reddy if (ioc->diag_trigger_active) { 367f92363d1SSreekanth Reddy spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags); 368f92363d1SSreekanth Reddy goto out; 369f92363d1SSreekanth Reddy } 370f92363d1SSreekanth Reddy 371f92363d1SSreekanth Reddy /* check for the trigger condition */ 372f92363d1SSreekanth Reddy scsi_trigger = ioc->diag_trigger_scsi.SCSITriggerEntry; 373f92363d1SSreekanth Reddy for (i = 0 , found_match = 0; i < ioc->diag_trigger_scsi.ValidEntries 374f92363d1SSreekanth Reddy && !found_match; i++, scsi_trigger++) { 375f92363d1SSreekanth Reddy if (scsi_trigger->SenseKey != sense_key) 376f92363d1SSreekanth Reddy continue; 377f92363d1SSreekanth Reddy if (!(scsi_trigger->ASC == 0xFF || scsi_trigger->ASC == asc)) 378f92363d1SSreekanth Reddy continue; 379f92363d1SSreekanth Reddy if (!(scsi_trigger->ASCQ == 0xFF || scsi_trigger->ASCQ == ascq)) 380f92363d1SSreekanth Reddy continue; 381f92363d1SSreekanth Reddy found_match = 1; 382f92363d1SSreekanth Reddy ioc->diag_trigger_active = 1; 383f92363d1SSreekanth Reddy } 384f92363d1SSreekanth Reddy spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags); 385f92363d1SSreekanth Reddy 386f92363d1SSreekanth Reddy if (!found_match) 387f92363d1SSreekanth Reddy goto out; 388f92363d1SSreekanth Reddy 389919d8a3fSJoe Perches dTriggerDiagPrintk(ioc, 390919d8a3fSJoe Perches ioc_info(ioc, "%s: setting diag_trigger_active flag\n", 391919d8a3fSJoe Perches __func__)); 392f92363d1SSreekanth Reddy memset(&event_data, 0, sizeof(struct SL_WH_TRIGGERS_EVENT_DATA_T)); 393f92363d1SSreekanth Reddy event_data.trigger_type = MPT3SAS_TRIGGER_SCSI; 394f92363d1SSreekanth Reddy event_data.u.scsi.SenseKey = sense_key; 395f92363d1SSreekanth Reddy event_data.u.scsi.ASC = asc; 396f92363d1SSreekanth Reddy event_data.u.scsi.ASCQ = ascq; 397f92363d1SSreekanth Reddy mpt3sas_send_trigger_data_event(ioc, &event_data); 398f92363d1SSreekanth Reddy out: 399919d8a3fSJoe Perches dTriggerDiagPrintk(ioc, ioc_info(ioc, "%s: exit\n", 400f92363d1SSreekanth Reddy __func__)); 401f92363d1SSreekanth Reddy } 402f92363d1SSreekanth Reddy 403f92363d1SSreekanth Reddy /** 404f92363d1SSreekanth Reddy * mpt3sas_trigger_mpi - MPI trigger handler 405f92363d1SSreekanth Reddy * @ioc: per adapter object 4064beb4867SBart Van Assche * @ioc_status: ? 4074beb4867SBart Van Assche * @loginfo: ? 408f92363d1SSreekanth Reddy * 409f92363d1SSreekanth Reddy */ 410f92363d1SSreekanth Reddy void 411f92363d1SSreekanth Reddy mpt3sas_trigger_mpi(struct MPT3SAS_ADAPTER *ioc, u16 ioc_status, u32 loginfo) 412f92363d1SSreekanth Reddy { 413f92363d1SSreekanth Reddy struct SL_WH_TRIGGERS_EVENT_DATA_T event_data; 414f92363d1SSreekanth Reddy struct SL_WH_MPI_TRIGGER_T *mpi_trigger; 415f92363d1SSreekanth Reddy int i; 416f92363d1SSreekanth Reddy unsigned long flags; 417f92363d1SSreekanth Reddy u8 found_match; 418f92363d1SSreekanth Reddy 419f92363d1SSreekanth Reddy spin_lock_irqsave(&ioc->diag_trigger_lock, flags); 420f92363d1SSreekanth Reddy 421f92363d1SSreekanth Reddy /* check to see if trace buffers are currently registered */ 422f92363d1SSreekanth Reddy if ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] & 423f92363d1SSreekanth Reddy MPT3_DIAG_BUFFER_IS_REGISTERED) == 0) { 424f92363d1SSreekanth Reddy spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags); 425f92363d1SSreekanth Reddy return; 426f92363d1SSreekanth Reddy } 427f92363d1SSreekanth Reddy 428f92363d1SSreekanth Reddy /* check to see if trace buffers are currently released */ 429f92363d1SSreekanth Reddy if (ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] & 430f92363d1SSreekanth Reddy MPT3_DIAG_BUFFER_IS_RELEASED) { 431f92363d1SSreekanth Reddy spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags); 432f92363d1SSreekanth Reddy return; 433f92363d1SSreekanth Reddy } 434f92363d1SSreekanth Reddy 435919d8a3fSJoe Perches dTriggerDiagPrintk(ioc, 436919d8a3fSJoe Perches ioc_info(ioc, "%s: enter - ioc_status = 0x%04x, loginfo = 0x%08x\n", 437919d8a3fSJoe Perches __func__, ioc_status, loginfo)); 438f92363d1SSreekanth Reddy 439f92363d1SSreekanth Reddy /* don't send trigger if an trigger is currently active */ 440f92363d1SSreekanth Reddy if (ioc->diag_trigger_active) { 441f92363d1SSreekanth Reddy spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags); 442f92363d1SSreekanth Reddy goto out; 443f92363d1SSreekanth Reddy } 444f92363d1SSreekanth Reddy 445f92363d1SSreekanth Reddy /* check for the trigger condition */ 446f92363d1SSreekanth Reddy mpi_trigger = ioc->diag_trigger_mpi.MPITriggerEntry; 447f92363d1SSreekanth Reddy for (i = 0 , found_match = 0; i < ioc->diag_trigger_mpi.ValidEntries 448f92363d1SSreekanth Reddy && !found_match; i++, mpi_trigger++) { 449f92363d1SSreekanth Reddy if (mpi_trigger->IOCStatus != ioc_status) 450f92363d1SSreekanth Reddy continue; 451f92363d1SSreekanth Reddy if (!(mpi_trigger->IocLogInfo == 0xFFFFFFFF || 452f92363d1SSreekanth Reddy mpi_trigger->IocLogInfo == loginfo)) 453f92363d1SSreekanth Reddy continue; 454f92363d1SSreekanth Reddy found_match = 1; 455f92363d1SSreekanth Reddy ioc->diag_trigger_active = 1; 456f92363d1SSreekanth Reddy } 457f92363d1SSreekanth Reddy spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags); 458f92363d1SSreekanth Reddy 459f92363d1SSreekanth Reddy if (!found_match) 460f92363d1SSreekanth Reddy goto out; 461f92363d1SSreekanth Reddy 462919d8a3fSJoe Perches dTriggerDiagPrintk(ioc, 463919d8a3fSJoe Perches ioc_info(ioc, "%s: setting diag_trigger_active flag\n", 464919d8a3fSJoe Perches __func__)); 465f92363d1SSreekanth Reddy memset(&event_data, 0, sizeof(struct SL_WH_TRIGGERS_EVENT_DATA_T)); 466f92363d1SSreekanth Reddy event_data.trigger_type = MPT3SAS_TRIGGER_MPI; 467f92363d1SSreekanth Reddy event_data.u.mpi.IOCStatus = ioc_status; 468f92363d1SSreekanth Reddy event_data.u.mpi.IocLogInfo = loginfo; 469f92363d1SSreekanth Reddy mpt3sas_send_trigger_data_event(ioc, &event_data); 470f92363d1SSreekanth Reddy out: 471919d8a3fSJoe Perches dTriggerDiagPrintk(ioc, ioc_info(ioc, "%s: exit\n", 472f92363d1SSreekanth Reddy __func__)); 473f92363d1SSreekanth Reddy } 474