1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* Copyright(c) 2017 - 2019 Pensando Systems, Inc */ 3 4 #ifndef _IONIC_LIF_H_ 5 #define _IONIC_LIF_H_ 6 7 #include <linux/dim.h> 8 #include <linux/pci.h> 9 #include "ionic_rx_filter.h" 10 11 #define IONIC_ADMINQ_LENGTH 16 /* must be a power of two */ 12 #define IONIC_NOTIFYQ_LENGTH 64 /* must be a power of two */ 13 14 #define IONIC_MAX_NUM_NAPI_CNTR (NAPI_POLL_WEIGHT + 1) 15 #define IONIC_MAX_NUM_SG_CNTR (IONIC_TX_MAX_SG_ELEMS + 1) 16 17 #define ADD_ADDR true 18 #define DEL_ADDR false 19 #define CAN_SLEEP true 20 #define CAN_NOT_SLEEP false 21 22 #define IONIC_RX_COPYBREAK_DEFAULT 256 23 #define IONIC_TX_BUDGET_DEFAULT 256 24 25 struct ionic_tx_stats { 26 u64 pkts; 27 u64 bytes; 28 u64 csum_none; 29 u64 csum; 30 u64 tso; 31 u64 tso_bytes; 32 u64 frags; 33 u64 vlan_inserted; 34 u64 clean; 35 u64 linearize; 36 u64 crc32_csum; 37 u64 sg_cntr[IONIC_MAX_NUM_SG_CNTR]; 38 u64 dma_map_err; 39 }; 40 41 struct ionic_rx_stats { 42 u64 pkts; 43 u64 bytes; 44 u64 csum_none; 45 u64 csum_complete; 46 u64 buffers_posted; 47 u64 dropped; 48 u64 vlan_stripped; 49 u64 csum_error; 50 u64 dma_map_err; 51 u64 alloc_err; 52 }; 53 54 #define IONIC_QCQ_F_INITED BIT(0) 55 #define IONIC_QCQ_F_SG BIT(1) 56 #define IONIC_QCQ_F_INTR BIT(2) 57 #define IONIC_QCQ_F_TX_STATS BIT(3) 58 #define IONIC_QCQ_F_RX_STATS BIT(4) 59 #define IONIC_QCQ_F_NOTIFYQ BIT(5) 60 61 struct ionic_napi_stats { 62 u64 poll_count; 63 u64 work_done_cntr[IONIC_MAX_NUM_NAPI_CNTR]; 64 }; 65 66 struct ionic_qcq { 67 void *q_base; 68 dma_addr_t q_base_pa; 69 u32 q_size; 70 void *cq_base; 71 dma_addr_t cq_base_pa; 72 u32 cq_size; 73 void *sg_base; 74 dma_addr_t sg_base_pa; 75 u32 sg_size; 76 struct dim dim; 77 struct ionic_queue q; 78 struct ionic_cq cq; 79 struct ionic_intr_info intr; 80 struct napi_struct napi; 81 struct ionic_napi_stats napi_stats; 82 unsigned int flags; 83 struct dentry *dentry; 84 }; 85 86 #define q_to_qcq(q) container_of(q, struct ionic_qcq, q) 87 #define q_to_tx_stats(q) (&(q)->lif->txqstats[(q)->index]) 88 #define q_to_rx_stats(q) (&(q)->lif->rxqstats[(q)->index]) 89 #define napi_to_qcq(napi) container_of(napi, struct ionic_qcq, napi) 90 #define napi_to_cq(napi) (&napi_to_qcq(napi)->cq) 91 92 enum ionic_deferred_work_type { 93 IONIC_DW_TYPE_RX_MODE, 94 IONIC_DW_TYPE_RX_ADDR_ADD, 95 IONIC_DW_TYPE_RX_ADDR_DEL, 96 IONIC_DW_TYPE_LINK_STATUS, 97 IONIC_DW_TYPE_LIF_RESET, 98 }; 99 100 struct ionic_deferred_work { 101 struct list_head list; 102 enum ionic_deferred_work_type type; 103 union { 104 unsigned int rx_mode; 105 u8 addr[ETH_ALEN]; 106 u8 fw_status; 107 }; 108 }; 109 110 struct ionic_deferred { 111 spinlock_t lock; /* lock for deferred work list */ 112 struct list_head list; 113 struct work_struct work; 114 }; 115 116 struct ionic_lif_sw_stats { 117 u64 tx_packets; 118 u64 tx_bytes; 119 u64 rx_packets; 120 u64 rx_bytes; 121 u64 tx_tso; 122 u64 tx_tso_bytes; 123 u64 tx_csum_none; 124 u64 tx_csum; 125 u64 rx_csum_none; 126 u64 rx_csum_complete; 127 u64 rx_csum_error; 128 u64 hw_tx_dropped; 129 u64 hw_rx_dropped; 130 u64 hw_rx_over_errors; 131 u64 hw_rx_missed_errors; 132 u64 hw_tx_aborted_errors; 133 }; 134 135 enum ionic_lif_state_flags { 136 IONIC_LIF_F_INITED, 137 IONIC_LIF_F_SW_DEBUG_STATS, 138 IONIC_LIF_F_UP, 139 IONIC_LIF_F_LINK_CHECK_REQUESTED, 140 IONIC_LIF_F_FW_RESET, 141 IONIC_LIF_F_SPLIT_INTR, 142 IONIC_LIF_F_TX_DIM_INTR, 143 IONIC_LIF_F_RX_DIM_INTR, 144 145 /* leave this as last */ 146 IONIC_LIF_F_STATE_SIZE 147 }; 148 149 struct ionic_qtype_info { 150 u8 version; 151 u8 supported; 152 u64 features; 153 u16 desc_sz; 154 u16 comp_sz; 155 u16 sg_desc_sz; 156 u16 max_sg_elems; 157 u16 sg_desc_stride; 158 }; 159 160 #define IONIC_LIF_NAME_MAX_SZ 32 161 struct ionic_lif { 162 struct net_device *netdev; 163 DECLARE_BITMAP(state, IONIC_LIF_F_STATE_SIZE); 164 struct ionic *ionic; 165 unsigned int index; 166 unsigned int hw_index; 167 struct mutex queue_lock; /* lock for queue structures */ 168 spinlock_t adminq_lock; /* lock for AdminQ operations */ 169 struct ionic_qcq *adminqcq; 170 struct ionic_qcq *notifyqcq; 171 struct ionic_qcq **txqcqs; 172 struct ionic_tx_stats *txqstats; 173 struct ionic_qcq **rxqcqs; 174 struct ionic_rx_stats *rxqstats; 175 struct ionic_deferred deferred; 176 struct work_struct tx_timeout_work; 177 u64 last_eid; 178 unsigned int kern_pid; 179 u64 __iomem *kern_dbpage; 180 unsigned int neqs; 181 unsigned int nxqs; 182 unsigned int ntxq_descs; 183 unsigned int nrxq_descs; 184 u32 rx_copybreak; 185 unsigned int rx_mode; 186 u64 hw_features; 187 bool registered; 188 bool mc_overflow; 189 bool uc_overflow; 190 u16 lif_type; 191 unsigned int nmcast; 192 unsigned int nucast; 193 char name[IONIC_LIF_NAME_MAX_SZ]; 194 195 union ionic_lif_identity *identity; 196 struct ionic_lif_info *info; 197 dma_addr_t info_pa; 198 u32 info_sz; 199 struct ionic_qtype_info qtype_info[IONIC_QTYPE_MAX]; 200 201 u16 rss_types; 202 u8 rss_hash_key[IONIC_RSS_HASH_KEY_SIZE]; 203 u8 *rss_ind_tbl; 204 dma_addr_t rss_ind_tbl_pa; 205 u32 rss_ind_tbl_sz; 206 207 struct ionic_rx_filters rx_filters; 208 u32 rx_coalesce_usecs; /* what the user asked for */ 209 u32 rx_coalesce_hw; /* what the hw is using */ 210 u32 tx_coalesce_usecs; /* what the user asked for */ 211 u32 tx_coalesce_hw; /* what the hw is using */ 212 unsigned long *dbid_inuse; 213 unsigned int dbid_count; 214 215 struct dentry *dentry; 216 }; 217 218 struct ionic_queue_params { 219 unsigned int nxqs; 220 unsigned int ntxq_descs; 221 unsigned int nrxq_descs; 222 unsigned int intr_split; 223 }; 224 225 static inline void ionic_init_queue_params(struct ionic_lif *lif, 226 struct ionic_queue_params *qparam) 227 { 228 qparam->nxqs = lif->nxqs; 229 qparam->ntxq_descs = lif->ntxq_descs; 230 qparam->nrxq_descs = lif->nrxq_descs; 231 qparam->intr_split = test_bit(IONIC_LIF_F_SPLIT_INTR, lif->state); 232 } 233 234 static inline u32 ionic_coal_usec_to_hw(struct ionic *ionic, u32 usecs) 235 { 236 u32 mult = le32_to_cpu(ionic->ident.dev.intr_coal_mult); 237 u32 div = le32_to_cpu(ionic->ident.dev.intr_coal_div); 238 239 /* Div-by-zero should never be an issue, but check anyway */ 240 if (!div || !mult) 241 return 0; 242 243 /* Round up in case usecs is close to the next hw unit */ 244 usecs += (div / mult) >> 1; 245 246 /* Convert from usecs to device units */ 247 return (usecs * mult) / div; 248 } 249 250 void ionic_link_status_check_request(struct ionic_lif *lif, bool can_sleep); 251 void ionic_get_stats64(struct net_device *netdev, 252 struct rtnl_link_stats64 *ns); 253 void ionic_lif_deferred_enqueue(struct ionic_deferred *def, 254 struct ionic_deferred_work *work); 255 int ionic_lif_alloc(struct ionic *ionic); 256 int ionic_lif_init(struct ionic_lif *lif); 257 void ionic_lif_free(struct ionic_lif *lif); 258 void ionic_lif_deinit(struct ionic_lif *lif); 259 int ionic_lif_register(struct ionic_lif *lif); 260 void ionic_lif_unregister(struct ionic_lif *lif); 261 int ionic_lif_identify(struct ionic *ionic, u8 lif_type, 262 union ionic_lif_identity *lif_ident); 263 int ionic_lif_size(struct ionic *ionic); 264 int ionic_lif_rss_config(struct ionic_lif *lif, u16 types, 265 const u8 *key, const u32 *indir); 266 int ionic_reconfigure_queues(struct ionic_lif *lif, 267 struct ionic_queue_params *qparam); 268 269 static inline void debug_stats_txq_post(struct ionic_queue *q, bool dbell) 270 { 271 struct ionic_txq_desc *desc = &q->txq[q->head_idx]; 272 u8 num_sg_elems; 273 274 q->dbell_count += dbell; 275 276 num_sg_elems = ((le64_to_cpu(desc->cmd) >> IONIC_TXQ_DESC_NSGE_SHIFT) 277 & IONIC_TXQ_DESC_NSGE_MASK); 278 if (num_sg_elems > (IONIC_MAX_NUM_SG_CNTR - 1)) 279 num_sg_elems = IONIC_MAX_NUM_SG_CNTR - 1; 280 281 q->lif->txqstats[q->index].sg_cntr[num_sg_elems]++; 282 } 283 284 static inline void debug_stats_napi_poll(struct ionic_qcq *qcq, 285 unsigned int work_done) 286 { 287 qcq->napi_stats.poll_count++; 288 289 if (work_done > (IONIC_MAX_NUM_NAPI_CNTR - 1)) 290 work_done = IONIC_MAX_NUM_NAPI_CNTR - 1; 291 292 qcq->napi_stats.work_done_cntr[work_done]++; 293 } 294 295 #define DEBUG_STATS_CQE_CNT(cq) ((cq)->compl_count++) 296 #define DEBUG_STATS_RX_BUFF_CNT(q) ((q)->lif->rxqstats[q->index].buffers_posted++) 297 #define DEBUG_STATS_TXQ_POST(q, dbell) debug_stats_txq_post(q, dbell) 298 #define DEBUG_STATS_NAPI_POLL(qcq, work_done) \ 299 debug_stats_napi_poll(qcq, work_done) 300 301 #endif /* _IONIC_LIF_H_ */ 302