[SCSI] lpfc 8.3.5: fix reset path, ELS ordering and discovery issues
[linux-2.6-block.git] / drivers / scsi / lpfc / lpfc_sli4.h
CommitLineData
da0436e9
JS
1/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2009 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
6 * www.emulex.com *
7 * *
8 * This program is free software; you can redistribute it and/or *
9 * modify it under the terms of version 2 of the GNU General *
10 * Public License as published by the Free Software Foundation. *
11 * This program is distributed in the hope that it will be useful. *
12 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
13 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
14 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
15 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
16 * TO BE LEGALLY INVALID. See the GNU General Public License for *
17 * more details, a copy of which can be found in the file COPYING *
18 * included with this package. *
19 *******************************************************************/
20
21#define LPFC_ACTIVE_MBOX_WAIT_CNT 100
22#define LPFC_RELEASE_NOTIFICATION_INTERVAL 32
23#define LPFC_GET_QE_REL_INT 32
24#define LPFC_RPI_LOW_WATER_MARK 10
25/* Number of SGL entries can be posted in a 4KB nonembedded mbox command */
26#define LPFC_NEMBED_MBOX_SGL_CNT 254
27
28/* Multi-queue arrangement for fast-path FCP work queues */
29#define LPFC_FN_EQN_MAX 8
30#define LPFC_SP_EQN_DEF 1
31#define LPFC_FP_EQN_DEF 1
32#define LPFC_FP_EQN_MIN 1
33#define LPFC_FP_EQN_MAX (LPFC_FN_EQN_MAX - LPFC_SP_EQN_DEF)
34
35#define LPFC_FN_WQN_MAX 32
36#define LPFC_SP_WQN_DEF 1
37#define LPFC_FP_WQN_DEF 4
38#define LPFC_FP_WQN_MIN 1
39#define LPFC_FP_WQN_MAX (LPFC_FN_WQN_MAX - LPFC_SP_WQN_DEF)
40
41/*
42 * Provide the default FCF Record attributes used by the driver
43 * when nonFIP mode is configured and there is no other default
44 * FCF Record attributes.
45 */
46#define LPFC_FCOE_FCF_DEF_INDEX 0
47#define LPFC_FCOE_FCF_GET_FIRST 0xFFFF
48#define LPFC_FCOE_FCF_NEXT_NONE 0xFFFF
49
50/* First 3 bytes of default FCF MAC is specified by FC_MAP */
51#define LPFC_FCOE_FCF_MAC3 0xFF
52#define LPFC_FCOE_FCF_MAC4 0xFF
53#define LPFC_FCOE_FCF_MAC5 0xFE
54#define LPFC_FCOE_FCF_MAP0 0x0E
55#define LPFC_FCOE_FCF_MAP1 0xFC
56#define LPFC_FCOE_FCF_MAP2 0x00
57#define LPFC_FCOE_MAX_RCV_SIZE 0x5AC
58#define LPFC_FCOE_FKA_ADV_PER 0
59#define LPFC_FCOE_FIP_PRIORITY 0x80
60
61enum lpfc_sli4_queue_type {
62 LPFC_EQ,
63 LPFC_GCQ,
64 LPFC_MCQ,
65 LPFC_WCQ,
66 LPFC_RCQ,
67 LPFC_MQ,
68 LPFC_WQ,
69 LPFC_HRQ,
70 LPFC_DRQ
71};
72
73/* The queue sub-type defines the functional purpose of the queue */
74enum lpfc_sli4_queue_subtype {
75 LPFC_NONE,
76 LPFC_MBOX,
77 LPFC_FCP,
78 LPFC_ELS,
79 LPFC_USOL
80};
81
82union sli4_qe {
83 void *address;
84 struct lpfc_eqe *eqe;
85 struct lpfc_cqe *cqe;
86 struct lpfc_mcqe *mcqe;
87 struct lpfc_wcqe_complete *wcqe_complete;
88 struct lpfc_wcqe_release *wcqe_release;
89 struct sli4_wcqe_xri_aborted *wcqe_xri_aborted;
90 struct lpfc_rcqe_complete *rcqe_complete;
91 struct lpfc_mqe *mqe;
92 union lpfc_wqe *wqe;
93 struct lpfc_rqe *rqe;
94};
95
96struct lpfc_queue {
97 struct list_head list;
98 enum lpfc_sli4_queue_type type;
99 enum lpfc_sli4_queue_subtype subtype;
100 struct lpfc_hba *phba;
101 struct list_head child_list;
102 uint32_t entry_count; /* Number of entries to support on the queue */
103 uint32_t entry_size; /* Size of each queue entry. */
104 uint32_t queue_id; /* Queue ID assigned by the hardware */
105 struct list_head page_list;
106 uint32_t page_count; /* Number of pages allocated for this queue */
107
108 uint32_t host_index; /* The host's index for putting or getting */
109 uint32_t hba_index; /* The last known hba index for get or put */
110 union sli4_qe qe[1]; /* array to index entries (must be last) */
111};
112
da0436e9
JS
113struct lpfc_sli4_link {
114 uint8_t speed;
115 uint8_t duplex;
116 uint8_t status;
117 uint8_t physical;
118 uint8_t fault;
119};
120
121struct lpfc_fcf {
122 uint8_t fabric_name[8];
8fa38513 123 uint8_t switch_name[8];
da0436e9
JS
124 uint8_t mac_addr[6];
125 uint16_t fcf_indx;
126 uint16_t fcfi;
127 uint32_t fcf_flag;
128#define FCF_AVAILABLE 0x01 /* FCF available for discovery */
129#define FCF_REGISTERED 0x02 /* FCF registered with FW */
130#define FCF_DISCOVERED 0x04 /* FCF discovery started */
131#define FCF_BOOT_ENABLE 0x08 /* Boot bios use this FCF */
132#define FCF_IN_USE 0x10 /* Atleast one discovery completed */
133#define FCF_VALID_VLAN 0x20 /* Use the vlan id specified */
134 uint32_t priority;
135 uint32_t addr_mode;
136 uint16_t vlan_id;
137};
138
139#define LPFC_REGION23_SIGNATURE "RG23"
140#define LPFC_REGION23_VERSION 1
141#define LPFC_REGION23_LAST_REC 0xff
a0c87cbd
JS
142#define DRIVER_SPECIFIC_TYPE 0xA2
143#define LINUX_DRIVER_ID 0x20
144#define PORT_STE_TYPE 0x1
145
da0436e9
JS
146struct lpfc_fip_param_hdr {
147 uint8_t type;
148#define FCOE_PARAM_TYPE 0xA0
149 uint8_t length;
150#define FCOE_PARAM_LENGTH 2
151 uint8_t parm_version;
152#define FIPP_VERSION 0x01
153 uint8_t parm_flags;
154#define lpfc_fip_param_hdr_fipp_mode_SHIFT 6
155#define lpfc_fip_param_hdr_fipp_mode_MASK 0x3
156#define lpfc_fip_param_hdr_fipp_mode_WORD parm_flags
157#define FIPP_MODE_ON 0x2
158#define FIPP_MODE_OFF 0x0
159#define FIPP_VLAN_VALID 0x1
160};
161
162struct lpfc_fcoe_params {
163 uint8_t fc_map[3];
164 uint8_t reserved1;
165 uint16_t vlan_tag;
166 uint8_t reserved[2];
167};
168
169struct lpfc_fcf_conn_hdr {
170 uint8_t type;
171#define FCOE_CONN_TBL_TYPE 0xA1
172 uint8_t length; /* words */
173 uint8_t reserved[2];
174};
175
176struct lpfc_fcf_conn_rec {
177 uint16_t flags;
178#define FCFCNCT_VALID 0x0001
179#define FCFCNCT_BOOT 0x0002
180#define FCFCNCT_PRIMARY 0x0004 /* if not set, Secondary */
181#define FCFCNCT_FBNM_VALID 0x0008
182#define FCFCNCT_SWNM_VALID 0x0010
183#define FCFCNCT_VLAN_VALID 0x0020
184#define FCFCNCT_AM_VALID 0x0040
185#define FCFCNCT_AM_PREFERRED 0x0080 /* if not set, AM Required */
186#define FCFCNCT_AM_SPMA 0x0100 /* if not set, FPMA */
187
188 uint16_t vlan_tag;
189 uint8_t fabric_name[8];
190 uint8_t switch_name[8];
191};
192
193struct lpfc_fcf_conn_entry {
194 struct list_head list;
195 struct lpfc_fcf_conn_rec conn_rec;
196};
197
198/*
199 * Define the host's bootstrap mailbox. This structure contains
200 * the member attributes needed to create, use, and destroy the
201 * bootstrap mailbox region.
202 *
203 * The macro definitions for the bmbx data structure are defined
204 * in lpfc_hw4.h with the register definition.
205 */
206struct lpfc_bmbx {
207 struct lpfc_dmabuf *dmabuf;
208 struct dma_address dma_address;
209 void *avirt;
210 dma_addr_t aphys;
211 uint32_t bmbx_size;
212};
213
214#define LPFC_EQE_SIZE LPFC_EQE_SIZE_4
215
216#define LPFC_EQE_SIZE_4B 4
217#define LPFC_EQE_SIZE_16B 16
218#define LPFC_CQE_SIZE 16
219#define LPFC_WQE_SIZE 64
220#define LPFC_MQE_SIZE 256
221#define LPFC_RQE_SIZE 8
222
223#define LPFC_EQE_DEF_COUNT 1024
224#define LPFC_CQE_DEF_COUNT 256
f1126688 225#define LPFC_WQE_DEF_COUNT 256
da0436e9
JS
226#define LPFC_MQE_DEF_COUNT 16
227#define LPFC_RQE_DEF_COUNT 512
228
229#define LPFC_QUEUE_NOARM false
230#define LPFC_QUEUE_REARM true
231
232
233/*
234 * SLI4 CT field defines
235 */
236#define SLI4_CT_RPI 0
237#define SLI4_CT_VPI 1
238#define SLI4_CT_VFI 2
239#define SLI4_CT_FCFI 3
240
241#define LPFC_SLI4_MAX_SEGMENT_SIZE 0x10000
242
243/*
244 * SLI4 specific data structures
245 */
246struct lpfc_max_cfg_param {
247 uint16_t max_xri;
248 uint16_t xri_base;
249 uint16_t xri_used;
250 uint16_t max_rpi;
251 uint16_t rpi_base;
252 uint16_t rpi_used;
253 uint16_t max_vpi;
254 uint16_t vpi_base;
255 uint16_t vpi_used;
256 uint16_t max_vfi;
257 uint16_t vfi_base;
258 uint16_t vfi_used;
259 uint16_t max_fcfi;
260 uint16_t fcfi_base;
261 uint16_t fcfi_used;
262 uint16_t max_eq;
263 uint16_t max_rq;
264 uint16_t max_cq;
265 uint16_t max_wq;
266};
267
268struct lpfc_hba;
269/* SLI4 HBA multi-fcp queue handler struct */
270struct lpfc_fcp_eq_hdl {
271 uint32_t idx;
272 struct lpfc_hba *phba;
273};
274
275/* SLI4 HBA data structure entries */
276struct lpfc_sli4_hba {
277 void __iomem *conf_regs_memmap_p; /* Kernel memory mapped address for
278 PCI BAR0, config space registers */
279 void __iomem *ctrl_regs_memmap_p; /* Kernel memory mapped address for
280 PCI BAR1, control registers */
281 void __iomem *drbl_regs_memmap_p; /* Kernel memory mapped address for
282 PCI BAR2, doorbell registers */
283 /* BAR0 PCI config space register memory map */
284 void __iomem *UERRLOregaddr; /* Address to UERR_STATUS_LO register */
285 void __iomem *UERRHIregaddr; /* Address to UERR_STATUS_HI register */
286 void __iomem *ONLINE0regaddr; /* Address to components of internal UE */
287 void __iomem *ONLINE1regaddr; /* Address to components of internal UE */
288#define LPFC_ONLINE_NERR 0xFFFFFFFF
289 void __iomem *SCRATCHPADregaddr; /* Address to scratchpad register */
290 /* BAR1 FCoE function CSR register memory map */
291 void __iomem *STAregaddr; /* Address to HST_STATE register */
292 void __iomem *ISRregaddr; /* Address to HST_ISR register */
293 void __iomem *IMRregaddr; /* Address to HST_IMR register */
294 void __iomem *ISCRregaddr; /* Address to HST_ISCR register */
295 /* BAR2 VF-0 doorbell register memory map */
296 void __iomem *RQDBregaddr; /* Address to RQ_DOORBELL register */
297 void __iomem *WQDBregaddr; /* Address to WQ_DOORBELL register */
298 void __iomem *EQCQDBregaddr; /* Address to EQCQ_DOORBELL register */
299 void __iomem *MQDBregaddr; /* Address to MQ_DOORBELL register */
300 void __iomem *BMBXregaddr; /* Address to BootStrap MBX register */
301
302 struct msix_entry *msix_entries;
303 uint32_t cfg_eqn;
304 struct lpfc_fcp_eq_hdl *fcp_eq_hdl; /* FCP per-WQ handle */
305 /* Pointers to the constructed SLI4 queues */
306 struct lpfc_queue **fp_eq; /* Fast-path event queue */
307 struct lpfc_queue *sp_eq; /* Slow-path event queue */
308 struct lpfc_queue **fcp_wq;/* Fast-path FCP work queue */
309 struct lpfc_queue *mbx_wq; /* Slow-path MBOX work queue */
310 struct lpfc_queue *els_wq; /* Slow-path ELS work queue */
311 struct lpfc_queue *hdr_rq; /* Slow-path Header Receive queue */
312 struct lpfc_queue *dat_rq; /* Slow-path Data Receive queue */
313 struct lpfc_queue **fcp_cq;/* Fast-path FCP compl queue */
314 struct lpfc_queue *mbx_cq; /* Slow-path mailbox complete queue */
315 struct lpfc_queue *els_cq; /* Slow-path ELS response complete queue */
da0436e9
JS
316
317 /* Setup information for various queue parameters */
318 int eq_esize;
319 int eq_ecount;
320 int cq_esize;
321 int cq_ecount;
322 int wq_esize;
323 int wq_ecount;
324 int mq_esize;
325 int mq_ecount;
326 int rq_esize;
327 int rq_ecount;
328#define LPFC_SP_EQ_MAX_INTR_SEC 10000
329#define LPFC_FP_EQ_MAX_INTR_SEC 10000
330
331 uint32_t intr_enable;
332 struct lpfc_bmbx bmbx;
333 struct lpfc_max_cfg_param max_cfg_param;
334 uint16_t next_xri; /* last_xri - max_cfg_param.xri_base = used */
335 uint16_t next_rpi;
336 uint16_t scsi_xri_max;
337 uint16_t scsi_xri_cnt;
338 struct list_head lpfc_free_sgl_list;
339 struct list_head lpfc_sgl_list;
340 struct lpfc_sglq **lpfc_els_sgl_array;
341 struct list_head lpfc_abts_els_sgl_list;
342 struct lpfc_scsi_buf **lpfc_scsi_psb_array;
343 struct list_head lpfc_abts_scsi_buf_list;
344 uint32_t total_sglq_bufs;
345 struct lpfc_sglq **lpfc_sglq_active_list;
346 struct list_head lpfc_rpi_hdr_list;
347 unsigned long *rpi_bmask;
348 uint16_t rpi_count;
349 struct lpfc_sli4_flags sli4_flags;
350 struct list_head sp_rspiocb_work_queue;
351 struct list_head sp_cqe_event_pool;
352 struct list_head sp_asynce_work_queue;
353 struct list_head sp_fcp_xri_aborted_work_queue;
354 struct list_head sp_els_xri_aborted_work_queue;
355 struct list_head sp_unsol_work_queue;
356 struct lpfc_sli4_link link_state;
357 spinlock_t abts_scsi_buf_list_lock; /* list of aborted SCSI IOs */
358 spinlock_t abts_sgl_list_lock; /* list of aborted els IOs */
359};
360
361enum lpfc_sge_type {
362 GEN_BUFF_TYPE,
363 SCSI_BUFF_TYPE
364};
365
366struct lpfc_sglq {
367 /* lpfc_sglqs are used in double linked lists */
368 struct list_head list;
369 struct list_head clist;
370 enum lpfc_sge_type buff_type; /* is this a scsi sgl */
371 uint16_t iotag; /* pre-assigned IO tag */
372 uint16_t sli4_xritag; /* pre-assigned XRI, (OXID) tag. */
373 struct sli4_sge *sgl; /* pre-assigned SGL */
374 void *virt; /* virtual address. */
375 dma_addr_t phys; /* physical address */
376};
377
378struct lpfc_rpi_hdr {
379 struct list_head list;
380 uint32_t len;
381 struct lpfc_dmabuf *dmabuf;
382 uint32_t page_count;
383 uint32_t start_rpi;
384};
385
386/*
387 * SLI4 specific function prototypes
388 */
389int lpfc_pci_function_reset(struct lpfc_hba *);
390int lpfc_sli4_hba_setup(struct lpfc_hba *);
391int lpfc_sli4_hba_down(struct lpfc_hba *);
392int lpfc_sli4_config(struct lpfc_hba *, struct lpfcMboxq *, uint8_t,
393 uint8_t, uint32_t, bool);
394void lpfc_sli4_mbox_cmd_free(struct lpfc_hba *, struct lpfcMboxq *);
395void lpfc_sli4_mbx_sge_set(struct lpfcMboxq *, uint32_t, dma_addr_t, uint32_t);
396void lpfc_sli4_mbx_sge_get(struct lpfcMboxq *, uint32_t,
397 struct lpfc_mbx_sge *);
398
399void lpfc_sli4_hba_reset(struct lpfc_hba *);
400struct lpfc_queue *lpfc_sli4_queue_alloc(struct lpfc_hba *, uint32_t,
401 uint32_t);
402void lpfc_sli4_queue_free(struct lpfc_queue *);
403uint32_t lpfc_eq_create(struct lpfc_hba *, struct lpfc_queue *, uint16_t);
404uint32_t lpfc_cq_create(struct lpfc_hba *, struct lpfc_queue *,
405 struct lpfc_queue *, uint32_t, uint32_t);
406uint32_t lpfc_mq_create(struct lpfc_hba *, struct lpfc_queue *,
407 struct lpfc_queue *, uint32_t);
408uint32_t lpfc_wq_create(struct lpfc_hba *, struct lpfc_queue *,
409 struct lpfc_queue *, uint32_t);
410uint32_t lpfc_rq_create(struct lpfc_hba *, struct lpfc_queue *,
411 struct lpfc_queue *, struct lpfc_queue *, uint32_t);
412uint32_t lpfc_eq_destroy(struct lpfc_hba *, struct lpfc_queue *);
413uint32_t lpfc_cq_destroy(struct lpfc_hba *, struct lpfc_queue *);
414uint32_t lpfc_mq_destroy(struct lpfc_hba *, struct lpfc_queue *);
415uint32_t lpfc_wq_destroy(struct lpfc_hba *, struct lpfc_queue *);
416uint32_t lpfc_rq_destroy(struct lpfc_hba *, struct lpfc_queue *,
417 struct lpfc_queue *);
418int lpfc_sli4_queue_setup(struct lpfc_hba *);
419void lpfc_sli4_queue_unset(struct lpfc_hba *);
420int lpfc_sli4_post_sgl(struct lpfc_hba *, dma_addr_t, dma_addr_t, uint16_t);
421int lpfc_sli4_repost_scsi_sgl_list(struct lpfc_hba *);
422int lpfc_sli4_remove_all_sgl_pages(struct lpfc_hba *);
423uint16_t lpfc_sli4_next_xritag(struct lpfc_hba *);
424int lpfc_sli4_post_async_mbox(struct lpfc_hba *);
425int lpfc_sli4_post_sgl_list(struct lpfc_hba *phba);
426int lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *, struct list_head *, int);
427struct lpfc_cq_event *__lpfc_sli4_cq_event_alloc(struct lpfc_hba *);
428struct lpfc_cq_event *lpfc_sli4_cq_event_alloc(struct lpfc_hba *);
429void __lpfc_sli4_cq_event_release(struct lpfc_hba *, struct lpfc_cq_event *);
430void lpfc_sli4_cq_event_release(struct lpfc_hba *, struct lpfc_cq_event *);
431int lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *);
432int lpfc_sli4_post_rpi_hdr(struct lpfc_hba *, struct lpfc_rpi_hdr *);
433int lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *);
434struct lpfc_rpi_hdr *lpfc_sli4_create_rpi_hdr(struct lpfc_hba *);
435void lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *);
436int lpfc_sli4_alloc_rpi(struct lpfc_hba *);
437void lpfc_sli4_free_rpi(struct lpfc_hba *, int);
438void lpfc_sli4_remove_rpis(struct lpfc_hba *);
439void lpfc_sli4_async_event_proc(struct lpfc_hba *);
440int lpfc_sli4_resume_rpi(struct lpfc_nodelist *);
441void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *);
442void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *);
443void lpfc_sli4_fcp_xri_aborted(struct lpfc_hba *,
444 struct sli4_wcqe_xri_aborted *);
445void lpfc_sli4_els_xri_aborted(struct lpfc_hba *,
446 struct sli4_wcqe_xri_aborted *);
447int lpfc_sli4_brdreset(struct lpfc_hba *);
448int lpfc_sli4_add_fcf_record(struct lpfc_hba *, struct fcf_record *);
449void lpfc_sli_remove_dflt_fcf(struct lpfc_hba *);
450int lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *);
451int lpfc_sli4_init_vpi(struct lpfc_hba *, uint16_t);
452uint32_t lpfc_sli4_cq_release(struct lpfc_queue *, bool);
453uint32_t lpfc_sli4_eq_release(struct lpfc_queue *, bool);
454void lpfc_sli4_fcfi_unreg(struct lpfc_hba *, uint16_t);
455int lpfc_sli4_read_fcf_record(struct lpfc_hba *, uint16_t);
456void lpfc_mbx_cmpl_read_fcf_record(struct lpfc_hba *, LPFC_MBOXQ_t *);
457int lpfc_sli4_post_status_check(struct lpfc_hba *);
458uint8_t lpfc_sli4_mbox_opcode_get(struct lpfc_hba *, struct lpfcMboxq *);
459