1 /****************************************************************************** 2 * 3 * This file is provided under a dual BSD/GPLv2 license. When using or 4 * redistributing this file, you may do so under either license. 5 * 6 * GPL LICENSE SUMMARY 7 * 8 * Copyright(c) 2008 - 2014 Intel Corporation. All rights reserved. 9 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH 10 * Copyright(c) 2015 - 2017 Intel Deutschland GmbH 11 * Copyright(c) 2018 - 2019 Intel Corporation 12 * 13 * This program is free software; you can redistribute it and/or modify 14 * it under the terms of version 2 of the GNU General Public License as 15 * published by the Free Software Foundation. 16 * 17 * This program is distributed in the hope that it will be useful, but 18 * WITHOUT ANY WARRANTY; without even the implied warranty of 19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 * General Public License for more details. 21 * 22 * The full GNU General Public License is included in this distribution 23 * in the file called COPYING. 24 * 25 * Contact Information: 26 * Intel Linux Wireless <linuxwifi@intel.com> 27 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 28 * 29 * BSD LICENSE 30 * 31 * Copyright(c) 2005 - 2014 Intel Corporation. All rights reserved. 32 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH 33 * Copyright(c) 2015 - 2017 Intel Deutschland GmbH 34 * Copyright(c) 2018 - 2019 Intel Corporation 35 * All rights reserved. 36 * 37 * Redistribution and use in source and binary forms, with or without 38 * modification, are permitted provided that the following conditions 39 * are met: 40 * 41 * * Redistributions of source code must retain the above copyright 42 * notice, this list of conditions and the following disclaimer. 43 * * Redistributions in binary form must reproduce the above copyright 44 * notice, this list of conditions and the following disclaimer in 45 * the documentation and/or other materials provided with the 46 * distribution. 47 * * Neither the name Intel Corporation nor the names of its 48 * contributors may be used to endorse or promote products derived 49 * from this software without specific prior written permission. 50 * 51 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 52 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 53 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 54 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 55 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 56 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 57 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 58 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 59 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 60 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 61 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 62 * 63 *****************************************************************************/ 64 65 #ifndef __iwl_fw_dbg_h__ 66 #define __iwl_fw_dbg_h__ 67 #include <linux/workqueue.h> 68 #include <net/cfg80211.h> 69 #include "runtime.h" 70 #include "iwl-prph.h" 71 #include "iwl-io.h" 72 #include "file.h" 73 #include "error-dump.h" 74 #include "api/commands.h" 75 #include "api/dbg-tlv.h" 76 77 /** 78 * struct iwl_fw_dump_desc - describes the dump 79 * @len: length of trig_desc->data 80 * @trig_desc: the description of the dump 81 */ 82 struct iwl_fw_dump_desc { 83 size_t len; 84 /* must be last */ 85 struct iwl_fw_error_dump_trigger_desc trig_desc; 86 }; 87 88 /** 89 * struct iwl_fw_dbg_params - register values to restore 90 * @in_sample: DBGC_IN_SAMPLE value 91 * @out_ctrl: DBGC_OUT_CTRL value 92 */ 93 struct iwl_fw_dbg_params { 94 u32 in_sample; 95 u32 out_ctrl; 96 }; 97 98 extern const struct iwl_fw_dump_desc iwl_dump_desc_assert; 99 100 static inline void iwl_fw_free_dump_desc(struct iwl_fw_runtime *fwrt) 101 { 102 if (fwrt->dump.desc != &iwl_dump_desc_assert) 103 kfree(fwrt->dump.desc); 104 fwrt->dump.desc = NULL; 105 fwrt->dump.lmac_err_id[0] = 0; 106 if (fwrt->smem_cfg.num_lmacs > 1) 107 fwrt->dump.lmac_err_id[1] = 0; 108 fwrt->dump.umac_err_id = 0; 109 } 110 111 int iwl_fw_dbg_collect_desc(struct iwl_fw_runtime *fwrt, 112 const struct iwl_fw_dump_desc *desc, 113 bool monitor_only, unsigned int delay); 114 int iwl_fw_dbg_error_collect(struct iwl_fw_runtime *fwrt, 115 enum iwl_fw_dbg_trigger trig_type); 116 int _iwl_fw_dbg_ini_collect(struct iwl_fw_runtime *fwrt, 117 enum iwl_fw_ini_trigger_id id); 118 int iwl_fw_dbg_ini_collect(struct iwl_fw_runtime *fwrt, u32 legacy_trigger_id); 119 int iwl_fw_dbg_collect(struct iwl_fw_runtime *fwrt, 120 enum iwl_fw_dbg_trigger trig, const char *str, 121 size_t len, struct iwl_fw_dbg_trigger_tlv *trigger); 122 int iwl_fw_dbg_collect_trig(struct iwl_fw_runtime *fwrt, 123 struct iwl_fw_dbg_trigger_tlv *trigger, 124 const char *fmt, ...) __printf(3, 4); 125 int iwl_fw_start_dbg_conf(struct iwl_fw_runtime *fwrt, u8 id); 126 127 #define iwl_fw_dbg_trigger_enabled(fw, id) ({ \ 128 void *__dbg_trigger = (fw)->dbg.trigger_tlv[(id)]; \ 129 unlikely(__dbg_trigger); \ 130 }) 131 132 static inline struct iwl_fw_dbg_trigger_tlv* 133 _iwl_fw_dbg_get_trigger(const struct iwl_fw *fw, enum iwl_fw_dbg_trigger id) 134 { 135 return fw->dbg.trigger_tlv[id]; 136 } 137 138 #define iwl_fw_dbg_get_trigger(fw, id) ({ \ 139 BUILD_BUG_ON(!__builtin_constant_p(id)); \ 140 BUILD_BUG_ON((id) >= FW_DBG_TRIGGER_MAX); \ 141 _iwl_fw_dbg_get_trigger((fw), (id)); \ 142 }) 143 144 static inline bool 145 iwl_fw_dbg_trigger_vif_match(struct iwl_fw_dbg_trigger_tlv *trig, 146 struct wireless_dev *wdev) 147 { 148 u32 trig_vif = le32_to_cpu(trig->vif_type); 149 150 return trig_vif == IWL_FW_DBG_CONF_VIF_ANY || 151 wdev->iftype == trig_vif; 152 } 153 154 static inline bool 155 iwl_fw_dbg_trigger_stop_conf_match(struct iwl_fw_runtime *fwrt, 156 struct iwl_fw_dbg_trigger_tlv *trig) 157 { 158 return ((trig->mode & IWL_FW_DBG_TRIGGER_STOP) && 159 (fwrt->dump.conf == FW_DBG_INVALID || 160 (BIT(fwrt->dump.conf) & le32_to_cpu(trig->stop_conf_ids)))); 161 } 162 163 static inline bool 164 iwl_fw_dbg_no_trig_window(struct iwl_fw_runtime *fwrt, u32 id, u32 dis_usec) 165 { 166 unsigned long wind_jiff = usecs_to_jiffies(dis_usec); 167 168 /* If this is the first event checked, jump to update start ts */ 169 if (fwrt->dump.non_collect_ts_start[id] && 170 (time_after(fwrt->dump.non_collect_ts_start[id] + wind_jiff, 171 jiffies))) 172 return true; 173 174 fwrt->dump.non_collect_ts_start[id] = jiffies; 175 return false; 176 } 177 178 static inline bool 179 iwl_fw_dbg_trigger_check_stop(struct iwl_fw_runtime *fwrt, 180 struct wireless_dev *wdev, 181 struct iwl_fw_dbg_trigger_tlv *trig) 182 { 183 u32 usec = le16_to_cpu(trig->trig_dis_ms) * USEC_PER_MSEC; 184 185 if (wdev && !iwl_fw_dbg_trigger_vif_match(trig, wdev)) 186 return false; 187 188 if (iwl_fw_dbg_no_trig_window(fwrt, le32_to_cpu(trig->id), usec)) { 189 IWL_WARN(fwrt, "Trigger %d occurred while no-collect window.\n", 190 trig->id); 191 return false; 192 } 193 194 return iwl_fw_dbg_trigger_stop_conf_match(fwrt, trig); 195 } 196 197 static inline struct iwl_fw_dbg_trigger_tlv* 198 _iwl_fw_dbg_trigger_on(struct iwl_fw_runtime *fwrt, 199 struct wireless_dev *wdev, 200 const enum iwl_fw_dbg_trigger id) 201 { 202 struct iwl_fw_dbg_trigger_tlv *trig; 203 204 if (fwrt->trans->ini_valid) 205 return NULL; 206 207 if (!iwl_fw_dbg_trigger_enabled(fwrt->fw, id)) 208 return NULL; 209 210 trig = _iwl_fw_dbg_get_trigger(fwrt->fw, id); 211 212 if (!iwl_fw_dbg_trigger_check_stop(fwrt, wdev, trig)) 213 return NULL; 214 215 return trig; 216 } 217 218 #define iwl_fw_dbg_trigger_on(fwrt, wdev, id) ({ \ 219 BUILD_BUG_ON(!__builtin_constant_p(id)); \ 220 BUILD_BUG_ON((id) >= FW_DBG_TRIGGER_MAX); \ 221 _iwl_fw_dbg_trigger_on((fwrt), (wdev), (id)); \ 222 }) 223 224 static inline bool 225 iwl_fw_ini_trigger_on(struct iwl_fw_runtime *fwrt, 226 enum iwl_fw_ini_trigger_id id) 227 { 228 struct iwl_fw_ini_trigger *trig; 229 u32 usec; 230 231 if (!fwrt->trans->ini_valid || id == IWL_FW_TRIGGER_ID_INVALID || 232 id >= IWL_FW_TRIGGER_ID_NUM || !fwrt->dump.active_trigs[id].active) 233 return false; 234 235 trig = fwrt->dump.active_trigs[id].trig; 236 usec = le32_to_cpu(trig->ignore_consec); 237 238 if (iwl_fw_dbg_no_trig_window(fwrt, id, usec)) { 239 IWL_WARN(fwrt, "Trigger %d fired in no-collect window\n", id); 240 return false; 241 } 242 243 return true; 244 } 245 246 static inline void 247 _iwl_fw_dbg_trigger_simple_stop(struct iwl_fw_runtime *fwrt, 248 struct wireless_dev *wdev, 249 struct iwl_fw_dbg_trigger_tlv *trigger) 250 { 251 if (!trigger) 252 return; 253 254 if (!iwl_fw_dbg_trigger_check_stop(fwrt, wdev, trigger)) 255 return; 256 257 iwl_fw_dbg_collect_trig(fwrt, trigger, NULL); 258 } 259 260 #define iwl_fw_dbg_trigger_simple_stop(fwrt, wdev, trig) \ 261 _iwl_fw_dbg_trigger_simple_stop((fwrt), (wdev), \ 262 iwl_fw_dbg_get_trigger((fwrt)->fw,\ 263 (trig))) 264 265 static inline int 266 iwl_fw_dbg_start_stop_hcmd(struct iwl_fw_runtime *fwrt, bool start) 267 { 268 struct iwl_ldbg_config_cmd cmd = { 269 .type = start ? cpu_to_le32(START_DEBUG_RECORDING) : 270 cpu_to_le32(STOP_DEBUG_RECORDING), 271 }; 272 struct iwl_host_cmd hcmd = { 273 .id = LDBG_CONFIG_CMD, 274 .flags = CMD_ASYNC, 275 .data[0] = &cmd, 276 .len[0] = sizeof(cmd), 277 }; 278 279 return iwl_trans_send_cmd(fwrt->trans, &hcmd); 280 } 281 282 static inline void 283 _iwl_fw_dbg_stop_recording(struct iwl_trans *trans, 284 struct iwl_fw_dbg_params *params) 285 { 286 if (trans->cfg->device_family == IWL_DEVICE_FAMILY_7000) { 287 iwl_set_bits_prph(trans, MON_BUFF_SAMPLE_CTL, 0x100); 288 return; 289 } 290 291 if (params) { 292 params->in_sample = iwl_read_umac_prph(trans, DBGC_IN_SAMPLE); 293 params->out_ctrl = iwl_read_umac_prph(trans, DBGC_OUT_CTRL); 294 } 295 296 iwl_write_umac_prph(trans, DBGC_IN_SAMPLE, 0); 297 udelay(100); 298 iwl_write_umac_prph(trans, DBGC_OUT_CTRL, 0); 299 #ifdef CONFIG_IWLWIFI_DEBUGFS 300 trans->dbg_rec_on = false; 301 #endif 302 } 303 304 static inline void 305 iwl_fw_dbg_stop_recording(struct iwl_fw_runtime *fwrt, 306 struct iwl_fw_dbg_params *params) 307 { 308 if (fwrt->trans->cfg->device_family < IWL_DEVICE_FAMILY_22560) 309 _iwl_fw_dbg_stop_recording(fwrt->trans, params); 310 else 311 iwl_fw_dbg_start_stop_hcmd(fwrt, false); 312 } 313 314 static inline void 315 _iwl_fw_dbg_restart_recording(struct iwl_trans *trans, 316 struct iwl_fw_dbg_params *params) 317 { 318 if (WARN_ON(!params)) 319 return; 320 321 if (trans->cfg->device_family == IWL_DEVICE_FAMILY_7000) { 322 iwl_clear_bits_prph(trans, MON_BUFF_SAMPLE_CTL, 0x100); 323 iwl_clear_bits_prph(trans, MON_BUFF_SAMPLE_CTL, 0x1); 324 iwl_set_bits_prph(trans, MON_BUFF_SAMPLE_CTL, 0x1); 325 } else { 326 iwl_write_umac_prph(trans, DBGC_IN_SAMPLE, params->in_sample); 327 udelay(100); 328 iwl_write_umac_prph(trans, DBGC_OUT_CTRL, params->out_ctrl); 329 } 330 } 331 332 #ifdef CONFIG_IWLWIFI_DEBUGFS 333 static inline void iwl_fw_set_dbg_rec_on(struct iwl_fw_runtime *fwrt) 334 { 335 if (fwrt->fw->dbg.dest_tlv && fwrt->cur_fw_img == IWL_UCODE_REGULAR) 336 fwrt->trans->dbg_rec_on = true; 337 } 338 #endif 339 340 static inline void 341 iwl_fw_dbg_restart_recording(struct iwl_fw_runtime *fwrt, 342 struct iwl_fw_dbg_params *params) 343 { 344 if (fwrt->trans->cfg->device_family < IWL_DEVICE_FAMILY_22560) 345 _iwl_fw_dbg_restart_recording(fwrt->trans, params); 346 else 347 iwl_fw_dbg_start_stop_hcmd(fwrt, true); 348 #ifdef CONFIG_IWLWIFI_DEBUGFS 349 iwl_fw_set_dbg_rec_on(fwrt); 350 #endif 351 } 352 353 static inline void iwl_fw_dump_conf_clear(struct iwl_fw_runtime *fwrt) 354 { 355 fwrt->dump.conf = FW_DBG_INVALID; 356 } 357 358 void iwl_fw_error_dump_wk(struct work_struct *work); 359 360 static inline bool iwl_fw_dbg_type_on(struct iwl_fw_runtime *fwrt, u32 type) 361 { 362 return (fwrt->fw->dbg.dump_mask & BIT(type) || fwrt->trans->ini_valid); 363 } 364 365 static inline bool iwl_fw_dbg_is_d3_debug_enabled(struct iwl_fw_runtime *fwrt) 366 { 367 return fw_has_capa(&fwrt->fw->ucode_capa, 368 IWL_UCODE_TLV_CAPA_D3_DEBUG) && 369 fwrt->trans->cfg->d3_debug_data_length && fwrt->ops && 370 fwrt->ops->d3_debug_enable && 371 fwrt->ops->d3_debug_enable(fwrt->ops_ctx) && 372 iwl_fw_dbg_type_on(fwrt, IWL_FW_ERROR_DUMP_D3_DEBUG_DATA); 373 } 374 375 static inline bool iwl_fw_dbg_is_paging_enabled(struct iwl_fw_runtime *fwrt) 376 { 377 return iwl_fw_dbg_type_on(fwrt, IWL_FW_ERROR_DUMP_PAGING) && 378 !fwrt->trans->cfg->gen2 && 379 fwrt->cur_fw_img < IWL_UCODE_TYPE_MAX && 380 fwrt->fw->img[fwrt->cur_fw_img].paging_mem_size && 381 fwrt->fw_paging_db[0].fw_paging_block; 382 } 383 384 void iwl_fw_dbg_read_d3_debug_data(struct iwl_fw_runtime *fwrt); 385 386 static inline void iwl_fw_flush_dump(struct iwl_fw_runtime *fwrt) 387 { 388 del_timer(&fwrt->dump.periodic_trig); 389 flush_delayed_work(&fwrt->dump.wk); 390 } 391 392 static inline void iwl_fw_cancel_dump(struct iwl_fw_runtime *fwrt) 393 { 394 del_timer(&fwrt->dump.periodic_trig); 395 cancel_delayed_work_sync(&fwrt->dump.wk); 396 } 397 398 #ifdef CONFIG_IWLWIFI_DEBUGFS 399 static inline void iwl_fw_cancel_timestamp(struct iwl_fw_runtime *fwrt) 400 { 401 fwrt->timestamp.delay = 0; 402 cancel_delayed_work_sync(&fwrt->timestamp.wk); 403 } 404 405 void iwl_fw_trigger_timestamp(struct iwl_fw_runtime *fwrt, u32 delay); 406 407 static inline void iwl_fw_suspend_timestamp(struct iwl_fw_runtime *fwrt) 408 { 409 cancel_delayed_work_sync(&fwrt->timestamp.wk); 410 } 411 412 static inline void iwl_fw_resume_timestamp(struct iwl_fw_runtime *fwrt) 413 { 414 if (!fwrt->timestamp.delay) 415 return; 416 417 schedule_delayed_work(&fwrt->timestamp.wk, 418 round_jiffies_relative(fwrt->timestamp.delay)); 419 } 420 421 #else 422 423 static inline void iwl_fw_cancel_timestamp(struct iwl_fw_runtime *fwrt) {} 424 425 static inline void iwl_fw_trigger_timestamp(struct iwl_fw_runtime *fwrt, 426 u32 delay) {} 427 428 static inline void iwl_fw_suspend_timestamp(struct iwl_fw_runtime *fwrt) {} 429 430 static inline void iwl_fw_resume_timestamp(struct iwl_fw_runtime *fwrt) {} 431 432 #endif /* CONFIG_IWLWIFI_DEBUGFS */ 433 434 void iwl_fw_dbg_collect_sync(struct iwl_fw_runtime *fwrt); 435 void iwl_fw_dbg_apply_point(struct iwl_fw_runtime *fwrt, 436 enum iwl_fw_ini_apply_point apply_point); 437 438 void iwl_fwrt_stop_device(struct iwl_fw_runtime *fwrt); 439 440 static inline void iwl_fw_lmac1_set_alive_err_table(struct iwl_trans *trans, 441 u32 lmac_error_event_table) 442 { 443 if (!(trans->error_event_table_tlv_status & 444 IWL_ERROR_EVENT_TABLE_LMAC1) || 445 WARN_ON(trans->lmac_error_event_table[0] != 446 lmac_error_event_table)) 447 trans->lmac_error_event_table[0] = lmac_error_event_table; 448 } 449 450 static inline void iwl_fw_umac_set_alive_err_table(struct iwl_trans *trans, 451 u32 umac_error_event_table) 452 { 453 if (!(trans->error_event_table_tlv_status & 454 IWL_ERROR_EVENT_TABLE_UMAC) || 455 WARN_ON(trans->umac_error_event_table != 456 umac_error_event_table)) 457 trans->umac_error_event_table = umac_error_event_table; 458 } 459 460 /* This bit is used to differentiate the legacy dump from the ini dump */ 461 #define INI_DUMP_BIT BIT(31) 462 463 static inline void iwl_fw_error_collect(struct iwl_fw_runtime *fwrt) 464 { 465 if (fwrt->trans->ini_valid && fwrt->trans->hw_error) { 466 _iwl_fw_dbg_ini_collect(fwrt, IWL_FW_TRIGGER_ID_FW_HW_ERROR); 467 fwrt->trans->hw_error = false; 468 } else { 469 iwl_fw_dbg_collect_desc(fwrt, &iwl_dump_desc_assert, false, 0); 470 } 471 } 472 473 void iwl_fw_dbg_periodic_trig_handler(struct timer_list *t); 474 #endif /* __iwl_fw_dbg_h__ */ 475