2 * QLogic FCoE Offload Driver
3 * Copyright (c) 2016-2018 Cavium Inc.
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
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>
21 /* qedf_hsi.h needs to before included any qed includes */
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"
29 #include "drv_fcoe_fw_funcs.h"
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))
35 #define QEDF_DESCR "QLogic FCoE Offload Driver"
36 #define QEDF_MODULE_NAME "qedf"
38 #define QEDF_MIN_XID 0
39 #define QEDF_MAX_SCSI_XID (NUM_TASKS_PER_CONNECTION - 1)
40 #define QEDF_MAX_ELS_XID 4095
41 #define QEDF_FLOGI_RETRY_CNT 3
42 #define QEDF_RPORT_RETRY_CNT 255
43 #define QEDF_MAX_SESSIONS 1024
44 #define QEDF_MAX_PAYLOAD 2048
45 #define QEDF_MAX_BDS_PER_CMD 256
46 #define QEDF_MAX_BD_LEN 0xffff
47 #define QEDF_BD_SPLIT_SZ 0x1000
48 #define QEDF_PAGE_SIZE 4096
49 #define QED_HW_DMA_BOUNDARY 0xfff
50 #define QEDF_MAX_SGLEN_FOR_CACHESGL ((1U << 16) - 1)
51 #define QEDF_MFS (QEDF_MAX_PAYLOAD + \
52 sizeof(struct fc_frame_header))
53 #define QEDF_MAX_NPIV 64
54 #define QEDF_TM_TIMEOUT 10
55 #define QEDF_ABORT_TIMEOUT 10
56 #define QEDF_CLEANUP_TIMEOUT 10
57 #define QEDF_MAX_CDB_LEN 16
59 #define UPSTREAM_REMOVE 1
60 #define UPSTREAM_KEEP 1
65 dma_addr_t req_buf_dma
;
66 struct scsi_sge
*mp_req_bd
;
67 dma_addr_t mp_req_bd_dma
;
68 struct fc_frame_header req_fc_hdr
;
72 dma_addr_t resp_buf_dma
;
73 struct scsi_sge
*mp_resp_bd
;
74 dma_addr_t mp_resp_bd_dma
;
75 struct fc_frame_header resp_fc_hdr
;
78 struct qedf_els_cb_arg
{
79 struct qedf_ioreq
*aborted_io_req
;
80 struct qedf_ioreq
*io_req
;
81 u8 op
; /* Used to keep track of ELS op */
83 u32 offset
; /* Used for sequence cleanup */
84 u8 r_ctl
; /* Used for sequence cleanup */
87 enum qedf_ioreq_event
{
88 QEDF_IOREQ_EV_ABORT_SUCCESS
,
89 QEDF_IOREQ_EV_ABORT_FAILED
,
90 QEDF_IOREQ_EV_SEND_RRQ
,
91 QEDF_IOREQ_EV_ELS_TMO
,
92 QEDF_IOREQ_EV_ELS_ERR_DETECT
,
93 QEDF_IOREQ_EV_ELS_FLUSH
,
94 QEDF_IOREQ_EV_CLEANUP_SUCCESS
,
95 QEDF_IOREQ_EV_CLEANUP_FAILED
,
99 #define FCOE_FCP_RSP_FLAGS_FCP_RESID_OVER (0x1<<2)
100 #define FCOE_FCP_RSP_FLAGS_FCP_RESID_UNDER (0x1<<3)
101 #define CMD_SCSI_STATUS(Cmnd) ((Cmnd)->SCp.Status)
102 #define FCOE_FCP_RSP_FLAGS_FCP_RSP_LEN_VALID (0x1<<0)
103 #define FCOE_FCP_RSP_FLAGS_FCP_SNS_LEN_VALID (0x1<<1)
105 struct list_head link
;
107 struct scsi_cmnd
*sc_cmd
;
108 bool use_slowpath
; /* Use slow SGL for this I/O */
109 #define QEDF_SCSI_CMD 1
110 #define QEDF_TASK_MGMT_CMD 2
113 #define QEDF_CLEANUP 5
114 #define QEDF_SEQ_CLEANUP 6
116 #define QEDF_CMD_OUTSTANDING 0x0
117 #define QEDF_CMD_IN_ABORT 0x1
118 #define QEDF_CMD_IN_CLEANUP 0x2
119 #define QEDF_CMD_SRR_SENT 0x3
122 struct qedf_rport
*fcport
;
124 enum qedf_ioreq_event event
;
125 size_t data_xfer_len
;
126 struct kref refcount
;
127 struct qedf_cmd_mgr
*cmd_mgr
;
128 struct io_bdt
*bd_tbl
;
129 struct delayed_work timeout_work
;
130 struct completion tm_done
;
131 struct completion abts_done
;
132 struct e4_fcoe_task_context
*task
;
133 struct fcoe_task_params
*task_params
;
134 struct scsi_sgl_task_params
*sgl_task_params
;
137 * Need to allocate enough room for both sense data and FCP response data
138 * which has a max length of 8 bytes according to spec.
140 #define QEDF_SCSI_SENSE_BUFFERSIZE (SCSI_SENSE_BUFFERSIZE + 8)
141 uint8_t *sense_buffer
;
142 dma_addr_t sense_buffer_dma
;
150 #define QEDF_MAX_REUSE 0xfff
152 struct qedf_mp_req mp_req
;
153 void (*cb_func
)(struct qedf_els_cb_arg
*cb_arg
);
154 struct qedf_els_cb_arg
*cb_arg
;
157 unsigned int int_cpu
;
158 #define QEDF_IOREQ_SLOW_SGE 0
159 #define QEDF_IOREQ_SINGLE_SGE 1
160 #define QEDF_IOREQ_FAST_SGE 2
162 struct delayed_work rrq_work
;
164 /* Used for sequence level recovery; i.e. REC/SRR */
168 uint32_t task_retry_identifier
;
171 * Used to tell if we need to return a SCSI command
172 * during some form of error processing.
174 bool return_scsi_cmd_on_abts
;
177 extern struct workqueue_struct
*qedf_io_wq
;
180 spinlock_t rport_lock
;
181 #define QEDF_RPORT_SESSION_READY 1
182 #define QEDF_RPORT_UPLOADING_CONNECTION 2
183 #define QEDF_RPORT_IN_RESET 3
185 unsigned long retry_delay_timestamp
;
186 struct fc_rport
*rport
;
187 struct fc_rport_priv
*rdata
;
188 struct qedf_ctx
*qedf
;
189 u32 handle
; /* Handle from qed */
190 u32 fw_cid
; /* fw_cid from qed */
191 void __iomem
*p_doorbell
;
192 /* Send queue management */
194 atomic_t num_active_ios
;
202 dma_addr_t sq_pbl_dma
;
205 #define QEDF_RPORT_TYPE_DISK 0
206 #define QEDF_RPORT_TYPE_TAPE 1
207 uint dev_type
; /* Disk or tape */
208 struct list_head peers
;
211 /* Used to contain LL2 skb's in ll2_skb_list */
212 struct qedf_skb_work
{
213 struct work_struct work
;
215 struct qedf_ctx
*qedf
;
218 struct qedf_fastpath
{
219 #define QEDF_SB_ID_NULL 0xffff
221 struct qed_sb_info
*sb_info
;
222 struct qedf_ctx
*qedf
;
223 /* Keep track of number of completions on this fastpath */
224 unsigned long completions
;
225 uint32_t cq_num_entries
;
228 /* Used to pass fastpath information needed to process CQEs */
229 struct qedf_io_work
{
230 struct work_struct work
;
232 struct qedf_ctx
*qedf
;
236 struct qedf_glbl_q_params
{
237 u64 hw_p_cq
; /* Completion queue PBL */
238 u64 hw_p_rq
; /* Request queue PBL */
239 u64 hw_p_cmdq
; /* Command queue PBL */
242 struct global_queue
{
246 u32 cq_cons_idx
; /* Completion queue consumer index */
250 dma_addr_t cq_pbl_dma
;
254 /* I/O tracing entry */
255 #define QEDF_IO_TRACE_SIZE 2048
257 #define QEDF_IO_TRACE_REQ 0
258 #define QEDF_IO_TRACE_RSP 1
261 uint32_t port_id
; /* Remote port fabric ID */
263 unsigned char op
; /* SCSI CDB */
265 unsigned int bufflen
; /* SCSI buffer length */
266 unsigned int sg_count
; /* Number of SG elements */
267 int result
; /* Result passed back to mid-layer */
268 unsigned long jiffies
; /* Time stamp when I/O logged */
269 int refcount
; /* Reference count for task id */
270 unsigned int req_cpu
; /* CPU that the task is queued on */
271 unsigned int int_cpu
; /* Interrupt CPU that the task is received on */
272 unsigned int rsp_cpu
; /* CPU that task is returned on */
273 u8 sge_type
; /* Did we take the slow, single or fast SGE path */
276 /* Number of entries in BDQ */
277 #define QEDF_BDQ_SIZE 256
278 #define QEDF_BDQ_BUF_SIZE 2072
280 /* DMA coherent buffers for BDQ */
281 struct qedf_bdq_buf
{
286 /* Main adapter struct */
288 struct qedf_dbg_ctx dbg_ctx
;
289 struct fcoe_ctlr ctlr
;
290 struct fc_lport
*lport
;
291 u8 data_src_addr
[ETH_ALEN
];
292 #define QEDF_LINK_DOWN 0
293 #define QEDF_LINK_UP 1
295 #define QEDF_DCBX_PENDING 0
296 #define QEDF_DCBX_DONE 1
298 uint16_t max_scsi_xid
;
299 uint16_t max_els_xid
;
300 #define QEDF_NULL_VLAN_ID -1
301 #define QEDF_FALLBACK_VLAN 1002
302 #define QEDF_DEFAULT_PRIO 3
305 struct qed_dev
*cdev
;
306 struct qed_dev_fcoe_info dev_info
;
307 struct qed_int_info int_info
;
308 uint16_t last_command
;
310 struct pci_dev
*pdev
;
313 u8
__aligned(16) mac
[ETH_ALEN
];
314 struct list_head fcports
;
315 atomic_t num_offloads
;
316 unsigned int curr_conn_id
;
317 struct workqueue_struct
*ll2_recv_wq
;
318 struct workqueue_struct
*link_update_wq
;
319 struct delayed_work link_update
;
320 struct delayed_work link_recovery
;
321 struct completion flogi_compl
;
322 struct completion fipvlan_compl
;
325 * Used to tell if we're in the window where we are waiting for
326 * the link to come back up before informting fcoe that the link is
329 atomic_t link_down_tmo_valid
;
330 #define QEDF_TIMER_INTERVAL (1 * HZ)
331 struct timer_list timer
; /* One second book keeping timer */
332 #define QEDF_DRAIN_ACTIVE 1
333 #define QEDF_LL2_STARTED 2
334 #define QEDF_UNLOADING 3
335 #define QEDF_GRCDUMP_CAPTURE 4
336 #define QEDF_IN_RECOVERY 5
337 #define QEDF_DBG_STOP_IO 6
338 #define QEDF_PROBING 8
339 unsigned long flags
; /* Miscellaneous state flags */
342 struct global_queue
**global_queues
;
343 /* Pointer to array of queue structures */
344 struct qedf_glbl_q_params
*p_cpuq
;
345 /* Physical address of array of queue structures */
346 dma_addr_t hw_p_cpuq
;
348 struct qedf_bdq_buf bdq
[QEDF_BDQ_SIZE
];
350 dma_addr_t bdq_pbl_dma
;
351 size_t bdq_pbl_mem_size
;
353 dma_addr_t bdq_pbl_list_dma
;
354 u8 bdq_pbl_list_num_entries
;
355 void __iomem
*bdq_primary_prod
;
356 void __iomem
*bdq_secondary_prod
;
357 uint16_t bdq_prod_idx
;
359 /* Structure for holding all the fastpath for this qedf_ctx */
360 struct qedf_fastpath
*fp_array
;
361 struct qed_fcoe_tid tasks
;
362 struct qedf_cmd_mgr
*cmd_mgr
;
363 /* Holds the PF parameters we pass to qed to start he FCoE function */
364 struct qed_pf_params pf_params
;
365 /* Used to time middle path ELS and TM commands */
366 struct workqueue_struct
*timer_work_queue
;
368 #define QEDF_IO_WORK_MIN 64
369 mempool_t
*io_mempool
;
370 struct workqueue_struct
*dpc_wq
;
371 struct delayed_work grcdump_work
;
378 uint32_t grcdump_size
;
380 struct qedf_io_log io_trace_buf
[QEDF_IO_TRACE_SIZE
];
381 spinlock_t io_trace_lock
;
382 uint16_t io_trace_idx
;
384 bool stop_io_on_error
;
389 /* Used for fc statistics */
390 struct mutex stats_mutex
;
393 u64 control_requests
;
403 struct qedf_ioreq
*io_req
;
404 struct scsi_sge
*bd_tbl
;
405 dma_addr_t bd_tbl_dma
;
409 struct qedf_cmd_mgr
{
410 struct qedf_ctx
*qedf
;
412 struct io_bdt
**io_bdt_pool
;
413 #define FCOE_PARAMS_NUM_TASKS 2048
414 struct qedf_ioreq cmds
[FCOE_PARAMS_NUM_TASKS
];
416 atomic_t free_list_cnt
;
419 /* Stolen from qed_cxt_api.h and adapted for qed_fcoe_info
423 * ptr = qedf_get_task_mem(&qedf->tasks, 128);
425 static inline void *qedf_get_task_mem(struct qed_fcoe_tid
*info
, u32 tid
)
427 return (void *)(info
->blocks
[tid
/ info
->num_tids_per_block
] +
428 (tid
% info
->num_tids_per_block
) * info
->size
);
431 static inline void qedf_stop_all_io(struct qedf_ctx
*qedf
)
433 set_bit(QEDF_DBG_STOP_IO
, &qedf
->flags
);
439 #define QEDF_DEFAULT_LOG_MASK 0x3CFB6
440 extern const struct qed_fcoe_ops
*qed_ops
;
441 extern uint qedf_dump_frames
;
442 extern uint qedf_io_tracing
;
443 extern uint qedf_stop_io_on_error
;
444 extern uint qedf_link_down_tmo
;
445 #define QEDF_RETRY_DELAY_MAX 20 /* 2 seconds */
446 extern bool qedf_retry_delay
;
447 extern uint qedf_debug
;
449 extern struct qedf_cmd_mgr
*qedf_cmd_mgr_alloc(struct qedf_ctx
*qedf
);
450 extern void qedf_cmd_mgr_free(struct qedf_cmd_mgr
*cmgr
);
451 extern int qedf_queuecommand(struct Scsi_Host
*host
,
452 struct scsi_cmnd
*sc_cmd
);
453 extern void qedf_fip_send(struct fcoe_ctlr
*fip
, struct sk_buff
*skb
);
454 extern u8
*qedf_get_src_mac(struct fc_lport
*lport
);
455 extern void qedf_fip_recv(struct qedf_ctx
*qedf
, struct sk_buff
*skb
);
456 extern void qedf_fcoe_send_vlan_req(struct qedf_ctx
*qedf
);
457 extern void qedf_scsi_completion(struct qedf_ctx
*qedf
, struct fcoe_cqe
*cqe
,
458 struct qedf_ioreq
*io_req
);
459 extern void qedf_process_warning_compl(struct qedf_ctx
*qedf
,
460 struct fcoe_cqe
*cqe
, struct qedf_ioreq
*io_req
);
461 extern void qedf_process_error_detect(struct qedf_ctx
*qedf
,
462 struct fcoe_cqe
*cqe
, struct qedf_ioreq
*io_req
);
463 extern void qedf_flush_active_ios(struct qedf_rport
*fcport
, int lun
);
464 extern void qedf_release_cmd(struct kref
*ref
);
465 extern int qedf_initiate_abts(struct qedf_ioreq
*io_req
,
466 bool return_scsi_cmd_on_abts
);
467 extern void qedf_process_abts_compl(struct qedf_ctx
*qedf
, struct fcoe_cqe
*cqe
,
468 struct qedf_ioreq
*io_req
);
469 extern struct qedf_ioreq
*qedf_alloc_cmd(struct qedf_rport
*fcport
,
472 extern struct device_attribute
*qedf_host_attrs
[];
473 extern void qedf_cmd_timer_set(struct qedf_ctx
*qedf
, struct qedf_ioreq
*io_req
,
474 unsigned int timer_msec
);
475 extern int qedf_init_mp_req(struct qedf_ioreq
*io_req
);
476 extern void qedf_init_mp_task(struct qedf_ioreq
*io_req
,
477 struct e4_fcoe_task_context
*task_ctx
, struct fcoe_wqe
*sqe
);
478 extern u16
qedf_get_sqe_idx(struct qedf_rport
*fcport
);
479 extern void qedf_ring_doorbell(struct qedf_rport
*fcport
);
480 extern void qedf_process_els_compl(struct qedf_ctx
*qedf
, struct fcoe_cqe
*cqe
,
481 struct qedf_ioreq
*els_req
);
482 extern int qedf_send_rrq(struct qedf_ioreq
*aborted_io_req
);
483 extern int qedf_send_adisc(struct qedf_rport
*fcport
, struct fc_frame
*fp
);
484 extern int qedf_initiate_cleanup(struct qedf_ioreq
*io_req
,
485 bool return_scsi_cmd_on_abts
);
486 extern void qedf_process_cleanup_compl(struct qedf_ctx
*qedf
,
487 struct fcoe_cqe
*cqe
, struct qedf_ioreq
*io_req
);
488 extern int qedf_initiate_tmf(struct scsi_cmnd
*sc_cmd
, u8 tm_flags
);
489 extern void qedf_process_tmf_compl(struct qedf_ctx
*qedf
, struct fcoe_cqe
*cqe
,
490 struct qedf_ioreq
*io_req
);
491 extern void qedf_process_cqe(struct qedf_ctx
*qedf
, struct fcoe_cqe
*cqe
);
492 extern void qedf_scsi_done(struct qedf_ctx
*qedf
, struct qedf_ioreq
*io_req
,
494 extern void qedf_set_vlan_id(struct qedf_ctx
*qedf
, int vlan_id
);
495 extern void qedf_create_sysfs_ctx_attr(struct qedf_ctx
*qedf
);
496 extern void qedf_remove_sysfs_ctx_attr(struct qedf_ctx
*qedf
);
497 extern void qedf_capture_grc_dump(struct qedf_ctx
*qedf
);
498 extern void qedf_wait_for_upload(struct qedf_ctx
*qedf
);
499 extern void qedf_process_unsol_compl(struct qedf_ctx
*qedf
, uint16_t que_idx
,
500 struct fcoe_cqe
*cqe
);
501 extern void qedf_restart_rport(struct qedf_rport
*fcport
);
502 extern int qedf_send_rec(struct qedf_ioreq
*orig_io_req
);
503 extern int qedf_post_io_req(struct qedf_rport
*fcport
,
504 struct qedf_ioreq
*io_req
);
505 extern void qedf_process_seq_cleanup_compl(struct qedf_ctx
*qedf
,
506 struct fcoe_cqe
*cqe
, struct qedf_ioreq
*io_req
);
507 extern int qedf_send_flogi(struct qedf_ctx
*qedf
);
508 extern void qedf_get_protocol_tlv_data(void *dev
, void *data
);
509 extern void qedf_fp_io_handler(struct work_struct
*work
);
510 extern void qedf_get_generic_tlv_data(void *dev
, struct qed_generic_tlvs
*data
);
511 extern void qedf_wq_grcdump(struct work_struct
*work
);
513 #define FCOE_WORD_TO_BYTE 4
514 #define QEDF_MAX_TASK_NUM 0xFFFF
518 struct fip_header fip
;
520 struct fip_mac_desc mac
;
521 struct fip_wwn_desc wwnn
;
526 #define GBL_RSVD_TASKS 16
527 #define NUM_TASKS_PER_CONNECTION 1024
528 #define NUM_RW_TASKS_PER_CONNECTION 512
529 #define FCOE_PARAMS_CQ_NUM_ENTRIES FCOE_PARAMS_NUM_TASKS
531 #define FCOE_PARAMS_CMDQ_NUM_ENTRIES FCOE_PARAMS_NUM_TASKS
532 #define SQ_NUM_ENTRIES NUM_TASKS_PER_CONNECTION
534 #define QEDF_FCOE_PARAMS_GL_RQ_PI 0
535 #define QEDF_FCOE_PARAMS_GL_CMD_PI 1
537 #define QEDF_READ (1 << 1)
538 #define QEDF_WRITE (1 << 0)
539 #define MAX_FIBRE_LUNS 0xffffffff
541 #define MIN_NUM_CPUS_MSIX(x) min_t(u32, x->dev_info.num_cqs, \
545 * PCI function probe defines
547 /* Probe/remove called during normal PCI probe */
548 #define QEDF_MODE_NORMAL 0
549 /* Probe/remove called from qed error recovery */
550 #define QEDF_MODE_RECOVERY 1
552 #define SUPPORTED_25000baseKR_Full (1<<27)
553 #define SUPPORTED_50000baseKR2_Full (1<<28)
554 #define SUPPORTED_100000baseKR4_Full (1<<29)
555 #define SUPPORTED_100000baseCR4_Full (1<<30)