1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
|
/*
* This module provides common API to set Diagnostic trigger for MPT
* (Message Passing Technology) based controllers
*
* This code is based on drivers/scsi/mpt3sas/mpt3sas_trigger_diag.c
* Copyright (C) 2012-2014 LSI Corporation
* Copyright (C) 2013-2014 Avago Technologies
* (mailto: MPT-FusionLinux.pdl@avagotech.com)
*
* 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; either version 2
* of the License, or (at your option) any later version.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*/
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/errno.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/types.h>
#include <linux/pci.h>
#include <linux/delay.h>
#include <linux/compat.h>
#include <linux/poll.h>
#include <linux/io.h>
#include <linux/uaccess.h>
#include "mpt3sas_base.h"
/**
* _mpt3sas_raise_sigio - notifiy app
* @ioc: per adapter object
* @event_data: ?
*/
static void
_mpt3sas_raise_sigio(struct MPT3SAS_ADAPTER *ioc,
struct SL_WH_TRIGGERS_EVENT_DATA_T *event_data)
{
Mpi2EventNotificationReply_t *mpi_reply;
u16 sz, event_data_sz;
unsigned long flags;
dTriggerDiagPrintk(ioc, pr_info(MPT3SAS_FMT "%s: enter\n",
ioc->name, __func__));
sz = offsetof(Mpi2EventNotificationReply_t, EventData) +
sizeof(struct SL_WH_TRIGGERS_EVENT_DATA_T) + 4;
mpi_reply = kzalloc(sz, GFP_KERNEL);
if (!mpi_reply)
goto out;
mpi_reply->Event = cpu_to_le16(MPI3_EVENT_DIAGNOSTIC_TRIGGER_FIRED);
event_data_sz = (sizeof(struct SL_WH_TRIGGERS_EVENT_DATA_T) + 4) / 4;
mpi_reply->EventDataLength = cpu_to_le16(event_data_sz);
memcpy(&mpi_reply->EventData, event_data,
sizeof(struct SL_WH_TRIGGERS_EVENT_DATA_T));
dTriggerDiagPrintk(ioc, pr_info(MPT3SAS_FMT
"%s: add to driver event log\n",
ioc->name, __func__));
mpt3sas_ctl_add_to_event_log(ioc, mpi_reply);
kfree(mpi_reply);
out:
/* clearing the diag_trigger_active flag */
spin_lock_irqsave(&ioc->diag_trigger_lock, flags);
dTriggerDiagPrintk(ioc, pr_info(MPT3SAS_FMT
"%s: clearing diag_trigger_active flag\n",
ioc->name, __func__));
ioc->diag_trigger_active = 0;
spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
dTriggerDiagPrintk(ioc, pr_info(MPT3SAS_FMT "%s: exit\n", ioc->name,
__func__));
}
/**
* mpt3sas_process_trigger_data - process the event data for the trigger
* @ioc: per adapter object
* @event_data: ?
*/
void
mpt3sas_process_trigger_data(struct MPT3SAS_ADAPTER *ioc,
struct SL_WH_TRIGGERS_EVENT_DATA_T *event_data)
{
u8 issue_reset = 0;
dTriggerDiagPrintk(ioc, pr_info(MPT3SAS_FMT "%s: enter\n",
ioc->name, __func__));
/* release the diag buffer trace */
if ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
MPT3_DIAG_BUFFER_IS_RELEASED) == 0) {
dTriggerDiagPrintk(ioc, pr_info(MPT3SAS_FMT
"%s: release trace diag buffer\n", ioc->name, __func__));
mpt3sas_send_diag_release(ioc, MPI2_DIAG_BUF_TYPE_TRACE,
&issue_reset);
}
_mpt3sas_raise_sigio(ioc, event_data);
dTriggerDiagPrintk(ioc, pr_info(MPT3SAS_FMT "%s: exit\n", ioc->name,
__func__));
}
/**
* mpt3sas_trigger_master - Master trigger handler
* @ioc: per adapter object
* @trigger_bitmask:
*
*/
void
mpt3sas_trigger_master(struct MPT3SAS_ADAPTER *ioc, u32 trigger_bitmask)
{
struct SL_WH_TRIGGERS_EVENT_DATA_T event_data;
unsigned long flags;
u8 found_match = 0;
spin_lock_irqsave(&ioc->diag_trigger_lock, flags);
if (trigger_bitmask & MASTER_TRIGGER_FW_FAULT ||
trigger_bitmask & MASTER_TRIGGER_ADAPTER_RESET)
goto by_pass_checks;
/* check to see if trace buffers are currently registered */
if ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
MPT3_DIAG_BUFFER_IS_REGISTERED) == 0) {
spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
return;
}
/* check to see if trace buffers are currently released */
if (ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
MPT3_DIAG_BUFFER_IS_RELEASED) {
spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
return;
}
by_pass_checks:
dTriggerDiagPrintk(ioc, pr_info(MPT3SAS_FMT
"%s: enter - trigger_bitmask = 0x%08x\n",
ioc->name, __func__, trigger_bitmask));
/* don't send trigger if an trigger is currently active */
if (ioc->diag_trigger_active) {
spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
goto out;
}
/* check for the trigger condition */
if (ioc->diag_trigger_master.MasterData & trigger_bitmask) {
found_match = 1;
ioc->diag_trigger_active = 1;
dTriggerDiagPrintk(ioc, pr_info(MPT3SAS_FMT
"%s: setting diag_trigger_active flag\n",
ioc->name, __func__));
}
spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
if (!found_match)
goto out;
memset(&event_data, 0, sizeof(struct SL_WH_TRIGGERS_EVENT_DATA_T));
event_data.trigger_type = MPT3SAS_TRIGGER_MASTER;
event_data.u.master.MasterData = trigger_bitmask;
if (trigger_bitmask & MASTER_TRIGGER_FW_FAULT ||
trigger_bitmask & MASTER_TRIGGER_ADAPTER_RESET)
_mpt3sas_raise_sigio(ioc, &event_data);
else
mpt3sas_send_trigger_data_event(ioc, &event_data);
out:
dTriggerDiagPrintk(ioc, pr_info(MPT3SAS_FMT "%s: exit\n", ioc->name,
__func__));
}
/**
* mpt3sas_trigger_event - Event trigger handler
* @ioc: per adapter object
* @event: ?
* @log_entry_qualifier: ?
*
*/
void
mpt3sas_trigger_event(struct MPT3SAS_ADAPTER *ioc, u16 event,
u16 log_entry_qualifier)
{
struct SL_WH_TRIGGERS_EVENT_DATA_T event_data;
struct SL_WH_EVENT_TRIGGER_T *event_trigger;
int i;
unsigned long flags;
u8 found_match;
spin_lock_irqsave(&ioc->diag_trigger_lock, flags);
/* check to see if trace buffers are currently registered */
if ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
MPT3_DIAG_BUFFER_IS_REGISTERED) == 0) {
spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
return;
}
/* check to see if trace buffers are currently released */
if (ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
MPT3_DIAG_BUFFER_IS_RELEASED) {
spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
return;
}
dTriggerDiagPrintk(ioc, pr_info(MPT3SAS_FMT
"%s: enter - event = 0x%04x, log_entry_qualifier = 0x%04x\n",
ioc->name, __func__, event, log_entry_qualifier));
/* don't send trigger if an trigger is currently active */
if (ioc->diag_trigger_active) {
spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
goto out;
}
/* check for the trigger condition */
event_trigger = ioc->diag_trigger_event.EventTriggerEntry;
for (i = 0 , found_match = 0; i < ioc->diag_trigger_event.ValidEntries
&& !found_match; i++, event_trigger++) {
if (event_trigger->EventValue != event)
continue;
if (event == MPI2_EVENT_LOG_ENTRY_ADDED) {
if (event_trigger->LogEntryQualifier ==
log_entry_qualifier)
found_match = 1;
continue;
}
found_match = 1;
ioc->diag_trigger_active = 1;
dTriggerDiagPrintk(ioc, pr_info(MPT3SAS_FMT
"%s: setting diag_trigger_active flag\n",
ioc->name, __func__));
}
spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
if (!found_match)
goto out;
dTriggerDiagPrintk(ioc, pr_info(MPT3SAS_FMT
"%s: setting diag_trigger_active flag\n",
ioc->name, __func__));
memset(&event_data, 0, sizeof(struct SL_WH_TRIGGERS_EVENT_DATA_T));
event_data.trigger_type = MPT3SAS_TRIGGER_EVENT;
event_data.u.event.EventValue = event;
event_data.u.event.LogEntryQualifier = log_entry_qualifier;
mpt3sas_send_trigger_data_event(ioc, &event_data);
out:
dTriggerDiagPrintk(ioc, pr_info(MPT3SAS_FMT "%s: exit\n", ioc->name,
__func__));
}
/**
* mpt3sas_trigger_scsi - SCSI trigger handler
* @ioc: per adapter object
* @sense_key: ?
* @asc: ?
* @ascq: ?
*
*/
void
mpt3sas_trigger_scsi(struct MPT3SAS_ADAPTER *ioc, u8 sense_key, u8 asc,
u8 ascq)
{
struct SL_WH_TRIGGERS_EVENT_DATA_T event_data;
struct SL_WH_SCSI_TRIGGER_T *scsi_trigger;
int i;
unsigned long flags;
u8 found_match;
spin_lock_irqsave(&ioc->diag_trigger_lock, flags);
/* check to see if trace buffers are currently registered */
if ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
MPT3_DIAG_BUFFER_IS_REGISTERED) == 0) {
spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
return;
}
/* check to see if trace buffers are currently released */
if (ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
MPT3_DIAG_BUFFER_IS_RELEASED) {
spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
return;
}
dTriggerDiagPrintk(ioc, pr_info(MPT3SAS_FMT
"%s: enter - sense_key = 0x%02x, asc = 0x%02x, ascq = 0x%02x\n",
ioc->name, __func__, sense_key, asc, ascq));
/* don't send trigger if an trigger is currently active */
if (ioc->diag_trigger_active) {
spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
goto out;
}
/* check for the trigger condition */
scsi_trigger = ioc->diag_trigger_scsi.SCSITriggerEntry;
for (i = 0 , found_match = 0; i < ioc->diag_trigger_scsi.ValidEntries
&& !found_match; i++, scsi_trigger++) {
if (scsi_trigger->SenseKey != sense_key)
continue;
if (!(scsi_trigger->ASC == 0xFF || scsi_trigger->ASC == asc))
continue;
if (!(scsi_trigger->ASCQ == 0xFF || scsi_trigger->ASCQ == ascq))
continue;
found_match = 1;
ioc->diag_trigger_active = 1;
}
spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
if (!found_match)
goto out;
dTriggerDiagPrintk(ioc, pr_info(MPT3SAS_FMT
"%s: setting diag_trigger_active flag\n",
ioc->name, __func__));
memset(&event_data, 0, sizeof(struct SL_WH_TRIGGERS_EVENT_DATA_T));
event_data.trigger_type = MPT3SAS_TRIGGER_SCSI;
event_data.u.scsi.SenseKey = sense_key;
event_data.u.scsi.ASC = asc;
event_data.u.scsi.ASCQ = ascq;
mpt3sas_send_trigger_data_event(ioc, &event_data);
out:
dTriggerDiagPrintk(ioc, pr_info(MPT3SAS_FMT "%s: exit\n", ioc->name,
__func__));
}
/**
* mpt3sas_trigger_mpi - MPI trigger handler
* @ioc: per adapter object
* @ioc_status: ?
* @loginfo: ?
*
*/
void
mpt3sas_trigger_mpi(struct MPT3SAS_ADAPTER *ioc, u16 ioc_status, u32 loginfo)
{
struct SL_WH_TRIGGERS_EVENT_DATA_T event_data;
struct SL_WH_MPI_TRIGGER_T *mpi_trigger;
int i;
unsigned long flags;
u8 found_match;
spin_lock_irqsave(&ioc->diag_trigger_lock, flags);
/* check to see if trace buffers are currently registered */
if ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
MPT3_DIAG_BUFFER_IS_REGISTERED) == 0) {
spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
return;
}
/* check to see if trace buffers are currently released */
if (ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
MPT3_DIAG_BUFFER_IS_RELEASED) {
spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
return;
}
dTriggerDiagPrintk(ioc, pr_info(MPT3SAS_FMT
"%s: enter - ioc_status = 0x%04x, loginfo = 0x%08x\n",
ioc->name, __func__, ioc_status, loginfo));
/* don't send trigger if an trigger is currently active */
if (ioc->diag_trigger_active) {
spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
goto out;
}
/* check for the trigger condition */
mpi_trigger = ioc->diag_trigger_mpi.MPITriggerEntry;
for (i = 0 , found_match = 0; i < ioc->diag_trigger_mpi.ValidEntries
&& !found_match; i++, mpi_trigger++) {
if (mpi_trigger->IOCStatus != ioc_status)
continue;
if (!(mpi_trigger->IocLogInfo == 0xFFFFFFFF ||
mpi_trigger->IocLogInfo == loginfo))
continue;
found_match = 1;
ioc->diag_trigger_active = 1;
}
spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
if (!found_match)
goto out;
dTriggerDiagPrintk(ioc, pr_info(MPT3SAS_FMT
"%s: setting diag_trigger_active flag\n",
ioc->name, __func__));
memset(&event_data, 0, sizeof(struct SL_WH_TRIGGERS_EVENT_DATA_T));
event_data.trigger_type = MPT3SAS_TRIGGER_MPI;
event_data.u.mpi.IOCStatus = ioc_status;
event_data.u.mpi.IocLogInfo = loginfo;
mpt3sas_send_trigger_data_event(ioc, &event_data);
out:
dTriggerDiagPrintk(ioc, pr_info(MPT3SAS_FMT "%s: exit\n", ioc->name,
__func__));
}
|