1 // SPDX-License-Identifier: GPL-2.0-only 2 /* Copyright (C) 2023 Intel Corporation */ 3 4 #include "idpf.h" 5 #include "idpf_lan_vf_regs.h" 6 7 #define IDPF_VF_ITR_IDX_SPACING 0x40 8 9 /** 10 * idpf_vf_ctlq_reg_init - initialize default mailbox registers 11 * @cq: pointer to the array of create control queues 12 */ 13 static void idpf_vf_ctlq_reg_init(struct idpf_ctlq_create_info *cq) 14 { 15 int i; 16 17 for (i = 0; i < IDPF_NUM_DFLT_MBX_Q; i++) { 18 struct idpf_ctlq_create_info *ccq = cq + i; 19 20 switch (ccq->type) { 21 case IDPF_CTLQ_TYPE_MAILBOX_TX: 22 /* set head and tail registers in our local struct */ 23 ccq->reg.head = VF_ATQH; 24 ccq->reg.tail = VF_ATQT; 25 ccq->reg.len = VF_ATQLEN; 26 ccq->reg.bah = VF_ATQBAH; 27 ccq->reg.bal = VF_ATQBAL; 28 ccq->reg.len_mask = VF_ATQLEN_ATQLEN_M; 29 ccq->reg.len_ena_mask = VF_ATQLEN_ATQENABLE_M; 30 ccq->reg.head_mask = VF_ATQH_ATQH_M; 31 break; 32 case IDPF_CTLQ_TYPE_MAILBOX_RX: 33 /* set head and tail registers in our local struct */ 34 ccq->reg.head = VF_ARQH; 35 ccq->reg.tail = VF_ARQT; 36 ccq->reg.len = VF_ARQLEN; 37 ccq->reg.bah = VF_ARQBAH; 38 ccq->reg.bal = VF_ARQBAL; 39 ccq->reg.len_mask = VF_ARQLEN_ARQLEN_M; 40 ccq->reg.len_ena_mask = VF_ARQLEN_ARQENABLE_M; 41 ccq->reg.head_mask = VF_ARQH_ARQH_M; 42 break; 43 default: 44 break; 45 } 46 } 47 } 48 49 /** 50 * idpf_vf_mb_intr_reg_init - Initialize the mailbox register 51 * @adapter: adapter structure 52 */ 53 static void idpf_vf_mb_intr_reg_init(struct idpf_adapter *adapter) 54 { 55 struct idpf_intr_reg *intr = &adapter->mb_vector.intr_reg; 56 u32 dyn_ctl = le32_to_cpu(adapter->caps.mailbox_dyn_ctl); 57 58 intr->dyn_ctl = idpf_get_reg_addr(adapter, dyn_ctl); 59 intr->dyn_ctl_intena_m = VF_INT_DYN_CTL0_INTENA_M; 60 intr->dyn_ctl_itridx_m = VF_INT_DYN_CTL0_ITR_INDX_M; 61 intr->icr_ena = idpf_get_reg_addr(adapter, VF_INT_ICR0_ENA1); 62 intr->icr_ena_ctlq_m = VF_INT_ICR0_ENA1_ADMINQ_M; 63 } 64 65 /** 66 * idpf_vf_intr_reg_init - Initialize interrupt registers 67 * @vport: virtual port structure 68 */ 69 static int idpf_vf_intr_reg_init(struct idpf_vport *vport) 70 { 71 struct idpf_adapter *adapter = vport->adapter; 72 int num_vecs = vport->num_q_vectors; 73 struct idpf_vec_regs *reg_vals; 74 int num_regs, i, err = 0; 75 u32 rx_itr, tx_itr; 76 u16 total_vecs; 77 78 total_vecs = idpf_get_reserved_vecs(vport->adapter); 79 reg_vals = kcalloc(total_vecs, sizeof(struct idpf_vec_regs), 80 GFP_KERNEL); 81 if (!reg_vals) 82 return -ENOMEM; 83 84 num_regs = idpf_get_reg_intr_vecs(vport, reg_vals); 85 if (num_regs < num_vecs) { 86 err = -EINVAL; 87 goto free_reg_vals; 88 } 89 90 for (i = 0; i < num_vecs; i++) { 91 struct idpf_q_vector *q_vector = &vport->q_vectors[i]; 92 u16 vec_id = vport->q_vector_idxs[i] - IDPF_MBX_Q_VEC; 93 struct idpf_intr_reg *intr = &q_vector->intr_reg; 94 u32 spacing; 95 96 intr->dyn_ctl = idpf_get_reg_addr(adapter, 97 reg_vals[vec_id].dyn_ctl_reg); 98 intr->dyn_ctl_intena_m = VF_INT_DYN_CTLN_INTENA_M; 99 intr->dyn_ctl_itridx_s = VF_INT_DYN_CTLN_ITR_INDX_S; 100 101 spacing = IDPF_ITR_IDX_SPACING(reg_vals[vec_id].itrn_index_spacing, 102 IDPF_VF_ITR_IDX_SPACING); 103 rx_itr = VF_INT_ITRN_ADDR(VIRTCHNL2_ITR_IDX_0, 104 reg_vals[vec_id].itrn_reg, 105 spacing); 106 tx_itr = VF_INT_ITRN_ADDR(VIRTCHNL2_ITR_IDX_1, 107 reg_vals[vec_id].itrn_reg, 108 spacing); 109 intr->rx_itr = idpf_get_reg_addr(adapter, rx_itr); 110 intr->tx_itr = idpf_get_reg_addr(adapter, tx_itr); 111 } 112 113 free_reg_vals: 114 kfree(reg_vals); 115 116 return err; 117 } 118 119 /** 120 * idpf_vf_reset_reg_init - Initialize reset registers 121 * @adapter: Driver specific private structure 122 */ 123 static void idpf_vf_reset_reg_init(struct idpf_adapter *adapter) 124 { 125 adapter->reset_reg.rstat = idpf_get_reg_addr(adapter, VFGEN_RSTAT); 126 adapter->reset_reg.rstat_m = VFGEN_RSTAT_VFR_STATE_M; 127 } 128 129 /** 130 * idpf_vf_trigger_reset - trigger reset 131 * @adapter: Driver specific private structure 132 * @trig_cause: Reason to trigger a reset 133 */ 134 static void idpf_vf_trigger_reset(struct idpf_adapter *adapter, 135 enum idpf_flags trig_cause) 136 { 137 /* Do not send VIRTCHNL2_OP_RESET_VF message on driver unload */ 138 if (trig_cause == IDPF_HR_FUNC_RESET && 139 !test_bit(IDPF_REMOVE_IN_PROG, adapter->flags)) 140 idpf_send_mb_msg(adapter, VIRTCHNL2_OP_RESET_VF, 0, NULL); 141 } 142 143 /** 144 * idpf_vf_reg_ops_init - Initialize register API function pointers 145 * @adapter: Driver specific private structure 146 */ 147 static void idpf_vf_reg_ops_init(struct idpf_adapter *adapter) 148 { 149 adapter->dev_ops.reg_ops.ctlq_reg_init = idpf_vf_ctlq_reg_init; 150 adapter->dev_ops.reg_ops.intr_reg_init = idpf_vf_intr_reg_init; 151 adapter->dev_ops.reg_ops.mb_intr_reg_init = idpf_vf_mb_intr_reg_init; 152 adapter->dev_ops.reg_ops.reset_reg_init = idpf_vf_reset_reg_init; 153 adapter->dev_ops.reg_ops.trigger_reset = idpf_vf_trigger_reset; 154 } 155 156 /** 157 * idpf_vf_dev_ops_init - Initialize device API function pointers 158 * @adapter: Driver specific private structure 159 */ 160 void idpf_vf_dev_ops_init(struct idpf_adapter *adapter) 161 { 162 idpf_vf_reg_ops_init(adapter); 163 } 164