Path: blob/main/sys/contrib/dev/iwlwifi/iwl-op-mode.h
48253 views
/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */1/*2* Copyright (C) 2005-2014, 2018-2021, 2024-2025 Intel Corporation3* Copyright (C) 2013-2014 Intel Mobile Communications GmbH4* Copyright (C) 2015 Intel Deutschland GmbH5*/6#ifndef __iwl_op_mode_h__7#define __iwl_op_mode_h__89#include <linux/netdevice.h>10#include <linux/debugfs.h>11#include "iwl-dbg-tlv.h"1213struct iwl_op_mode;14struct iwl_trans;15struct sk_buff;16struct iwl_device_cmd;17struct iwl_rx_cmd_buffer;18struct iwl_fw;19struct iwl_rf_cfg;2021/**22* DOC: Operational mode - what is it ?23*24* The operational mode (a.k.a. op_mode) is the layer that implements25* mac80211's handlers. It knows two APIs: mac80211's and the fw's. It uses26* the transport API to access the HW. The op_mode doesn't need to know how the27* underlying HW works, since the transport layer takes care of that.28*29* There can be several op_mode: i.e. different fw APIs will require two30* different op_modes. This is why the op_mode is virtualized.31*/3233/**34* DOC: Life cycle of the Operational mode35*36* The operational mode has a very simple life cycle.37*38* 1) The driver layer (iwl-drv.c) chooses the op_mode based on the39* capabilities advertised by the fw file (in TLV format).40* 2) The driver layer starts the op_mode (ops->start)41* 3) The op_mode registers mac8021142* 4) The op_mode is governed by mac8021143* 5) The driver layer stops the op_mode44*/4546/**47* enum iwl_fw_error_type - FW error types/sources48* @IWL_ERR_TYPE_IRQ: "normal" FW error through an IRQ49* @IWL_ERR_TYPE_NMI_FORCED: NMI was forced by driver50* @IWL_ERR_TYPE_RESET_HS_TIMEOUT: reset handshake timed out,51* any debug collection must happen synchronously as52* the device will be shut down53* @IWL_ERR_TYPE_CMD_QUEUE_FULL: command queue was full54* @IWL_ERR_TYPE_TOP_RESET_BY_BT: TOP reset initiated by BT55* @IWL_ERR_TYPE_TOP_FATAL_ERROR: TOP fatal error56* @IWL_ERR_TYPE_TOP_RESET_FAILED: TOP reset failed57* @IWL_ERR_TYPE_DEBUGFS: error/reset indication from debugfs58*/59enum iwl_fw_error_type {60IWL_ERR_TYPE_IRQ,61IWL_ERR_TYPE_NMI_FORCED,62IWL_ERR_TYPE_RESET_HS_TIMEOUT,63IWL_ERR_TYPE_CMD_QUEUE_FULL,64IWL_ERR_TYPE_TOP_RESET_BY_BT,65IWL_ERR_TYPE_TOP_FATAL_ERROR,66IWL_ERR_TYPE_TOP_RESET_FAILED,67IWL_ERR_TYPE_DEBUGFS,68};6970/**71* enum iwl_fw_error_context - error dump context72* @IWL_ERR_CONTEXT_WORKER: regular from worker context,73* opmode must acquire locks and must also check74* for @IWL_ERR_CONTEXT_ABORT after acquiring locks75* @IWL_ERR_CONTEXT_FROM_OPMODE: context is in a call76* originating from the opmode, e.g. while resetting77* or stopping the device, so opmode must not acquire78* any locks79* @IWL_ERR_CONTEXT_ABORT: after lock acquisition, indicates80* that the dump already happened via another callback81* (currently only while stopping the device) via the82* @IWL_ERR_CONTEXT_FROM_OPMODE context, and this call83* must be aborted84*/85enum iwl_fw_error_context {86IWL_ERR_CONTEXT_WORKER,87IWL_ERR_CONTEXT_FROM_OPMODE,88IWL_ERR_CONTEXT_ABORT,89};9091/**92* struct iwl_fw_error_dump_mode - error dump mode for callback93* @type: The reason for the dump, per &enum iwl_fw_error_type.94* @context: The context for the dump, may also indicate this95* call needs to be skipped. This MUST be checked before96* and after acquiring any locks in the op-mode!97*/98struct iwl_fw_error_dump_mode {99enum iwl_fw_error_type type;100enum iwl_fw_error_context context;101};102103/**104* struct iwl_op_mode_ops - op_mode specific operations105*106* The op_mode exports its ops so that external components can start it and107* interact with it. The driver layer typically calls the start and stop108* handlers, the transport layer calls the others.109*110* All the handlers MUST be implemented, except @rx_rss which can be left111* out *iff* the opmode will never run on hardware with multi-queue capability.112*113* @start: start the op_mode. The transport layer is already allocated.114* May sleep115* @stop: stop the op_mode. Must free all the memory allocated.116* May sleep117* @rx: Rx notification to the op_mode. rxb is the Rx buffer itself. Cmd is the118* HCMD this Rx responds to. Can't sleep.119* @rx_rss: data queue RX notification to the op_mode, for (data) notifications120* received on the RSS queue(s). The queue parameter indicates which of the121* RSS queues received this frame; it will always be non-zero.122* This method must not sleep.123* @queue_full: notifies that a HW queue is full.124* Must be atomic and called with BH disabled.125* @queue_not_full: notifies that a HW queue is not full any more.126* Must be atomic and called with BH disabled.127* @hw_rf_kill: notifies of a change in the HW rf kill switch. True means that128* the radio is killed. Return %true if the device should be stopped by129* the transport immediately after the call. May sleep.130* Note that this must not return %true for newer devices using gen2 PCIe131* transport.132* @free_skb: allows the transport layer to free skbs that haven't been133* reclaimed by the op_mode. This can happen when the driver is freed and134* there are Tx packets pending in the transport layer.135* Must be atomic136* @nic_error: error notification. Must be atomic, the op mode should handle137* the error (e.g. abort notification waiters) and print the error if138* applicable139* @dump_error: NIC error dump collection (can sleep, synchronous)140* @sw_reset: (maybe) initiate a software reset, return %true if started141* @nic_config: configure NIC, called before firmware is started.142* May sleep143* @wimax_active: invoked when WiMax becomes active. May sleep144* @time_point: called when transport layer wants to collect debug data145* @device_powered_off: called upon resume from hibernation but not only.146* Op_mode needs to reset its internal state because the device did not147* survive the system state transition. The firmware is no longer running,148* etc...149* @dump: Op_mode needs to collect the firmware dump upon this handler150* being called.151*/152struct iwl_op_mode_ops {153struct iwl_op_mode *(*start)(struct iwl_trans *trans,154const struct iwl_rf_cfg *cfg,155const struct iwl_fw *fw,156struct dentry *dbgfs_dir);157void (*stop)(struct iwl_op_mode *op_mode);158void (*rx)(struct iwl_op_mode *op_mode, struct napi_struct *napi,159struct iwl_rx_cmd_buffer *rxb);160void (*rx_rss)(struct iwl_op_mode *op_mode, struct napi_struct *napi,161struct iwl_rx_cmd_buffer *rxb, unsigned int queue);162void (*queue_full)(struct iwl_op_mode *op_mode, int queue);163void (*queue_not_full)(struct iwl_op_mode *op_mode, int queue);164bool (*hw_rf_kill)(struct iwl_op_mode *op_mode, bool state);165void (*free_skb)(struct iwl_op_mode *op_mode, struct sk_buff *skb);166void (*nic_error)(struct iwl_op_mode *op_mode,167enum iwl_fw_error_type type);168void (*dump_error)(struct iwl_op_mode *op_mode,169struct iwl_fw_error_dump_mode *mode);170bool (*sw_reset)(struct iwl_op_mode *op_mode,171enum iwl_fw_error_type type);172void (*nic_config)(struct iwl_op_mode *op_mode);173void (*wimax_active)(struct iwl_op_mode *op_mode);174void (*time_point)(struct iwl_op_mode *op_mode,175enum iwl_fw_ini_time_point tp_id,176union iwl_dbg_tlv_tp_data *tp_data);177void (*device_powered_off)(struct iwl_op_mode *op_mode);178void (*dump)(struct iwl_op_mode *op_mode);179};180181int iwl_opmode_register(const char *name, const struct iwl_op_mode_ops *ops);182void iwl_opmode_deregister(const char *name);183184/**185* struct iwl_op_mode - operational mode186* @ops: pointer to its own ops187*188* This holds an implementation of the mac80211 / fw API.189*/190struct iwl_op_mode {191const struct iwl_op_mode_ops *ops;192193char op_mode_specific[] __aligned(sizeof(void *));194};195196static inline void iwl_op_mode_stop(struct iwl_op_mode *op_mode)197{198might_sleep();199op_mode->ops->stop(op_mode);200}201202static inline void iwl_op_mode_rx(struct iwl_op_mode *op_mode,203struct napi_struct *napi,204struct iwl_rx_cmd_buffer *rxb)205{206return op_mode->ops->rx(op_mode, napi, rxb);207}208209static inline void iwl_op_mode_rx_rss(struct iwl_op_mode *op_mode,210struct napi_struct *napi,211struct iwl_rx_cmd_buffer *rxb,212unsigned int queue)213{214op_mode->ops->rx_rss(op_mode, napi, rxb, queue);215}216217static inline void iwl_op_mode_queue_full(struct iwl_op_mode *op_mode,218int queue)219{220op_mode->ops->queue_full(op_mode, queue);221}222223static inline void iwl_op_mode_queue_not_full(struct iwl_op_mode *op_mode,224int queue)225{226op_mode->ops->queue_not_full(op_mode, queue);227}228229static inline bool __must_check230iwl_op_mode_hw_rf_kill(struct iwl_op_mode *op_mode, bool state)231{232might_sleep();233return op_mode->ops->hw_rf_kill(op_mode, state);234}235236static inline void iwl_op_mode_free_skb(struct iwl_op_mode *op_mode,237struct sk_buff *skb)238{239if (WARN_ON_ONCE(!op_mode))240return;241op_mode->ops->free_skb(op_mode, skb);242}243244static inline void iwl_op_mode_nic_error(struct iwl_op_mode *op_mode,245enum iwl_fw_error_type type)246{247op_mode->ops->nic_error(op_mode, type);248}249250static inline void iwl_op_mode_dump_error(struct iwl_op_mode *op_mode,251struct iwl_fw_error_dump_mode *mode)252{253might_sleep();254255if (WARN_ON(mode->type == IWL_ERR_TYPE_TOP_RESET_BY_BT))256return;257258if (op_mode->ops->dump_error)259op_mode->ops->dump_error(op_mode, mode);260}261262static inline void iwl_op_mode_nic_config(struct iwl_op_mode *op_mode)263{264might_sleep();265if (op_mode->ops->nic_config)266op_mode->ops->nic_config(op_mode);267}268269static inline void iwl_op_mode_wimax_active(struct iwl_op_mode *op_mode)270{271might_sleep();272op_mode->ops->wimax_active(op_mode);273}274275static inline void iwl_op_mode_time_point(struct iwl_op_mode *op_mode,276enum iwl_fw_ini_time_point tp_id,277union iwl_dbg_tlv_tp_data *tp_data)278{279if (!op_mode || !op_mode->ops || !op_mode->ops->time_point)280return;281op_mode->ops->time_point(op_mode, tp_id, tp_data);282}283284static inline void iwl_op_mode_device_powered_off(struct iwl_op_mode *op_mode)285{286if (!op_mode || !op_mode->ops || !op_mode->ops->device_powered_off)287return;288op_mode->ops->device_powered_off(op_mode);289}290291static inline void iwl_op_mode_dump(struct iwl_op_mode *op_mode)292{293if (!op_mode || !op_mode->ops || !op_mode->ops->dump)294return;295op_mode->ops->dump(op_mode);296}297298#endif /* __iwl_op_mode_h__ */299300301