162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Copyright (C) 2005-2014, 2018-2021 Intel Corporation 462306a36Sopenharmony_ci * Copyright (C) 2013-2014 Intel Mobile Communications GmbH 562306a36Sopenharmony_ci * Copyright (C) 2015 Intel Deutschland GmbH 662306a36Sopenharmony_ci */ 762306a36Sopenharmony_ci#ifndef __iwl_op_mode_h__ 862306a36Sopenharmony_ci#define __iwl_op_mode_h__ 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ci#include <linux/netdevice.h> 1162306a36Sopenharmony_ci#include <linux/debugfs.h> 1262306a36Sopenharmony_ci#include "iwl-dbg-tlv.h" 1362306a36Sopenharmony_ci 1462306a36Sopenharmony_cistruct iwl_op_mode; 1562306a36Sopenharmony_cistruct iwl_trans; 1662306a36Sopenharmony_cistruct sk_buff; 1762306a36Sopenharmony_cistruct iwl_device_cmd; 1862306a36Sopenharmony_cistruct iwl_rx_cmd_buffer; 1962306a36Sopenharmony_cistruct iwl_fw; 2062306a36Sopenharmony_cistruct iwl_cfg; 2162306a36Sopenharmony_ci 2262306a36Sopenharmony_ci/** 2362306a36Sopenharmony_ci * DOC: Operational mode - what is it ? 2462306a36Sopenharmony_ci * 2562306a36Sopenharmony_ci * The operational mode (a.k.a. op_mode) is the layer that implements 2662306a36Sopenharmony_ci * mac80211's handlers. It knows two APIs: mac80211's and the fw's. It uses 2762306a36Sopenharmony_ci * the transport API to access the HW. The op_mode doesn't need to know how the 2862306a36Sopenharmony_ci * underlying HW works, since the transport layer takes care of that. 2962306a36Sopenharmony_ci * 3062306a36Sopenharmony_ci * There can be several op_mode: i.e. different fw APIs will require two 3162306a36Sopenharmony_ci * different op_modes. This is why the op_mode is virtualized. 3262306a36Sopenharmony_ci */ 3362306a36Sopenharmony_ci 3462306a36Sopenharmony_ci/** 3562306a36Sopenharmony_ci * DOC: Life cycle of the Operational mode 3662306a36Sopenharmony_ci * 3762306a36Sopenharmony_ci * The operational mode has a very simple life cycle. 3862306a36Sopenharmony_ci * 3962306a36Sopenharmony_ci * 1) The driver layer (iwl-drv.c) chooses the op_mode based on the 4062306a36Sopenharmony_ci * capabilities advertised by the fw file (in TLV format). 4162306a36Sopenharmony_ci * 2) The driver layer starts the op_mode (ops->start) 4262306a36Sopenharmony_ci * 3) The op_mode registers mac80211 4362306a36Sopenharmony_ci * 4) The op_mode is governed by mac80211 4462306a36Sopenharmony_ci * 5) The driver layer stops the op_mode 4562306a36Sopenharmony_ci */ 4662306a36Sopenharmony_ci 4762306a36Sopenharmony_ci/** 4862306a36Sopenharmony_ci * struct iwl_op_mode_ops - op_mode specific operations 4962306a36Sopenharmony_ci * 5062306a36Sopenharmony_ci * The op_mode exports its ops so that external components can start it and 5162306a36Sopenharmony_ci * interact with it. The driver layer typically calls the start and stop 5262306a36Sopenharmony_ci * handlers, the transport layer calls the others. 5362306a36Sopenharmony_ci * 5462306a36Sopenharmony_ci * All the handlers MUST be implemented, except @rx_rss which can be left 5562306a36Sopenharmony_ci * out *iff* the opmode will never run on hardware with multi-queue capability. 5662306a36Sopenharmony_ci * 5762306a36Sopenharmony_ci * @start: start the op_mode. The transport layer is already allocated. 5862306a36Sopenharmony_ci * May sleep 5962306a36Sopenharmony_ci * @stop: stop the op_mode. Must free all the memory allocated. 6062306a36Sopenharmony_ci * May sleep 6162306a36Sopenharmony_ci * @rx: Rx notification to the op_mode. rxb is the Rx buffer itself. Cmd is the 6262306a36Sopenharmony_ci * HCMD this Rx responds to. Can't sleep. 6362306a36Sopenharmony_ci * @rx_rss: data queue RX notification to the op_mode, for (data) notifications 6462306a36Sopenharmony_ci * received on the RSS queue(s). The queue parameter indicates which of the 6562306a36Sopenharmony_ci * RSS queues received this frame; it will always be non-zero. 6662306a36Sopenharmony_ci * This method must not sleep. 6762306a36Sopenharmony_ci * @async_cb: called when an ASYNC command with CMD_WANT_ASYNC_CALLBACK set 6862306a36Sopenharmony_ci * completes. Must be atomic. 6962306a36Sopenharmony_ci * @queue_full: notifies that a HW queue is full. 7062306a36Sopenharmony_ci * Must be atomic and called with BH disabled. 7162306a36Sopenharmony_ci * @queue_not_full: notifies that a HW queue is not full any more. 7262306a36Sopenharmony_ci * Must be atomic and called with BH disabled. 7362306a36Sopenharmony_ci * @hw_rf_kill:notifies of a change in the HW rf kill switch. True means that 7462306a36Sopenharmony_ci * the radio is killed. Return %true if the device should be stopped by 7562306a36Sopenharmony_ci * the transport immediately after the call. May sleep. 7662306a36Sopenharmony_ci * @free_skb: allows the transport layer to free skbs that haven't been 7762306a36Sopenharmony_ci * reclaimed by the op_mode. This can happen when the driver is freed and 7862306a36Sopenharmony_ci * there are Tx packets pending in the transport layer. 7962306a36Sopenharmony_ci * Must be atomic 8062306a36Sopenharmony_ci * @nic_error: error notification. Must be atomic and must be called with BH 8162306a36Sopenharmony_ci * disabled, unless the sync parameter is true. 8262306a36Sopenharmony_ci * @cmd_queue_full: Called when the command queue gets full. Must be atomic and 8362306a36Sopenharmony_ci * called with BH disabled. 8462306a36Sopenharmony_ci * @nic_config: configure NIC, called before firmware is started. 8562306a36Sopenharmony_ci * May sleep 8662306a36Sopenharmony_ci * @wimax_active: invoked when WiMax becomes active. May sleep 8762306a36Sopenharmony_ci * @time_point: called when transport layer wants to collect debug data 8862306a36Sopenharmony_ci */ 8962306a36Sopenharmony_cistruct iwl_op_mode_ops { 9062306a36Sopenharmony_ci struct iwl_op_mode *(*start)(struct iwl_trans *trans, 9162306a36Sopenharmony_ci const struct iwl_cfg *cfg, 9262306a36Sopenharmony_ci const struct iwl_fw *fw, 9362306a36Sopenharmony_ci struct dentry *dbgfs_dir); 9462306a36Sopenharmony_ci void (*stop)(struct iwl_op_mode *op_mode); 9562306a36Sopenharmony_ci void (*rx)(struct iwl_op_mode *op_mode, struct napi_struct *napi, 9662306a36Sopenharmony_ci struct iwl_rx_cmd_buffer *rxb); 9762306a36Sopenharmony_ci void (*rx_rss)(struct iwl_op_mode *op_mode, struct napi_struct *napi, 9862306a36Sopenharmony_ci struct iwl_rx_cmd_buffer *rxb, unsigned int queue); 9962306a36Sopenharmony_ci void (*async_cb)(struct iwl_op_mode *op_mode, 10062306a36Sopenharmony_ci const struct iwl_device_cmd *cmd); 10162306a36Sopenharmony_ci void (*queue_full)(struct iwl_op_mode *op_mode, int queue); 10262306a36Sopenharmony_ci void (*queue_not_full)(struct iwl_op_mode *op_mode, int queue); 10362306a36Sopenharmony_ci bool (*hw_rf_kill)(struct iwl_op_mode *op_mode, bool state); 10462306a36Sopenharmony_ci void (*free_skb)(struct iwl_op_mode *op_mode, struct sk_buff *skb); 10562306a36Sopenharmony_ci void (*nic_error)(struct iwl_op_mode *op_mode, bool sync); 10662306a36Sopenharmony_ci void (*cmd_queue_full)(struct iwl_op_mode *op_mode); 10762306a36Sopenharmony_ci void (*nic_config)(struct iwl_op_mode *op_mode); 10862306a36Sopenharmony_ci void (*wimax_active)(struct iwl_op_mode *op_mode); 10962306a36Sopenharmony_ci void (*time_point)(struct iwl_op_mode *op_mode, 11062306a36Sopenharmony_ci enum iwl_fw_ini_time_point tp_id, 11162306a36Sopenharmony_ci union iwl_dbg_tlv_tp_data *tp_data); 11262306a36Sopenharmony_ci}; 11362306a36Sopenharmony_ci 11462306a36Sopenharmony_ciint iwl_opmode_register(const char *name, const struct iwl_op_mode_ops *ops); 11562306a36Sopenharmony_civoid iwl_opmode_deregister(const char *name); 11662306a36Sopenharmony_ci 11762306a36Sopenharmony_ci/** 11862306a36Sopenharmony_ci * struct iwl_op_mode - operational mode 11962306a36Sopenharmony_ci * @ops: pointer to its own ops 12062306a36Sopenharmony_ci * 12162306a36Sopenharmony_ci * This holds an implementation of the mac80211 / fw API. 12262306a36Sopenharmony_ci */ 12362306a36Sopenharmony_cistruct iwl_op_mode { 12462306a36Sopenharmony_ci const struct iwl_op_mode_ops *ops; 12562306a36Sopenharmony_ci 12662306a36Sopenharmony_ci char op_mode_specific[] __aligned(sizeof(void *)); 12762306a36Sopenharmony_ci}; 12862306a36Sopenharmony_ci 12962306a36Sopenharmony_cistatic inline void iwl_op_mode_stop(struct iwl_op_mode *op_mode) 13062306a36Sopenharmony_ci{ 13162306a36Sopenharmony_ci might_sleep(); 13262306a36Sopenharmony_ci op_mode->ops->stop(op_mode); 13362306a36Sopenharmony_ci} 13462306a36Sopenharmony_ci 13562306a36Sopenharmony_cistatic inline void iwl_op_mode_rx(struct iwl_op_mode *op_mode, 13662306a36Sopenharmony_ci struct napi_struct *napi, 13762306a36Sopenharmony_ci struct iwl_rx_cmd_buffer *rxb) 13862306a36Sopenharmony_ci{ 13962306a36Sopenharmony_ci return op_mode->ops->rx(op_mode, napi, rxb); 14062306a36Sopenharmony_ci} 14162306a36Sopenharmony_ci 14262306a36Sopenharmony_cistatic inline void iwl_op_mode_rx_rss(struct iwl_op_mode *op_mode, 14362306a36Sopenharmony_ci struct napi_struct *napi, 14462306a36Sopenharmony_ci struct iwl_rx_cmd_buffer *rxb, 14562306a36Sopenharmony_ci unsigned int queue) 14662306a36Sopenharmony_ci{ 14762306a36Sopenharmony_ci op_mode->ops->rx_rss(op_mode, napi, rxb, queue); 14862306a36Sopenharmony_ci} 14962306a36Sopenharmony_ci 15062306a36Sopenharmony_cistatic inline void iwl_op_mode_async_cb(struct iwl_op_mode *op_mode, 15162306a36Sopenharmony_ci const struct iwl_device_cmd *cmd) 15262306a36Sopenharmony_ci{ 15362306a36Sopenharmony_ci if (op_mode->ops->async_cb) 15462306a36Sopenharmony_ci op_mode->ops->async_cb(op_mode, cmd); 15562306a36Sopenharmony_ci} 15662306a36Sopenharmony_ci 15762306a36Sopenharmony_cistatic inline void iwl_op_mode_queue_full(struct iwl_op_mode *op_mode, 15862306a36Sopenharmony_ci int queue) 15962306a36Sopenharmony_ci{ 16062306a36Sopenharmony_ci op_mode->ops->queue_full(op_mode, queue); 16162306a36Sopenharmony_ci} 16262306a36Sopenharmony_ci 16362306a36Sopenharmony_cistatic inline void iwl_op_mode_queue_not_full(struct iwl_op_mode *op_mode, 16462306a36Sopenharmony_ci int queue) 16562306a36Sopenharmony_ci{ 16662306a36Sopenharmony_ci op_mode->ops->queue_not_full(op_mode, queue); 16762306a36Sopenharmony_ci} 16862306a36Sopenharmony_ci 16962306a36Sopenharmony_cistatic inline bool __must_check 17062306a36Sopenharmony_ciiwl_op_mode_hw_rf_kill(struct iwl_op_mode *op_mode, bool state) 17162306a36Sopenharmony_ci{ 17262306a36Sopenharmony_ci might_sleep(); 17362306a36Sopenharmony_ci return op_mode->ops->hw_rf_kill(op_mode, state); 17462306a36Sopenharmony_ci} 17562306a36Sopenharmony_ci 17662306a36Sopenharmony_cistatic inline void iwl_op_mode_free_skb(struct iwl_op_mode *op_mode, 17762306a36Sopenharmony_ci struct sk_buff *skb) 17862306a36Sopenharmony_ci{ 17962306a36Sopenharmony_ci if (WARN_ON_ONCE(!op_mode)) 18062306a36Sopenharmony_ci return; 18162306a36Sopenharmony_ci op_mode->ops->free_skb(op_mode, skb); 18262306a36Sopenharmony_ci} 18362306a36Sopenharmony_ci 18462306a36Sopenharmony_cistatic inline void iwl_op_mode_nic_error(struct iwl_op_mode *op_mode, bool sync) 18562306a36Sopenharmony_ci{ 18662306a36Sopenharmony_ci op_mode->ops->nic_error(op_mode, sync); 18762306a36Sopenharmony_ci} 18862306a36Sopenharmony_ci 18962306a36Sopenharmony_cistatic inline void iwl_op_mode_cmd_queue_full(struct iwl_op_mode *op_mode) 19062306a36Sopenharmony_ci{ 19162306a36Sopenharmony_ci op_mode->ops->cmd_queue_full(op_mode); 19262306a36Sopenharmony_ci} 19362306a36Sopenharmony_ci 19462306a36Sopenharmony_cistatic inline void iwl_op_mode_nic_config(struct iwl_op_mode *op_mode) 19562306a36Sopenharmony_ci{ 19662306a36Sopenharmony_ci might_sleep(); 19762306a36Sopenharmony_ci op_mode->ops->nic_config(op_mode); 19862306a36Sopenharmony_ci} 19962306a36Sopenharmony_ci 20062306a36Sopenharmony_cistatic inline void iwl_op_mode_wimax_active(struct iwl_op_mode *op_mode) 20162306a36Sopenharmony_ci{ 20262306a36Sopenharmony_ci might_sleep(); 20362306a36Sopenharmony_ci op_mode->ops->wimax_active(op_mode); 20462306a36Sopenharmony_ci} 20562306a36Sopenharmony_ci 20662306a36Sopenharmony_cistatic inline void iwl_op_mode_time_point(struct iwl_op_mode *op_mode, 20762306a36Sopenharmony_ci enum iwl_fw_ini_time_point tp_id, 20862306a36Sopenharmony_ci union iwl_dbg_tlv_tp_data *tp_data) 20962306a36Sopenharmony_ci{ 21062306a36Sopenharmony_ci if (!op_mode || !op_mode->ops || !op_mode->ops->time_point) 21162306a36Sopenharmony_ci return; 21262306a36Sopenharmony_ci op_mode->ops->time_point(op_mode, tp_id, tp_data); 21362306a36Sopenharmony_ci} 21462306a36Sopenharmony_ci 21562306a36Sopenharmony_ci#endif /* __iwl_op_mode_h__ */ 216