1 /* 2 * QLogic FCoE Offload Driver 3 * Copyright (c) 2016-2018 Cavium Inc. 4 * 5 * This software is available under the terms of the GNU General Public License 6 * (GPL) Version 2, available from the file COPYING in the main directory of 7 * this source tree. 8 */ 9 #ifndef _QEDFC_H_ 10 #define _QEDFC_H_ 11 12 #include <scsi/libfcoe.h> 13 #include <scsi/libfc.h> 14 #include <scsi/fc/fc_fip.h> 15 #include <scsi/fc/fc_fc2.h> 16 #include <scsi/scsi_tcq.h> 17 #include <scsi/fc_encode.h> 18 #include <linux/version.h> 19 20 21 /* qedf_hsi.h needs to before included any qed includes */ 22 #include "qedf_hsi.h" 23 24 #include <linux/qed/qed_if.h> 25 #include <linux/qed/qed_fcoe_if.h> 26 #include <linux/qed/qed_ll2_if.h> 27 #include "qedf_version.h" 28 #include "qedf_dbg.h" 29 #include "drv_fcoe_fw_funcs.h" 30 31 /* Helpers to extract upper and lower 32-bits of pointer */ 32 #define U64_HI(val) ((u32)(((u64)(val)) >> 32)) 33 #define U64_LO(val) ((u32)(((u64)(val)) & 0xffffffff)) 34 35 #define QEDF_DESCR "QLogic FCoE Offload Driver" 36 #define QEDF_MODULE_NAME "qedf" 37 38 #define QEDF_FLOGI_RETRY_CNT 3 39 #define QEDF_RPORT_RETRY_CNT 255 40 #define QEDF_MAX_SESSIONS 1024 41 #define QEDF_MAX_PAYLOAD 2048 42 #define QEDF_MAX_BDS_PER_CMD 256 43 #define QEDF_MAX_BD_LEN 0xffff 44 #define QEDF_BD_SPLIT_SZ 0x1000 45 #define QEDF_PAGE_SIZE 4096 46 #define QED_HW_DMA_BOUNDARY 0xfff 47 #define QEDF_MAX_SGLEN_FOR_CACHESGL ((1U << 16) - 1) 48 #define QEDF_MFS (QEDF_MAX_PAYLOAD + \ 49 sizeof(struct fc_frame_header)) 50 #define QEDF_MAX_NPIV 64 51 #define QEDF_TM_TIMEOUT 10 52 #define QEDF_ABORT_TIMEOUT 10 53 #define QEDF_CLEANUP_TIMEOUT 10 54 #define QEDF_MAX_CDB_LEN 16 55 56 #define UPSTREAM_REMOVE 1 57 #define UPSTREAM_KEEP 1 58 59 struct qedf_mp_req { 60 uint32_t req_len; 61 void *req_buf; 62 dma_addr_t req_buf_dma; 63 struct scsi_sge *mp_req_bd; 64 dma_addr_t mp_req_bd_dma; 65 struct fc_frame_header req_fc_hdr; 66 67 uint32_t resp_len; 68 void *resp_buf; 69 dma_addr_t resp_buf_dma; 70 struct scsi_sge *mp_resp_bd; 71 dma_addr_t mp_resp_bd_dma; 72 struct fc_frame_header resp_fc_hdr; 73 }; 74 75 struct qedf_els_cb_arg { 76 struct qedf_ioreq *aborted_io_req; 77 struct qedf_ioreq *io_req; 78 u8 op; /* Used to keep track of ELS op */ 79 uint16_t l2_oxid; 80 u32 offset; /* Used for sequence cleanup */ 81 u8 r_ctl; /* Used for sequence cleanup */ 82 }; 83 84 enum qedf_ioreq_event { 85 QEDF_IOREQ_EV_ABORT_SUCCESS, 86 QEDF_IOREQ_EV_ABORT_FAILED, 87 QEDF_IOREQ_EV_SEND_RRQ, 88 QEDF_IOREQ_EV_ELS_TMO, 89 QEDF_IOREQ_EV_ELS_ERR_DETECT, 90 QEDF_IOREQ_EV_ELS_FLUSH, 91 QEDF_IOREQ_EV_CLEANUP_SUCCESS, 92 QEDF_IOREQ_EV_CLEANUP_FAILED, 93 }; 94 95 #define FC_GOOD 0 96 #define FCOE_FCP_RSP_FLAGS_FCP_RESID_OVER (0x1<<2) 97 #define FCOE_FCP_RSP_FLAGS_FCP_RESID_UNDER (0x1<<3) 98 #define CMD_SCSI_STATUS(Cmnd) ((Cmnd)->SCp.Status) 99 #define FCOE_FCP_RSP_FLAGS_FCP_RSP_LEN_VALID (0x1<<0) 100 #define FCOE_FCP_RSP_FLAGS_FCP_SNS_LEN_VALID (0x1<<1) 101 struct qedf_ioreq { 102 struct list_head link; 103 uint16_t xid; 104 struct scsi_cmnd *sc_cmd; 105 #define QEDF_SCSI_CMD 1 106 #define QEDF_TASK_MGMT_CMD 2 107 #define QEDF_ABTS 3 108 #define QEDF_ELS 4 109 #define QEDF_CLEANUP 5 110 #define QEDF_SEQ_CLEANUP 6 111 u8 cmd_type; 112 #define QEDF_CMD_OUTSTANDING 0x0 113 #define QEDF_CMD_IN_ABORT 0x1 114 #define QEDF_CMD_IN_CLEANUP 0x2 115 #define QEDF_CMD_SRR_SENT 0x3 116 u8 io_req_flags; 117 uint8_t tm_flags; 118 struct qedf_rport *fcport; 119 unsigned long flags; 120 enum qedf_ioreq_event event; 121 size_t data_xfer_len; 122 struct kref refcount; 123 struct qedf_cmd_mgr *cmd_mgr; 124 struct io_bdt *bd_tbl; 125 struct delayed_work timeout_work; 126 struct completion tm_done; 127 struct completion abts_done; 128 struct e4_fcoe_task_context *task; 129 struct fcoe_task_params *task_params; 130 struct scsi_sgl_task_params *sgl_task_params; 131 int idx; 132 /* 133 * Need to allocate enough room for both sense data and FCP response data 134 * which has a max length of 8 bytes according to spec. 135 */ 136 #define QEDF_SCSI_SENSE_BUFFERSIZE (SCSI_SENSE_BUFFERSIZE + 8) 137 uint8_t *sense_buffer; 138 dma_addr_t sense_buffer_dma; 139 u32 fcp_resid; 140 u32 fcp_rsp_len; 141 u32 fcp_sns_len; 142 u8 cdb_status; 143 u8 fcp_status; 144 u8 fcp_rsp_code; 145 u8 scsi_comp_flags; 146 #define QEDF_MAX_REUSE 0xfff 147 u16 reuse_count; 148 struct qedf_mp_req mp_req; 149 void (*cb_func)(struct qedf_els_cb_arg *cb_arg); 150 struct qedf_els_cb_arg *cb_arg; 151 int fp_idx; 152 unsigned int cpu; 153 unsigned int int_cpu; 154 #define QEDF_IOREQ_UNKNOWN_SGE 1 155 #define QEDF_IOREQ_SLOW_SGE 2 156 #define QEDF_IOREQ_FAST_SGE 3 157 u8 sge_type; 158 struct delayed_work rrq_work; 159 160 /* Used for sequence level recovery; i.e. REC/SRR */ 161 uint32_t rx_buf_off; 162 uint32_t tx_buf_off; 163 uint32_t rx_id; 164 uint32_t task_retry_identifier; 165 166 /* 167 * Used to tell if we need to return a SCSI command 168 * during some form of error processing. 169 */ 170 bool return_scsi_cmd_on_abts; 171 }; 172 173 extern struct workqueue_struct *qedf_io_wq; 174 175 struct qedf_rport { 176 spinlock_t rport_lock; 177 #define QEDF_RPORT_SESSION_READY 1 178 #define QEDF_RPORT_UPLOADING_CONNECTION 2 179 #define QEDF_RPORT_IN_RESET 3 180 unsigned long flags; 181 unsigned long retry_delay_timestamp; 182 struct fc_rport *rport; 183 struct fc_rport_priv *rdata; 184 struct qedf_ctx *qedf; 185 u32 handle; /* Handle from qed */ 186 u32 fw_cid; /* fw_cid from qed */ 187 void __iomem *p_doorbell; 188 /* Send queue management */ 189 atomic_t free_sqes; 190 atomic_t num_active_ios; 191 struct fcoe_wqe *sq; 192 dma_addr_t sq_dma; 193 u16 sq_prod_idx; 194 u16 fw_sq_prod_idx; 195 u16 sq_con_idx; 196 u32 sq_mem_size; 197 void *sq_pbl; 198 dma_addr_t sq_pbl_dma; 199 u32 sq_pbl_size; 200 u32 sid; 201 #define QEDF_RPORT_TYPE_DISK 0 202 #define QEDF_RPORT_TYPE_TAPE 1 203 uint dev_type; /* Disk or tape */ 204 struct list_head peers; 205 }; 206 207 /* Used to contain LL2 skb's in ll2_skb_list */ 208 struct qedf_skb_work { 209 struct work_struct work; 210 struct sk_buff *skb; 211 struct qedf_ctx *qedf; 212 }; 213 214 struct qedf_fastpath { 215 #define QEDF_SB_ID_NULL 0xffff 216 u16 sb_id; 217 struct qed_sb_info *sb_info; 218 struct qedf_ctx *qedf; 219 /* Keep track of number of completions on this fastpath */ 220 unsigned long completions; 221 uint32_t cq_num_entries; 222 }; 223 224 /* Used to pass fastpath information needed to process CQEs */ 225 struct qedf_io_work { 226 struct work_struct work; 227 struct fcoe_cqe cqe; 228 struct qedf_ctx *qedf; 229 struct fc_frame *fp; 230 }; 231 232 struct qedf_glbl_q_params { 233 u64 hw_p_cq; /* Completion queue PBL */ 234 u64 hw_p_rq; /* Request queue PBL */ 235 u64 hw_p_cmdq; /* Command queue PBL */ 236 }; 237 238 struct global_queue { 239 struct fcoe_cqe *cq; 240 dma_addr_t cq_dma; 241 u32 cq_mem_size; 242 u32 cq_cons_idx; /* Completion queue consumer index */ 243 u32 cq_prod_idx; 244 245 void *cq_pbl; 246 dma_addr_t cq_pbl_dma; 247 u32 cq_pbl_size; 248 }; 249 250 /* I/O tracing entry */ 251 #define QEDF_IO_TRACE_SIZE 2048 252 struct qedf_io_log { 253 #define QEDF_IO_TRACE_REQ 0 254 #define QEDF_IO_TRACE_RSP 1 255 uint8_t direction; 256 uint16_t task_id; 257 uint32_t port_id; /* Remote port fabric ID */ 258 int lun; 259 unsigned char op; /* SCSI CDB */ 260 uint8_t lba[4]; 261 unsigned int bufflen; /* SCSI buffer length */ 262 unsigned int sg_count; /* Number of SG elements */ 263 int result; /* Result passed back to mid-layer */ 264 unsigned long jiffies; /* Time stamp when I/O logged */ 265 int refcount; /* Reference count for task id */ 266 unsigned int req_cpu; /* CPU that the task is queued on */ 267 unsigned int int_cpu; /* Interrupt CPU that the task is received on */ 268 unsigned int rsp_cpu; /* CPU that task is returned on */ 269 u8 sge_type; /* Did we take the slow, single or fast SGE path */ 270 }; 271 272 /* Number of entries in BDQ */ 273 #define QEDF_BDQ_SIZE 256 274 #define QEDF_BDQ_BUF_SIZE 2072 275 276 /* DMA coherent buffers for BDQ */ 277 struct qedf_bdq_buf { 278 void *buf_addr; 279 dma_addr_t buf_dma; 280 }; 281 282 /* Main adapter struct */ 283 struct qedf_ctx { 284 struct qedf_dbg_ctx dbg_ctx; 285 struct fcoe_ctlr ctlr; 286 struct fc_lport *lport; 287 u8 data_src_addr[ETH_ALEN]; 288 #define QEDF_LINK_DOWN 0 289 #define QEDF_LINK_UP 1 290 atomic_t link_state; 291 #define QEDF_DCBX_PENDING 0 292 #define QEDF_DCBX_DONE 1 293 atomic_t dcbx; 294 #define QEDF_NULL_VLAN_ID -1 295 #define QEDF_FALLBACK_VLAN 1002 296 #define QEDF_DEFAULT_PRIO 3 297 int vlan_id; 298 u8 prio; 299 struct qed_dev *cdev; 300 struct qed_dev_fcoe_info dev_info; 301 struct qed_int_info int_info; 302 uint16_t last_command; 303 spinlock_t hba_lock; 304 struct pci_dev *pdev; 305 u64 wwnn; 306 u64 wwpn; 307 u8 __aligned(16) mac[ETH_ALEN]; 308 struct list_head fcports; 309 atomic_t num_offloads; 310 unsigned int curr_conn_id; 311 struct workqueue_struct *ll2_recv_wq; 312 struct workqueue_struct *link_update_wq; 313 struct delayed_work link_update; 314 struct delayed_work link_recovery; 315 struct completion flogi_compl; 316 struct completion fipvlan_compl; 317 318 /* 319 * Used to tell if we're in the window where we are waiting for 320 * the link to come back up before informting fcoe that the link is 321 * done. 322 */ 323 atomic_t link_down_tmo_valid; 324 #define QEDF_TIMER_INTERVAL (1 * HZ) 325 struct timer_list timer; /* One second book keeping timer */ 326 #define QEDF_DRAIN_ACTIVE 1 327 #define QEDF_LL2_STARTED 2 328 #define QEDF_UNLOADING 3 329 #define QEDF_GRCDUMP_CAPTURE 4 330 #define QEDF_IN_RECOVERY 5 331 #define QEDF_DBG_STOP_IO 6 332 unsigned long flags; /* Miscellaneous state flags */ 333 int fipvlan_retries; 334 u8 num_queues; 335 struct global_queue **global_queues; 336 /* Pointer to array of queue structures */ 337 struct qedf_glbl_q_params *p_cpuq; 338 /* Physical address of array of queue structures */ 339 dma_addr_t hw_p_cpuq; 340 341 struct qedf_bdq_buf bdq[QEDF_BDQ_SIZE]; 342 void *bdq_pbl; 343 dma_addr_t bdq_pbl_dma; 344 size_t bdq_pbl_mem_size; 345 void *bdq_pbl_list; 346 dma_addr_t bdq_pbl_list_dma; 347 u8 bdq_pbl_list_num_entries; 348 void __iomem *bdq_primary_prod; 349 void __iomem *bdq_secondary_prod; 350 uint16_t bdq_prod_idx; 351 352 /* Structure for holding all the fastpath for this qedf_ctx */ 353 struct qedf_fastpath *fp_array; 354 struct qed_fcoe_tid tasks; 355 struct qedf_cmd_mgr *cmd_mgr; 356 /* Holds the PF parameters we pass to qed to start he FCoE function */ 357 struct qed_pf_params pf_params; 358 /* Used to time middle path ELS and TM commands */ 359 struct workqueue_struct *timer_work_queue; 360 361 #define QEDF_IO_WORK_MIN 64 362 mempool_t *io_mempool; 363 struct workqueue_struct *dpc_wq; 364 struct delayed_work grcdump_work; 365 366 u32 slow_sge_ios; 367 u32 fast_sge_ios; 368 369 uint8_t *grcdump; 370 uint32_t grcdump_size; 371 372 struct qedf_io_log io_trace_buf[QEDF_IO_TRACE_SIZE]; 373 spinlock_t io_trace_lock; 374 uint16_t io_trace_idx; 375 376 bool stop_io_on_error; 377 378 u32 flogi_cnt; 379 u32 flogi_failed; 380 381 /* Used for fc statistics */ 382 struct mutex stats_mutex; 383 u64 input_requests; 384 u64 output_requests; 385 u64 control_requests; 386 u64 packet_aborts; 387 u64 alloc_failures; 388 u8 lun_resets; 389 u8 target_resets; 390 u8 task_set_fulls; 391 u8 busy; 392 }; 393 394 struct io_bdt { 395 struct qedf_ioreq *io_req; 396 struct scsi_sge *bd_tbl; 397 dma_addr_t bd_tbl_dma; 398 u16 bd_valid; 399 }; 400 401 struct qedf_cmd_mgr { 402 struct qedf_ctx *qedf; 403 u16 idx; 404 struct io_bdt **io_bdt_pool; 405 #define FCOE_PARAMS_NUM_TASKS 2048 406 struct qedf_ioreq cmds[FCOE_PARAMS_NUM_TASKS]; 407 spinlock_t lock; 408 atomic_t free_list_cnt; 409 }; 410 411 /* Stolen from qed_cxt_api.h and adapted for qed_fcoe_info 412 * Usage: 413 * 414 * void *ptr; 415 * ptr = qedf_get_task_mem(&qedf->tasks, 128); 416 */ 417 static inline void *qedf_get_task_mem(struct qed_fcoe_tid *info, u32 tid) 418 { 419 return (void *)(info->blocks[tid / info->num_tids_per_block] + 420 (tid % info->num_tids_per_block) * info->size); 421 } 422 423 static inline void qedf_stop_all_io(struct qedf_ctx *qedf) 424 { 425 set_bit(QEDF_DBG_STOP_IO, &qedf->flags); 426 } 427 428 /* 429 * Externs 430 */ 431 #define QEDF_DEFAULT_LOG_MASK 0x3CFB6 432 extern const struct qed_fcoe_ops *qed_ops; 433 extern uint qedf_dump_frames; 434 extern uint qedf_io_tracing; 435 extern uint qedf_stop_io_on_error; 436 extern uint qedf_link_down_tmo; 437 #define QEDF_RETRY_DELAY_MAX 20 /* 2 seconds */ 438 extern bool qedf_retry_delay; 439 extern uint qedf_debug; 440 441 extern struct qedf_cmd_mgr *qedf_cmd_mgr_alloc(struct qedf_ctx *qedf); 442 extern void qedf_cmd_mgr_free(struct qedf_cmd_mgr *cmgr); 443 extern int qedf_queuecommand(struct Scsi_Host *host, 444 struct scsi_cmnd *sc_cmd); 445 extern void qedf_fip_send(struct fcoe_ctlr *fip, struct sk_buff *skb); 446 extern u8 *qedf_get_src_mac(struct fc_lport *lport); 447 extern void qedf_fip_recv(struct qedf_ctx *qedf, struct sk_buff *skb); 448 extern void qedf_fcoe_send_vlan_req(struct qedf_ctx *qedf); 449 extern void qedf_scsi_completion(struct qedf_ctx *qedf, struct fcoe_cqe *cqe, 450 struct qedf_ioreq *io_req); 451 extern void qedf_process_warning_compl(struct qedf_ctx *qedf, 452 struct fcoe_cqe *cqe, struct qedf_ioreq *io_req); 453 extern void qedf_process_error_detect(struct qedf_ctx *qedf, 454 struct fcoe_cqe *cqe, struct qedf_ioreq *io_req); 455 extern void qedf_flush_active_ios(struct qedf_rport *fcport, int lun); 456 extern void qedf_release_cmd(struct kref *ref); 457 extern int qedf_initiate_abts(struct qedf_ioreq *io_req, 458 bool return_scsi_cmd_on_abts); 459 extern void qedf_process_abts_compl(struct qedf_ctx *qedf, struct fcoe_cqe *cqe, 460 struct qedf_ioreq *io_req); 461 extern struct qedf_ioreq *qedf_alloc_cmd(struct qedf_rport *fcport, 462 u8 cmd_type); 463 464 extern struct device_attribute *qedf_host_attrs[]; 465 extern void qedf_cmd_timer_set(struct qedf_ctx *qedf, struct qedf_ioreq *io_req, 466 unsigned int timer_msec); 467 extern int qedf_init_mp_req(struct qedf_ioreq *io_req); 468 extern void qedf_init_mp_task(struct qedf_ioreq *io_req, 469 struct e4_fcoe_task_context *task_ctx, struct fcoe_wqe *sqe); 470 extern u16 qedf_get_sqe_idx(struct qedf_rport *fcport); 471 extern void qedf_ring_doorbell(struct qedf_rport *fcport); 472 extern void qedf_process_els_compl(struct qedf_ctx *qedf, struct fcoe_cqe *cqe, 473 struct qedf_ioreq *els_req); 474 extern int qedf_send_rrq(struct qedf_ioreq *aborted_io_req); 475 extern int qedf_send_adisc(struct qedf_rport *fcport, struct fc_frame *fp); 476 extern int qedf_initiate_cleanup(struct qedf_ioreq *io_req, 477 bool return_scsi_cmd_on_abts); 478 extern void qedf_process_cleanup_compl(struct qedf_ctx *qedf, 479 struct fcoe_cqe *cqe, struct qedf_ioreq *io_req); 480 extern int qedf_initiate_tmf(struct scsi_cmnd *sc_cmd, u8 tm_flags); 481 extern void qedf_process_tmf_compl(struct qedf_ctx *qedf, struct fcoe_cqe *cqe, 482 struct qedf_ioreq *io_req); 483 extern void qedf_process_cqe(struct qedf_ctx *qedf, struct fcoe_cqe *cqe); 484 extern void qedf_scsi_done(struct qedf_ctx *qedf, struct qedf_ioreq *io_req, 485 int result); 486 extern void qedf_set_vlan_id(struct qedf_ctx *qedf, int vlan_id); 487 extern void qedf_create_sysfs_ctx_attr(struct qedf_ctx *qedf); 488 extern void qedf_remove_sysfs_ctx_attr(struct qedf_ctx *qedf); 489 extern void qedf_capture_grc_dump(struct qedf_ctx *qedf); 490 extern void qedf_wait_for_upload(struct qedf_ctx *qedf); 491 extern void qedf_process_unsol_compl(struct qedf_ctx *qedf, uint16_t que_idx, 492 struct fcoe_cqe *cqe); 493 extern void qedf_restart_rport(struct qedf_rport *fcport); 494 extern int qedf_send_rec(struct qedf_ioreq *orig_io_req); 495 extern int qedf_post_io_req(struct qedf_rport *fcport, 496 struct qedf_ioreq *io_req); 497 extern void qedf_process_seq_cleanup_compl(struct qedf_ctx *qedf, 498 struct fcoe_cqe *cqe, struct qedf_ioreq *io_req); 499 extern int qedf_send_flogi(struct qedf_ctx *qedf); 500 extern void qedf_get_protocol_tlv_data(void *dev, void *data); 501 extern void qedf_fp_io_handler(struct work_struct *work); 502 extern void qedf_get_generic_tlv_data(void *dev, struct qed_generic_tlvs *data); 503 extern void qedf_wq_grcdump(struct work_struct *work); 504 505 #define FCOE_WORD_TO_BYTE 4 506 #define QEDF_MAX_TASK_NUM 0xFFFF 507 508 struct fip_vlan { 509 struct ethhdr eth; 510 struct fip_header fip; 511 struct { 512 struct fip_mac_desc mac; 513 struct fip_wwn_desc wwnn; 514 } desc; 515 }; 516 517 /* SQ/CQ Sizes */ 518 #define GBL_RSVD_TASKS 16 519 #define NUM_TASKS_PER_CONNECTION 1024 520 #define NUM_RW_TASKS_PER_CONNECTION 512 521 #define FCOE_PARAMS_CQ_NUM_ENTRIES FCOE_PARAMS_NUM_TASKS 522 523 #define FCOE_PARAMS_CMDQ_NUM_ENTRIES FCOE_PARAMS_NUM_TASKS 524 #define SQ_NUM_ENTRIES NUM_TASKS_PER_CONNECTION 525 526 #define QEDF_FCOE_PARAMS_GL_RQ_PI 0 527 #define QEDF_FCOE_PARAMS_GL_CMD_PI 1 528 529 #define QEDF_READ (1 << 1) 530 #define QEDF_WRITE (1 << 0) 531 #define MAX_FIBRE_LUNS 0xffffffff 532 533 #define MIN_NUM_CPUS_MSIX(x) min_t(u32, x->dev_info.num_cqs, \ 534 num_online_cpus()) 535 536 /* 537 * PCI function probe defines 538 */ 539 /* Probe/remove called during normal PCI probe */ 540 #define QEDF_MODE_NORMAL 0 541 /* Probe/remove called from qed error recovery */ 542 #define QEDF_MODE_RECOVERY 1 543 544 #define SUPPORTED_25000baseKR_Full (1<<27) 545 #define SUPPORTED_50000baseKR2_Full (1<<28) 546 #define SUPPORTED_100000baseKR4_Full (1<<29) 547 #define SUPPORTED_100000baseCR4_Full (1<<30) 548 549 #endif 550