| 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | /* Copyright (C) 2024 Intel Corporation */ |
| 3 | |
| 4 | #ifndef _IDPF_VIRTCHNL_H_ |
| 5 | #define _IDPF_VIRTCHNL_H_ |
| 6 | |
| 7 | #define IDPF_VC_XN_MIN_TIMEOUT_MSEC 2000 |
| 8 | #define IDPF_VC_XN_DEFAULT_TIMEOUT_MSEC (60 * 1000) |
| 9 | #define IDPF_VC_XN_IDX_M GENMASK(7, 0) |
| 10 | #define IDPF_VC_XN_SALT_M GENMASK(15, 8) |
| 11 | #define IDPF_VC_XN_RING_LEN U8_MAX |
| 12 | |
| 13 | /** |
| 14 | * enum idpf_vc_xn_state - Virtchnl transaction status |
| 15 | * @IDPF_VC_XN_IDLE: not expecting a reply, ready to be used |
| 16 | * @IDPF_VC_XN_WAITING: expecting a reply, not yet received |
| 17 | * @IDPF_VC_XN_COMPLETED_SUCCESS: a reply was expected and received, buffer |
| 18 | * updated |
| 19 | * @IDPF_VC_XN_COMPLETED_FAILED: a reply was expected and received, but there |
| 20 | * was an error, buffer not updated |
| 21 | * @IDPF_VC_XN_SHUTDOWN: transaction object cannot be used, VC torn down |
| 22 | * @IDPF_VC_XN_ASYNC: transaction sent asynchronously and doesn't have the |
| 23 | * return context; a callback may be provided to handle |
| 24 | * return |
| 25 | */ |
| 26 | enum idpf_vc_xn_state { |
| 27 | IDPF_VC_XN_IDLE = 1, |
| 28 | IDPF_VC_XN_WAITING, |
| 29 | IDPF_VC_XN_COMPLETED_SUCCESS, |
| 30 | IDPF_VC_XN_COMPLETED_FAILED, |
| 31 | IDPF_VC_XN_SHUTDOWN, |
| 32 | IDPF_VC_XN_ASYNC, |
| 33 | }; |
| 34 | |
| 35 | struct idpf_vc_xn; |
| 36 | /* Callback for asynchronous messages */ |
| 37 | typedef int (*async_vc_cb) (struct idpf_adapter *, struct idpf_vc_xn *, |
| 38 | const struct idpf_ctlq_msg *); |
| 39 | |
| 40 | /** |
| 41 | * struct idpf_vc_xn - Data structure representing virtchnl transactions |
| 42 | * @completed: virtchnl event loop uses that to signal when a reply is |
| 43 | * available, uses kernel completion API |
| 44 | * @state: virtchnl event loop stores the data below, protected by the |
| 45 | * completion's lock. |
| 46 | * @reply_sz: Original size of reply, may be > reply_buf.iov_len; it will be |
| 47 | * truncated on its way to the receiver thread according to |
| 48 | * reply_buf.iov_len. |
| 49 | * @reply: Reference to the buffer(s) where the reply data should be written |
| 50 | * to. May be 0-length (then NULL address permitted) if the reply data |
| 51 | * should be ignored. |
| 52 | * @async_handler: if sent asynchronously, a callback can be provided to handle |
| 53 | * the reply when it's received |
| 54 | * @vc_op: corresponding opcode sent with this transaction |
| 55 | * @idx: index used as retrieval on reply receive, used for cookie |
| 56 | * @salt: changed every message to make unique, used for cookie |
| 57 | */ |
| 58 | struct idpf_vc_xn { |
| 59 | struct completion completed; |
| 60 | enum idpf_vc_xn_state state; |
| 61 | size_t reply_sz; |
| 62 | struct kvec reply; |
| 63 | async_vc_cb async_handler; |
| 64 | u32 vc_op; |
| 65 | u8 idx; |
| 66 | u8 salt; |
| 67 | }; |
| 68 | |
| 69 | /** |
| 70 | * struct idpf_vc_xn_params - Parameters for executing transaction |
| 71 | * @send_buf: kvec for send buffer |
| 72 | * @recv_buf: kvec for recv buffer, may be NULL, must then have zero length |
| 73 | * @timeout_ms: timeout to wait for reply |
| 74 | * @async: send message asynchronously, will not wait on completion |
| 75 | * @async_handler: If sent asynchronously, optional callback handler. The user |
| 76 | * must be careful when using async handlers as the memory for |
| 77 | * the recv_buf _cannot_ be on stack if this is async. |
| 78 | * @vc_op: virtchnl op to send |
| 79 | */ |
| 80 | struct idpf_vc_xn_params { |
| 81 | struct kvec send_buf; |
| 82 | struct kvec recv_buf; |
| 83 | int timeout_ms; |
| 84 | bool async; |
| 85 | async_vc_cb async_handler; |
| 86 | u32 vc_op; |
| 87 | }; |
| 88 | |
| 89 | struct idpf_adapter; |
| 90 | struct idpf_netdev_priv; |
| 91 | struct idpf_vec_regs; |
| 92 | struct idpf_vport; |
| 93 | struct idpf_vport_max_q; |
| 94 | struct idpf_vport_user_config_data; |
| 95 | |
| 96 | ssize_t idpf_vc_xn_exec(struct idpf_adapter *adapter, |
| 97 | const struct idpf_vc_xn_params *params); |
| 98 | int idpf_init_dflt_mbx(struct idpf_adapter *adapter); |
| 99 | void idpf_deinit_dflt_mbx(struct idpf_adapter *adapter); |
| 100 | int idpf_vc_core_init(struct idpf_adapter *adapter); |
| 101 | void idpf_vc_core_deinit(struct idpf_adapter *adapter); |
| 102 | |
| 103 | int idpf_get_reg_intr_vecs(struct idpf_vport *vport, |
| 104 | struct idpf_vec_regs *reg_vals); |
| 105 | int idpf_queue_reg_init(struct idpf_vport *vport); |
| 106 | int idpf_vport_queue_ids_init(struct idpf_vport *vport); |
| 107 | |
| 108 | int idpf_recv_mb_msg(struct idpf_adapter *adapter); |
| 109 | int idpf_send_mb_msg(struct idpf_adapter *adapter, u32 op, |
| 110 | u16 msg_size, u8 *msg, u16 cookie); |
| 111 | |
| 112 | void idpf_vport_init(struct idpf_vport *vport, struct idpf_vport_max_q *max_q); |
| 113 | u32 idpf_get_vport_id(struct idpf_vport *vport); |
| 114 | int idpf_send_create_vport_msg(struct idpf_adapter *adapter, |
| 115 | struct idpf_vport_max_q *max_q); |
| 116 | int idpf_send_destroy_vport_msg(struct idpf_vport *vport); |
| 117 | int idpf_send_enable_vport_msg(struct idpf_vport *vport); |
| 118 | int idpf_send_disable_vport_msg(struct idpf_vport *vport); |
| 119 | |
| 120 | int idpf_vport_adjust_qs(struct idpf_vport *vport); |
| 121 | int idpf_vport_alloc_max_qs(struct idpf_adapter *adapter, |
| 122 | struct idpf_vport_max_q *max_q); |
| 123 | void idpf_vport_dealloc_max_qs(struct idpf_adapter *adapter, |
| 124 | struct idpf_vport_max_q *max_q); |
| 125 | int idpf_send_add_queues_msg(const struct idpf_vport *vport, u16 num_tx_q, |
| 126 | u16 num_complq, u16 num_rx_q, u16 num_rx_bufq); |
| 127 | int idpf_send_delete_queues_msg(struct idpf_vport *vport); |
| 128 | int idpf_send_enable_queues_msg(struct idpf_vport *vport); |
| 129 | int idpf_send_disable_queues_msg(struct idpf_vport *vport); |
| 130 | int idpf_send_config_queues_msg(struct idpf_vport *vport); |
| 131 | |
| 132 | int idpf_vport_alloc_vec_indexes(struct idpf_vport *vport); |
| 133 | int idpf_get_vec_ids(struct idpf_adapter *adapter, |
| 134 | u16 *vecids, int num_vecids, |
| 135 | struct virtchnl2_vector_chunks *chunks); |
| 136 | int idpf_send_alloc_vectors_msg(struct idpf_adapter *adapter, u16 num_vectors); |
| 137 | int idpf_send_dealloc_vectors_msg(struct idpf_adapter *adapter); |
| 138 | int idpf_send_map_unmap_queue_vector_msg(struct idpf_vport *vport, bool map); |
| 139 | |
| 140 | int idpf_add_del_mac_filters(struct idpf_vport *vport, |
| 141 | struct idpf_netdev_priv *np, |
| 142 | bool add, bool async); |
| 143 | int idpf_set_promiscuous(struct idpf_adapter *adapter, |
| 144 | struct idpf_vport_user_config_data *config_data, |
| 145 | u32 vport_id); |
| 146 | int idpf_check_supported_desc_ids(struct idpf_vport *vport); |
| 147 | int idpf_send_get_rx_ptype_msg(struct idpf_vport *vport); |
| 148 | int idpf_send_ena_dis_loopback_msg(struct idpf_vport *vport); |
| 149 | int idpf_send_get_stats_msg(struct idpf_vport *vport); |
| 150 | int idpf_send_set_sriov_vfs_msg(struct idpf_adapter *adapter, u16 num_vfs); |
| 151 | int (struct idpf_vport *vport, bool get); |
| 152 | int (struct idpf_vport *vport, bool get); |
| 153 | void idpf_vc_xn_shutdown(struct idpf_vc_xn_manager *vcxn_mngr); |
| 154 | |
| 155 | #endif /* _IDPF_VIRTCHNL_H_ */ |
| 156 | |