2 * This module provides common API to set Diagnostic trigger for MPT
3 * (Message Passing Technology) based controllers
5 * This code is based on drivers/scsi/mpt3sas/mpt3sas_trigger_diag.c
6 * Copyright (C) 2012-2014 LSI Corporation
7 * Copyright (C) 2013-2014 Avago Technologies
8 * (mailto: MPT-FusionLinux.pdl@avagotech.com)
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
21 * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
22 * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
23 * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
24 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
25 * solely responsible for determining the appropriateness of using and
26 * distributing the Program and assumes all risks associated with its
27 * exercise of rights under this Agreement, including but not limited to
28 * the risks and costs of program errors, damage to or loss of data,
29 * programs or equipment, and unavailability or interruption of operations.
31 * DISCLAIMER OF LIABILITY
32 * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
33 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34 * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
35 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
36 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
37 * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
38 * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
40 * You should have received a copy of the GNU General Public License
41 * along with this program; if not, write to the Free Software
42 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
46 #include <linux/kernel.h>
47 #include <linux/module.h>
48 #include <linux/errno.h>
49 #include <linux/init.h>
50 #include <linux/slab.h>
51 #include <linux/types.h>
52 #include <linux/pci.h>
53 #include <linux/delay.h>
54 #include <linux/compat.h>
55 #include <linux/poll.h>
58 #include <linux/uaccess.h>
60 #include "mpt3sas_base.h"
63 * _mpt3sas_raise_sigio - notifiy app
64 * @ioc: per adapter object
68 _mpt3sas_raise_sigio(struct MPT3SAS_ADAPTER *ioc,
69 struct SL_WH_TRIGGERS_EVENT_DATA_T *event_data)
71 Mpi2EventNotificationReply_t *mpi_reply;
72 u16 sz, event_data_sz;
75 dTriggerDiagPrintk(ioc, pr_info(MPT3SAS_FMT "%s: enter\n",
76 ioc->name, __func__));
78 sz = offsetof(Mpi2EventNotificationReply_t, EventData) +
79 sizeof(struct SL_WH_TRIGGERS_EVENT_DATA_T) + 4;
80 mpi_reply = kzalloc(sz, GFP_KERNEL);
83 mpi_reply->Event = cpu_to_le16(MPI3_EVENT_DIAGNOSTIC_TRIGGER_FIRED);
84 event_data_sz = (sizeof(struct SL_WH_TRIGGERS_EVENT_DATA_T) + 4) / 4;
85 mpi_reply->EventDataLength = cpu_to_le16(event_data_sz);
86 memcpy(&mpi_reply->EventData, event_data,
87 sizeof(struct SL_WH_TRIGGERS_EVENT_DATA_T));
88 dTriggerDiagPrintk(ioc, pr_info(MPT3SAS_FMT
89 "%s: add to driver event log\n",
90 ioc->name, __func__));
91 mpt3sas_ctl_add_to_event_log(ioc, mpi_reply);
95 /* clearing the diag_trigger_active flag */
96 spin_lock_irqsave(&ioc->diag_trigger_lock, flags);
97 dTriggerDiagPrintk(ioc, pr_info(MPT3SAS_FMT
98 "%s: clearing diag_trigger_active flag\n",
99 ioc->name, __func__));
100 ioc->diag_trigger_active = 0;
101 spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
103 dTriggerDiagPrintk(ioc, pr_info(MPT3SAS_FMT "%s: exit\n", ioc->name,
108 * mpt3sas_process_trigger_data - process the event data for the trigger
109 * @ioc: per adapter object
113 mpt3sas_process_trigger_data(struct MPT3SAS_ADAPTER *ioc,
114 struct SL_WH_TRIGGERS_EVENT_DATA_T *event_data)
118 dTriggerDiagPrintk(ioc, pr_info(MPT3SAS_FMT "%s: enter\n",
119 ioc->name, __func__));
121 /* release the diag buffer trace */
122 if ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
123 MPT3_DIAG_BUFFER_IS_RELEASED) == 0) {
124 dTriggerDiagPrintk(ioc, pr_info(MPT3SAS_FMT
125 "%s: release trace diag buffer\n", ioc->name, __func__));
126 mpt3sas_send_diag_release(ioc, MPI2_DIAG_BUF_TYPE_TRACE,
130 _mpt3sas_raise_sigio(ioc, event_data);
132 dTriggerDiagPrintk(ioc, pr_info(MPT3SAS_FMT "%s: exit\n", ioc->name,
137 * mpt3sas_trigger_master - Master trigger handler
138 * @ioc: per adapter object
143 mpt3sas_trigger_master(struct MPT3SAS_ADAPTER *ioc, u32 trigger_bitmask)
145 struct SL_WH_TRIGGERS_EVENT_DATA_T event_data;
149 spin_lock_irqsave(&ioc->diag_trigger_lock, flags);
151 if (trigger_bitmask & MASTER_TRIGGER_FW_FAULT ||
152 trigger_bitmask & MASTER_TRIGGER_ADAPTER_RESET)
155 /* check to see if trace buffers are currently registered */
156 if ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
157 MPT3_DIAG_BUFFER_IS_REGISTERED) == 0) {
158 spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
162 /* check to see if trace buffers are currently released */
163 if (ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
164 MPT3_DIAG_BUFFER_IS_RELEASED) {
165 spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
171 dTriggerDiagPrintk(ioc, pr_info(MPT3SAS_FMT
172 "%s: enter - trigger_bitmask = 0x%08x\n",
173 ioc->name, __func__, trigger_bitmask));
175 /* don't send trigger if an trigger is currently active */
176 if (ioc->diag_trigger_active) {
177 spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
181 /* check for the trigger condition */
182 if (ioc->diag_trigger_master.MasterData & trigger_bitmask) {
184 ioc->diag_trigger_active = 1;
185 dTriggerDiagPrintk(ioc, pr_info(MPT3SAS_FMT
186 "%s: setting diag_trigger_active flag\n",
187 ioc->name, __func__));
189 spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
194 memset(&event_data, 0, sizeof(struct SL_WH_TRIGGERS_EVENT_DATA_T));
195 event_data.trigger_type = MPT3SAS_TRIGGER_MASTER;
196 event_data.u.master.MasterData = trigger_bitmask;
198 if (trigger_bitmask & MASTER_TRIGGER_FW_FAULT ||
199 trigger_bitmask & MASTER_TRIGGER_ADAPTER_RESET)
200 _mpt3sas_raise_sigio(ioc, &event_data);
202 mpt3sas_send_trigger_data_event(ioc, &event_data);
205 dTriggerDiagPrintk(ioc, pr_info(MPT3SAS_FMT "%s: exit\n", ioc->name,
210 * mpt3sas_trigger_event - Event trigger handler
211 * @ioc: per adapter object
213 * @log_entry_qualifier:
217 mpt3sas_trigger_event(struct MPT3SAS_ADAPTER *ioc, u16 event,
218 u16 log_entry_qualifier)
220 struct SL_WH_TRIGGERS_EVENT_DATA_T event_data;
221 struct SL_WH_EVENT_TRIGGER_T *event_trigger;
226 spin_lock_irqsave(&ioc->diag_trigger_lock, flags);
228 /* check to see if trace buffers are currently registered */
229 if ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
230 MPT3_DIAG_BUFFER_IS_REGISTERED) == 0) {
231 spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
235 /* check to see if trace buffers are currently released */
236 if (ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
237 MPT3_DIAG_BUFFER_IS_RELEASED) {
238 spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
242 dTriggerDiagPrintk(ioc, pr_info(MPT3SAS_FMT
243 "%s: enter - event = 0x%04x, log_entry_qualifier = 0x%04x\n",
244 ioc->name, __func__, event, log_entry_qualifier));
246 /* don't send trigger if an trigger is currently active */
247 if (ioc->diag_trigger_active) {
248 spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
252 /* check for the trigger condition */
253 event_trigger = ioc->diag_trigger_event.EventTriggerEntry;
254 for (i = 0 , found_match = 0; i < ioc->diag_trigger_event.ValidEntries
255 && !found_match; i++, event_trigger++) {
256 if (event_trigger->EventValue != event)
258 if (event == MPI2_EVENT_LOG_ENTRY_ADDED) {
259 if (event_trigger->LogEntryQualifier ==
265 ioc->diag_trigger_active = 1;
266 dTriggerDiagPrintk(ioc, pr_info(MPT3SAS_FMT
267 "%s: setting diag_trigger_active flag\n",
268 ioc->name, __func__));
270 spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
275 dTriggerDiagPrintk(ioc, pr_info(MPT3SAS_FMT
276 "%s: setting diag_trigger_active flag\n",
277 ioc->name, __func__));
278 memset(&event_data, 0, sizeof(struct SL_WH_TRIGGERS_EVENT_DATA_T));
279 event_data.trigger_type = MPT3SAS_TRIGGER_EVENT;
280 event_data.u.event.EventValue = event;
281 event_data.u.event.LogEntryQualifier = log_entry_qualifier;
282 mpt3sas_send_trigger_data_event(ioc, &event_data);
284 dTriggerDiagPrintk(ioc, pr_info(MPT3SAS_FMT "%s: exit\n", ioc->name,
289 * mpt3sas_trigger_scsi - SCSI trigger handler
290 * @ioc: per adapter object
297 mpt3sas_trigger_scsi(struct MPT3SAS_ADAPTER *ioc, u8 sense_key, u8 asc,
300 struct SL_WH_TRIGGERS_EVENT_DATA_T event_data;
301 struct SL_WH_SCSI_TRIGGER_T *scsi_trigger;
306 spin_lock_irqsave(&ioc->diag_trigger_lock, flags);
308 /* check to see if trace buffers are currently registered */
309 if ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
310 MPT3_DIAG_BUFFER_IS_REGISTERED) == 0) {
311 spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
315 /* check to see if trace buffers are currently released */
316 if (ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
317 MPT3_DIAG_BUFFER_IS_RELEASED) {
318 spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
322 dTriggerDiagPrintk(ioc, pr_info(MPT3SAS_FMT
323 "%s: enter - sense_key = 0x%02x, asc = 0x%02x, ascq = 0x%02x\n",
324 ioc->name, __func__, sense_key, asc, ascq));
326 /* don't send trigger if an trigger is currently active */
327 if (ioc->diag_trigger_active) {
328 spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
332 /* check for the trigger condition */
333 scsi_trigger = ioc->diag_trigger_scsi.SCSITriggerEntry;
334 for (i = 0 , found_match = 0; i < ioc->diag_trigger_scsi.ValidEntries
335 && !found_match; i++, scsi_trigger++) {
336 if (scsi_trigger->SenseKey != sense_key)
338 if (!(scsi_trigger->ASC == 0xFF || scsi_trigger->ASC == asc))
340 if (!(scsi_trigger->ASCQ == 0xFF || scsi_trigger->ASCQ == ascq))
343 ioc->diag_trigger_active = 1;
345 spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
350 dTriggerDiagPrintk(ioc, pr_info(MPT3SAS_FMT
351 "%s: setting diag_trigger_active flag\n",
352 ioc->name, __func__));
353 memset(&event_data, 0, sizeof(struct SL_WH_TRIGGERS_EVENT_DATA_T));
354 event_data.trigger_type = MPT3SAS_TRIGGER_SCSI;
355 event_data.u.scsi.SenseKey = sense_key;
356 event_data.u.scsi.ASC = asc;
357 event_data.u.scsi.ASCQ = ascq;
358 mpt3sas_send_trigger_data_event(ioc, &event_data);
360 dTriggerDiagPrintk(ioc, pr_info(MPT3SAS_FMT "%s: exit\n", ioc->name,
365 * mpt3sas_trigger_mpi - MPI trigger handler
366 * @ioc: per adapter object
372 mpt3sas_trigger_mpi(struct MPT3SAS_ADAPTER *ioc, u16 ioc_status, u32 loginfo)
374 struct SL_WH_TRIGGERS_EVENT_DATA_T event_data;
375 struct SL_WH_MPI_TRIGGER_T *mpi_trigger;
380 spin_lock_irqsave(&ioc->diag_trigger_lock, flags);
382 /* check to see if trace buffers are currently registered */
383 if ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
384 MPT3_DIAG_BUFFER_IS_REGISTERED) == 0) {
385 spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
389 /* check to see if trace buffers are currently released */
390 if (ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
391 MPT3_DIAG_BUFFER_IS_RELEASED) {
392 spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
396 dTriggerDiagPrintk(ioc, pr_info(MPT3SAS_FMT
397 "%s: enter - ioc_status = 0x%04x, loginfo = 0x%08x\n",
398 ioc->name, __func__, ioc_status, loginfo));
400 /* don't send trigger if an trigger is currently active */
401 if (ioc->diag_trigger_active) {
402 spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
406 /* check for the trigger condition */
407 mpi_trigger = ioc->diag_trigger_mpi.MPITriggerEntry;
408 for (i = 0 , found_match = 0; i < ioc->diag_trigger_mpi.ValidEntries
409 && !found_match; i++, mpi_trigger++) {
410 if (mpi_trigger->IOCStatus != ioc_status)
412 if (!(mpi_trigger->IocLogInfo == 0xFFFFFFFF ||
413 mpi_trigger->IocLogInfo == loginfo))
416 ioc->diag_trigger_active = 1;
418 spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
423 dTriggerDiagPrintk(ioc, pr_info(MPT3SAS_FMT
424 "%s: setting diag_trigger_active flag\n",
425 ioc->name, __func__));
426 memset(&event_data, 0, sizeof(struct SL_WH_TRIGGERS_EVENT_DATA_T));
427 event_data.trigger_type = MPT3SAS_TRIGGER_MPI;
428 event_data.u.mpi.IOCStatus = ioc_status;
429 event_data.u.mpi.IocLogInfo = loginfo;
430 mpt3sas_send_trigger_data_event(ioc, &event_data);
432 dTriggerDiagPrintk(ioc, pr_info(MPT3SAS_FMT "%s: exit\n", ioc->name,