Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | * |
| 3 | * Intel Ethernet Controller XL710 Family Linux Driver |
Greg Rose | dc641b7 | 2013-12-18 13:45:51 +0000 | [diff] [blame] | 4 | * Copyright(c) 2013 - 2014 Intel Corporation. |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify it |
| 7 | * under the terms and conditions of the GNU General Public License, |
| 8 | * version 2, as published by the Free Software Foundation. |
| 9 | * |
| 10 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 13 | * more details. |
| 14 | * |
Greg Rose | dc641b7 | 2013-12-18 13:45:51 +0000 | [diff] [blame] | 15 | * You should have received a copy of the GNU General Public License along |
| 16 | * with this program. If not, see <http://www.gnu.org/licenses/>. |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 17 | * |
| 18 | * The full GNU General Public License is included in this distribution in |
| 19 | * the file called "COPYING". |
| 20 | * |
| 21 | * Contact Information: |
| 22 | * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> |
| 23 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 24 | * |
| 25 | ******************************************************************************/ |
| 26 | |
| 27 | #include "i40e_status.h" |
| 28 | #include "i40e_type.h" |
| 29 | #include "i40e_register.h" |
| 30 | #include "i40e_adminq.h" |
| 31 | #include "i40e_prototype.h" |
| 32 | |
Stephen Hemminger | af28eec | 2013-12-13 04:37:50 +0000 | [diff] [blame] | 33 | static void i40e_resume_aq(struct i40e_hw *hw); |
| 34 | |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 35 | /** |
Shannon Nelson | c9296ad | 2014-03-14 07:32:22 +0000 | [diff] [blame] | 36 | * i40e_is_nvm_update_op - return true if this is an NVM update operation |
| 37 | * @desc: API request descriptor |
| 38 | **/ |
| 39 | static inline bool i40e_is_nvm_update_op(struct i40e_aq_desc *desc) |
| 40 | { |
| 41 | return (desc->opcode == i40e_aqc_opc_nvm_erase) || |
| 42 | (desc->opcode == i40e_aqc_opc_nvm_update); |
| 43 | } |
| 44 | |
| 45 | /** |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 46 | * i40e_adminq_init_regs - Initialize AdminQ registers |
| 47 | * @hw: pointer to the hardware structure |
| 48 | * |
| 49 | * This assumes the alloc_asq and alloc_arq functions have already been called |
| 50 | **/ |
| 51 | static void i40e_adminq_init_regs(struct i40e_hw *hw) |
| 52 | { |
| 53 | /* set head and tail registers in our local struct */ |
| 54 | if (hw->mac.type == I40E_MAC_VF) { |
| 55 | hw->aq.asq.tail = I40E_VF_ATQT1; |
| 56 | hw->aq.asq.head = I40E_VF_ATQH1; |
Shannon Nelson | 17e6a84 | 2013-11-16 10:00:36 +0000 | [diff] [blame] | 57 | hw->aq.asq.len = I40E_VF_ATQLEN1; |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 58 | hw->aq.arq.tail = I40E_VF_ARQT1; |
| 59 | hw->aq.arq.head = I40E_VF_ARQH1; |
Shannon Nelson | 17e6a84 | 2013-11-16 10:00:36 +0000 | [diff] [blame] | 60 | hw->aq.arq.len = I40E_VF_ARQLEN1; |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 61 | } else { |
| 62 | hw->aq.asq.tail = I40E_PF_ATQT; |
| 63 | hw->aq.asq.head = I40E_PF_ATQH; |
Shannon Nelson | 17e6a84 | 2013-11-16 10:00:36 +0000 | [diff] [blame] | 64 | hw->aq.asq.len = I40E_PF_ATQLEN; |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 65 | hw->aq.arq.tail = I40E_PF_ARQT; |
| 66 | hw->aq.arq.head = I40E_PF_ARQH; |
Shannon Nelson | 17e6a84 | 2013-11-16 10:00:36 +0000 | [diff] [blame] | 67 | hw->aq.arq.len = I40E_PF_ARQLEN; |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 68 | } |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * i40e_alloc_adminq_asq_ring - Allocate Admin Queue send rings |
| 73 | * @hw: pointer to the hardware structure |
| 74 | **/ |
| 75 | static i40e_status i40e_alloc_adminq_asq_ring(struct i40e_hw *hw) |
| 76 | { |
| 77 | i40e_status ret_code; |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 78 | |
David Cassard | 90bb776 | 2013-11-28 06:39:35 +0000 | [diff] [blame] | 79 | ret_code = i40e_allocate_dma_mem(hw, &hw->aq.asq.desc_buf, |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 80 | i40e_mem_atq_ring, |
| 81 | (hw->aq.num_asq_entries * |
| 82 | sizeof(struct i40e_aq_desc)), |
| 83 | I40E_ADMINQ_DESC_ALIGNMENT); |
| 84 | if (ret_code) |
| 85 | return ret_code; |
| 86 | |
David Cassard | 90bb776 | 2013-11-28 06:39:35 +0000 | [diff] [blame] | 87 | ret_code = i40e_allocate_virt_mem(hw, &hw->aq.asq.cmd_buf, |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 88 | (hw->aq.num_asq_entries * |
| 89 | sizeof(struct i40e_asq_cmd_details))); |
| 90 | if (ret_code) { |
David Cassard | 90bb776 | 2013-11-28 06:39:35 +0000 | [diff] [blame] | 91 | i40e_free_dma_mem(hw, &hw->aq.asq.desc_buf); |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 92 | return ret_code; |
| 93 | } |
| 94 | |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 95 | return ret_code; |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * i40e_alloc_adminq_arq_ring - Allocate Admin Queue receive rings |
| 100 | * @hw: pointer to the hardware structure |
| 101 | **/ |
| 102 | static i40e_status i40e_alloc_adminq_arq_ring(struct i40e_hw *hw) |
| 103 | { |
| 104 | i40e_status ret_code; |
| 105 | |
David Cassard | 90bb776 | 2013-11-28 06:39:35 +0000 | [diff] [blame] | 106 | ret_code = i40e_allocate_dma_mem(hw, &hw->aq.arq.desc_buf, |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 107 | i40e_mem_arq_ring, |
| 108 | (hw->aq.num_arq_entries * |
| 109 | sizeof(struct i40e_aq_desc)), |
| 110 | I40E_ADMINQ_DESC_ALIGNMENT); |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 111 | |
| 112 | return ret_code; |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * i40e_free_adminq_asq - Free Admin Queue send rings |
| 117 | * @hw: pointer to the hardware structure |
| 118 | * |
| 119 | * This assumes the posted send buffers have already been cleaned |
| 120 | * and de-allocated |
| 121 | **/ |
| 122 | static void i40e_free_adminq_asq(struct i40e_hw *hw) |
| 123 | { |
David Cassard | 90bb776 | 2013-11-28 06:39:35 +0000 | [diff] [blame] | 124 | i40e_free_dma_mem(hw, &hw->aq.asq.desc_buf); |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | /** |
| 128 | * i40e_free_adminq_arq - Free Admin Queue receive rings |
| 129 | * @hw: pointer to the hardware structure |
| 130 | * |
| 131 | * This assumes the posted receive buffers have already been cleaned |
| 132 | * and de-allocated |
| 133 | **/ |
| 134 | static void i40e_free_adminq_arq(struct i40e_hw *hw) |
| 135 | { |
David Cassard | 90bb776 | 2013-11-28 06:39:35 +0000 | [diff] [blame] | 136 | i40e_free_dma_mem(hw, &hw->aq.arq.desc_buf); |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | /** |
| 140 | * i40e_alloc_arq_bufs - Allocate pre-posted buffers for the receive queue |
Jeff Kirsher | 98d4438 | 2013-12-21 05:44:42 +0000 | [diff] [blame] | 141 | * @hw: pointer to the hardware structure |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 142 | **/ |
| 143 | static i40e_status i40e_alloc_arq_bufs(struct i40e_hw *hw) |
| 144 | { |
| 145 | i40e_status ret_code; |
| 146 | struct i40e_aq_desc *desc; |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 147 | struct i40e_dma_mem *bi; |
| 148 | int i; |
| 149 | |
| 150 | /* We'll be allocating the buffer info memory first, then we can |
| 151 | * allocate the mapped buffers for the event processing |
| 152 | */ |
| 153 | |
| 154 | /* buffer_info structures do not need alignment */ |
David Cassard | 90bb776 | 2013-11-28 06:39:35 +0000 | [diff] [blame] | 155 | ret_code = i40e_allocate_virt_mem(hw, &hw->aq.arq.dma_head, |
| 156 | (hw->aq.num_arq_entries * sizeof(struct i40e_dma_mem))); |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 157 | if (ret_code) |
| 158 | goto alloc_arq_bufs; |
David Cassard | 90bb776 | 2013-11-28 06:39:35 +0000 | [diff] [blame] | 159 | hw->aq.arq.r.arq_bi = (struct i40e_dma_mem *)hw->aq.arq.dma_head.va; |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 160 | |
| 161 | /* allocate the mapped buffers */ |
| 162 | for (i = 0; i < hw->aq.num_arq_entries; i++) { |
| 163 | bi = &hw->aq.arq.r.arq_bi[i]; |
| 164 | ret_code = i40e_allocate_dma_mem(hw, bi, |
| 165 | i40e_mem_arq_buf, |
| 166 | hw->aq.arq_buf_size, |
| 167 | I40E_ADMINQ_DESC_ALIGNMENT); |
| 168 | if (ret_code) |
| 169 | goto unwind_alloc_arq_bufs; |
| 170 | |
| 171 | /* now configure the descriptors for use */ |
| 172 | desc = I40E_ADMINQ_DESC(hw->aq.arq, i); |
| 173 | |
| 174 | desc->flags = cpu_to_le16(I40E_AQ_FLAG_BUF); |
| 175 | if (hw->aq.arq_buf_size > I40E_AQ_LARGE_BUF) |
| 176 | desc->flags |= cpu_to_le16(I40E_AQ_FLAG_LB); |
| 177 | desc->opcode = 0; |
| 178 | /* This is in accordance with Admin queue design, there is no |
| 179 | * register for buffer size configuration |
| 180 | */ |
| 181 | desc->datalen = cpu_to_le16((u16)bi->size); |
| 182 | desc->retval = 0; |
| 183 | desc->cookie_high = 0; |
| 184 | desc->cookie_low = 0; |
| 185 | desc->params.external.addr_high = |
| 186 | cpu_to_le32(upper_32_bits(bi->pa)); |
| 187 | desc->params.external.addr_low = |
| 188 | cpu_to_le32(lower_32_bits(bi->pa)); |
| 189 | desc->params.external.param0 = 0; |
| 190 | desc->params.external.param1 = 0; |
| 191 | } |
| 192 | |
| 193 | alloc_arq_bufs: |
| 194 | return ret_code; |
| 195 | |
| 196 | unwind_alloc_arq_bufs: |
| 197 | /* don't try to free the one that failed... */ |
| 198 | i--; |
| 199 | for (; i >= 0; i--) |
| 200 | i40e_free_dma_mem(hw, &hw->aq.arq.r.arq_bi[i]); |
David Cassard | 90bb776 | 2013-11-28 06:39:35 +0000 | [diff] [blame] | 201 | i40e_free_virt_mem(hw, &hw->aq.arq.dma_head); |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 202 | |
| 203 | return ret_code; |
| 204 | } |
| 205 | |
| 206 | /** |
| 207 | * i40e_alloc_asq_bufs - Allocate empty buffer structs for the send queue |
Jeff Kirsher | 98d4438 | 2013-12-21 05:44:42 +0000 | [diff] [blame] | 208 | * @hw: pointer to the hardware structure |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 209 | **/ |
| 210 | static i40e_status i40e_alloc_asq_bufs(struct i40e_hw *hw) |
| 211 | { |
| 212 | i40e_status ret_code; |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 213 | struct i40e_dma_mem *bi; |
| 214 | int i; |
| 215 | |
| 216 | /* No mapped memory needed yet, just the buffer info structures */ |
David Cassard | 90bb776 | 2013-11-28 06:39:35 +0000 | [diff] [blame] | 217 | ret_code = i40e_allocate_virt_mem(hw, &hw->aq.asq.dma_head, |
| 218 | (hw->aq.num_asq_entries * sizeof(struct i40e_dma_mem))); |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 219 | if (ret_code) |
| 220 | goto alloc_asq_bufs; |
David Cassard | 90bb776 | 2013-11-28 06:39:35 +0000 | [diff] [blame] | 221 | hw->aq.asq.r.asq_bi = (struct i40e_dma_mem *)hw->aq.asq.dma_head.va; |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 222 | |
| 223 | /* allocate the mapped buffers */ |
| 224 | for (i = 0; i < hw->aq.num_asq_entries; i++) { |
| 225 | bi = &hw->aq.asq.r.asq_bi[i]; |
| 226 | ret_code = i40e_allocate_dma_mem(hw, bi, |
| 227 | i40e_mem_asq_buf, |
| 228 | hw->aq.asq_buf_size, |
| 229 | I40E_ADMINQ_DESC_ALIGNMENT); |
| 230 | if (ret_code) |
| 231 | goto unwind_alloc_asq_bufs; |
| 232 | } |
| 233 | alloc_asq_bufs: |
| 234 | return ret_code; |
| 235 | |
| 236 | unwind_alloc_asq_bufs: |
| 237 | /* don't try to free the one that failed... */ |
| 238 | i--; |
| 239 | for (; i >= 0; i--) |
| 240 | i40e_free_dma_mem(hw, &hw->aq.asq.r.asq_bi[i]); |
David Cassard | 90bb776 | 2013-11-28 06:39:35 +0000 | [diff] [blame] | 241 | i40e_free_virt_mem(hw, &hw->aq.asq.dma_head); |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 242 | |
| 243 | return ret_code; |
| 244 | } |
| 245 | |
| 246 | /** |
| 247 | * i40e_free_arq_bufs - Free receive queue buffer info elements |
Jeff Kirsher | 98d4438 | 2013-12-21 05:44:42 +0000 | [diff] [blame] | 248 | * @hw: pointer to the hardware structure |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 249 | **/ |
| 250 | static void i40e_free_arq_bufs(struct i40e_hw *hw) |
| 251 | { |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 252 | int i; |
| 253 | |
David Cassard | 90bb776 | 2013-11-28 06:39:35 +0000 | [diff] [blame] | 254 | /* free descriptors */ |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 255 | for (i = 0; i < hw->aq.num_arq_entries; i++) |
| 256 | i40e_free_dma_mem(hw, &hw->aq.arq.r.arq_bi[i]); |
| 257 | |
David Cassard | 90bb776 | 2013-11-28 06:39:35 +0000 | [diff] [blame] | 258 | /* free the descriptor memory */ |
| 259 | i40e_free_dma_mem(hw, &hw->aq.arq.desc_buf); |
| 260 | |
| 261 | /* free the dma header */ |
| 262 | i40e_free_virt_mem(hw, &hw->aq.arq.dma_head); |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | /** |
| 266 | * i40e_free_asq_bufs - Free send queue buffer info elements |
Jeff Kirsher | 98d4438 | 2013-12-21 05:44:42 +0000 | [diff] [blame] | 267 | * @hw: pointer to the hardware structure |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 268 | **/ |
| 269 | static void i40e_free_asq_bufs(struct i40e_hw *hw) |
| 270 | { |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 271 | int i; |
| 272 | |
| 273 | /* only unmap if the address is non-NULL */ |
| 274 | for (i = 0; i < hw->aq.num_asq_entries; i++) |
| 275 | if (hw->aq.asq.r.asq_bi[i].pa) |
| 276 | i40e_free_dma_mem(hw, &hw->aq.asq.r.asq_bi[i]); |
| 277 | |
David Cassard | 90bb776 | 2013-11-28 06:39:35 +0000 | [diff] [blame] | 278 | /* free the buffer info list */ |
| 279 | i40e_free_virt_mem(hw, &hw->aq.asq.cmd_buf); |
| 280 | |
| 281 | /* free the descriptor memory */ |
| 282 | i40e_free_dma_mem(hw, &hw->aq.asq.desc_buf); |
| 283 | |
| 284 | /* free the dma header */ |
| 285 | i40e_free_virt_mem(hw, &hw->aq.asq.dma_head); |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | /** |
| 289 | * i40e_config_asq_regs - configure ASQ registers |
Jeff Kirsher | 98d4438 | 2013-12-21 05:44:42 +0000 | [diff] [blame] | 290 | * @hw: pointer to the hardware structure |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 291 | * |
| 292 | * Configure base address and length registers for the transmit queue |
| 293 | **/ |
Kamil Krawczyk | e03af1e | 2014-04-23 04:50:02 +0000 | [diff] [blame] | 294 | static i40e_status i40e_config_asq_regs(struct i40e_hw *hw) |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 295 | { |
Kamil Krawczyk | e03af1e | 2014-04-23 04:50:02 +0000 | [diff] [blame] | 296 | i40e_status ret_code = 0; |
| 297 | u32 reg = 0; |
| 298 | |
Michal Kosiarz | 80a977e | 2014-06-03 23:50:13 +0000 | [diff] [blame] | 299 | /* Clear Head and Tail */ |
| 300 | wr32(hw, hw->aq.asq.head, 0); |
| 301 | wr32(hw, hw->aq.asq.tail, 0); |
| 302 | |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 303 | if (hw->mac.type == I40E_MAC_VF) { |
| 304 | /* configure the transmit queue */ |
David Cassard | 90bb776 | 2013-11-28 06:39:35 +0000 | [diff] [blame] | 305 | wr32(hw, I40E_VF_ATQBAH1, |
| 306 | upper_32_bits(hw->aq.asq.desc_buf.pa)); |
| 307 | wr32(hw, I40E_VF_ATQBAL1, |
| 308 | lower_32_bits(hw->aq.asq.desc_buf.pa)); |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 309 | wr32(hw, I40E_VF_ATQLEN1, (hw->aq.num_asq_entries | |
| 310 | I40E_VF_ATQLEN1_ATQENABLE_MASK)); |
Kamil Krawczyk | e03af1e | 2014-04-23 04:50:02 +0000 | [diff] [blame] | 311 | reg = rd32(hw, I40E_VF_ATQBAL1); |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 312 | } else { |
| 313 | /* configure the transmit queue */ |
David Cassard | 90bb776 | 2013-11-28 06:39:35 +0000 | [diff] [blame] | 314 | wr32(hw, I40E_PF_ATQBAH, |
| 315 | upper_32_bits(hw->aq.asq.desc_buf.pa)); |
| 316 | wr32(hw, I40E_PF_ATQBAL, |
| 317 | lower_32_bits(hw->aq.asq.desc_buf.pa)); |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 318 | wr32(hw, I40E_PF_ATQLEN, (hw->aq.num_asq_entries | |
| 319 | I40E_PF_ATQLEN_ATQENABLE_MASK)); |
Kamil Krawczyk | e03af1e | 2014-04-23 04:50:02 +0000 | [diff] [blame] | 320 | reg = rd32(hw, I40E_PF_ATQBAL); |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 321 | } |
Kamil Krawczyk | e03af1e | 2014-04-23 04:50:02 +0000 | [diff] [blame] | 322 | |
| 323 | /* Check one register to verify that config was applied */ |
| 324 | if (reg != lower_32_bits(hw->aq.asq.desc_buf.pa)) |
| 325 | ret_code = I40E_ERR_ADMIN_QUEUE_ERROR; |
| 326 | |
| 327 | return ret_code; |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | /** |
| 331 | * i40e_config_arq_regs - ARQ register configuration |
Jeff Kirsher | 98d4438 | 2013-12-21 05:44:42 +0000 | [diff] [blame] | 332 | * @hw: pointer to the hardware structure |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 333 | * |
| 334 | * Configure base address and length registers for the receive (event queue) |
| 335 | **/ |
Kamil Krawczyk | e03af1e | 2014-04-23 04:50:02 +0000 | [diff] [blame] | 336 | static i40e_status i40e_config_arq_regs(struct i40e_hw *hw) |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 337 | { |
Kamil Krawczyk | e03af1e | 2014-04-23 04:50:02 +0000 | [diff] [blame] | 338 | i40e_status ret_code = 0; |
| 339 | u32 reg = 0; |
| 340 | |
Michal Kosiarz | 80a977e | 2014-06-03 23:50:13 +0000 | [diff] [blame] | 341 | /* Clear Head and Tail */ |
| 342 | wr32(hw, hw->aq.arq.head, 0); |
| 343 | wr32(hw, hw->aq.arq.tail, 0); |
| 344 | |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 345 | if (hw->mac.type == I40E_MAC_VF) { |
| 346 | /* configure the receive queue */ |
David Cassard | 90bb776 | 2013-11-28 06:39:35 +0000 | [diff] [blame] | 347 | wr32(hw, I40E_VF_ARQBAH1, |
| 348 | upper_32_bits(hw->aq.arq.desc_buf.pa)); |
| 349 | wr32(hw, I40E_VF_ARQBAL1, |
| 350 | lower_32_bits(hw->aq.arq.desc_buf.pa)); |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 351 | wr32(hw, I40E_VF_ARQLEN1, (hw->aq.num_arq_entries | |
| 352 | I40E_VF_ARQLEN1_ARQENABLE_MASK)); |
Kamil Krawczyk | e03af1e | 2014-04-23 04:50:02 +0000 | [diff] [blame] | 353 | reg = rd32(hw, I40E_VF_ARQBAL1); |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 354 | } else { |
| 355 | /* configure the receive queue */ |
David Cassard | 90bb776 | 2013-11-28 06:39:35 +0000 | [diff] [blame] | 356 | wr32(hw, I40E_PF_ARQBAH, |
| 357 | upper_32_bits(hw->aq.arq.desc_buf.pa)); |
| 358 | wr32(hw, I40E_PF_ARQBAL, |
| 359 | lower_32_bits(hw->aq.arq.desc_buf.pa)); |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 360 | wr32(hw, I40E_PF_ARQLEN, (hw->aq.num_arq_entries | |
| 361 | I40E_PF_ARQLEN_ARQENABLE_MASK)); |
Kamil Krawczyk | e03af1e | 2014-04-23 04:50:02 +0000 | [diff] [blame] | 362 | reg = rd32(hw, I40E_PF_ARQBAL); |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | /* Update tail in the HW to post pre-allocated buffers */ |
| 366 | wr32(hw, hw->aq.arq.tail, hw->aq.num_arq_entries - 1); |
Kamil Krawczyk | e03af1e | 2014-04-23 04:50:02 +0000 | [diff] [blame] | 367 | |
| 368 | /* Check one register to verify that config was applied */ |
| 369 | if (reg != lower_32_bits(hw->aq.arq.desc_buf.pa)) |
| 370 | ret_code = I40E_ERR_ADMIN_QUEUE_ERROR; |
| 371 | |
| 372 | return ret_code; |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | /** |
| 376 | * i40e_init_asq - main initialization routine for ASQ |
Jeff Kirsher | 98d4438 | 2013-12-21 05:44:42 +0000 | [diff] [blame] | 377 | * @hw: pointer to the hardware structure |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 378 | * |
| 379 | * This is the main initialization routine for the Admin Send Queue |
| 380 | * Prior to calling this function, drivers *MUST* set the following fields |
| 381 | * in the hw->aq structure: |
| 382 | * - hw->aq.num_asq_entries |
| 383 | * - hw->aq.arq_buf_size |
| 384 | * |
| 385 | * Do *NOT* hold the lock when calling this as the memory allocation routines |
| 386 | * called are not going to be atomic context safe |
| 387 | **/ |
| 388 | static i40e_status i40e_init_asq(struct i40e_hw *hw) |
| 389 | { |
| 390 | i40e_status ret_code = 0; |
| 391 | |
| 392 | if (hw->aq.asq.count > 0) { |
| 393 | /* queue already initialized */ |
| 394 | ret_code = I40E_ERR_NOT_READY; |
| 395 | goto init_adminq_exit; |
| 396 | } |
| 397 | |
| 398 | /* verify input for valid configuration */ |
| 399 | if ((hw->aq.num_asq_entries == 0) || |
| 400 | (hw->aq.asq_buf_size == 0)) { |
| 401 | ret_code = I40E_ERR_CONFIG; |
| 402 | goto init_adminq_exit; |
| 403 | } |
| 404 | |
| 405 | hw->aq.asq.next_to_use = 0; |
| 406 | hw->aq.asq.next_to_clean = 0; |
| 407 | hw->aq.asq.count = hw->aq.num_asq_entries; |
| 408 | |
| 409 | /* allocate the ring memory */ |
| 410 | ret_code = i40e_alloc_adminq_asq_ring(hw); |
| 411 | if (ret_code) |
| 412 | goto init_adminq_exit; |
| 413 | |
| 414 | /* allocate buffers in the rings */ |
| 415 | ret_code = i40e_alloc_asq_bufs(hw); |
| 416 | if (ret_code) |
| 417 | goto init_adminq_free_rings; |
| 418 | |
| 419 | /* initialize base registers */ |
Kamil Krawczyk | e03af1e | 2014-04-23 04:50:02 +0000 | [diff] [blame] | 420 | ret_code = i40e_config_asq_regs(hw); |
| 421 | if (ret_code) |
| 422 | goto init_adminq_free_rings; |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 423 | |
| 424 | /* success! */ |
| 425 | goto init_adminq_exit; |
| 426 | |
| 427 | init_adminq_free_rings: |
| 428 | i40e_free_adminq_asq(hw); |
| 429 | |
| 430 | init_adminq_exit: |
| 431 | return ret_code; |
| 432 | } |
| 433 | |
| 434 | /** |
| 435 | * i40e_init_arq - initialize ARQ |
Jeff Kirsher | 98d4438 | 2013-12-21 05:44:42 +0000 | [diff] [blame] | 436 | * @hw: pointer to the hardware structure |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 437 | * |
| 438 | * The main initialization routine for the Admin Receive (Event) Queue. |
| 439 | * Prior to calling this function, drivers *MUST* set the following fields |
| 440 | * in the hw->aq structure: |
| 441 | * - hw->aq.num_asq_entries |
| 442 | * - hw->aq.arq_buf_size |
| 443 | * |
| 444 | * Do *NOT* hold the lock when calling this as the memory allocation routines |
| 445 | * called are not going to be atomic context safe |
| 446 | **/ |
| 447 | static i40e_status i40e_init_arq(struct i40e_hw *hw) |
| 448 | { |
| 449 | i40e_status ret_code = 0; |
| 450 | |
| 451 | if (hw->aq.arq.count > 0) { |
| 452 | /* queue already initialized */ |
| 453 | ret_code = I40E_ERR_NOT_READY; |
| 454 | goto init_adminq_exit; |
| 455 | } |
| 456 | |
| 457 | /* verify input for valid configuration */ |
| 458 | if ((hw->aq.num_arq_entries == 0) || |
| 459 | (hw->aq.arq_buf_size == 0)) { |
| 460 | ret_code = I40E_ERR_CONFIG; |
| 461 | goto init_adminq_exit; |
| 462 | } |
| 463 | |
| 464 | hw->aq.arq.next_to_use = 0; |
| 465 | hw->aq.arq.next_to_clean = 0; |
| 466 | hw->aq.arq.count = hw->aq.num_arq_entries; |
| 467 | |
| 468 | /* allocate the ring memory */ |
| 469 | ret_code = i40e_alloc_adminq_arq_ring(hw); |
| 470 | if (ret_code) |
| 471 | goto init_adminq_exit; |
| 472 | |
| 473 | /* allocate buffers in the rings */ |
| 474 | ret_code = i40e_alloc_arq_bufs(hw); |
| 475 | if (ret_code) |
| 476 | goto init_adminq_free_rings; |
| 477 | |
| 478 | /* initialize base registers */ |
Kamil Krawczyk | e03af1e | 2014-04-23 04:50:02 +0000 | [diff] [blame] | 479 | ret_code = i40e_config_arq_regs(hw); |
| 480 | if (ret_code) |
| 481 | goto init_adminq_free_rings; |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 482 | |
| 483 | /* success! */ |
| 484 | goto init_adminq_exit; |
| 485 | |
| 486 | init_adminq_free_rings: |
| 487 | i40e_free_adminq_arq(hw); |
| 488 | |
| 489 | init_adminq_exit: |
| 490 | return ret_code; |
| 491 | } |
| 492 | |
| 493 | /** |
| 494 | * i40e_shutdown_asq - shutdown the ASQ |
Jeff Kirsher | 98d4438 | 2013-12-21 05:44:42 +0000 | [diff] [blame] | 495 | * @hw: pointer to the hardware structure |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 496 | * |
| 497 | * The main shutdown routine for the Admin Send Queue |
| 498 | **/ |
| 499 | static i40e_status i40e_shutdown_asq(struct i40e_hw *hw) |
| 500 | { |
| 501 | i40e_status ret_code = 0; |
| 502 | |
| 503 | if (hw->aq.asq.count == 0) |
| 504 | return I40E_ERR_NOT_READY; |
| 505 | |
| 506 | /* Stop firmware AdminQ processing */ |
Shannon Nelson | 17e6a84 | 2013-11-16 10:00:36 +0000 | [diff] [blame] | 507 | wr32(hw, hw->aq.asq.head, 0); |
| 508 | wr32(hw, hw->aq.asq.tail, 0); |
| 509 | wr32(hw, hw->aq.asq.len, 0); |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 510 | |
| 511 | /* make sure lock is available */ |
| 512 | mutex_lock(&hw->aq.asq_mutex); |
| 513 | |
| 514 | hw->aq.asq.count = 0; /* to indicate uninitialized queue */ |
| 515 | |
| 516 | /* free ring buffers */ |
| 517 | i40e_free_asq_bufs(hw); |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 518 | |
| 519 | mutex_unlock(&hw->aq.asq_mutex); |
| 520 | |
| 521 | return ret_code; |
| 522 | } |
| 523 | |
| 524 | /** |
| 525 | * i40e_shutdown_arq - shutdown ARQ |
Jeff Kirsher | 98d4438 | 2013-12-21 05:44:42 +0000 | [diff] [blame] | 526 | * @hw: pointer to the hardware structure |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 527 | * |
| 528 | * The main shutdown routine for the Admin Receive Queue |
| 529 | **/ |
| 530 | static i40e_status i40e_shutdown_arq(struct i40e_hw *hw) |
| 531 | { |
| 532 | i40e_status ret_code = 0; |
| 533 | |
| 534 | if (hw->aq.arq.count == 0) |
| 535 | return I40E_ERR_NOT_READY; |
| 536 | |
| 537 | /* Stop firmware AdminQ processing */ |
Shannon Nelson | 17e6a84 | 2013-11-16 10:00:36 +0000 | [diff] [blame] | 538 | wr32(hw, hw->aq.arq.head, 0); |
| 539 | wr32(hw, hw->aq.arq.tail, 0); |
| 540 | wr32(hw, hw->aq.arq.len, 0); |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 541 | |
| 542 | /* make sure lock is available */ |
| 543 | mutex_lock(&hw->aq.arq_mutex); |
| 544 | |
| 545 | hw->aq.arq.count = 0; /* to indicate uninitialized queue */ |
| 546 | |
| 547 | /* free ring buffers */ |
| 548 | i40e_free_arq_bufs(hw); |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 549 | |
| 550 | mutex_unlock(&hw->aq.arq_mutex); |
| 551 | |
| 552 | return ret_code; |
| 553 | } |
| 554 | |
| 555 | /** |
| 556 | * i40e_init_adminq - main initialization routine for Admin Queue |
Jeff Kirsher | 98d4438 | 2013-12-21 05:44:42 +0000 | [diff] [blame] | 557 | * @hw: pointer to the hardware structure |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 558 | * |
| 559 | * Prior to calling this function, drivers *MUST* set the following fields |
| 560 | * in the hw->aq structure: |
| 561 | * - hw->aq.num_asq_entries |
| 562 | * - hw->aq.num_arq_entries |
| 563 | * - hw->aq.arq_buf_size |
| 564 | * - hw->aq.asq_buf_size |
| 565 | **/ |
| 566 | i40e_status i40e_init_adminq(struct i40e_hw *hw) |
| 567 | { |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 568 | i40e_status ret_code; |
Shannon Nelson | d4946cf | 2013-11-16 10:00:40 +0000 | [diff] [blame] | 569 | u16 eetrack_lo, eetrack_hi; |
| 570 | int retry = 0; |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 571 | |
| 572 | /* verify input for valid configuration */ |
| 573 | if ((hw->aq.num_arq_entries == 0) || |
| 574 | (hw->aq.num_asq_entries == 0) || |
| 575 | (hw->aq.arq_buf_size == 0) || |
| 576 | (hw->aq.asq_buf_size == 0)) { |
| 577 | ret_code = I40E_ERR_CONFIG; |
| 578 | goto init_adminq_exit; |
| 579 | } |
| 580 | |
| 581 | /* initialize locks */ |
| 582 | mutex_init(&hw->aq.asq_mutex); |
| 583 | mutex_init(&hw->aq.arq_mutex); |
| 584 | |
| 585 | /* Set up register offsets */ |
| 586 | i40e_adminq_init_regs(hw); |
| 587 | |
| 588 | /* allocate the ASQ */ |
| 589 | ret_code = i40e_init_asq(hw); |
| 590 | if (ret_code) |
| 591 | goto init_adminq_destroy_locks; |
| 592 | |
| 593 | /* allocate the ARQ */ |
| 594 | ret_code = i40e_init_arq(hw); |
| 595 | if (ret_code) |
| 596 | goto init_adminq_free_asq; |
| 597 | |
Shannon Nelson | d4946cf | 2013-11-16 10:00:40 +0000 | [diff] [blame] | 598 | /* There are some cases where the firmware may not be quite ready |
| 599 | * for AdminQ operations, so we retry the AdminQ setup a few times |
| 600 | * if we see timeouts in this first AQ call. |
| 601 | */ |
| 602 | do { |
| 603 | ret_code = i40e_aq_get_firmware_version(hw, |
| 604 | &hw->aq.fw_maj_ver, |
| 605 | &hw->aq.fw_min_ver, |
| 606 | &hw->aq.api_maj_ver, |
| 607 | &hw->aq.api_min_ver, |
| 608 | NULL); |
| 609 | if (ret_code != I40E_ERR_ADMIN_QUEUE_TIMEOUT) |
| 610 | break; |
| 611 | retry++; |
| 612 | msleep(100); |
| 613 | i40e_resume_aq(hw); |
| 614 | } while (retry < 10); |
| 615 | if (ret_code != I40E_SUCCESS) |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 616 | goto init_adminq_free_arq; |
| 617 | |
Shannon Nelson | 981b754 | 2013-12-11 08:17:11 +0000 | [diff] [blame] | 618 | /* get the NVM version info */ |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 619 | i40e_read_nvm_word(hw, I40E_SR_NVM_IMAGE_VERSION, &hw->nvm.version); |
| 620 | i40e_read_nvm_word(hw, I40E_SR_NVM_EETRACK_LO, &eetrack_lo); |
| 621 | i40e_read_nvm_word(hw, I40E_SR_NVM_EETRACK_HI, &eetrack_hi); |
| 622 | hw->nvm.eetrack = (eetrack_hi << 16) | eetrack_lo; |
| 623 | |
Shannon Nelson | 7e61241 | 2014-05-29 06:55:59 +0000 | [diff] [blame] | 624 | if (hw->aq.api_maj_ver > I40E_FW_API_VERSION_MAJOR) { |
Shannon Nelson | 981b754 | 2013-12-11 08:17:11 +0000 | [diff] [blame] | 625 | ret_code = I40E_ERR_FIRMWARE_API_VERSION; |
| 626 | goto init_adminq_free_arq; |
| 627 | } |
| 628 | |
Shannon Nelson | ff2ff3b | 2013-12-18 13:45:56 +0000 | [diff] [blame] | 629 | /* pre-emptive resource lock release */ |
| 630 | i40e_aq_release_resource(hw, I40E_NVM_RESOURCE_ID, 0, NULL); |
Shannon Nelson | c9296ad | 2014-03-14 07:32:22 +0000 | [diff] [blame] | 631 | hw->aq.nvm_busy = false; |
Shannon Nelson | ff2ff3b | 2013-12-18 13:45:56 +0000 | [diff] [blame] | 632 | |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 633 | ret_code = i40e_aq_set_hmc_resource_profile(hw, |
| 634 | I40E_HMC_PROFILE_DEFAULT, |
| 635 | 0, |
| 636 | NULL); |
| 637 | ret_code = 0; |
| 638 | |
| 639 | /* success! */ |
| 640 | goto init_adminq_exit; |
| 641 | |
| 642 | init_adminq_free_arq: |
| 643 | i40e_shutdown_arq(hw); |
| 644 | init_adminq_free_asq: |
| 645 | i40e_shutdown_asq(hw); |
| 646 | init_adminq_destroy_locks: |
| 647 | |
| 648 | init_adminq_exit: |
| 649 | return ret_code; |
| 650 | } |
| 651 | |
| 652 | /** |
| 653 | * i40e_shutdown_adminq - shutdown routine for the Admin Queue |
Jeff Kirsher | 98d4438 | 2013-12-21 05:44:42 +0000 | [diff] [blame] | 654 | * @hw: pointer to the hardware structure |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 655 | **/ |
| 656 | i40e_status i40e_shutdown_adminq(struct i40e_hw *hw) |
| 657 | { |
| 658 | i40e_status ret_code = 0; |
| 659 | |
Anjali Singhai Jain | e1860d8 | 2013-11-28 06:39:45 +0000 | [diff] [blame] | 660 | if (i40e_check_asq_alive(hw)) |
| 661 | i40e_aq_queue_shutdown(hw, true); |
| 662 | |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 663 | i40e_shutdown_asq(hw); |
| 664 | i40e_shutdown_arq(hw); |
| 665 | |
| 666 | /* destroy the locks */ |
| 667 | |
| 668 | return ret_code; |
| 669 | } |
| 670 | |
| 671 | /** |
| 672 | * i40e_clean_asq - cleans Admin send queue |
Jeff Kirsher | 98d4438 | 2013-12-21 05:44:42 +0000 | [diff] [blame] | 673 | * @hw: pointer to the hardware structure |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 674 | * |
| 675 | * returns the number of free desc |
| 676 | **/ |
| 677 | static u16 i40e_clean_asq(struct i40e_hw *hw) |
| 678 | { |
| 679 | struct i40e_adminq_ring *asq = &(hw->aq.asq); |
| 680 | struct i40e_asq_cmd_details *details; |
| 681 | u16 ntc = asq->next_to_clean; |
| 682 | struct i40e_aq_desc desc_cb; |
| 683 | struct i40e_aq_desc *desc; |
| 684 | |
| 685 | desc = I40E_ADMINQ_DESC(*asq, ntc); |
| 686 | details = I40E_ADMINQ_DETAILS(*asq, ntc); |
| 687 | while (rd32(hw, hw->aq.asq.head) != ntc) { |
Michal Kosiarz | 80a977e | 2014-06-03 23:50:13 +0000 | [diff] [blame] | 688 | i40e_debug(hw, I40E_DEBUG_AQ_MESSAGE, |
| 689 | "%s: ntc %d head %d.\n", __func__, ntc, |
| 690 | rd32(hw, hw->aq.asq.head)); |
| 691 | |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 692 | if (details->callback) { |
| 693 | I40E_ADMINQ_CALLBACK cb_func = |
| 694 | (I40E_ADMINQ_CALLBACK)details->callback; |
| 695 | desc_cb = *desc; |
| 696 | cb_func(hw, &desc_cb); |
| 697 | } |
Mitch Williams | a63fa1c | 2014-02-13 03:48:42 -0800 | [diff] [blame] | 698 | memset(desc, 0, sizeof(*desc)); |
| 699 | memset(details, 0, sizeof(*details)); |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 700 | ntc++; |
| 701 | if (ntc == asq->count) |
| 702 | ntc = 0; |
| 703 | desc = I40E_ADMINQ_DESC(*asq, ntc); |
| 704 | details = I40E_ADMINQ_DETAILS(*asq, ntc); |
| 705 | } |
| 706 | |
| 707 | asq->next_to_clean = ntc; |
| 708 | |
| 709 | return I40E_DESC_UNUSED(asq); |
| 710 | } |
| 711 | |
| 712 | /** |
| 713 | * i40e_asq_done - check if FW has processed the Admin Send Queue |
| 714 | * @hw: pointer to the hw struct |
| 715 | * |
| 716 | * Returns true if the firmware has processed all descriptors on the |
| 717 | * admin send queue. Returns false if there are still requests pending. |
| 718 | **/ |
Stephen Hemminger | af28eec | 2013-12-13 04:37:50 +0000 | [diff] [blame] | 719 | static bool i40e_asq_done(struct i40e_hw *hw) |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 720 | { |
| 721 | /* AQ designers suggest use of head for better |
| 722 | * timing reliability than DD bit |
| 723 | */ |
Shannon Nelson | 922680b | 2013-12-18 05:29:17 +0000 | [diff] [blame] | 724 | return rd32(hw, hw->aq.asq.head) == hw->aq.asq.next_to_use; |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 725 | |
| 726 | } |
| 727 | |
| 728 | /** |
| 729 | * i40e_asq_send_command - send command to Admin Queue |
| 730 | * @hw: pointer to the hw struct |
| 731 | * @desc: prefilled descriptor describing the command (non DMA mem) |
| 732 | * @buff: buffer to use for indirect commands |
| 733 | * @buff_size: size of buffer for indirect commands |
Shannon Nelson | 922680b | 2013-12-18 05:29:17 +0000 | [diff] [blame] | 734 | * @cmd_details: pointer to command details structure |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 735 | * |
| 736 | * This is the main send command driver routine for the Admin Queue send |
| 737 | * queue. It runs the queue, cleans the queue, etc |
| 738 | **/ |
| 739 | i40e_status i40e_asq_send_command(struct i40e_hw *hw, |
| 740 | struct i40e_aq_desc *desc, |
| 741 | void *buff, /* can be NULL */ |
| 742 | u16 buff_size, |
| 743 | struct i40e_asq_cmd_details *cmd_details) |
| 744 | { |
| 745 | i40e_status status = 0; |
| 746 | struct i40e_dma_mem *dma_buff = NULL; |
| 747 | struct i40e_asq_cmd_details *details; |
| 748 | struct i40e_aq_desc *desc_on_ring; |
| 749 | bool cmd_completed = false; |
| 750 | u16 retval = 0; |
Michal Kosiarz | 80a977e | 2014-06-03 23:50:13 +0000 | [diff] [blame] | 751 | u32 val = 0; |
| 752 | |
| 753 | val = rd32(hw, hw->aq.asq.head); |
| 754 | if (val >= hw->aq.num_asq_entries) { |
| 755 | i40e_debug(hw, I40E_DEBUG_AQ_MESSAGE, |
| 756 | "AQTX: head overrun at %d\n", val); |
| 757 | status = I40E_ERR_QUEUE_EMPTY; |
| 758 | goto asq_send_command_exit; |
| 759 | } |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 760 | |
| 761 | if (hw->aq.asq.count == 0) { |
| 762 | i40e_debug(hw, I40E_DEBUG_AQ_MESSAGE, |
| 763 | "AQTX: Admin queue not initialized.\n"); |
| 764 | status = I40E_ERR_QUEUE_EMPTY; |
| 765 | goto asq_send_command_exit; |
| 766 | } |
| 767 | |
Shannon Nelson | c9296ad | 2014-03-14 07:32:22 +0000 | [diff] [blame] | 768 | if (i40e_is_nvm_update_op(desc) && hw->aq.nvm_busy) { |
| 769 | i40e_debug(hw, I40E_DEBUG_AQ_MESSAGE, "AQTX: NVM busy.\n"); |
| 770 | status = I40E_ERR_NVM; |
| 771 | goto asq_send_command_exit; |
| 772 | } |
| 773 | |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 774 | details = I40E_ADMINQ_DETAILS(hw->aq.asq, hw->aq.asq.next_to_use); |
| 775 | if (cmd_details) { |
Jesse Brandeburg | d7595a2 | 2013-09-13 08:23:22 +0000 | [diff] [blame] | 776 | *details = *cmd_details; |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 777 | |
| 778 | /* If the cmd_details are defined copy the cookie. The |
| 779 | * cpu_to_le32 is not needed here because the data is ignored |
| 780 | * by the FW, only used by the driver |
| 781 | */ |
| 782 | if (details->cookie) { |
| 783 | desc->cookie_high = |
| 784 | cpu_to_le32(upper_32_bits(details->cookie)); |
| 785 | desc->cookie_low = |
| 786 | cpu_to_le32(lower_32_bits(details->cookie)); |
| 787 | } |
| 788 | } else { |
| 789 | memset(details, 0, sizeof(struct i40e_asq_cmd_details)); |
| 790 | } |
| 791 | |
| 792 | /* clear requested flags and then set additional flags if defined */ |
| 793 | desc->flags &= ~cpu_to_le16(details->flags_dis); |
| 794 | desc->flags |= cpu_to_le16(details->flags_ena); |
| 795 | |
| 796 | mutex_lock(&hw->aq.asq_mutex); |
| 797 | |
| 798 | if (buff_size > hw->aq.asq_buf_size) { |
| 799 | i40e_debug(hw, |
| 800 | I40E_DEBUG_AQ_MESSAGE, |
| 801 | "AQTX: Invalid buffer size: %d.\n", |
| 802 | buff_size); |
| 803 | status = I40E_ERR_INVALID_SIZE; |
| 804 | goto asq_send_command_error; |
| 805 | } |
| 806 | |
| 807 | if (details->postpone && !details->async) { |
| 808 | i40e_debug(hw, |
| 809 | I40E_DEBUG_AQ_MESSAGE, |
| 810 | "AQTX: Async flag not set along with postpone flag"); |
| 811 | status = I40E_ERR_PARAM; |
| 812 | goto asq_send_command_error; |
| 813 | } |
| 814 | |
| 815 | /* call clean and check queue available function to reclaim the |
| 816 | * descriptors that were processed by FW, the function returns the |
| 817 | * number of desc available |
| 818 | */ |
| 819 | /* the clean function called here could be called in a separate thread |
| 820 | * in case of asynchronous completions |
| 821 | */ |
| 822 | if (i40e_clean_asq(hw) == 0) { |
| 823 | i40e_debug(hw, |
| 824 | I40E_DEBUG_AQ_MESSAGE, |
| 825 | "AQTX: Error queue is full.\n"); |
| 826 | status = I40E_ERR_ADMIN_QUEUE_FULL; |
| 827 | goto asq_send_command_error; |
| 828 | } |
| 829 | |
| 830 | /* initialize the temp desc pointer with the right desc */ |
| 831 | desc_on_ring = I40E_ADMINQ_DESC(hw->aq.asq, hw->aq.asq.next_to_use); |
| 832 | |
| 833 | /* if the desc is available copy the temp desc to the right place */ |
Jesse Brandeburg | d7595a2 | 2013-09-13 08:23:22 +0000 | [diff] [blame] | 834 | *desc_on_ring = *desc; |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 835 | |
| 836 | /* if buff is not NULL assume indirect command */ |
| 837 | if (buff != NULL) { |
| 838 | dma_buff = &(hw->aq.asq.r.asq_bi[hw->aq.asq.next_to_use]); |
| 839 | /* copy the user buff into the respective DMA buff */ |
| 840 | memcpy(dma_buff->va, buff, buff_size); |
| 841 | desc_on_ring->datalen = cpu_to_le16(buff_size); |
| 842 | |
| 843 | /* Update the address values in the desc with the pa value |
| 844 | * for respective buffer |
| 845 | */ |
| 846 | desc_on_ring->params.external.addr_high = |
| 847 | cpu_to_le32(upper_32_bits(dma_buff->pa)); |
| 848 | desc_on_ring->params.external.addr_low = |
| 849 | cpu_to_le32(lower_32_bits(dma_buff->pa)); |
| 850 | } |
| 851 | |
| 852 | /* bump the tail */ |
Kamil Krawczyk | 66d90e7 | 2014-06-04 00:57:12 +0000 | [diff] [blame^] | 853 | i40e_debug(hw, I40E_DEBUG_AQ_MESSAGE, "AQTX: desc and buffer:\n"); |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 854 | i40e_debug_aq(hw, I40E_DEBUG_AQ_COMMAND, (void *)desc_on_ring, buff); |
| 855 | (hw->aq.asq.next_to_use)++; |
| 856 | if (hw->aq.asq.next_to_use == hw->aq.asq.count) |
| 857 | hw->aq.asq.next_to_use = 0; |
| 858 | if (!details->postpone) |
| 859 | wr32(hw, hw->aq.asq.tail, hw->aq.asq.next_to_use); |
| 860 | |
| 861 | /* if cmd_details are not defined or async flag is not set, |
| 862 | * we need to wait for desc write back |
| 863 | */ |
| 864 | if (!details->async && !details->postpone) { |
| 865 | u32 total_delay = 0; |
| 866 | u32 delay_len = 10; |
| 867 | |
| 868 | do { |
| 869 | /* AQ designers suggest use of head for better |
| 870 | * timing reliability than DD bit |
| 871 | */ |
| 872 | if (i40e_asq_done(hw)) |
| 873 | break; |
| 874 | /* ugh! delay while spin_lock */ |
| 875 | udelay(delay_len); |
| 876 | total_delay += delay_len; |
| 877 | } while (total_delay < I40E_ASQ_CMD_TIMEOUT); |
| 878 | } |
| 879 | |
| 880 | /* if ready, copy the desc back to temp */ |
| 881 | if (i40e_asq_done(hw)) { |
Jesse Brandeburg | d7595a2 | 2013-09-13 08:23:22 +0000 | [diff] [blame] | 882 | *desc = *desc_on_ring; |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 883 | if (buff != NULL) |
| 884 | memcpy(buff, dma_buff->va, buff_size); |
| 885 | retval = le16_to_cpu(desc->retval); |
| 886 | if (retval != 0) { |
| 887 | i40e_debug(hw, |
| 888 | I40E_DEBUG_AQ_MESSAGE, |
| 889 | "AQTX: Command completed with error 0x%X.\n", |
| 890 | retval); |
Kamil Krawczyk | 66d90e7 | 2014-06-04 00:57:12 +0000 | [diff] [blame^] | 891 | |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 892 | /* strip off FW internal code */ |
| 893 | retval &= 0xff; |
| 894 | } |
| 895 | cmd_completed = true; |
| 896 | if ((enum i40e_admin_queue_err)retval == I40E_AQ_RC_OK) |
| 897 | status = 0; |
| 898 | else |
| 899 | status = I40E_ERR_ADMIN_QUEUE_ERROR; |
| 900 | hw->aq.asq_last_status = (enum i40e_admin_queue_err)retval; |
| 901 | } |
| 902 | |
Shannon Nelson | c9296ad | 2014-03-14 07:32:22 +0000 | [diff] [blame] | 903 | if (i40e_is_nvm_update_op(desc)) |
| 904 | hw->aq.nvm_busy = true; |
| 905 | |
Kamil Krawczyk | 66d90e7 | 2014-06-04 00:57:12 +0000 | [diff] [blame^] | 906 | if (le16_to_cpu(desc->datalen) == buff_size) { |
| 907 | i40e_debug(hw, I40E_DEBUG_AQ_MESSAGE, |
| 908 | "AQTX: desc and buffer writeback:\n"); |
| 909 | i40e_debug_aq(hw, I40E_DEBUG_AQ_COMMAND, (void *)desc, buff); |
| 910 | } |
| 911 | |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 912 | /* update the error if time out occurred */ |
| 913 | if ((!cmd_completed) && |
| 914 | (!details->async && !details->postpone)) { |
| 915 | i40e_debug(hw, |
| 916 | I40E_DEBUG_AQ_MESSAGE, |
| 917 | "AQTX: Writeback timeout.\n"); |
| 918 | status = I40E_ERR_ADMIN_QUEUE_TIMEOUT; |
| 919 | } |
| 920 | |
| 921 | asq_send_command_error: |
| 922 | mutex_unlock(&hw->aq.asq_mutex); |
| 923 | asq_send_command_exit: |
| 924 | return status; |
| 925 | } |
| 926 | |
| 927 | /** |
| 928 | * i40e_fill_default_direct_cmd_desc - AQ descriptor helper function |
| 929 | * @desc: pointer to the temp descriptor (non DMA mem) |
| 930 | * @opcode: the opcode can be used to decide which flags to turn off or on |
| 931 | * |
| 932 | * Fill the desc with default values |
| 933 | **/ |
| 934 | void i40e_fill_default_direct_cmd_desc(struct i40e_aq_desc *desc, |
| 935 | u16 opcode) |
| 936 | { |
| 937 | /* zero out the desc */ |
| 938 | memset((void *)desc, 0, sizeof(struct i40e_aq_desc)); |
| 939 | desc->opcode = cpu_to_le16(opcode); |
Shannon Nelson | ab954cb | 2013-12-18 13:45:57 +0000 | [diff] [blame] | 940 | desc->flags = cpu_to_le16(I40E_AQ_FLAG_SI); |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 941 | } |
| 942 | |
| 943 | /** |
| 944 | * i40e_clean_arq_element |
| 945 | * @hw: pointer to the hw struct |
| 946 | * @e: event info from the receive descriptor, includes any buffers |
| 947 | * @pending: number of events that could be left to process |
| 948 | * |
| 949 | * This function cleans one Admin Receive Queue element and returns |
| 950 | * the contents through e. It can also return how many events are |
| 951 | * left to process through 'pending' |
| 952 | **/ |
| 953 | i40e_status i40e_clean_arq_element(struct i40e_hw *hw, |
| 954 | struct i40e_arq_event_info *e, |
| 955 | u16 *pending) |
| 956 | { |
| 957 | i40e_status ret_code = 0; |
| 958 | u16 ntc = hw->aq.arq.next_to_clean; |
| 959 | struct i40e_aq_desc *desc; |
| 960 | struct i40e_dma_mem *bi; |
| 961 | u16 desc_idx; |
| 962 | u16 datalen; |
| 963 | u16 flags; |
| 964 | u16 ntu; |
| 965 | |
| 966 | /* take the lock before we start messing with the ring */ |
| 967 | mutex_lock(&hw->aq.arq_mutex); |
| 968 | |
| 969 | /* set next_to_use to head */ |
| 970 | ntu = (rd32(hw, hw->aq.arq.head) & I40E_PF_ARQH_ARQH_MASK); |
| 971 | if (ntu == ntc) { |
| 972 | /* nothing to do - shouldn't need to update ring's values */ |
| 973 | i40e_debug(hw, |
| 974 | I40E_DEBUG_AQ_MESSAGE, |
| 975 | "AQRX: Queue is empty.\n"); |
| 976 | ret_code = I40E_ERR_ADMIN_QUEUE_NO_WORK; |
| 977 | goto clean_arq_element_out; |
| 978 | } |
| 979 | |
| 980 | /* now clean the next descriptor */ |
| 981 | desc = I40E_ADMINQ_DESC(hw->aq.arq, ntc); |
| 982 | desc_idx = ntc; |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 983 | |
| 984 | flags = le16_to_cpu(desc->flags); |
| 985 | if (flags & I40E_AQ_FLAG_ERR) { |
| 986 | ret_code = I40E_ERR_ADMIN_QUEUE_ERROR; |
| 987 | hw->aq.arq_last_status = |
| 988 | (enum i40e_admin_queue_err)le16_to_cpu(desc->retval); |
| 989 | i40e_debug(hw, |
| 990 | I40E_DEBUG_AQ_MESSAGE, |
| 991 | "AQRX: Event received with error 0x%X.\n", |
| 992 | hw->aq.arq_last_status); |
| 993 | } else { |
Mitch Williams | c36bd4a7 | 2013-12-18 13:46:04 +0000 | [diff] [blame] | 994 | e->desc = *desc; |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 995 | datalen = le16_to_cpu(desc->datalen); |
| 996 | e->msg_size = min(datalen, e->msg_size); |
| 997 | if (e->msg_buf != NULL && (e->msg_size != 0)) |
| 998 | memcpy(e->msg_buf, hw->aq.arq.r.arq_bi[desc_idx].va, |
| 999 | e->msg_size); |
| 1000 | } |
| 1001 | |
Shannon Nelson | c9296ad | 2014-03-14 07:32:22 +0000 | [diff] [blame] | 1002 | if (i40e_is_nvm_update_op(&e->desc)) |
| 1003 | hw->aq.nvm_busy = false; |
| 1004 | |
Kamil Krawczyk | 66d90e7 | 2014-06-04 00:57:12 +0000 | [diff] [blame^] | 1005 | i40e_debug(hw, I40E_DEBUG_AQ_MESSAGE, "AQRX: desc and buffer:\n"); |
| 1006 | i40e_debug_aq(hw, I40E_DEBUG_AQ_COMMAND, (void *)desc, e->msg_buf); |
| 1007 | |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 1008 | /* Restore the original datalen and buffer address in the desc, |
| 1009 | * FW updates datalen to indicate the event message |
| 1010 | * size |
| 1011 | */ |
| 1012 | bi = &hw->aq.arq.r.arq_bi[ntc]; |
Mitch Williams | 9007777 | 2013-12-18 13:45:48 +0000 | [diff] [blame] | 1013 | memset((void *)desc, 0, sizeof(struct i40e_aq_desc)); |
| 1014 | |
| 1015 | desc->flags = cpu_to_le16(I40E_AQ_FLAG_BUF); |
| 1016 | if (hw->aq.arq_buf_size > I40E_AQ_LARGE_BUF) |
| 1017 | desc->flags |= cpu_to_le16(I40E_AQ_FLAG_LB); |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 1018 | desc->datalen = cpu_to_le16((u16)bi->size); |
| 1019 | desc->params.external.addr_high = cpu_to_le32(upper_32_bits(bi->pa)); |
| 1020 | desc->params.external.addr_low = cpu_to_le32(lower_32_bits(bi->pa)); |
| 1021 | |
| 1022 | /* set tail = the last cleaned desc index. */ |
| 1023 | wr32(hw, hw->aq.arq.tail, ntc); |
| 1024 | /* ntc is updated to tail + 1 */ |
| 1025 | ntc++; |
| 1026 | if (ntc == hw->aq.num_arq_entries) |
| 1027 | ntc = 0; |
| 1028 | hw->aq.arq.next_to_clean = ntc; |
| 1029 | hw->aq.arq.next_to_use = ntu; |
| 1030 | |
| 1031 | clean_arq_element_out: |
| 1032 | /* Set pending if needed, unlock and return */ |
| 1033 | if (pending != NULL) |
| 1034 | *pending = (ntc > ntu ? hw->aq.arq.count : 0) + (ntu - ntc); |
| 1035 | mutex_unlock(&hw->aq.arq_mutex); |
| 1036 | |
| 1037 | return ret_code; |
| 1038 | } |
| 1039 | |
Stephen Hemminger | af28eec | 2013-12-13 04:37:50 +0000 | [diff] [blame] | 1040 | static void i40e_resume_aq(struct i40e_hw *hw) |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 1041 | { |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 1042 | /* Registers are reset after PF reset */ |
| 1043 | hw->aq.asq.next_to_use = 0; |
| 1044 | hw->aq.asq.next_to_clean = 0; |
| 1045 | |
| 1046 | i40e_config_asq_regs(hw); |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 1047 | |
| 1048 | hw->aq.arq.next_to_use = 0; |
| 1049 | hw->aq.arq.next_to_clean = 0; |
| 1050 | |
| 1051 | i40e_config_arq_regs(hw); |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 1052 | } |