1 /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) */ 2 /* QLogic qed NIC Driver 3 * Copyright (c) 2015-2017 QLogic Corporation 4 * Copyright (c) 2019-2020 Marvell International Ltd. 5 */ 6 7 #ifndef _QED_DEV_API_H 8 #define _QED_DEV_API_H 9 10 #include <linux/types.h> 11 #include <linux/kernel.h> 12 #include <linux/slab.h> 13 #include <linux/qed/qed_chain.h> 14 #include <linux/qed/qed_if.h> 15 #include "qed_int.h" 16 17 /** 18 * @brief qed_init_dp - initialize the debug level 19 * 20 * @param cdev 21 * @param dp_module 22 * @param dp_level 23 */ 24 void qed_init_dp(struct qed_dev *cdev, 25 u32 dp_module, 26 u8 dp_level); 27 28 /** 29 * @brief qed_init_struct - initialize the device structure to 30 * its defaults 31 * 32 * @param cdev 33 */ 34 void qed_init_struct(struct qed_dev *cdev); 35 36 /** 37 * @brief qed_resc_free - 38 * 39 * @param cdev 40 */ 41 void qed_resc_free(struct qed_dev *cdev); 42 43 /** 44 * @brief qed_resc_alloc - 45 * 46 * @param cdev 47 * 48 * @return int 49 */ 50 int qed_resc_alloc(struct qed_dev *cdev); 51 52 /** 53 * @brief qed_resc_setup - 54 * 55 * @param cdev 56 */ 57 void qed_resc_setup(struct qed_dev *cdev); 58 59 enum qed_override_force_load { 60 QED_OVERRIDE_FORCE_LOAD_NONE, 61 QED_OVERRIDE_FORCE_LOAD_ALWAYS, 62 QED_OVERRIDE_FORCE_LOAD_NEVER, 63 }; 64 65 struct qed_drv_load_params { 66 /* Indicates whether the driver is running over a crash kernel. 67 * As part of the load request, this will be used for providing the 68 * driver role to the MFW. 69 * In case of a crash kernel over PDA - this should be set to false. 70 */ 71 bool is_crash_kernel; 72 73 /* The timeout value that the MFW should use when locking the engine for 74 * the driver load process. 75 * A value of '0' means the default value, and '255' means no timeout. 76 */ 77 u8 mfw_timeout_val; 78 #define QED_LOAD_REQ_LOCK_TO_DEFAULT 0 79 #define QED_LOAD_REQ_LOCK_TO_NONE 255 80 81 /* Avoid engine reset when first PF loads on it */ 82 bool avoid_eng_reset; 83 84 /* Allow overriding the default force load behavior */ 85 enum qed_override_force_load override_force_load; 86 }; 87 88 struct qed_hw_init_params { 89 /* Tunneling parameters */ 90 struct qed_tunnel_info *p_tunn; 91 92 bool b_hw_start; 93 94 /* Interrupt mode [msix, inta, etc.] to use */ 95 enum qed_int_mode int_mode; 96 97 /* NPAR tx switching to be used for vports for tx-switching */ 98 bool allow_npar_tx_switch; 99 100 /* Binary fw data pointer in binary fw file */ 101 const u8 *bin_fw_data; 102 103 /* Driver load parameters */ 104 struct qed_drv_load_params *p_drv_load_params; 105 }; 106 107 /** 108 * @brief qed_hw_init - 109 * 110 * @param cdev 111 * @param p_params 112 * 113 * @return int 114 */ 115 int qed_hw_init(struct qed_dev *cdev, struct qed_hw_init_params *p_params); 116 117 /** 118 * @brief qed_hw_timers_stop_all - stop the timers HW block 119 * 120 * @param cdev 121 * 122 * @return void 123 */ 124 void qed_hw_timers_stop_all(struct qed_dev *cdev); 125 126 /** 127 * @brief qed_hw_stop - 128 * 129 * @param cdev 130 * 131 * @return int 132 */ 133 int qed_hw_stop(struct qed_dev *cdev); 134 135 /** 136 * @brief qed_hw_stop_fastpath -should be called incase 137 * slowpath is still required for the device, 138 * but fastpath is not. 139 * 140 * @param cdev 141 * 142 * @return int 143 */ 144 int qed_hw_stop_fastpath(struct qed_dev *cdev); 145 146 /** 147 * @brief qed_hw_start_fastpath -restart fastpath traffic, 148 * only if hw_stop_fastpath was called 149 * 150 * @param p_hwfn 151 * 152 * @return int 153 */ 154 int qed_hw_start_fastpath(struct qed_hwfn *p_hwfn); 155 156 157 /** 158 * @brief qed_hw_prepare - 159 * 160 * @param cdev 161 * @param personality - personality to initialize 162 * 163 * @return int 164 */ 165 int qed_hw_prepare(struct qed_dev *cdev, 166 int personality); 167 168 /** 169 * @brief qed_hw_remove - 170 * 171 * @param cdev 172 */ 173 void qed_hw_remove(struct qed_dev *cdev); 174 175 /** 176 * @brief qed_ptt_acquire - Allocate a PTT window 177 * 178 * Should be called at the entry point to the driver (at the beginning of an 179 * exported function) 180 * 181 * @param p_hwfn 182 * 183 * @return struct qed_ptt 184 */ 185 struct qed_ptt *qed_ptt_acquire(struct qed_hwfn *p_hwfn); 186 187 /** 188 * @brief qed_ptt_release - Release PTT Window 189 * 190 * Should be called at the end of a flow - at the end of the function that 191 * acquired the PTT. 192 * 193 * 194 * @param p_hwfn 195 * @param p_ptt 196 */ 197 void qed_ptt_release(struct qed_hwfn *p_hwfn, 198 struct qed_ptt *p_ptt); 199 void qed_reset_vport_stats(struct qed_dev *cdev); 200 201 enum qed_dmae_address_type_t { 202 QED_DMAE_ADDRESS_HOST_VIRT, 203 QED_DMAE_ADDRESS_HOST_PHYS, 204 QED_DMAE_ADDRESS_GRC 205 }; 206 207 /** 208 * @brief qed_dmae_host2grc - copy data from source addr to 209 * dmae registers using the given ptt 210 * 211 * @param p_hwfn 212 * @param p_ptt 213 * @param source_addr 214 * @param grc_addr (dmae_data_offset) 215 * @param size_in_dwords 216 * @param p_params (default parameters will be used in case of NULL) 217 */ 218 int 219 qed_dmae_host2grc(struct qed_hwfn *p_hwfn, 220 struct qed_ptt *p_ptt, 221 u64 source_addr, 222 u32 grc_addr, 223 u32 size_in_dwords, 224 struct qed_dmae_params *p_params); 225 226 /** 227 * @brief qed_dmae_grc2host - Read data from dmae data offset 228 * to source address using the given ptt 229 * 230 * @param p_ptt 231 * @param grc_addr (dmae_data_offset) 232 * @param dest_addr 233 * @param size_in_dwords 234 * @param p_params (default parameters will be used in case of NULL) 235 */ 236 int qed_dmae_grc2host(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt, 237 u32 grc_addr, dma_addr_t dest_addr, u32 size_in_dwords, 238 struct qed_dmae_params *p_params); 239 240 /** 241 * @brief qed_dmae_host2host - copy data from to source address 242 * to a destination adress (for SRIOV) using the given ptt 243 * 244 * @param p_hwfn 245 * @param p_ptt 246 * @param source_addr 247 * @param dest_addr 248 * @param size_in_dwords 249 * @param p_params (default parameters will be used in case of NULL) 250 */ 251 int qed_dmae_host2host(struct qed_hwfn *p_hwfn, 252 struct qed_ptt *p_ptt, 253 dma_addr_t source_addr, 254 dma_addr_t dest_addr, 255 u32 size_in_dwords, struct qed_dmae_params *p_params); 256 257 /** 258 * @brief qed_chain_alloc - Allocate and initialize a chain 259 * 260 * @param p_hwfn 261 * @param intended_use 262 * @param mode 263 * @param num_elems 264 * @param elem_size 265 * @param p_chain 266 * @param ext_pbl - a possible external PBL 267 * 268 * @return int 269 */ 270 int 271 qed_chain_alloc(struct qed_dev *cdev, 272 enum qed_chain_use_mode intended_use, 273 enum qed_chain_mode mode, 274 enum qed_chain_cnt_type cnt_type, 275 u32 num_elems, 276 size_t elem_size, 277 struct qed_chain *p_chain, struct qed_chain_ext_pbl *ext_pbl); 278 279 /** 280 * @brief qed_chain_free - Free chain DMA memory 281 * 282 * @param p_hwfn 283 * @param p_chain 284 */ 285 void qed_chain_free(struct qed_dev *cdev, struct qed_chain *p_chain); 286 287 /** 288 * @@brief qed_fw_l2_queue - Get absolute L2 queue ID 289 * 290 * @param p_hwfn 291 * @param src_id - relative to p_hwfn 292 * @param dst_id - absolute per engine 293 * 294 * @return int 295 */ 296 int qed_fw_l2_queue(struct qed_hwfn *p_hwfn, 297 u16 src_id, 298 u16 *dst_id); 299 300 /** 301 * @@brief qed_fw_vport - Get absolute vport ID 302 * 303 * @param p_hwfn 304 * @param src_id - relative to p_hwfn 305 * @param dst_id - absolute per engine 306 * 307 * @return int 308 */ 309 int qed_fw_vport(struct qed_hwfn *p_hwfn, 310 u8 src_id, 311 u8 *dst_id); 312 313 /** 314 * @@brief qed_fw_rss_eng - Get absolute RSS engine ID 315 * 316 * @param p_hwfn 317 * @param src_id - relative to p_hwfn 318 * @param dst_id - absolute per engine 319 * 320 * @return int 321 */ 322 int qed_fw_rss_eng(struct qed_hwfn *p_hwfn, 323 u8 src_id, 324 u8 *dst_id); 325 326 /** 327 * @brief qed_llh_get_num_ppfid - Return the allocated number of LLH filter 328 * banks that are allocated to the PF. 329 * 330 * @param cdev 331 * 332 * @return u8 - Number of LLH filter banks 333 */ 334 u8 qed_llh_get_num_ppfid(struct qed_dev *cdev); 335 336 enum qed_eng { 337 QED_ENG0, 338 QED_ENG1, 339 QED_BOTH_ENG, 340 }; 341 342 /** 343 * @brief qed_llh_set_ppfid_affinity - Set the engine affinity for the given 344 * LLH filter bank. 345 * 346 * @param cdev 347 * @param ppfid - relative within the allocated ppfids ('0' is the default one). 348 * @param eng 349 * 350 * @return int 351 */ 352 int qed_llh_set_ppfid_affinity(struct qed_dev *cdev, 353 u8 ppfid, enum qed_eng eng); 354 355 /** 356 * @brief qed_llh_set_roce_affinity - Set the RoCE engine affinity 357 * 358 * @param cdev 359 * @param eng 360 * 361 * @return int 362 */ 363 int qed_llh_set_roce_affinity(struct qed_dev *cdev, enum qed_eng eng); 364 365 /** 366 * @brief qed_llh_add_mac_filter - Add a LLH MAC filter into the given filter 367 * bank. 368 * 369 * @param cdev 370 * @param ppfid - relative within the allocated ppfids ('0' is the default one). 371 * @param mac_addr - MAC to add 372 */ 373 int qed_llh_add_mac_filter(struct qed_dev *cdev, 374 u8 ppfid, u8 mac_addr[ETH_ALEN]); 375 376 /** 377 * @brief qed_llh_remove_mac_filter - Remove a LLH MAC filter from the given 378 * filter bank. 379 * 380 * @param p_ptt 381 * @param p_filter - MAC to remove 382 */ 383 void qed_llh_remove_mac_filter(struct qed_dev *cdev, 384 u8 ppfid, u8 mac_addr[ETH_ALEN]); 385 386 enum qed_llh_prot_filter_type_t { 387 QED_LLH_FILTER_ETHERTYPE, 388 QED_LLH_FILTER_TCP_SRC_PORT, 389 QED_LLH_FILTER_TCP_DEST_PORT, 390 QED_LLH_FILTER_TCP_SRC_AND_DEST_PORT, 391 QED_LLH_FILTER_UDP_SRC_PORT, 392 QED_LLH_FILTER_UDP_DEST_PORT, 393 QED_LLH_FILTER_UDP_SRC_AND_DEST_PORT 394 }; 395 396 /** 397 * @brief qed_llh_add_protocol_filter - Add a LLH protocol filter into the 398 * given filter bank. 399 * 400 * @param cdev 401 * @param ppfid - relative within the allocated ppfids ('0' is the default one). 402 * @param type - type of filters and comparing 403 * @param source_port_or_eth_type - source port or ethertype to add 404 * @param dest_port - destination port to add 405 * @param type - type of filters and comparing 406 */ 407 int 408 qed_llh_add_protocol_filter(struct qed_dev *cdev, 409 u8 ppfid, 410 enum qed_llh_prot_filter_type_t type, 411 u16 source_port_or_eth_type, u16 dest_port); 412 413 /** 414 * @brief qed_llh_remove_protocol_filter - Remove a LLH protocol filter from 415 * the given filter bank. 416 * 417 * @param cdev 418 * @param ppfid - relative within the allocated ppfids ('0' is the default one). 419 * @param type - type of filters and comparing 420 * @param source_port_or_eth_type - source port or ethertype to add 421 * @param dest_port - destination port to add 422 */ 423 void 424 qed_llh_remove_protocol_filter(struct qed_dev *cdev, 425 u8 ppfid, 426 enum qed_llh_prot_filter_type_t type, 427 u16 source_port_or_eth_type, u16 dest_port); 428 429 /** 430 * *@brief Cleanup of previous driver remains prior to load 431 * 432 * @param p_hwfn 433 * @param p_ptt 434 * @param id - For PF, engine-relative. For VF, PF-relative. 435 * @param is_vf - true iff cleanup is made for a VF. 436 * 437 * @return int 438 */ 439 int qed_final_cleanup(struct qed_hwfn *p_hwfn, 440 struct qed_ptt *p_ptt, u16 id, bool is_vf); 441 442 /** 443 * @brief qed_get_queue_coalesce - Retrieve coalesce value for a given queue. 444 * 445 * @param p_hwfn 446 * @param p_coal - store coalesce value read from the hardware. 447 * @param p_handle 448 * 449 * @return int 450 **/ 451 int qed_get_queue_coalesce(struct qed_hwfn *p_hwfn, u16 *coal, void *handle); 452 453 /** 454 * @brief qed_set_queue_coalesce - Configure coalesce parameters for Rx and 455 * Tx queue. The fact that we can configure coalescing to up to 511, but on 456 * varying accuracy [the bigger the value the less accurate] up to a mistake 457 * of 3usec for the highest values. 458 * While the API allows setting coalescing per-qid, all queues sharing a SB 459 * should be in same range [i.e., either 0-0x7f, 0x80-0xff or 0x100-0x1ff] 460 * otherwise configuration would break. 461 * 462 * 463 * @param rx_coal - Rx Coalesce value in micro seconds. 464 * @param tx_coal - TX Coalesce value in micro seconds. 465 * @param p_handle 466 * 467 * @return int 468 **/ 469 int 470 qed_set_queue_coalesce(u16 rx_coal, u16 tx_coal, void *p_handle); 471 472 /** 473 * @brief qed_pglueb_set_pfid_enable - Enable or disable PCI BUS MASTER 474 * 475 * @param p_hwfn 476 * @param p_ptt 477 * @param b_enable - true/false 478 * 479 * @return int 480 */ 481 int qed_pglueb_set_pfid_enable(struct qed_hwfn *p_hwfn, 482 struct qed_ptt *p_ptt, bool b_enable); 483 484 /** 485 * @brief db_recovery_add - add doorbell information to the doorbell 486 * recovery mechanism. 487 * 488 * @param cdev 489 * @param db_addr - doorbell address 490 * @param db_data - address of where db_data is stored 491 * @param db_width - doorbell is 32b pr 64b 492 * @param db_space - doorbell recovery addresses are user or kernel space 493 */ 494 int qed_db_recovery_add(struct qed_dev *cdev, 495 void __iomem *db_addr, 496 void *db_data, 497 enum qed_db_rec_width db_width, 498 enum qed_db_rec_space db_space); 499 500 /** 501 * @brief db_recovery_del - remove doorbell information from the doorbell 502 * recovery mechanism. db_data serves as key (db_addr is not unique). 503 * 504 * @param cdev 505 * @param db_addr - doorbell address 506 * @param db_data - address where db_data is stored. Serves as key for the 507 * entry to delete. 508 */ 509 int qed_db_recovery_del(struct qed_dev *cdev, 510 void __iomem *db_addr, void *db_data); 511 512 513 const char *qed_hw_get_resc_name(enum qed_resources res_id); 514 #endif 515