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