Yuval Mintz | e712d52 | 2015-10-26 11:02:27 +0200 | [diff] [blame] | 1 | /* QLogic qede NIC Driver |
| 2 | * Copyright (c) 2015 QLogic Corporation |
| 3 | * |
| 4 | * This software is available under the terms of the GNU General Public License |
| 5 | * (GPL) Version 2, available from the file COPYING in the main directory of |
| 6 | * this source tree. |
| 7 | */ |
| 8 | |
| 9 | #ifndef _QEDE_H_ |
| 10 | #define _QEDE_H_ |
| 11 | #include <linux/compiler.h> |
| 12 | #include <linux/version.h> |
| 13 | #include <linux/workqueue.h> |
| 14 | #include <linux/netdevice.h> |
| 15 | #include <linux/interrupt.h> |
| 16 | #include <linux/bitmap.h> |
| 17 | #include <linux/kernel.h> |
| 18 | #include <linux/mutex.h> |
| 19 | #include <linux/io.h> |
| 20 | #include <linux/qed/common_hsi.h> |
| 21 | #include <linux/qed/eth_common.h> |
| 22 | #include <linux/qed/qed_if.h> |
| 23 | #include <linux/qed/qed_chain.h> |
| 24 | #include <linux/qed/qed_eth_if.h> |
| 25 | |
| 26 | #define QEDE_MAJOR_VERSION 8 |
| 27 | #define QEDE_MINOR_VERSION 4 |
| 28 | #define QEDE_REVISION_VERSION 0 |
| 29 | #define QEDE_ENGINEERING_VERSION 0 |
| 30 | #define DRV_MODULE_VERSION __stringify(QEDE_MAJOR_VERSION) "." \ |
| 31 | __stringify(QEDE_MINOR_VERSION) "." \ |
| 32 | __stringify(QEDE_REVISION_VERSION) "." \ |
| 33 | __stringify(QEDE_ENGINEERING_VERSION) |
| 34 | |
| 35 | #define QEDE_ETH_INTERFACE_VERSION 300 |
| 36 | |
| 37 | #define DRV_MODULE_SYM qede |
| 38 | |
| 39 | struct qede_dev { |
| 40 | struct qed_dev *cdev; |
| 41 | struct net_device *ndev; |
| 42 | struct pci_dev *pdev; |
| 43 | |
| 44 | u32 dp_module; |
| 45 | u8 dp_level; |
| 46 | |
| 47 | const struct qed_eth_ops *ops; |
| 48 | |
| 49 | struct qed_dev_eth_info dev_info; |
| 50 | #define QEDE_MAX_RSS_CNT(edev) ((edev)->dev_info.num_queues) |
| 51 | #define QEDE_MAX_TSS_CNT(edev) ((edev)->dev_info.num_queues * \ |
| 52 | (edev)->dev_info.num_tc) |
| 53 | |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame^] | 54 | struct qede_fastpath *fp_array; |
Yuval Mintz | e712d52 | 2015-10-26 11:02:27 +0200 | [diff] [blame] | 55 | u16 num_rss; |
| 56 | u8 num_tc; |
| 57 | #define QEDE_RSS_CNT(edev) ((edev)->num_rss) |
| 58 | #define QEDE_TSS_CNT(edev) ((edev)->num_rss * \ |
| 59 | (edev)->num_tc) |
| 60 | #define QEDE_TSS_IDX(edev, txqidx) ((txqidx) % (edev)->num_rss) |
| 61 | #define QEDE_TC_IDX(edev, txqidx) ((txqidx) / (edev)->num_rss) |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame^] | 62 | #define QEDE_TX_QUEUE(edev, txqidx) \ |
| 63 | (&(edev)->fp_array[QEDE_TSS_IDX((edev), (txqidx))].txqs[QEDE_TC_IDX( \ |
| 64 | (edev), (txqidx))]) |
Yuval Mintz | e712d52 | 2015-10-26 11:02:27 +0200 | [diff] [blame] | 65 | |
| 66 | struct qed_int_info int_info; |
| 67 | unsigned char primary_mac[ETH_ALEN]; |
| 68 | |
| 69 | /* Smaller private varaiant of the RTNL lock */ |
| 70 | struct mutex qede_lock; |
| 71 | u32 state; /* Protected by qede_lock */ |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame^] | 72 | u16 rx_buf_size; |
| 73 | /* L2 header size + 2*VLANs (8 bytes) + LLC SNAP (8 bytes) */ |
| 74 | #define ETH_OVERHEAD (ETH_HLEN + 8 + 8) |
| 75 | /* Max supported alignment is 256 (8 shift) |
| 76 | * minimal alignment shift 6 is optimal for 57xxx HW performance |
| 77 | */ |
| 78 | #define QEDE_RX_ALIGN_SHIFT max(6, min(8, L1_CACHE_SHIFT)) |
| 79 | /* We assume skb_build() uses sizeof(struct skb_shared_info) bytes |
| 80 | * at the end of skb->data, to avoid wasting a full cache line. |
| 81 | * This reduces memory use (skb->truesize). |
| 82 | */ |
| 83 | #define QEDE_FW_RX_ALIGN_END \ |
| 84 | max_t(u64, 1UL << QEDE_RX_ALIGN_SHIFT, \ |
| 85 | SKB_DATA_ALIGN(sizeof(struct skb_shared_info))) |
| 86 | |
| 87 | struct qed_update_vport_rss_params rss_params; |
| 88 | u16 q_num_rx_buffers; /* Must be a power of two */ |
| 89 | u16 q_num_tx_buffers; /* Must be a power of two */ |
| 90 | }; |
| 91 | |
| 92 | enum QEDE_STATE { |
| 93 | QEDE_STATE_CLOSED, |
| 94 | QEDE_STATE_OPEN, |
| 95 | }; |
| 96 | |
| 97 | #define HILO_U64(hi, lo) ((((u64)(hi)) << 32) + (lo)) |
| 98 | |
| 99 | #define MAX_NUM_TC 8 |
| 100 | #define MAX_NUM_PRI 8 |
| 101 | |
| 102 | /* The driver supports the new build_skb() API: |
| 103 | * RX ring buffer contains pointer to kmalloc() data only, |
| 104 | * skb are built only after the frame was DMA-ed. |
| 105 | */ |
| 106 | struct sw_rx_data { |
| 107 | u8 *data; |
| 108 | |
| 109 | DEFINE_DMA_UNMAP_ADDR(mapping); |
| 110 | }; |
| 111 | |
| 112 | struct qede_rx_queue { |
| 113 | __le16 *hw_cons_ptr; |
| 114 | struct sw_rx_data *sw_rx_ring; |
| 115 | u16 sw_rx_cons; |
| 116 | u16 sw_rx_prod; |
| 117 | struct qed_chain rx_bd_ring; |
| 118 | struct qed_chain rx_comp_ring; |
| 119 | void __iomem *hw_rxq_prod_addr; |
| 120 | |
| 121 | int rx_buf_size; |
| 122 | |
| 123 | u16 num_rx_buffers; |
| 124 | u16 rxq_id; |
| 125 | |
| 126 | u64 rx_hw_errors; |
| 127 | u64 rx_alloc_errors; |
| 128 | }; |
| 129 | |
| 130 | union db_prod { |
| 131 | struct eth_db_data data; |
| 132 | u32 raw; |
| 133 | }; |
| 134 | |
| 135 | struct sw_tx_bd { |
| 136 | struct sk_buff *skb; |
| 137 | u8 flags; |
| 138 | /* Set on the first BD descriptor when there is a split BD */ |
| 139 | #define QEDE_TSO_SPLIT_BD BIT(0) |
| 140 | }; |
| 141 | |
| 142 | struct qede_tx_queue { |
| 143 | int index; /* Queue index */ |
| 144 | __le16 *hw_cons_ptr; |
| 145 | struct sw_tx_bd *sw_tx_ring; |
| 146 | u16 sw_tx_cons; |
| 147 | u16 sw_tx_prod; |
| 148 | struct qed_chain tx_pbl; |
| 149 | void __iomem *doorbell_addr; |
| 150 | union db_prod tx_db; |
| 151 | |
| 152 | u16 num_tx_buffers; |
| 153 | }; |
| 154 | |
| 155 | #define BD_UNMAP_ADDR(bd) HILO_U64(le32_to_cpu((bd)->addr.hi), \ |
| 156 | le32_to_cpu((bd)->addr.lo)) |
| 157 | #define BD_SET_UNMAP_ADDR_LEN(bd, maddr, len) \ |
| 158 | do { \ |
| 159 | (bd)->addr.hi = cpu_to_le32(upper_32_bits(maddr)); \ |
| 160 | (bd)->addr.lo = cpu_to_le32(lower_32_bits(maddr)); \ |
| 161 | (bd)->nbytes = cpu_to_le16(len); \ |
| 162 | } while (0) |
| 163 | #define BD_UNMAP_LEN(bd) (le16_to_cpu((bd)->nbytes)) |
| 164 | |
| 165 | struct qede_fastpath { |
| 166 | struct qede_dev *edev; |
| 167 | u8 rss_id; |
| 168 | struct napi_struct napi; |
| 169 | struct qed_sb_info *sb_info; |
| 170 | struct qede_rx_queue *rxq; |
| 171 | struct qede_tx_queue *txqs; |
| 172 | |
| 173 | #define VEC_NAME_SIZE (sizeof(((struct net_device *)0)->name) + 8) |
| 174 | char name[VEC_NAME_SIZE]; |
Yuval Mintz | e712d52 | 2015-10-26 11:02:27 +0200 | [diff] [blame] | 175 | }; |
| 176 | |
| 177 | /* Debug print definitions */ |
| 178 | #define DP_NAME(edev) ((edev)->ndev->name) |
| 179 | |
Yuval Mintz | 2950219 | 2015-10-26 11:02:29 +0200 | [diff] [blame^] | 180 | #define XMIT_PLAIN 0 |
| 181 | #define XMIT_L4_CSUM BIT(0) |
| 182 | #define XMIT_LSO BIT(1) |
| 183 | #define XMIT_ENC BIT(2) |
| 184 | |
| 185 | #define QEDE_CSUM_ERROR BIT(0) |
| 186 | #define QEDE_CSUM_UNNECESSARY BIT(1) |
| 187 | #define RX_RING_SIZE_POW 13 |
| 188 | #define RX_RING_SIZE BIT(RX_RING_SIZE_POW) |
| 189 | #define NUM_RX_BDS_MAX (RX_RING_SIZE - 1) |
| 190 | #define NUM_RX_BDS_MIN 128 |
| 191 | #define NUM_RX_BDS_DEF NUM_RX_BDS_MAX |
| 192 | |
| 193 | #define TX_RING_SIZE_POW 13 |
| 194 | #define TX_RING_SIZE BIT(TX_RING_SIZE_POW) |
| 195 | #define NUM_TX_BDS_MAX (TX_RING_SIZE - 1) |
| 196 | #define NUM_TX_BDS_MIN 128 |
| 197 | #define NUM_TX_BDS_DEF NUM_TX_BDS_MAX |
| 198 | |
| 199 | #define for_each_rss(i) for (i = 0; i < edev->num_rss; i++) |
| 200 | |
Yuval Mintz | e712d52 | 2015-10-26 11:02:27 +0200 | [diff] [blame] | 201 | #endif /* _QEDE_H_ */ |