mpt3sas_trigger_diag.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. /*
  2. * This module provides common API to set Diagnostic trigger for MPT
  3. * (Message Passing Technology) based controllers
  4. *
  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)
  9. *
  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.
  14. *
  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.
  19. *
  20. * NO WARRANTY
  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.
  30. * DISCLAIMER OF LIABILITY
  31. * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
  32. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  33. * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
  34. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
  35. * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  36. * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
  37. * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
  38. * You should have received a copy of the GNU General Public License
  39. * along with this program; if not, write to the Free Software
  40. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
  41. * USA.
  42. */
  43. #include <linux/kernel.h>
  44. #include <linux/module.h>
  45. #include <linux/errno.h>
  46. #include <linux/init.h>
  47. #include <linux/slab.h>
  48. #include <linux/types.h>
  49. #include <linux/pci.h>
  50. #include <linux/delay.h>
  51. #include <linux/compat.h>
  52. #include <linux/poll.h>
  53. #include <linux/io.h>
  54. #include <linux/uaccess.h>
  55. #include "mpt3sas_base.h"
  56. /**
  57. * _mpt3sas_raise_sigio - notifiy app
  58. * @ioc: per adapter object
  59. * @event_data:
  60. */
  61. static void
  62. _mpt3sas_raise_sigio(struct MPT3SAS_ADAPTER *ioc,
  63. struct SL_WH_TRIGGERS_EVENT_DATA_T *event_data)
  64. {
  65. Mpi2EventNotificationReply_t *mpi_reply;
  66. u16 sz, event_data_sz;
  67. unsigned long flags;
  68. dTriggerDiagPrintk(ioc, pr_info(MPT3SAS_FMT "%s: enter\n",
  69. ioc->name, __func__));
  70. sz = offsetof(Mpi2EventNotificationReply_t, EventData) +
  71. sizeof(struct SL_WH_TRIGGERS_EVENT_DATA_T) + 4;
  72. mpi_reply = kzalloc(sz, GFP_KERNEL);
  73. if (!mpi_reply)
  74. goto out;
  75. mpi_reply->Event = cpu_to_le16(MPI3_EVENT_DIAGNOSTIC_TRIGGER_FIRED);
  76. event_data_sz = (sizeof(struct SL_WH_TRIGGERS_EVENT_DATA_T) + 4) / 4;
  77. mpi_reply->EventDataLength = cpu_to_le16(event_data_sz);
  78. memcpy(&mpi_reply->EventData, event_data,
  79. sizeof(struct SL_WH_TRIGGERS_EVENT_DATA_T));
  80. dTriggerDiagPrintk(ioc, pr_info(MPT3SAS_FMT
  81. "%s: add to driver event log\n",
  82. ioc->name, __func__));
  83. mpt3sas_ctl_add_to_event_log(ioc, mpi_reply);
  84. kfree(mpi_reply);
  85. out:
  86. /* clearing the diag_trigger_active flag */
  87. spin_lock_irqsave(&ioc->diag_trigger_lock, flags);
  88. dTriggerDiagPrintk(ioc, pr_info(MPT3SAS_FMT
  89. "%s: clearing diag_trigger_active flag\n",
  90. ioc->name, __func__));
  91. ioc->diag_trigger_active = 0;
  92. spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
  93. dTriggerDiagPrintk(ioc, pr_info(MPT3SAS_FMT "%s: exit\n", ioc->name,
  94. __func__));
  95. }
  96. /**
  97. * mpt3sas_process_trigger_data - process the event data for the trigger
  98. * @ioc: per adapter object
  99. * @event_data:
  100. */
  101. void
  102. mpt3sas_process_trigger_data(struct MPT3SAS_ADAPTER *ioc,
  103. struct SL_WH_TRIGGERS_EVENT_DATA_T *event_data)
  104. {
  105. u8 issue_reset = 0;
  106. dTriggerDiagPrintk(ioc, pr_info(MPT3SAS_FMT "%s: enter\n",
  107. ioc->name, __func__));
  108. /* release the diag buffer trace */
  109. if ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
  110. MPT3_DIAG_BUFFER_IS_RELEASED) == 0) {
  111. dTriggerDiagPrintk(ioc, pr_info(MPT3SAS_FMT
  112. "%s: release trace diag buffer\n", ioc->name, __func__));
  113. mpt3sas_send_diag_release(ioc, MPI2_DIAG_BUF_TYPE_TRACE,
  114. &issue_reset);
  115. }
  116. _mpt3sas_raise_sigio(ioc, event_data);
  117. dTriggerDiagPrintk(ioc, pr_info(MPT3SAS_FMT "%s: exit\n", ioc->name,
  118. __func__));
  119. }
  120. /**
  121. * mpt3sas_trigger_master - Master trigger handler
  122. * @ioc: per adapter object
  123. * @trigger_bitmask:
  124. *
  125. */
  126. void
  127. mpt3sas_trigger_master(struct MPT3SAS_ADAPTER *ioc, u32 trigger_bitmask)
  128. {
  129. struct SL_WH_TRIGGERS_EVENT_DATA_T event_data;
  130. unsigned long flags;
  131. u8 found_match = 0;
  132. spin_lock_irqsave(&ioc->diag_trigger_lock, flags);
  133. if (trigger_bitmask & MASTER_TRIGGER_FW_FAULT ||
  134. trigger_bitmask & MASTER_TRIGGER_ADAPTER_RESET)
  135. goto by_pass_checks;
  136. /* check to see if trace buffers are currently registered */
  137. if ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
  138. MPT3_DIAG_BUFFER_IS_REGISTERED) == 0) {
  139. spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
  140. return;
  141. }
  142. /* check to see if trace buffers are currently released */
  143. if (ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
  144. MPT3_DIAG_BUFFER_IS_RELEASED) {
  145. spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
  146. return;
  147. }
  148. by_pass_checks:
  149. dTriggerDiagPrintk(ioc, pr_info(MPT3SAS_FMT
  150. "%s: enter - trigger_bitmask = 0x%08x\n",
  151. ioc->name, __func__, trigger_bitmask));
  152. /* don't send trigger if an trigger is currently active */
  153. if (ioc->diag_trigger_active) {
  154. spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
  155. goto out;
  156. }
  157. /* check for the trigger condition */
  158. if (ioc->diag_trigger_master.MasterData & trigger_bitmask) {
  159. found_match = 1;
  160. ioc->diag_trigger_active = 1;
  161. dTriggerDiagPrintk(ioc, pr_info(MPT3SAS_FMT
  162. "%s: setting diag_trigger_active flag\n",
  163. ioc->name, __func__));
  164. }
  165. spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
  166. if (!found_match)
  167. goto out;
  168. memset(&event_data, 0, sizeof(struct SL_WH_TRIGGERS_EVENT_DATA_T));
  169. event_data.trigger_type = MPT3SAS_TRIGGER_MASTER;
  170. event_data.u.master.MasterData = trigger_bitmask;
  171. if (trigger_bitmask & MASTER_TRIGGER_FW_FAULT ||
  172. trigger_bitmask & MASTER_TRIGGER_ADAPTER_RESET)
  173. _mpt3sas_raise_sigio(ioc, &event_data);
  174. else
  175. mpt3sas_send_trigger_data_event(ioc, &event_data);
  176. out:
  177. dTriggerDiagPrintk(ioc, pr_info(MPT3SAS_FMT "%s: exit\n", ioc->name,
  178. __func__));
  179. }
  180. /**
  181. * mpt3sas_trigger_event - Event trigger handler
  182. * @ioc: per adapter object
  183. * @event:
  184. * @log_entry_qualifier:
  185. *
  186. */
  187. void
  188. mpt3sas_trigger_event(struct MPT3SAS_ADAPTER *ioc, u16 event,
  189. u16 log_entry_qualifier)
  190. {
  191. struct SL_WH_TRIGGERS_EVENT_DATA_T event_data;
  192. struct SL_WH_EVENT_TRIGGER_T *event_trigger;
  193. int i;
  194. unsigned long flags;
  195. u8 found_match;
  196. spin_lock_irqsave(&ioc->diag_trigger_lock, flags);
  197. /* check to see if trace buffers are currently registered */
  198. if ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
  199. MPT3_DIAG_BUFFER_IS_REGISTERED) == 0) {
  200. spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
  201. return;
  202. }
  203. /* check to see if trace buffers are currently released */
  204. if (ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
  205. MPT3_DIAG_BUFFER_IS_RELEASED) {
  206. spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
  207. return;
  208. }
  209. dTriggerDiagPrintk(ioc, pr_info(MPT3SAS_FMT
  210. "%s: enter - event = 0x%04x, log_entry_qualifier = 0x%04x\n",
  211. ioc->name, __func__, event, log_entry_qualifier));
  212. /* don't send trigger if an trigger is currently active */
  213. if (ioc->diag_trigger_active) {
  214. spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
  215. goto out;
  216. }
  217. /* check for the trigger condition */
  218. event_trigger = ioc->diag_trigger_event.EventTriggerEntry;
  219. for (i = 0 , found_match = 0; i < ioc->diag_trigger_event.ValidEntries
  220. && !found_match; i++, event_trigger++) {
  221. if (event_trigger->EventValue != event)
  222. continue;
  223. if (event == MPI2_EVENT_LOG_ENTRY_ADDED) {
  224. if (event_trigger->LogEntryQualifier ==
  225. log_entry_qualifier)
  226. found_match = 1;
  227. continue;
  228. }
  229. found_match = 1;
  230. ioc->diag_trigger_active = 1;
  231. dTriggerDiagPrintk(ioc, pr_info(MPT3SAS_FMT
  232. "%s: setting diag_trigger_active flag\n",
  233. ioc->name, __func__));
  234. }
  235. spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
  236. if (!found_match)
  237. goto out;
  238. dTriggerDiagPrintk(ioc, pr_info(MPT3SAS_FMT
  239. "%s: setting diag_trigger_active flag\n",
  240. ioc->name, __func__));
  241. memset(&event_data, 0, sizeof(struct SL_WH_TRIGGERS_EVENT_DATA_T));
  242. event_data.trigger_type = MPT3SAS_TRIGGER_EVENT;
  243. event_data.u.event.EventValue = event;
  244. event_data.u.event.LogEntryQualifier = log_entry_qualifier;
  245. mpt3sas_send_trigger_data_event(ioc, &event_data);
  246. out:
  247. dTriggerDiagPrintk(ioc, pr_info(MPT3SAS_FMT "%s: exit\n", ioc->name,
  248. __func__));
  249. }
  250. /**
  251. * mpt3sas_trigger_scsi - SCSI trigger handler
  252. * @ioc: per adapter object
  253. * @sense_key:
  254. * @asc:
  255. * @ascq:
  256. *
  257. */
  258. void
  259. mpt3sas_trigger_scsi(struct MPT3SAS_ADAPTER *ioc, u8 sense_key, u8 asc,
  260. u8 ascq)
  261. {
  262. struct SL_WH_TRIGGERS_EVENT_DATA_T event_data;
  263. struct SL_WH_SCSI_TRIGGER_T *scsi_trigger;
  264. int i;
  265. unsigned long flags;
  266. u8 found_match;
  267. spin_lock_irqsave(&ioc->diag_trigger_lock, flags);
  268. /* check to see if trace buffers are currently registered */
  269. if ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
  270. MPT3_DIAG_BUFFER_IS_REGISTERED) == 0) {
  271. spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
  272. return;
  273. }
  274. /* check to see if trace buffers are currently released */
  275. if (ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
  276. MPT3_DIAG_BUFFER_IS_RELEASED) {
  277. spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
  278. return;
  279. }
  280. dTriggerDiagPrintk(ioc, pr_info(MPT3SAS_FMT
  281. "%s: enter - sense_key = 0x%02x, asc = 0x%02x, ascq = 0x%02x\n",
  282. ioc->name, __func__, sense_key, asc, ascq));
  283. /* don't send trigger if an trigger is currently active */
  284. if (ioc->diag_trigger_active) {
  285. spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
  286. goto out;
  287. }
  288. /* check for the trigger condition */
  289. scsi_trigger = ioc->diag_trigger_scsi.SCSITriggerEntry;
  290. for (i = 0 , found_match = 0; i < ioc->diag_trigger_scsi.ValidEntries
  291. && !found_match; i++, scsi_trigger++) {
  292. if (scsi_trigger->SenseKey != sense_key)
  293. continue;
  294. if (!(scsi_trigger->ASC == 0xFF || scsi_trigger->ASC == asc))
  295. continue;
  296. if (!(scsi_trigger->ASCQ == 0xFF || scsi_trigger->ASCQ == ascq))
  297. continue;
  298. found_match = 1;
  299. ioc->diag_trigger_active = 1;
  300. }
  301. spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
  302. if (!found_match)
  303. goto out;
  304. dTriggerDiagPrintk(ioc, pr_info(MPT3SAS_FMT
  305. "%s: setting diag_trigger_active flag\n",
  306. ioc->name, __func__));
  307. memset(&event_data, 0, sizeof(struct SL_WH_TRIGGERS_EVENT_DATA_T));
  308. event_data.trigger_type = MPT3SAS_TRIGGER_SCSI;
  309. event_data.u.scsi.SenseKey = sense_key;
  310. event_data.u.scsi.ASC = asc;
  311. event_data.u.scsi.ASCQ = ascq;
  312. mpt3sas_send_trigger_data_event(ioc, &event_data);
  313. out:
  314. dTriggerDiagPrintk(ioc, pr_info(MPT3SAS_FMT "%s: exit\n", ioc->name,
  315. __func__));
  316. }
  317. /**
  318. * mpt3sas_trigger_mpi - MPI trigger handler
  319. * @ioc: per adapter object
  320. * @ioc_status:
  321. * @loginfo:
  322. *
  323. */
  324. void
  325. mpt3sas_trigger_mpi(struct MPT3SAS_ADAPTER *ioc, u16 ioc_status, u32 loginfo)
  326. {
  327. struct SL_WH_TRIGGERS_EVENT_DATA_T event_data;
  328. struct SL_WH_MPI_TRIGGER_T *mpi_trigger;
  329. int i;
  330. unsigned long flags;
  331. u8 found_match;
  332. spin_lock_irqsave(&ioc->diag_trigger_lock, flags);
  333. /* check to see if trace buffers are currently registered */
  334. if ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
  335. MPT3_DIAG_BUFFER_IS_REGISTERED) == 0) {
  336. spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
  337. return;
  338. }
  339. /* check to see if trace buffers are currently released */
  340. if (ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
  341. MPT3_DIAG_BUFFER_IS_RELEASED) {
  342. spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
  343. return;
  344. }
  345. dTriggerDiagPrintk(ioc, pr_info(MPT3SAS_FMT
  346. "%s: enter - ioc_status = 0x%04x, loginfo = 0x%08x\n",
  347. ioc->name, __func__, ioc_status, loginfo));
  348. /* don't send trigger if an trigger is currently active */
  349. if (ioc->diag_trigger_active) {
  350. spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
  351. goto out;
  352. }
  353. /* check for the trigger condition */
  354. mpi_trigger = ioc->diag_trigger_mpi.MPITriggerEntry;
  355. for (i = 0 , found_match = 0; i < ioc->diag_trigger_mpi.ValidEntries
  356. && !found_match; i++, mpi_trigger++) {
  357. if (mpi_trigger->IOCStatus != ioc_status)
  358. continue;
  359. if (!(mpi_trigger->IocLogInfo == 0xFFFFFFFF ||
  360. mpi_trigger->IocLogInfo == loginfo))
  361. continue;
  362. found_match = 1;
  363. ioc->diag_trigger_active = 1;
  364. }
  365. spin_unlock_irqrestore(&ioc->diag_trigger_lock, flags);
  366. if (!found_match)
  367. goto out;
  368. dTriggerDiagPrintk(ioc, pr_info(MPT3SAS_FMT
  369. "%s: setting diag_trigger_active flag\n",
  370. ioc->name, __func__));
  371. memset(&event_data, 0, sizeof(struct SL_WH_TRIGGERS_EVENT_DATA_T));
  372. event_data.trigger_type = MPT3SAS_TRIGGER_MPI;
  373. event_data.u.mpi.IOCStatus = ioc_status;
  374. event_data.u.mpi.IocLogInfo = loginfo;
  375. mpt3sas_send_trigger_data_event(ioc, &event_data);
  376. out:
  377. dTriggerDiagPrintk(ioc, pr_info(MPT3SAS_FMT "%s: exit\n", ioc->name,
  378. __func__));
  379. }