1 /* QLogic qed NIC Driver 2 * Copyright (c) 2015-2017 QLogic Corporation 3 * 4 * This software is available to you under a choice of one of two 5 * licenses. You may choose to be licensed under the terms of the GNU 6 * General Public License (GPL) Version 2, available from the file 7 * COPYING in the main directory of this source tree, or the 8 * OpenIB.org BSD license below: 9 * 10 * Redistribution and use in source and binary forms, with or 11 * without modification, are permitted provided that the following 12 * conditions are met: 13 * 14 * - Redistributions of source code must retain the above 15 * copyright notice, this list of conditions and the following 16 * disclaimer. 17 * 18 * - Redistributions in binary form must reproduce the above 19 * copyright notice, this list of conditions and the following 20 * disclaimer in the documentation and /or other materials 21 * provided with the distribution. 22 * 23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 30 * SOFTWARE. 31 */ 32 33 #ifndef _QED_DEV_API_H 34 #define _QED_DEV_API_H 35 36 #include <linux/types.h> 37 #include <linux/kernel.h> 38 #include <linux/slab.h> 39 #include <linux/qed/qed_chain.h> 40 #include <linux/qed/qed_if.h> 41 #include "qed_int.h" 42 43 /** 44 * @brief qed_init_dp - initialize the debug level 45 * 46 * @param cdev 47 * @param dp_module 48 * @param dp_level 49 */ 50 void qed_init_dp(struct qed_dev *cdev, 51 u32 dp_module, 52 u8 dp_level); 53 54 /** 55 * @brief qed_init_struct - initialize the device structure to 56 * its defaults 57 * 58 * @param cdev 59 */ 60 void qed_init_struct(struct qed_dev *cdev); 61 62 /** 63 * @brief qed_resc_free - 64 * 65 * @param cdev 66 */ 67 void qed_resc_free(struct qed_dev *cdev); 68 69 /** 70 * @brief qed_resc_alloc - 71 * 72 * @param cdev 73 * 74 * @return int 75 */ 76 int qed_resc_alloc(struct qed_dev *cdev); 77 78 /** 79 * @brief qed_resc_setup - 80 * 81 * @param cdev 82 */ 83 void qed_resc_setup(struct qed_dev *cdev); 84 85 enum qed_override_force_load { 86 QED_OVERRIDE_FORCE_LOAD_NONE, 87 QED_OVERRIDE_FORCE_LOAD_ALWAYS, 88 QED_OVERRIDE_FORCE_LOAD_NEVER, 89 }; 90 91 struct qed_drv_load_params { 92 /* Indicates whether the driver is running over a crash kernel. 93 * As part of the load request, this will be used for providing the 94 * driver role to the MFW. 95 * In case of a crash kernel over PDA - this should be set to false. 96 */ 97 bool is_crash_kernel; 98 99 /* The timeout value that the MFW should use when locking the engine for 100 * the driver load process. 101 * A value of '0' means the default value, and '255' means no timeout. 102 */ 103 u8 mfw_timeout_val; 104 #define QED_LOAD_REQ_LOCK_TO_DEFAULT 0 105 #define QED_LOAD_REQ_LOCK_TO_NONE 255 106 107 /* Avoid engine reset when first PF loads on it */ 108 bool avoid_eng_reset; 109 110 /* Allow overriding the default force load behavior */ 111 enum qed_override_force_load override_force_load; 112 }; 113 114 struct qed_hw_init_params { 115 /* Tunneling parameters */ 116 struct qed_tunn_start_params *p_tunn; 117 118 bool b_hw_start; 119 120 /* Interrupt mode [msix, inta, etc.] to use */ 121 enum qed_int_mode int_mode; 122 123 /* NPAR tx switching to be used for vports for tx-switching */ 124 bool allow_npar_tx_switch; 125 126 /* Binary fw data pointer in binary fw file */ 127 const u8 *bin_fw_data; 128 129 /* Driver load parameters */ 130 struct qed_drv_load_params *p_drv_load_params; 131 }; 132 133 /** 134 * @brief qed_hw_init - 135 * 136 * @param cdev 137 * @param p_params 138 * 139 * @return int 140 */ 141 int qed_hw_init(struct qed_dev *cdev, struct qed_hw_init_params *p_params); 142 143 /** 144 * @brief qed_hw_timers_stop_all - stop the timers HW block 145 * 146 * @param cdev 147 * 148 * @return void 149 */ 150 void qed_hw_timers_stop_all(struct qed_dev *cdev); 151 152 /** 153 * @brief qed_hw_stop - 154 * 155 * @param cdev 156 * 157 * @return int 158 */ 159 int qed_hw_stop(struct qed_dev *cdev); 160 161 /** 162 * @brief qed_hw_stop_fastpath -should be called incase 163 * slowpath is still required for the device, 164 * but fastpath is not. 165 * 166 * @param cdev 167 * 168 */ 169 void qed_hw_stop_fastpath(struct qed_dev *cdev); 170 171 /** 172 * @brief qed_hw_start_fastpath -restart fastpath traffic, 173 * only if hw_stop_fastpath was called 174 * 175 * @param cdev 176 * 177 */ 178 void qed_hw_start_fastpath(struct qed_hwfn *p_hwfn); 179 180 181 /** 182 * @brief qed_hw_prepare - 183 * 184 * @param cdev 185 * @param personality - personality to initialize 186 * 187 * @return int 188 */ 189 int qed_hw_prepare(struct qed_dev *cdev, 190 int personality); 191 192 /** 193 * @brief qed_hw_remove - 194 * 195 * @param cdev 196 */ 197 void qed_hw_remove(struct qed_dev *cdev); 198 199 /** 200 * @brief qed_ptt_acquire - Allocate a PTT window 201 * 202 * Should be called at the entry point to the driver (at the beginning of an 203 * exported function) 204 * 205 * @param p_hwfn 206 * 207 * @return struct qed_ptt 208 */ 209 struct qed_ptt *qed_ptt_acquire(struct qed_hwfn *p_hwfn); 210 211 /** 212 * @brief qed_ptt_release - Release PTT Window 213 * 214 * Should be called at the end of a flow - at the end of the function that 215 * acquired the PTT. 216 * 217 * 218 * @param p_hwfn 219 * @param p_ptt 220 */ 221 void qed_ptt_release(struct qed_hwfn *p_hwfn, 222 struct qed_ptt *p_ptt); 223 void qed_reset_vport_stats(struct qed_dev *cdev); 224 225 enum qed_dmae_address_type_t { 226 QED_DMAE_ADDRESS_HOST_VIRT, 227 QED_DMAE_ADDRESS_HOST_PHYS, 228 QED_DMAE_ADDRESS_GRC 229 }; 230 231 /* value of flags If QED_DMAE_FLAG_RW_REPL_SRC flag is set and the 232 * source is a block of length DMAE_MAX_RW_SIZE and the 233 * destination is larger, the source block will be duplicated as 234 * many times as required to fill the destination block. This is 235 * used mostly to write a zeroed buffer to destination address 236 * using DMA 237 */ 238 #define QED_DMAE_FLAG_RW_REPL_SRC 0x00000001 239 #define QED_DMAE_FLAG_VF_SRC 0x00000002 240 #define QED_DMAE_FLAG_VF_DST 0x00000004 241 #define QED_DMAE_FLAG_COMPLETION_DST 0x00000008 242 243 struct qed_dmae_params { 244 u32 flags; /* consists of QED_DMAE_FLAG_* values */ 245 u8 src_vfid; 246 u8 dst_vfid; 247 }; 248 249 /** 250 * @brief qed_dmae_host2grc - copy data from source addr to 251 * dmae registers using the given ptt 252 * 253 * @param p_hwfn 254 * @param p_ptt 255 * @param source_addr 256 * @param grc_addr (dmae_data_offset) 257 * @param size_in_dwords 258 * @param flags (one of the flags defined above) 259 */ 260 int 261 qed_dmae_host2grc(struct qed_hwfn *p_hwfn, 262 struct qed_ptt *p_ptt, 263 u64 source_addr, 264 u32 grc_addr, 265 u32 size_in_dwords, 266 u32 flags); 267 268 /** 269 * @brief qed_dmae_grc2host - Read data from dmae data offset 270 * to source address using the given ptt 271 * 272 * @param p_ptt 273 * @param grc_addr (dmae_data_offset) 274 * @param dest_addr 275 * @param size_in_dwords 276 * @param flags - one of the flags defined above 277 */ 278 int qed_dmae_grc2host(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt, 279 u32 grc_addr, dma_addr_t dest_addr, u32 size_in_dwords, 280 u32 flags); 281 282 /** 283 * @brief qed_dmae_host2host - copy data from to source address 284 * to a destination adress (for SRIOV) using the given ptt 285 * 286 * @param p_hwfn 287 * @param p_ptt 288 * @param source_addr 289 * @param dest_addr 290 * @param size_in_dwords 291 * @param params 292 */ 293 int qed_dmae_host2host(struct qed_hwfn *p_hwfn, 294 struct qed_ptt *p_ptt, 295 dma_addr_t source_addr, 296 dma_addr_t dest_addr, 297 u32 size_in_dwords, struct qed_dmae_params *p_params); 298 299 /** 300 * @brief qed_chain_alloc - Allocate and initialize a chain 301 * 302 * @param p_hwfn 303 * @param intended_use 304 * @param mode 305 * @param num_elems 306 * @param elem_size 307 * @param p_chain 308 * 309 * @return int 310 */ 311 int 312 qed_chain_alloc(struct qed_dev *cdev, 313 enum qed_chain_use_mode intended_use, 314 enum qed_chain_mode mode, 315 enum qed_chain_cnt_type cnt_type, 316 u32 num_elems, size_t elem_size, struct qed_chain *p_chain); 317 318 /** 319 * @brief qed_chain_free - Free chain DMA memory 320 * 321 * @param p_hwfn 322 * @param p_chain 323 */ 324 void qed_chain_free(struct qed_dev *cdev, struct qed_chain *p_chain); 325 326 /** 327 * @@brief qed_fw_l2_queue - Get absolute L2 queue ID 328 * 329 * @param p_hwfn 330 * @param src_id - relative to p_hwfn 331 * @param dst_id - absolute per engine 332 * 333 * @return int 334 */ 335 int qed_fw_l2_queue(struct qed_hwfn *p_hwfn, 336 u16 src_id, 337 u16 *dst_id); 338 339 /** 340 * @@brief qed_fw_vport - Get absolute vport ID 341 * 342 * @param p_hwfn 343 * @param src_id - relative to p_hwfn 344 * @param dst_id - absolute per engine 345 * 346 * @return int 347 */ 348 int qed_fw_vport(struct qed_hwfn *p_hwfn, 349 u8 src_id, 350 u8 *dst_id); 351 352 /** 353 * @@brief qed_fw_rss_eng - Get absolute RSS engine ID 354 * 355 * @param p_hwfn 356 * @param src_id - relative to p_hwfn 357 * @param dst_id - absolute per engine 358 * 359 * @return int 360 */ 361 int qed_fw_rss_eng(struct qed_hwfn *p_hwfn, 362 u8 src_id, 363 u8 *dst_id); 364 365 /** 366 * @brief qed_llh_add_mac_filter - configures a MAC filter in llh 367 * 368 * @param p_hwfn 369 * @param p_ptt 370 * @param p_filter - MAC to add 371 */ 372 int qed_llh_add_mac_filter(struct qed_hwfn *p_hwfn, 373 struct qed_ptt *p_ptt, u8 *p_filter); 374 375 /** 376 * @brief qed_llh_remove_mac_filter - removes a MAC filter from llh 377 * 378 * @param p_hwfn 379 * @param p_ptt 380 * @param p_filter - MAC to remove 381 */ 382 void qed_llh_remove_mac_filter(struct qed_hwfn *p_hwfn, 383 struct qed_ptt *p_ptt, u8 *p_filter); 384 385 enum qed_llh_port_filter_type_t { 386 QED_LLH_FILTER_ETHERTYPE, 387 QED_LLH_FILTER_TCP_SRC_PORT, 388 QED_LLH_FILTER_TCP_DEST_PORT, 389 QED_LLH_FILTER_TCP_SRC_AND_DEST_PORT, 390 QED_LLH_FILTER_UDP_SRC_PORT, 391 QED_LLH_FILTER_UDP_DEST_PORT, 392 QED_LLH_FILTER_UDP_SRC_AND_DEST_PORT 393 }; 394 395 /** 396 * @brief qed_llh_add_protocol_filter - configures a protocol filter in llh 397 * 398 * @param p_hwfn 399 * @param p_ptt 400 * @param source_port_or_eth_type - source port or ethertype to add 401 * @param dest_port - destination port to add 402 * @param type - type of filters and comparing 403 */ 404 int 405 qed_llh_add_protocol_filter(struct qed_hwfn *p_hwfn, 406 struct qed_ptt *p_ptt, 407 u16 source_port_or_eth_type, 408 u16 dest_port, 409 enum qed_llh_port_filter_type_t type); 410 411 /** 412 * @brief qed_llh_remove_protocol_filter - remove a protocol filter in llh 413 * 414 * @param p_hwfn 415 * @param p_ptt 416 * @param source_port_or_eth_type - source port or ethertype to add 417 * @param dest_port - destination port to add 418 * @param type - type of filters and comparing 419 */ 420 void 421 qed_llh_remove_protocol_filter(struct qed_hwfn *p_hwfn, 422 struct qed_ptt *p_ptt, 423 u16 source_port_or_eth_type, 424 u16 dest_port, 425 enum qed_llh_port_filter_type_t type); 426 427 /** 428 * *@brief Cleanup of previous driver remains prior to load 429 * 430 * @param p_hwfn 431 * @param p_ptt 432 * @param id - For PF, engine-relative. For VF, PF-relative. 433 * @param is_vf - true iff cleanup is made for a VF. 434 * 435 * @return int 436 */ 437 int qed_final_cleanup(struct qed_hwfn *p_hwfn, 438 struct qed_ptt *p_ptt, u16 id, bool is_vf); 439 440 /** 441 * @brief qed_set_rxq_coalesce - Configure coalesce parameters for an Rx queue 442 * The fact that we can configure coalescing to up to 511, but on varying 443 * accuracy [the bigger the value the less accurate] up to a mistake of 3usec 444 * for the highest values. 445 * 446 * @param p_hwfn 447 * @param p_ptt 448 * @param coalesce - Coalesce value in micro seconds. 449 * @param qid - Queue index. 450 * @param qid - SB Id 451 * 452 * @return int 453 */ 454 int qed_set_rxq_coalesce(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt, 455 u16 coalesce, u8 qid, u16 sb_id); 456 457 /** 458 * @brief qed_set_txq_coalesce - Configure coalesce parameters for a Tx queue 459 * While the API allows setting coalescing per-qid, all tx queues sharing a 460 * SB should be in same range [i.e., either 0-0x7f, 0x80-0xff or 0x100-0x1ff] 461 * otherwise configuration would break. 462 * 463 * @param p_hwfn 464 * @param p_ptt 465 * @param coalesce - Coalesce value in micro seconds. 466 * @param qid - Queue index. 467 * @param qid - SB Id 468 * 469 * @return int 470 */ 471 int qed_set_txq_coalesce(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt, 472 u16 coalesce, u8 qid, u16 sb_id); 473 474 const char *qed_hw_get_resc_name(enum qed_resources res_id); 475 #endif 476