blob: 25d66d070cf8ff9e992b7bc164eaffd65bc336ec [file] [log] [blame]
James Smartda0436e2009-05-22 14:51:39 -04001/*******************************************************************
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
James Smart6669f9b2009-10-02 15:16:45 -040061#define sli4_sid_from_fc_hdr(fc_hdr) \
62 ((fc_hdr)->fh_s_id[0] << 16 | \
63 (fc_hdr)->fh_s_id[1] << 8 | \
64 (fc_hdr)->fh_s_id[2])
65
James Smart5ffc2662009-11-18 15:39:44 -050066#define sli4_fctl_from_fc_hdr(fc_hdr) \
67 ((fc_hdr)->fh_f_ctl[0] << 16 | \
68 (fc_hdr)->fh_f_ctl[1] << 8 | \
69 (fc_hdr)->fh_f_ctl[2])
70
James Smartda0436e2009-05-22 14:51:39 -040071enum lpfc_sli4_queue_type {
72 LPFC_EQ,
73 LPFC_GCQ,
74 LPFC_MCQ,
75 LPFC_WCQ,
76 LPFC_RCQ,
77 LPFC_MQ,
78 LPFC_WQ,
79 LPFC_HRQ,
80 LPFC_DRQ
81};
82
83/* The queue sub-type defines the functional purpose of the queue */
84enum lpfc_sli4_queue_subtype {
85 LPFC_NONE,
86 LPFC_MBOX,
87 LPFC_FCP,
88 LPFC_ELS,
89 LPFC_USOL
90};
91
92union sli4_qe {
93 void *address;
94 struct lpfc_eqe *eqe;
95 struct lpfc_cqe *cqe;
96 struct lpfc_mcqe *mcqe;
97 struct lpfc_wcqe_complete *wcqe_complete;
98 struct lpfc_wcqe_release *wcqe_release;
99 struct sli4_wcqe_xri_aborted *wcqe_xri_aborted;
100 struct lpfc_rcqe_complete *rcqe_complete;
101 struct lpfc_mqe *mqe;
102 union lpfc_wqe *wqe;
103 struct lpfc_rqe *rqe;
104};
105
106struct lpfc_queue {
107 struct list_head list;
108 enum lpfc_sli4_queue_type type;
109 enum lpfc_sli4_queue_subtype subtype;
110 struct lpfc_hba *phba;
111 struct list_head child_list;
112 uint32_t entry_count; /* Number of entries to support on the queue */
113 uint32_t entry_size; /* Size of each queue entry. */
114 uint32_t queue_id; /* Queue ID assigned by the hardware */
115 struct list_head page_list;
116 uint32_t page_count; /* Number of pages allocated for this queue */
117
118 uint32_t host_index; /* The host's index for putting or getting */
119 uint32_t hba_index; /* The last known hba index for get or put */
120 union sli4_qe qe[1]; /* array to index entries (must be last) */
121};
122
James Smartda0436e2009-05-22 14:51:39 -0400123struct lpfc_sli4_link {
124 uint8_t speed;
125 uint8_t duplex;
126 uint8_t status;
127 uint8_t physical;
128 uint8_t fault;
129};
130
131struct lpfc_fcf {
132 uint8_t fabric_name[8];
James Smart8fa38512009-07-19 10:01:03 -0400133 uint8_t switch_name[8];
James Smartda0436e2009-05-22 14:51:39 -0400134 uint8_t mac_addr[6];
135 uint16_t fcf_indx;
136 uint16_t fcfi;
137 uint32_t fcf_flag;
138#define FCF_AVAILABLE 0x01 /* FCF available for discovery */
139#define FCF_REGISTERED 0x02 /* FCF registered with FW */
140#define FCF_DISCOVERED 0x04 /* FCF discovery started */
141#define FCF_BOOT_ENABLE 0x08 /* Boot bios use this FCF */
142#define FCF_IN_USE 0x10 /* Atleast one discovery completed */
143#define FCF_VALID_VLAN 0x20 /* Use the vlan id specified */
144 uint32_t priority;
145 uint32_t addr_mode;
146 uint16_t vlan_id;
147};
148
149#define LPFC_REGION23_SIGNATURE "RG23"
150#define LPFC_REGION23_VERSION 1
151#define LPFC_REGION23_LAST_REC 0xff
James Smarta0c87cb2009-07-19 10:01:10 -0400152#define DRIVER_SPECIFIC_TYPE 0xA2
153#define LINUX_DRIVER_ID 0x20
154#define PORT_STE_TYPE 0x1
155
James Smartda0436e2009-05-22 14:51:39 -0400156struct lpfc_fip_param_hdr {
157 uint8_t type;
158#define FCOE_PARAM_TYPE 0xA0
159 uint8_t length;
160#define FCOE_PARAM_LENGTH 2
161 uint8_t parm_version;
162#define FIPP_VERSION 0x01
163 uint8_t parm_flags;
164#define lpfc_fip_param_hdr_fipp_mode_SHIFT 6
165#define lpfc_fip_param_hdr_fipp_mode_MASK 0x3
166#define lpfc_fip_param_hdr_fipp_mode_WORD parm_flags
James Smart6a9c52c2009-10-02 15:16:51 -0400167#define FIPP_MODE_ON 0x1
James Smartda0436e2009-05-22 14:51:39 -0400168#define FIPP_MODE_OFF 0x0
169#define FIPP_VLAN_VALID 0x1
170};
171
172struct lpfc_fcoe_params {
173 uint8_t fc_map[3];
174 uint8_t reserved1;
175 uint16_t vlan_tag;
176 uint8_t reserved[2];
177};
178
179struct lpfc_fcf_conn_hdr {
180 uint8_t type;
181#define FCOE_CONN_TBL_TYPE 0xA1
182 uint8_t length; /* words */
183 uint8_t reserved[2];
184};
185
186struct lpfc_fcf_conn_rec {
187 uint16_t flags;
188#define FCFCNCT_VALID 0x0001
189#define FCFCNCT_BOOT 0x0002
190#define FCFCNCT_PRIMARY 0x0004 /* if not set, Secondary */
191#define FCFCNCT_FBNM_VALID 0x0008
192#define FCFCNCT_SWNM_VALID 0x0010
193#define FCFCNCT_VLAN_VALID 0x0020
194#define FCFCNCT_AM_VALID 0x0040
195#define FCFCNCT_AM_PREFERRED 0x0080 /* if not set, AM Required */
196#define FCFCNCT_AM_SPMA 0x0100 /* if not set, FPMA */
197
198 uint16_t vlan_tag;
199 uint8_t fabric_name[8];
200 uint8_t switch_name[8];
201};
202
203struct lpfc_fcf_conn_entry {
204 struct list_head list;
205 struct lpfc_fcf_conn_rec conn_rec;
206};
207
208/*
209 * Define the host's bootstrap mailbox. This structure contains
210 * the member attributes needed to create, use, and destroy the
211 * bootstrap mailbox region.
212 *
213 * The macro definitions for the bmbx data structure are defined
214 * in lpfc_hw4.h with the register definition.
215 */
216struct lpfc_bmbx {
217 struct lpfc_dmabuf *dmabuf;
218 struct dma_address dma_address;
219 void *avirt;
220 dma_addr_t aphys;
221 uint32_t bmbx_size;
222};
223
224#define LPFC_EQE_SIZE LPFC_EQE_SIZE_4
225
226#define LPFC_EQE_SIZE_4B 4
227#define LPFC_EQE_SIZE_16B 16
228#define LPFC_CQE_SIZE 16
229#define LPFC_WQE_SIZE 64
230#define LPFC_MQE_SIZE 256
231#define LPFC_RQE_SIZE 8
232
233#define LPFC_EQE_DEF_COUNT 1024
234#define LPFC_CQE_DEF_COUNT 256
James Smartf1126682009-06-10 17:22:44 -0400235#define LPFC_WQE_DEF_COUNT 256
James Smartda0436e2009-05-22 14:51:39 -0400236#define LPFC_MQE_DEF_COUNT 16
237#define LPFC_RQE_DEF_COUNT 512
238
239#define LPFC_QUEUE_NOARM false
240#define LPFC_QUEUE_REARM true
241
242
243/*
244 * SLI4 CT field defines
245 */
246#define SLI4_CT_RPI 0
247#define SLI4_CT_VPI 1
248#define SLI4_CT_VFI 2
249#define SLI4_CT_FCFI 3
250
251#define LPFC_SLI4_MAX_SEGMENT_SIZE 0x10000
252
253/*
254 * SLI4 specific data structures
255 */
256struct lpfc_max_cfg_param {
257 uint16_t max_xri;
258 uint16_t xri_base;
259 uint16_t xri_used;
260 uint16_t max_rpi;
261 uint16_t rpi_base;
262 uint16_t rpi_used;
263 uint16_t max_vpi;
264 uint16_t vpi_base;
265 uint16_t vpi_used;
266 uint16_t max_vfi;
267 uint16_t vfi_base;
268 uint16_t vfi_used;
269 uint16_t max_fcfi;
270 uint16_t fcfi_base;
271 uint16_t fcfi_used;
272 uint16_t max_eq;
273 uint16_t max_rq;
274 uint16_t max_cq;
275 uint16_t max_wq;
276};
277
278struct lpfc_hba;
279/* SLI4 HBA multi-fcp queue handler struct */
280struct lpfc_fcp_eq_hdl {
281 uint32_t idx;
282 struct lpfc_hba *phba;
283};
284
285/* SLI4 HBA data structure entries */
286struct lpfc_sli4_hba {
287 void __iomem *conf_regs_memmap_p; /* Kernel memory mapped address for
288 PCI BAR0, config space registers */
289 void __iomem *ctrl_regs_memmap_p; /* Kernel memory mapped address for
290 PCI BAR1, control registers */
291 void __iomem *drbl_regs_memmap_p; /* Kernel memory mapped address for
292 PCI BAR2, doorbell registers */
293 /* BAR0 PCI config space register memory map */
294 void __iomem *UERRLOregaddr; /* Address to UERR_STATUS_LO register */
295 void __iomem *UERRHIregaddr; /* Address to UERR_STATUS_HI register */
James Smarta747c9c2009-11-18 15:41:10 -0500296 void __iomem *UEMASKLOregaddr; /* Address to UE_MASK_LO register */
297 void __iomem *UEMASKHIregaddr; /* Address to UE_MASK_HI register */
James Smartda0436e2009-05-22 14:51:39 -0400298 void __iomem *SCRATCHPADregaddr; /* Address to scratchpad register */
299 /* BAR1 FCoE function CSR register memory map */
300 void __iomem *STAregaddr; /* Address to HST_STATE register */
301 void __iomem *ISRregaddr; /* Address to HST_ISR register */
302 void __iomem *IMRregaddr; /* Address to HST_IMR register */
303 void __iomem *ISCRregaddr; /* Address to HST_ISCR register */
304 /* BAR2 VF-0 doorbell register memory map */
305 void __iomem *RQDBregaddr; /* Address to RQ_DOORBELL register */
306 void __iomem *WQDBregaddr; /* Address to WQ_DOORBELL register */
307 void __iomem *EQCQDBregaddr; /* Address to EQCQ_DOORBELL register */
308 void __iomem *MQDBregaddr; /* Address to MQ_DOORBELL register */
309 void __iomem *BMBXregaddr; /* Address to BootStrap MBX register */
310
James Smarta747c9c2009-11-18 15:41:10 -0500311 uint32_t ue_mask_lo;
312 uint32_t ue_mask_hi;
James Smartda0436e2009-05-22 14:51:39 -0400313 struct msix_entry *msix_entries;
314 uint32_t cfg_eqn;
315 struct lpfc_fcp_eq_hdl *fcp_eq_hdl; /* FCP per-WQ handle */
316 /* Pointers to the constructed SLI4 queues */
317 struct lpfc_queue **fp_eq; /* Fast-path event queue */
318 struct lpfc_queue *sp_eq; /* Slow-path event queue */
319 struct lpfc_queue **fcp_wq;/* Fast-path FCP work queue */
320 struct lpfc_queue *mbx_wq; /* Slow-path MBOX work queue */
321 struct lpfc_queue *els_wq; /* Slow-path ELS work queue */
322 struct lpfc_queue *hdr_rq; /* Slow-path Header Receive queue */
323 struct lpfc_queue *dat_rq; /* Slow-path Data Receive queue */
324 struct lpfc_queue **fcp_cq;/* Fast-path FCP compl queue */
325 struct lpfc_queue *mbx_cq; /* Slow-path mailbox complete queue */
326 struct lpfc_queue *els_cq; /* Slow-path ELS response complete queue */
James Smartda0436e2009-05-22 14:51:39 -0400327
328 /* Setup information for various queue parameters */
329 int eq_esize;
330 int eq_ecount;
331 int cq_esize;
332 int cq_ecount;
333 int wq_esize;
334 int wq_ecount;
335 int mq_esize;
336 int mq_ecount;
337 int rq_esize;
338 int rq_ecount;
339#define LPFC_SP_EQ_MAX_INTR_SEC 10000
340#define LPFC_FP_EQ_MAX_INTR_SEC 10000
341
342 uint32_t intr_enable;
343 struct lpfc_bmbx bmbx;
344 struct lpfc_max_cfg_param max_cfg_param;
345 uint16_t next_xri; /* last_xri - max_cfg_param.xri_base = used */
346 uint16_t next_rpi;
347 uint16_t scsi_xri_max;
348 uint16_t scsi_xri_cnt;
349 struct list_head lpfc_free_sgl_list;
350 struct list_head lpfc_sgl_list;
351 struct lpfc_sglq **lpfc_els_sgl_array;
352 struct list_head lpfc_abts_els_sgl_list;
353 struct lpfc_scsi_buf **lpfc_scsi_psb_array;
354 struct list_head lpfc_abts_scsi_buf_list;
355 uint32_t total_sglq_bufs;
356 struct lpfc_sglq **lpfc_sglq_active_list;
357 struct list_head lpfc_rpi_hdr_list;
358 unsigned long *rpi_bmask;
359 uint16_t rpi_count;
360 struct lpfc_sli4_flags sli4_flags;
James Smart45ed1192009-10-02 15:17:02 -0400361 struct list_head sp_queue_event;
James Smartda0436e2009-05-22 14:51:39 -0400362 struct list_head sp_cqe_event_pool;
363 struct list_head sp_asynce_work_queue;
364 struct list_head sp_fcp_xri_aborted_work_queue;
365 struct list_head sp_els_xri_aborted_work_queue;
366 struct list_head sp_unsol_work_queue;
367 struct lpfc_sli4_link link_state;
368 spinlock_t abts_scsi_buf_list_lock; /* list of aborted SCSI IOs */
369 spinlock_t abts_sgl_list_lock; /* list of aborted els IOs */
370};
371
372enum lpfc_sge_type {
373 GEN_BUFF_TYPE,
374 SCSI_BUFF_TYPE
375};
376
377struct lpfc_sglq {
378 /* lpfc_sglqs are used in double linked lists */
379 struct list_head list;
380 struct list_head clist;
381 enum lpfc_sge_type buff_type; /* is this a scsi sgl */
382 uint16_t iotag; /* pre-assigned IO tag */
383 uint16_t sli4_xritag; /* pre-assigned XRI, (OXID) tag. */
384 struct sli4_sge *sgl; /* pre-assigned SGL */
385 void *virt; /* virtual address. */
386 dma_addr_t phys; /* physical address */
387};
388
389struct lpfc_rpi_hdr {
390 struct list_head list;
391 uint32_t len;
392 struct lpfc_dmabuf *dmabuf;
393 uint32_t page_count;
394 uint32_t start_rpi;
395};
396
397/*
398 * SLI4 specific function prototypes
399 */
400int lpfc_pci_function_reset(struct lpfc_hba *);
401int lpfc_sli4_hba_setup(struct lpfc_hba *);
402int lpfc_sli4_hba_down(struct lpfc_hba *);
403int lpfc_sli4_config(struct lpfc_hba *, struct lpfcMboxq *, uint8_t,
404 uint8_t, uint32_t, bool);
405void lpfc_sli4_mbox_cmd_free(struct lpfc_hba *, struct lpfcMboxq *);
406void lpfc_sli4_mbx_sge_set(struct lpfcMboxq *, uint32_t, dma_addr_t, uint32_t);
407void lpfc_sli4_mbx_sge_get(struct lpfcMboxq *, uint32_t,
408 struct lpfc_mbx_sge *);
409
410void lpfc_sli4_hba_reset(struct lpfc_hba *);
411struct lpfc_queue *lpfc_sli4_queue_alloc(struct lpfc_hba *, uint32_t,
412 uint32_t);
413void lpfc_sli4_queue_free(struct lpfc_queue *);
414uint32_t lpfc_eq_create(struct lpfc_hba *, struct lpfc_queue *, uint16_t);
415uint32_t lpfc_cq_create(struct lpfc_hba *, struct lpfc_queue *,
416 struct lpfc_queue *, uint32_t, uint32_t);
417uint32_t lpfc_mq_create(struct lpfc_hba *, struct lpfc_queue *,
418 struct lpfc_queue *, uint32_t);
419uint32_t lpfc_wq_create(struct lpfc_hba *, struct lpfc_queue *,
420 struct lpfc_queue *, uint32_t);
421uint32_t lpfc_rq_create(struct lpfc_hba *, struct lpfc_queue *,
422 struct lpfc_queue *, struct lpfc_queue *, uint32_t);
423uint32_t lpfc_eq_destroy(struct lpfc_hba *, struct lpfc_queue *);
424uint32_t lpfc_cq_destroy(struct lpfc_hba *, struct lpfc_queue *);
425uint32_t lpfc_mq_destroy(struct lpfc_hba *, struct lpfc_queue *);
426uint32_t lpfc_wq_destroy(struct lpfc_hba *, struct lpfc_queue *);
427uint32_t lpfc_rq_destroy(struct lpfc_hba *, struct lpfc_queue *,
428 struct lpfc_queue *);
429int lpfc_sli4_queue_setup(struct lpfc_hba *);
430void lpfc_sli4_queue_unset(struct lpfc_hba *);
431int lpfc_sli4_post_sgl(struct lpfc_hba *, dma_addr_t, dma_addr_t, uint16_t);
432int lpfc_sli4_repost_scsi_sgl_list(struct lpfc_hba *);
433int lpfc_sli4_remove_all_sgl_pages(struct lpfc_hba *);
434uint16_t lpfc_sli4_next_xritag(struct lpfc_hba *);
435int lpfc_sli4_post_async_mbox(struct lpfc_hba *);
436int lpfc_sli4_post_sgl_list(struct lpfc_hba *phba);
437int lpfc_sli4_post_scsi_sgl_block(struct lpfc_hba *, struct list_head *, int);
438struct lpfc_cq_event *__lpfc_sli4_cq_event_alloc(struct lpfc_hba *);
439struct lpfc_cq_event *lpfc_sli4_cq_event_alloc(struct lpfc_hba *);
440void __lpfc_sli4_cq_event_release(struct lpfc_hba *, struct lpfc_cq_event *);
441void lpfc_sli4_cq_event_release(struct lpfc_hba *, struct lpfc_cq_event *);
442int lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *);
443int lpfc_sli4_post_rpi_hdr(struct lpfc_hba *, struct lpfc_rpi_hdr *);
444int lpfc_sli4_post_all_rpi_hdrs(struct lpfc_hba *);
445struct lpfc_rpi_hdr *lpfc_sli4_create_rpi_hdr(struct lpfc_hba *);
446void lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *);
447int lpfc_sli4_alloc_rpi(struct lpfc_hba *);
448void lpfc_sli4_free_rpi(struct lpfc_hba *, int);
449void lpfc_sli4_remove_rpis(struct lpfc_hba *);
450void lpfc_sli4_async_event_proc(struct lpfc_hba *);
451int lpfc_sli4_resume_rpi(struct lpfc_nodelist *);
452void lpfc_sli4_fcp_xri_abort_event_proc(struct lpfc_hba *);
453void lpfc_sli4_els_xri_abort_event_proc(struct lpfc_hba *);
454void lpfc_sli4_fcp_xri_aborted(struct lpfc_hba *,
455 struct sli4_wcqe_xri_aborted *);
456void lpfc_sli4_els_xri_aborted(struct lpfc_hba *,
457 struct sli4_wcqe_xri_aborted *);
458int lpfc_sli4_brdreset(struct lpfc_hba *);
459int lpfc_sli4_add_fcf_record(struct lpfc_hba *, struct fcf_record *);
460void lpfc_sli_remove_dflt_fcf(struct lpfc_hba *);
461int lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *);
462int lpfc_sli4_init_vpi(struct lpfc_hba *, uint16_t);
463uint32_t lpfc_sli4_cq_release(struct lpfc_queue *, bool);
464uint32_t lpfc_sli4_eq_release(struct lpfc_queue *, bool);
465void lpfc_sli4_fcfi_unreg(struct lpfc_hba *, uint16_t);
466int lpfc_sli4_read_fcf_record(struct lpfc_hba *, uint16_t);
467void lpfc_mbx_cmpl_read_fcf_record(struct lpfc_hba *, LPFC_MBOXQ_t *);
468int lpfc_sli4_post_status_check(struct lpfc_hba *);
469uint8_t lpfc_sli4_mbox_opcode_get(struct lpfc_hba *, struct lpfcMboxq *);
470