scsi: lpfc: Fix setting affinity hints to correlate with hardware queues
[linux-2.6-microblaze.git] / drivers / scsi / lpfc / lpfc_sli4.h
1 /*******************************************************************
2  * This file is part of the Emulex Linux Device Driver for         *
3  * Fibre Channel Host Bus Adapters.                                *
4  * Copyright (C) 2017-2018 Broadcom. All Rights Reserved. The term *
5  * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.     *
6  * Copyright (C) 2009-2016 Emulex.  All rights reserved.           *
7  * EMULEX and SLI are trademarks of Emulex.                        *
8  * www.broadcom.com                                                *
9  *                                                                 *
10  * This program is free software; you can redistribute it and/or   *
11  * modify it under the terms of version 2 of the GNU General       *
12  * Public License as published by the Free Software Foundation.    *
13  * This program is distributed in the hope that it will be useful. *
14  * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND          *
15  * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,  *
16  * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE      *
17  * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
18  * TO BE LEGALLY INVALID.  See the GNU General Public License for  *
19  * more details, a copy of which can be found in the file COPYING  *
20  * included with this package.                                     *
21  *******************************************************************/
22
23 #if defined(CONFIG_DEBUG_FS) && !defined(CONFIG_SCSI_LPFC_DEBUG_FS)
24 #define CONFIG_SCSI_LPFC_DEBUG_FS
25 #endif
26
27 #define LPFC_ACTIVE_MBOX_WAIT_CNT               100
28 #define LPFC_XRI_EXCH_BUSY_WAIT_TMO             10000
29 #define LPFC_XRI_EXCH_BUSY_WAIT_T1              10
30 #define LPFC_XRI_EXCH_BUSY_WAIT_T2              30000
31 #define LPFC_RPI_LOW_WATER_MARK                 10
32
33 #define LPFC_UNREG_FCF                          1
34 #define LPFC_SKIP_UNREG_FCF                     0
35
36 /* Amount of time in seconds for waiting FCF rediscovery to complete */
37 #define LPFC_FCF_REDISCOVER_WAIT_TMO            2000 /* msec */
38
39 /* Number of SGL entries can be posted in a 4KB nonembedded mbox command */
40 #define LPFC_NEMBED_MBOX_SGL_CNT                254
41
42 /* Multi-queue arrangement for FCP EQ/CQ/WQ tuples */
43 #define LPFC_HBA_HDWQ_MIN       0
44 #define LPFC_HBA_HDWQ_MAX       64
45 #define LPFC_HBA_HDWQ_DEF       0
46
47 /* Common buffer size to accomidate SCSI and NVME IO buffers */
48 #define LPFC_COMMON_IO_BUF_SZ   768
49
50 /*
51  * Provide the default FCF Record attributes used by the driver
52  * when nonFIP mode is configured and there is no other default
53  * FCF Record attributes.
54  */
55 #define LPFC_FCOE_FCF_DEF_INDEX 0
56 #define LPFC_FCOE_FCF_GET_FIRST 0xFFFF
57 #define LPFC_FCOE_FCF_NEXT_NONE 0xFFFF
58
59 #define LPFC_FCOE_NULL_VID      0xFFF
60 #define LPFC_FCOE_IGNORE_VID    0xFFFF
61
62 /* First 3 bytes of default FCF MAC is specified by FC_MAP */
63 #define LPFC_FCOE_FCF_MAC3      0xFF
64 #define LPFC_FCOE_FCF_MAC4      0xFF
65 #define LPFC_FCOE_FCF_MAC5      0xFE
66 #define LPFC_FCOE_FCF_MAP0      0x0E
67 #define LPFC_FCOE_FCF_MAP1      0xFC
68 #define LPFC_FCOE_FCF_MAP2      0x00
69 #define LPFC_FCOE_MAX_RCV_SIZE  0x800
70 #define LPFC_FCOE_FKA_ADV_PER   0
71 #define LPFC_FCOE_FIP_PRIORITY  0x80
72
73 #define sli4_sid_from_fc_hdr(fc_hdr)  \
74         ((fc_hdr)->fh_s_id[0] << 16 | \
75          (fc_hdr)->fh_s_id[1] <<  8 | \
76          (fc_hdr)->fh_s_id[2])
77
78 #define sli4_did_from_fc_hdr(fc_hdr)  \
79         ((fc_hdr)->fh_d_id[0] << 16 | \
80          (fc_hdr)->fh_d_id[1] <<  8 | \
81          (fc_hdr)->fh_d_id[2])
82
83 #define sli4_fctl_from_fc_hdr(fc_hdr)  \
84         ((fc_hdr)->fh_f_ctl[0] << 16 | \
85          (fc_hdr)->fh_f_ctl[1] <<  8 | \
86          (fc_hdr)->fh_f_ctl[2])
87
88 #define sli4_type_from_fc_hdr(fc_hdr)  \
89         ((fc_hdr)->fh_type)
90
91 #define LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT 12000
92
93 #define INT_FW_UPGRADE  0
94 #define RUN_FW_UPGRADE  1
95
96 enum lpfc_sli4_queue_type {
97         LPFC_EQ,
98         LPFC_GCQ,
99         LPFC_MCQ,
100         LPFC_WCQ,
101         LPFC_RCQ,
102         LPFC_MQ,
103         LPFC_WQ,
104         LPFC_HRQ,
105         LPFC_DRQ
106 };
107
108 /* The queue sub-type defines the functional purpose of the queue */
109 enum lpfc_sli4_queue_subtype {
110         LPFC_NONE,
111         LPFC_MBOX,
112         LPFC_FCP,
113         LPFC_ELS,
114         LPFC_NVME,
115         LPFC_NVMET,
116         LPFC_NVME_LS,
117         LPFC_USOL
118 };
119
120 union sli4_qe {
121         void *address;
122         struct lpfc_eqe *eqe;
123         struct lpfc_cqe *cqe;
124         struct lpfc_mcqe *mcqe;
125         struct lpfc_wcqe_complete *wcqe_complete;
126         struct lpfc_wcqe_release *wcqe_release;
127         struct sli4_wcqe_xri_aborted *wcqe_xri_aborted;
128         struct lpfc_rcqe_complete *rcqe_complete;
129         struct lpfc_mqe *mqe;
130         union  lpfc_wqe *wqe;
131         union  lpfc_wqe128 *wqe128;
132         struct lpfc_rqe *rqe;
133 };
134
135 /* RQ buffer list */
136 struct lpfc_rqb {
137         uint16_t entry_count;     /* Current number of RQ slots */
138         uint16_t buffer_count;    /* Current number of buffers posted */
139         struct list_head rqb_buffer_list;  /* buffers assigned to this HBQ */
140                                   /* Callback for HBQ buffer allocation */
141         struct rqb_dmabuf *(*rqb_alloc_buffer)(struct lpfc_hba *);
142                                   /* Callback for HBQ buffer free */
143         void               (*rqb_free_buffer)(struct lpfc_hba *,
144                                                struct rqb_dmabuf *);
145 };
146
147 struct lpfc_queue {
148         struct list_head list;
149         struct list_head wq_list;
150         struct list_head wqfull_list;
151         enum lpfc_sli4_queue_type type;
152         enum lpfc_sli4_queue_subtype subtype;
153         struct lpfc_hba *phba;
154         struct list_head child_list;
155         struct list_head page_list;
156         struct list_head sgl_list;
157         uint32_t entry_count;   /* Number of entries to support on the queue */
158         uint32_t entry_size;    /* Size of each queue entry. */
159         uint32_t entry_repost;  /* Count of entries before doorbell is rung */
160 #define LPFC_EQ_REPOST          8
161 #define LPFC_MQ_REPOST          8
162 #define LPFC_CQ_REPOST          64
163 #define LPFC_RQ_REPOST          64
164 #define LPFC_RELEASE_NOTIFICATION_INTERVAL      32  /* For WQs */
165         uint32_t queue_id;      /* Queue ID assigned by the hardware */
166         uint32_t assoc_qid;     /* Queue ID associated with, for CQ/WQ/MQ */
167         uint32_t host_index;    /* The host's index for putting or getting */
168         uint32_t hba_index;     /* The last known hba index for get or put */
169
170         struct lpfc_sli_ring *pring; /* ptr to io ring associated with q */
171         struct lpfc_rqb *rqbp;  /* ptr to RQ buffers */
172
173         uint32_t q_mode;
174         uint16_t page_count;    /* Number of pages allocated for this queue */
175         uint16_t page_size;     /* size of page allocated for this queue */
176 #define LPFC_EXPANDED_PAGE_SIZE 16384
177 #define LPFC_DEFAULT_PAGE_SIZE  4096
178         uint16_t chann;         /* IO channel this queue is associated with */
179         uint8_t db_format;
180 #define LPFC_DB_RING_FORMAT     0x01
181 #define LPFC_DB_LIST_FORMAT     0x02
182         uint8_t q_flag;
183 #define HBA_NVMET_WQFULL        0x1 /* We hit WQ Full condition for NVMET */
184         void __iomem *db_regaddr;
185         uint16_t dpp_enable;
186         uint16_t dpp_id;
187         void __iomem *dpp_regaddr;
188
189         /* For q stats */
190         uint32_t q_cnt_1;
191         uint32_t q_cnt_2;
192         uint32_t q_cnt_3;
193         uint64_t q_cnt_4;
194 /* defines for EQ stats */
195 #define EQ_max_eqe              q_cnt_1
196 #define EQ_no_entry             q_cnt_2
197 #define EQ_cqe_cnt              q_cnt_3
198 #define EQ_processed            q_cnt_4
199
200 /* defines for CQ stats */
201 #define CQ_mbox                 q_cnt_1
202 #define CQ_max_cqe              q_cnt_1
203 #define CQ_release_wqe          q_cnt_2
204 #define CQ_xri_aborted          q_cnt_3
205 #define CQ_wq                   q_cnt_4
206
207 /* defines for WQ stats */
208 #define WQ_overflow             q_cnt_1
209 #define WQ_posted               q_cnt_4
210
211 /* defines for RQ stats */
212 #define RQ_no_posted_buf        q_cnt_1
213 #define RQ_no_buf_found         q_cnt_2
214 #define RQ_buf_posted           q_cnt_3
215 #define RQ_rcv_buf              q_cnt_4
216
217         struct work_struct irqwork;
218         struct work_struct spwork;
219
220         uint64_t isr_timestamp;
221         uint16_t hdwq;
222         uint8_t qe_valid;
223         struct lpfc_queue *assoc_qp;
224         union sli4_qe qe[1];    /* array to index entries (must be last) */
225 };
226
227 struct lpfc_sli4_link {
228         uint16_t speed;
229         uint8_t duplex;
230         uint8_t status;
231         uint8_t type;
232         uint8_t number;
233         uint8_t fault;
234         uint16_t logical_speed;
235         uint16_t topology;
236 };
237
238 struct lpfc_fcf_rec {
239         uint8_t  fabric_name[8];
240         uint8_t  switch_name[8];
241         uint8_t  mac_addr[6];
242         uint16_t fcf_indx;
243         uint32_t priority;
244         uint16_t vlan_id;
245         uint32_t addr_mode;
246         uint32_t flag;
247 #define BOOT_ENABLE     0x01
248 #define RECORD_VALID    0x02
249 };
250
251 struct lpfc_fcf_pri_rec {
252         uint16_t fcf_index;
253 #define LPFC_FCF_ON_PRI_LIST 0x0001
254 #define LPFC_FCF_FLOGI_FAILED 0x0002
255         uint16_t flag;
256         uint32_t priority;
257 };
258
259 struct lpfc_fcf_pri {
260         struct list_head list;
261         struct lpfc_fcf_pri_rec fcf_rec;
262 };
263
264 /*
265  * Maximum FCF table index, it is for driver internal book keeping, it
266  * just needs to be no less than the supported HBA's FCF table size.
267  */
268 #define LPFC_SLI4_FCF_TBL_INDX_MAX      32
269
270 struct lpfc_fcf {
271         uint16_t fcfi;
272         uint32_t fcf_flag;
273 #define FCF_AVAILABLE   0x01 /* FCF available for discovery */
274 #define FCF_REGISTERED  0x02 /* FCF registered with FW */
275 #define FCF_SCAN_DONE   0x04 /* FCF table scan done */
276 #define FCF_IN_USE      0x08 /* Atleast one discovery completed */
277 #define FCF_INIT_DISC   0x10 /* Initial FCF discovery */
278 #define FCF_DEAD_DISC   0x20 /* FCF DEAD fast FCF failover discovery */
279 #define FCF_ACVL_DISC   0x40 /* All CVL fast FCF failover discovery */
280 #define FCF_DISCOVERY   (FCF_INIT_DISC | FCF_DEAD_DISC | FCF_ACVL_DISC)
281 #define FCF_REDISC_PEND 0x80 /* FCF rediscovery pending */
282 #define FCF_REDISC_EVT  0x100 /* FCF rediscovery event to worker thread */
283 #define FCF_REDISC_FOV  0x200 /* Post FCF rediscovery fast failover */
284 #define FCF_REDISC_PROG (FCF_REDISC_PEND | FCF_REDISC_EVT)
285         uint16_t fcf_redisc_attempted;
286         uint32_t addr_mode;
287         uint32_t eligible_fcf_cnt;
288         struct lpfc_fcf_rec current_rec;
289         struct lpfc_fcf_rec failover_rec;
290         struct list_head fcf_pri_list;
291         struct lpfc_fcf_pri fcf_pri[LPFC_SLI4_FCF_TBL_INDX_MAX];
292         uint32_t current_fcf_scan_pri;
293         struct timer_list redisc_wait;
294         unsigned long *fcf_rr_bmask; /* Eligible FCF indexes for RR failover */
295 };
296
297
298 #define LPFC_REGION23_SIGNATURE "RG23"
299 #define LPFC_REGION23_VERSION   1
300 #define LPFC_REGION23_LAST_REC  0xff
301 #define DRIVER_SPECIFIC_TYPE    0xA2
302 #define LINUX_DRIVER_ID         0x20
303 #define PORT_STE_TYPE           0x1
304
305 struct lpfc_fip_param_hdr {
306         uint8_t type;
307 #define FCOE_PARAM_TYPE         0xA0
308         uint8_t length;
309 #define FCOE_PARAM_LENGTH       2
310         uint8_t parm_version;
311 #define FIPP_VERSION            0x01
312         uint8_t parm_flags;
313 #define lpfc_fip_param_hdr_fipp_mode_SHIFT      6
314 #define lpfc_fip_param_hdr_fipp_mode_MASK       0x3
315 #define lpfc_fip_param_hdr_fipp_mode_WORD       parm_flags
316 #define FIPP_MODE_ON                            0x1
317 #define FIPP_MODE_OFF                           0x0
318 #define FIPP_VLAN_VALID                         0x1
319 };
320
321 struct lpfc_fcoe_params {
322         uint8_t fc_map[3];
323         uint8_t reserved1;
324         uint16_t vlan_tag;
325         uint8_t reserved[2];
326 };
327
328 struct lpfc_fcf_conn_hdr {
329         uint8_t type;
330 #define FCOE_CONN_TBL_TYPE              0xA1
331         uint8_t length;   /* words */
332         uint8_t reserved[2];
333 };
334
335 struct lpfc_fcf_conn_rec {
336         uint16_t flags;
337 #define FCFCNCT_VALID           0x0001
338 #define FCFCNCT_BOOT            0x0002
339 #define FCFCNCT_PRIMARY         0x0004   /* if not set, Secondary */
340 #define FCFCNCT_FBNM_VALID      0x0008
341 #define FCFCNCT_SWNM_VALID      0x0010
342 #define FCFCNCT_VLAN_VALID      0x0020
343 #define FCFCNCT_AM_VALID        0x0040
344 #define FCFCNCT_AM_PREFERRED    0x0080   /* if not set, AM Required */
345 #define FCFCNCT_AM_SPMA         0x0100   /* if not set, FPMA */
346
347         uint16_t vlan_tag;
348         uint8_t fabric_name[8];
349         uint8_t switch_name[8];
350 };
351
352 struct lpfc_fcf_conn_entry {
353         struct list_head list;
354         struct lpfc_fcf_conn_rec conn_rec;
355 };
356
357 /*
358  * Define the host's bootstrap mailbox.  This structure contains
359  * the member attributes needed to create, use, and destroy the
360  * bootstrap mailbox region.
361  *
362  * The macro definitions for the bmbx data structure are defined
363  * in lpfc_hw4.h with the register definition.
364  */
365 struct lpfc_bmbx {
366         struct lpfc_dmabuf *dmabuf;
367         struct dma_address dma_address;
368         void *avirt;
369         dma_addr_t aphys;
370         uint32_t bmbx_size;
371 };
372
373 #define LPFC_EQE_SIZE LPFC_EQE_SIZE_4
374
375 #define LPFC_EQE_SIZE_4B        4
376 #define LPFC_EQE_SIZE_16B       16
377 #define LPFC_CQE_SIZE           16
378 #define LPFC_WQE_SIZE           64
379 #define LPFC_WQE128_SIZE        128
380 #define LPFC_MQE_SIZE           256
381 #define LPFC_RQE_SIZE           8
382
383 #define LPFC_EQE_DEF_COUNT      1024
384 #define LPFC_CQE_DEF_COUNT      1024
385 #define LPFC_CQE_EXP_COUNT      4096
386 #define LPFC_WQE_DEF_COUNT      256
387 #define LPFC_WQE_EXP_COUNT      1024
388 #define LPFC_MQE_DEF_COUNT      16
389 #define LPFC_RQE_DEF_COUNT      512
390
391 #define LPFC_QUEUE_NOARM        false
392 #define LPFC_QUEUE_REARM        true
393
394
395 /*
396  * SLI4 CT field defines
397  */
398 #define SLI4_CT_RPI 0
399 #define SLI4_CT_VPI 1
400 #define SLI4_CT_VFI 2
401 #define SLI4_CT_FCFI 3
402
403 /*
404  * SLI4 specific data structures
405  */
406 struct lpfc_max_cfg_param {
407         uint16_t max_xri;
408         uint16_t xri_base;
409         uint16_t xri_used;
410         uint16_t max_rpi;
411         uint16_t rpi_base;
412         uint16_t rpi_used;
413         uint16_t max_vpi;
414         uint16_t vpi_base;
415         uint16_t vpi_used;
416         uint16_t max_vfi;
417         uint16_t vfi_base;
418         uint16_t vfi_used;
419         uint16_t max_fcfi;
420         uint16_t fcfi_used;
421         uint16_t max_eq;
422         uint16_t max_rq;
423         uint16_t max_cq;
424         uint16_t max_wq;
425 };
426
427 struct lpfc_hba;
428 /* SLI4 HBA multi-fcp queue handler struct */
429 #define LPFC_SLI4_HANDLER_NAME_SZ       16
430 struct lpfc_hba_eq_hdl {
431         uint32_t idx;
432         char handler_name[LPFC_SLI4_HANDLER_NAME_SZ];
433         struct lpfc_hba *phba;
434         atomic_t hba_eq_in_use;
435         struct cpumask *cpumask;
436         /* CPU affinitsed to or 0xffffffff if multiple */
437         uint32_t cpu;
438 #define LPFC_MULTI_CPU_AFFINITY 0xffffffff
439 };
440
441 /*BB Credit recovery value*/
442 struct lpfc_bbscn_params {
443         uint32_t word0;
444 #define lpfc_bbscn_min_SHIFT            0
445 #define lpfc_bbscn_min_MASK             0x0000000F
446 #define lpfc_bbscn_min_WORD             word0
447 #define lpfc_bbscn_max_SHIFT            4
448 #define lpfc_bbscn_max_MASK             0x0000000F
449 #define lpfc_bbscn_max_WORD             word0
450 #define lpfc_bbscn_def_SHIFT            8
451 #define lpfc_bbscn_def_MASK             0x0000000F
452 #define lpfc_bbscn_def_WORD             word0
453 };
454
455 /* Port Capabilities for SLI4 Parameters */
456 struct lpfc_pc_sli4_params {
457         uint32_t supported;
458         uint32_t if_type;
459         uint32_t sli_rev;
460         uint32_t sli_family;
461         uint32_t featurelevel_1;
462         uint32_t featurelevel_2;
463         uint32_t proto_types;
464 #define LPFC_SLI4_PROTO_FCOE    0x0000001
465 #define LPFC_SLI4_PROTO_FC      0x0000002
466 #define LPFC_SLI4_PROTO_NIC     0x0000004
467 #define LPFC_SLI4_PROTO_ISCSI   0x0000008
468 #define LPFC_SLI4_PROTO_RDMA    0x0000010
469         uint32_t sge_supp_len;
470         uint32_t if_page_sz;
471         uint32_t rq_db_window;
472         uint32_t loopbk_scope;
473         uint32_t oas_supported;
474         uint32_t eq_pages_max;
475         uint32_t eqe_size;
476         uint32_t cq_pages_max;
477         uint32_t cqe_size;
478         uint32_t mq_pages_max;
479         uint32_t mqe_size;
480         uint32_t mq_elem_cnt;
481         uint32_t wq_pages_max;
482         uint32_t wqe_size;
483         uint32_t rq_pages_max;
484         uint32_t rqe_size;
485         uint32_t hdr_pages_max;
486         uint32_t hdr_size;
487         uint32_t hdr_pp_align;
488         uint32_t sgl_pages_max;
489         uint32_t sgl_pp_align;
490         uint8_t cqv;
491         uint8_t mqv;
492         uint8_t wqv;
493         uint8_t rqv;
494         uint8_t eqav;
495         uint8_t cqav;
496         uint8_t wqsize;
497         uint8_t bv1s;
498 #define LPFC_WQ_SZ64_SUPPORT    1
499 #define LPFC_WQ_SZ128_SUPPORT   2
500         uint8_t wqpcnt;
501 };
502
503 #define LPFC_CQ_4K_PAGE_SZ      0x1
504 #define LPFC_CQ_16K_PAGE_SZ     0x4
505 #define LPFC_WQ_4K_PAGE_SZ      0x1
506 #define LPFC_WQ_16K_PAGE_SZ     0x4
507
508 struct lpfc_iov {
509         uint32_t pf_number;
510         uint32_t vf_number;
511 };
512
513 struct lpfc_sli4_lnk_info {
514         uint8_t lnk_dv;
515 #define LPFC_LNK_DAT_INVAL      0
516 #define LPFC_LNK_DAT_VAL        1
517         uint8_t lnk_tp;
518 #define LPFC_LNK_GE     0x0 /* FCoE */
519 #define LPFC_LNK_FC     0x1 /* FC   */
520         uint8_t lnk_no;
521         uint8_t optic_state;
522 };
523
524 #define LPFC_SLI4_HANDLER_CNT           (LPFC_HBA_IO_CHAN_MAX+ \
525                                          LPFC_FOF_IO_CHAN_NUM)
526
527 /* Used for IRQ vector to CPU mapping */
528 struct lpfc_vector_map_info {
529         uint16_t        phys_id;
530         uint16_t        core_id;
531         uint16_t        irq;
532         uint16_t        hdwq;
533 };
534 #define LPFC_VECTOR_MAP_EMPTY   0xffff
535
536 /* Multi-XRI pool */
537 #define XRI_BATCH               8
538
539 struct lpfc_pbl_pool {
540         struct list_head list;
541         u32 count;
542         spinlock_t lock;        /* lock for pbl_pool*/
543 };
544
545 struct lpfc_pvt_pool {
546         u32 low_watermark;
547         u32 high_watermark;
548
549         struct list_head list;
550         u32 count;
551         spinlock_t lock;        /* lock for pvt_pool */
552 };
553
554 struct lpfc_multixri_pool {
555         u32 xri_limit;
556
557         /* Starting point when searching a pbl_pool with round-robin method */
558         u32 rrb_next_hwqid;
559
560         /* Used by lpfc_adjust_pvt_pool_count.
561          * io_req_count is incremented by 1 during IO submission. The heartbeat
562          * handler uses these two variables to determine if pvt_pool is idle or
563          * busy.
564          */
565         u32 prev_io_req_count;
566         u32 io_req_count;
567
568         /* statistics */
569         u32 pbl_empty_count;
570 #ifdef LPFC_MXP_STAT
571         u32 above_limit_count;
572         u32 below_limit_count;
573         u32 local_pbl_hit_count;
574         u32 other_pbl_hit_count;
575         u32 stat_max_hwm;
576
577 #define LPFC_MXP_SNAPSHOT_TAKEN 3 /* snapshot is taken at 3rd heartbeats */
578         u32 stat_pbl_count;
579         u32 stat_pvt_count;
580         u32 stat_busy_count;
581         u32 stat_snapshot_taken;
582 #endif
583
584         /* TODO: Separate pvt_pool into get and put list */
585         struct lpfc_pbl_pool pbl_pool;   /* Public free XRI pool */
586         struct lpfc_pvt_pool pvt_pool;   /* Private free XRI pool */
587 };
588
589 struct lpfc_fc4_ctrl_stat {
590         u32 input_requests;
591         u32 output_requests;
592         u32 control_requests;
593         u32 io_cmpls;
594 };
595
596 /* SLI4 HBA data structure entries */
597 struct lpfc_sli4_hdw_queue {
598         /* Pointers to the constructed SLI4 queues */
599         struct lpfc_queue *hba_eq;  /* Event queues for HBA */
600         struct lpfc_queue *fcp_cq;  /* Fast-path FCP compl queue */
601         struct lpfc_queue *nvme_cq; /* Fast-path NVME compl queue */
602         struct lpfc_queue *fcp_wq;  /* Fast-path FCP work queue */
603         struct lpfc_queue *nvme_wq; /* Fast-path NVME work queue */
604         uint16_t fcp_cq_map;
605         uint16_t nvme_cq_map;
606
607         /* Keep track of IO buffers for this hardware queue */
608         spinlock_t io_buf_list_get_lock;  /* Common buf alloc list lock */
609         struct list_head lpfc_io_buf_list_get;
610         spinlock_t io_buf_list_put_lock;  /* Common buf free list lock */
611         struct list_head lpfc_io_buf_list_put;
612         spinlock_t abts_scsi_buf_list_lock; /* list of aborted SCSI IOs */
613         struct list_head lpfc_abts_scsi_buf_list;
614         spinlock_t abts_nvme_buf_list_lock; /* list of aborted NVME IOs */
615         struct list_head lpfc_abts_nvme_buf_list;
616         uint32_t total_io_bufs;
617         uint32_t get_io_bufs;
618         uint32_t put_io_bufs;
619         uint32_t empty_io_bufs;
620         uint32_t abts_scsi_io_bufs;
621         uint32_t abts_nvme_io_bufs;
622
623         /* Multi-XRI pool per HWQ */
624         struct lpfc_multixri_pool *p_multixri_pool;
625
626         /* FC-4 Stats counters */
627         struct lpfc_fc4_ctrl_stat nvme_cstat;
628         struct lpfc_fc4_ctrl_stat scsi_cstat;
629
630 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
631 #define LPFC_CHECK_CPU_CNT    128
632         uint32_t cpucheck_rcv_io[LPFC_CHECK_CPU_CNT];
633         uint32_t cpucheck_xmt_io[LPFC_CHECK_CPU_CNT];
634         uint32_t cpucheck_cmpl_io[LPFC_CHECK_CPU_CNT];
635 #endif
636 };
637
638 struct lpfc_sli4_hba {
639         void __iomem *conf_regs_memmap_p; /* Kernel memory mapped address for
640                                            * config space registers
641                                            */
642         void __iomem *ctrl_regs_memmap_p; /* Kernel memory mapped address for
643                                            * control registers
644                                            */
645         void __iomem *drbl_regs_memmap_p; /* Kernel memory mapped address for
646                                            * doorbell registers
647                                            */
648         void __iomem *dpp_regs_memmap_p;  /* Kernel memory mapped address for
649                                            * dpp registers
650                                            */
651         union {
652                 struct {
653                         /* IF Type 0, BAR 0 PCI cfg space reg mem map */
654                         void __iomem *UERRLOregaddr;
655                         void __iomem *UERRHIregaddr;
656                         void __iomem *UEMASKLOregaddr;
657                         void __iomem *UEMASKHIregaddr;
658                 } if_type0;
659                 struct {
660                         /* IF Type 2, BAR 0 PCI cfg space reg mem map. */
661                         void __iomem *STATUSregaddr;
662                         void __iomem *CTRLregaddr;
663                         void __iomem *ERR1regaddr;
664 #define SLIPORT_ERR1_REG_ERR_CODE_1             0x1
665 #define SLIPORT_ERR1_REG_ERR_CODE_2             0x2
666                         void __iomem *ERR2regaddr;
667 #define SLIPORT_ERR2_REG_FW_RESTART             0x0
668 #define SLIPORT_ERR2_REG_FUNC_PROVISON          0x1
669 #define SLIPORT_ERR2_REG_FORCED_DUMP            0x2
670 #define SLIPORT_ERR2_REG_FAILURE_EQ             0x3
671 #define SLIPORT_ERR2_REG_FAILURE_CQ             0x4
672 #define SLIPORT_ERR2_REG_FAILURE_BUS            0x5
673 #define SLIPORT_ERR2_REG_FAILURE_RQ             0x6
674                         void __iomem *EQDregaddr;
675                 } if_type2;
676         } u;
677
678         /* IF type 0, BAR1 and if type 2, Bar 0 CSR register memory map */
679         void __iomem *PSMPHRregaddr;
680
681         /* Well-known SLI INTF register memory map. */
682         void __iomem *SLIINTFregaddr;
683
684         /* IF type 0, BAR 1 function CSR register memory map */
685         void __iomem *ISRregaddr;       /* HST_ISR register */
686         void __iomem *IMRregaddr;       /* HST_IMR register */
687         void __iomem *ISCRregaddr;      /* HST_ISCR register */
688         /* IF type 0, BAR 0 and if type 2, BAR 0 doorbell register memory map */
689         void __iomem *RQDBregaddr;      /* RQ_DOORBELL register */
690         void __iomem *WQDBregaddr;      /* WQ_DOORBELL register */
691         void __iomem *CQDBregaddr;      /* CQ_DOORBELL register */
692         void __iomem *EQDBregaddr;      /* EQ_DOORBELL register */
693         void __iomem *MQDBregaddr;      /* MQ_DOORBELL register */
694         void __iomem *BMBXregaddr;      /* BootStrap MBX register */
695
696         uint32_t ue_mask_lo;
697         uint32_t ue_mask_hi;
698         uint32_t ue_to_sr;
699         uint32_t ue_to_rp;
700         struct lpfc_register sli_intf;
701         struct lpfc_pc_sli4_params pc_sli4_params;
702         struct lpfc_bbscn_params bbscn_params;
703         struct lpfc_hba_eq_hdl *hba_eq_hdl; /* HBA per-WQ handle */
704
705         void (*sli4_eq_clr_intr)(struct lpfc_queue *q);
706         uint32_t (*sli4_eq_release)(struct lpfc_queue *q, bool arm);
707         uint32_t (*sli4_cq_release)(struct lpfc_queue *q, bool arm);
708
709         /* Pointers to the constructed SLI4 queues */
710         struct lpfc_sli4_hdw_queue *hdwq;
711         struct list_head lpfc_wq_list;
712
713         /* Pointers to the constructed SLI4 queues for NVMET */
714         struct lpfc_queue **nvmet_cqset; /* Fast-path NVMET CQ Set queues */
715         struct lpfc_queue **nvmet_mrq_hdr; /* Fast-path NVMET hdr MRQs */
716         struct lpfc_queue **nvmet_mrq_data; /* Fast-path NVMET data MRQs */
717
718         struct lpfc_queue *mbx_cq; /* Slow-path mailbox complete queue */
719         struct lpfc_queue *els_cq; /* Slow-path ELS response complete queue */
720         struct lpfc_queue *nvmels_cq; /* NVME LS complete queue */
721         struct lpfc_queue *mbx_wq; /* Slow-path MBOX work queue */
722         struct lpfc_queue *els_wq; /* Slow-path ELS work queue */
723         struct lpfc_queue *nvmels_wq; /* NVME LS work queue */
724         struct lpfc_queue *hdr_rq; /* Slow-path Header Receive queue */
725         struct lpfc_queue *dat_rq; /* Slow-path Data Receive queue */
726
727         struct lpfc_name wwnn;
728         struct lpfc_name wwpn;
729
730         uint32_t fw_func_mode;  /* FW function protocol mode */
731         uint32_t ulp0_mode;     /* ULP0 protocol mode */
732         uint32_t ulp1_mode;     /* ULP1 protocol mode */
733
734         /* Optimized Access Storage specific queues/structures */
735         uint64_t oas_next_lun;
736         uint8_t oas_next_tgt_wwpn[8];
737         uint8_t oas_next_vpt_wwpn[8];
738
739         /* Setup information for various queue parameters */
740         int eq_esize;
741         int eq_ecount;
742         int cq_esize;
743         int cq_ecount;
744         int wq_esize;
745         int wq_ecount;
746         int mq_esize;
747         int mq_ecount;
748         int rq_esize;
749         int rq_ecount;
750 #define LPFC_SP_EQ_MAX_INTR_SEC         10000
751 #define LPFC_FP_EQ_MAX_INTR_SEC         10000
752
753         uint32_t intr_enable;
754         struct lpfc_bmbx bmbx;
755         struct lpfc_max_cfg_param max_cfg_param;
756         uint16_t extents_in_use; /* must allocate resource extents. */
757         uint16_t rpi_hdrs_in_use; /* must post rpi hdrs if set. */
758         uint16_t next_xri; /* last_xri - max_cfg_param.xri_base = used */
759         uint16_t next_rpi;
760         uint16_t io_xri_max;
761         uint16_t io_xri_cnt;
762         uint16_t io_xri_start;
763         uint16_t els_xri_cnt;
764         uint16_t nvmet_xri_cnt;
765         uint16_t nvmet_io_wait_cnt;
766         uint16_t nvmet_io_wait_total;
767         struct list_head lpfc_els_sgl_list;
768         struct list_head lpfc_abts_els_sgl_list;
769         spinlock_t abts_scsi_buf_list_lock; /* list of aborted SCSI IOs */
770         struct list_head lpfc_abts_scsi_buf_list;
771         struct list_head lpfc_nvmet_sgl_list;
772         spinlock_t abts_nvmet_buf_list_lock; /* list of aborted NVMET IOs */
773         struct list_head lpfc_abts_nvmet_ctx_list;
774         struct list_head lpfc_nvmet_io_wait_list;
775         struct lpfc_nvmet_ctx_info *nvmet_ctx_info;
776         struct lpfc_sglq **lpfc_sglq_active_list;
777         struct list_head lpfc_rpi_hdr_list;
778         unsigned long *rpi_bmask;
779         uint16_t *rpi_ids;
780         uint16_t rpi_count;
781         struct list_head lpfc_rpi_blk_list;
782         unsigned long *xri_bmask;
783         uint16_t *xri_ids;
784         struct list_head lpfc_xri_blk_list;
785         unsigned long *vfi_bmask;
786         uint16_t *vfi_ids;
787         uint16_t vfi_count;
788         struct list_head lpfc_vfi_blk_list;
789         struct lpfc_sli4_flags sli4_flags;
790         struct list_head sp_queue_event;
791         struct list_head sp_cqe_event_pool;
792         struct list_head sp_asynce_work_queue;
793         struct list_head sp_fcp_xri_aborted_work_queue;
794         struct list_head sp_els_xri_aborted_work_queue;
795         struct list_head sp_unsol_work_queue;
796         struct lpfc_sli4_link link_state;
797         struct lpfc_sli4_lnk_info lnk_info;
798         uint32_t pport_name_sta;
799 #define LPFC_SLI4_PPNAME_NON    0
800 #define LPFC_SLI4_PPNAME_GET    1
801         struct lpfc_iov iov;
802         spinlock_t sgl_list_lock; /* list of aborted els IOs */
803         spinlock_t nvmet_io_wait_lock; /* IOs waiting for ctx resources */
804         uint32_t physical_port;
805
806         /* CPU to vector mapping information */
807         struct lpfc_vector_map_info *cpu_map;
808         uint16_t num_online_cpu;
809         uint16_t num_present_cpu;
810         uint16_t curr_disp_cpu;
811         uint32_t conf_trunk;
812 #define lpfc_conf_trunk_port0_WORD      conf_trunk
813 #define lpfc_conf_trunk_port0_SHIFT     0
814 #define lpfc_conf_trunk_port0_MASK      0x1
815 #define lpfc_conf_trunk_port1_WORD      conf_trunk
816 #define lpfc_conf_trunk_port1_SHIFT     1
817 #define lpfc_conf_trunk_port1_MASK      0x1
818 #define lpfc_conf_trunk_port2_WORD      conf_trunk
819 #define lpfc_conf_trunk_port2_SHIFT     2
820 #define lpfc_conf_trunk_port2_MASK      0x1
821 #define lpfc_conf_trunk_port3_WORD      conf_trunk
822 #define lpfc_conf_trunk_port3_SHIFT     3
823 #define lpfc_conf_trunk_port3_MASK      0x1
824 };
825
826 enum lpfc_sge_type {
827         GEN_BUFF_TYPE,
828         SCSI_BUFF_TYPE,
829         NVMET_BUFF_TYPE
830 };
831
832 enum lpfc_sgl_state {
833         SGL_FREED,
834         SGL_ALLOCATED,
835         SGL_XRI_ABORTED
836 };
837
838 struct lpfc_sglq {
839         /* lpfc_sglqs are used in double linked lists */
840         struct list_head list;
841         struct list_head clist;
842         enum lpfc_sge_type buff_type; /* is this a scsi sgl */
843         enum lpfc_sgl_state state;
844         struct lpfc_nodelist *ndlp; /* ndlp associated with IO */
845         uint16_t iotag;         /* pre-assigned IO tag */
846         uint16_t sli4_lxritag;  /* logical pre-assigned xri. */
847         uint16_t sli4_xritag;   /* pre-assigned XRI, (OXID) tag. */
848         struct sli4_sge *sgl;   /* pre-assigned SGL */
849         void *virt;             /* virtual address. */
850         dma_addr_t phys;        /* physical address */
851 };
852
853 struct lpfc_rpi_hdr {
854         struct list_head list;
855         uint32_t len;
856         struct lpfc_dmabuf *dmabuf;
857         uint32_t page_count;
858         uint32_t start_rpi;
859         uint16_t next_rpi;
860 };
861
862 struct lpfc_rsrc_blks {
863         struct list_head list;
864         uint16_t rsrc_start;
865         uint16_t rsrc_size;
866         uint16_t rsrc_used;
867 };
868
869 struct lpfc_rdp_context {
870         struct lpfc_nodelist *ndlp;
871         uint16_t ox_id;
872         uint16_t rx_id;
873         READ_LNK_VAR link_stat;
874         uint8_t page_a0[DMP_SFF_PAGE_A0_SIZE];
875         uint8_t page_a2[DMP_SFF_PAGE_A2_SIZE];
876         void (*cmpl)(struct lpfc_hba *, struct lpfc_rdp_context*, int);
877 };
878
879 struct lpfc_lcb_context {
880         uint8_t  sub_command;
881         uint8_t  type;
882         uint8_t  capability;
883         uint8_t  frequency;
884         uint16_t  duration;
885         uint16_t ox_id;
886         uint16_t rx_id;
887         struct lpfc_nodelist *ndlp;
888 };
889
890
891 /*
892  * SLI4 specific function prototypes
893  */
894 int lpfc_pci_function_reset(struct lpfc_hba *);
895 int lpfc_sli4_pdev_status_reg_wait(struct lpfc_hba *);
896 int lpfc_sli4_hba_setup(struct lpfc_hba *);
897 int lpfc_sli4_config(struct lpfc_hba *, struct lpfcMboxq *, uint8_t,
898                      uint8_t, uint32_t, bool);
899 void lpfc_sli4_mbox_cmd_free(struct lpfc_hba *, struct lpfcMboxq *);
900 void lpfc_sli4_mbx_sge_set(struct lpfcMboxq *, uint32_t, dma_addr_t, uint32_t);
901 void lpfc_sli4_mbx_sge_get(struct lpfcMboxq *, uint32_t,
902                            struct lpfc_mbx_sge *);
903 int lpfc_sli4_mbx_read_fcf_rec(struct lpfc_hba *, struct lpfcMboxq *,
904                                uint16_t);
905
906 void lpfc_sli4_hba_reset(struct lpfc_hba *);
907 struct lpfc_queue *lpfc_sli4_queue_alloc(struct lpfc_hba *, uint32_t,
908                                          uint32_t, uint32_t);
909 void lpfc_sli4_queue_free(struct lpfc_queue *);
910 int lpfc_eq_create(struct lpfc_hba *, struct lpfc_queue *, uint32_t);
911 int lpfc_modify_hba_eq_delay(struct lpfc_hba *phba, uint32_t startq,
912                              uint32_t numq, uint32_t imax);
913 int lpfc_cq_create(struct lpfc_hba *, struct lpfc_queue *,
914                         struct lpfc_queue *, uint32_t, uint32_t);
915 int lpfc_cq_create_set(struct lpfc_hba *phba, struct lpfc_queue **cqp,
916                         struct lpfc_sli4_hdw_queue *hdwq, uint32_t type,
917                         uint32_t subtype);
918 int32_t lpfc_mq_create(struct lpfc_hba *, struct lpfc_queue *,
919                        struct lpfc_queue *, uint32_t);
920 int lpfc_wq_create(struct lpfc_hba *, struct lpfc_queue *,
921                         struct lpfc_queue *, uint32_t);
922 int lpfc_rq_create(struct lpfc_hba *, struct lpfc_queue *,
923                         struct lpfc_queue *, struct lpfc_queue *, uint32_t);
924 int lpfc_mrq_create(struct lpfc_hba *phba, struct lpfc_queue **hrqp,
925                         struct lpfc_queue **drqp, struct lpfc_queue **cqp,
926                         uint32_t subtype);
927 int lpfc_eq_destroy(struct lpfc_hba *, struct lpfc_queue *);
928 int lpfc_cq_destroy(struct lpfc_hba *, struct lpfc_queue *);
929 int lpfc_mq_destroy(struct lpfc_hba *, struct lpfc_queue *);
930 int lpfc_wq_destroy(struct lpfc_hba *, struct lpfc_queue *);
931 int lpfc_rq_destroy(struct lpfc_hba *, struct lpfc_queue *,
932                          struct lpfc_queue *);
933 int lpfc_sli4_queue_setup(struct lpfc_hba *);
934 void lpfc_sli4_queue_unset(struct lpfc_hba *);
935 int lpfc_sli4_post_sgl(struct lpfc_hba *, dma_addr_t, dma_addr_t, uint16_t);
936 int lpfc_repost_io_sgl_list(struct lpfc_hba *phba);
937 uint16_t lpfc_sli4_next_xritag(struct lpfc_hba *);
938 void lpfc_sli4_free_xri(struct lpfc_hba *, int);
939 int lpfc_sli4_post_async_mbox(struct lpfc_hba *);
940 struct lpfc_cq_event *__lpfc_sli4_cq_event_alloc(struct lpfc_hba *);
941 struct lpfc_cq_event *lpfc_sli4_cq_event_alloc(struct lpfc_hba *);
942 void __lpfc_sli4_cq_event_release(struct lpfc_hba *, struct lpfc_cq_event *);
943 void lpfc_sli4_cq_event_release(struct lpfc_hba *, struct lpfc_cq_event *);
944 int lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *);
945 int lpfc_sli4_post_rpi_hdr(struct lpfc_hba *, struct lpfc_rpi_hdr *);
946 int lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *);
947 struct lpfc_rpi_hdr *lpfc_sli4_create_rpi_hdr(struct lpfc_hba *);
948 void lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *);
949 int lpfc_sli4_alloc_rpi(struct lpfc_hba *);
950 void lpfc_sli4_free_rpi(struct lpfc_hba *, int);
951 void lpfc_sli4_remove_rpis(struct lpfc_hba *);
952 void lpfc_sli4_async_event_proc(struct lpfc_hba *);
953 void lpfc_sli4_fcf_redisc_event_proc(struct lpfc_hba *);
954 int lpfc_sli4_resume_rpi(struct lpfc_nodelist *,
955                         void (*)(struct lpfc_hba *, LPFC_MBOXQ_t *), void *);
956 void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *);
957 void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *);
958 void lpfc_sli4_fcp_xri_aborted(struct lpfc_hba *,
959                                struct sli4_wcqe_xri_aborted *, int);
960 void lpfc_sli4_nvme_xri_aborted(struct lpfc_hba *phba,
961                                 struct sli4_wcqe_xri_aborted *axri, int idx);
962 void lpfc_sli4_nvmet_xri_aborted(struct lpfc_hba *phba,
963                                  struct sli4_wcqe_xri_aborted *axri);
964 void lpfc_sli4_els_xri_aborted(struct lpfc_hba *,
965                                struct sli4_wcqe_xri_aborted *);
966 void lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport *);
967 void lpfc_sli4_vport_delete_fcp_xri_aborted(struct lpfc_vport *);
968 int lpfc_sli4_brdreset(struct lpfc_hba *);
969 int lpfc_sli4_add_fcf_record(struct lpfc_hba *, struct fcf_record *);
970 void lpfc_sli_remove_dflt_fcf(struct lpfc_hba *);
971 int lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *);
972 int lpfc_sli4_get_iocb_cnt(struct lpfc_hba *phba);
973 int lpfc_sli4_init_vpi(struct lpfc_vport *);
974 inline void lpfc_sli4_eq_clr_intr(struct lpfc_queue *);
975 uint32_t lpfc_sli4_cq_release(struct lpfc_queue *, bool);
976 uint32_t lpfc_sli4_eq_release(struct lpfc_queue *, bool);
977 inline void lpfc_sli4_if6_eq_clr_intr(struct lpfc_queue *q);
978 uint32_t lpfc_sli4_if6_cq_release(struct lpfc_queue *q, bool arm);
979 uint32_t lpfc_sli4_if6_eq_release(struct lpfc_queue *q, bool arm);
980 void lpfc_sli4_fcfi_unreg(struct lpfc_hba *, uint16_t);
981 int lpfc_sli4_fcf_scan_read_fcf_rec(struct lpfc_hba *, uint16_t);
982 int lpfc_sli4_fcf_rr_read_fcf_rec(struct lpfc_hba *, uint16_t);
983 int lpfc_sli4_read_fcf_rec(struct lpfc_hba *, uint16_t);
984 void lpfc_mbx_cmpl_fcf_scan_read_fcf_rec(struct lpfc_hba *, LPFC_MBOXQ_t *);
985 void lpfc_mbx_cmpl_fcf_rr_read_fcf_rec(struct lpfc_hba *, LPFC_MBOXQ_t *);
986 void lpfc_mbx_cmpl_read_fcf_rec(struct lpfc_hba *, LPFC_MBOXQ_t *);
987 int lpfc_sli4_unregister_fcf(struct lpfc_hba *);
988 int lpfc_sli4_post_status_check(struct lpfc_hba *);
989 uint8_t lpfc_sli_config_mbox_subsys_get(struct lpfc_hba *, LPFC_MBOXQ_t *);
990 uint8_t lpfc_sli_config_mbox_opcode_get(struct lpfc_hba *, LPFC_MBOXQ_t *);
991 void lpfc_sli4_ras_dma_free(struct lpfc_hba *phba);