1/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for         *
3 * Fibre Channel Host Bus Adapters.                                *
4 * Copyright (C) 2004-2007 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
21typedef int (*node_filter)(struct lpfc_nodelist *ndlp, void *param);
22
23struct fc_rport;
24void lpfc_dump_mem(struct lpfc_hba *, LPFC_MBOXQ_t *, uint16_t);
25void lpfc_read_nv(struct lpfc_hba *, LPFC_MBOXQ_t *);
26int lpfc_read_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb,
27		 struct lpfc_dmabuf *mp);
28void lpfc_clear_la(struct lpfc_hba *, LPFC_MBOXQ_t *);
29void lpfc_config_link(struct lpfc_hba *, LPFC_MBOXQ_t *);
30int lpfc_read_sparam(struct lpfc_hba *, LPFC_MBOXQ_t *);
31void lpfc_read_config(struct lpfc_hba *, LPFC_MBOXQ_t *);
32void lpfc_read_lnk_stat(struct lpfc_hba *, LPFC_MBOXQ_t *);
33int lpfc_reg_login(struct lpfc_hba *, uint32_t, uint8_t *, LPFC_MBOXQ_t *,
34		   uint32_t);
35void lpfc_unreg_login(struct lpfc_hba *, uint32_t, LPFC_MBOXQ_t *);
36void lpfc_unreg_did(struct lpfc_hba *, uint32_t, LPFC_MBOXQ_t *);
37void lpfc_init_link(struct lpfc_hba *, LPFC_MBOXQ_t *, uint32_t, uint32_t);
38
39
40int lpfc_linkdown(struct lpfc_hba *);
41void lpfc_mbx_cmpl_read_la(struct lpfc_hba *, LPFC_MBOXQ_t *);
42
43void lpfc_mbx_cmpl_clear_la(struct lpfc_hba *, LPFC_MBOXQ_t *);
44void lpfc_mbx_cmpl_reg_login(struct lpfc_hba *, LPFC_MBOXQ_t *);
45void lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba *, LPFC_MBOXQ_t *);
46void lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba *, LPFC_MBOXQ_t *);
47void lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba *, LPFC_MBOXQ_t *);
48void lpfc_dequeue_node(struct lpfc_hba *, struct lpfc_nodelist *);
49void lpfc_nlp_set_state(struct lpfc_hba *, struct lpfc_nodelist *, int);
50void lpfc_drop_node(struct lpfc_hba *, struct lpfc_nodelist *);
51void lpfc_set_disctmo(struct lpfc_hba *);
52int lpfc_can_disctmo(struct lpfc_hba *);
53int lpfc_unreg_rpi(struct lpfc_hba *, struct lpfc_nodelist *);
54int lpfc_check_sli_ndlp(struct lpfc_hba *, struct lpfc_sli_ring *,
55		    struct lpfc_iocbq *, struct lpfc_nodelist *);
56void lpfc_nlp_init(struct lpfc_hba *, struct lpfc_nodelist *, uint32_t);
57struct lpfc_nodelist *lpfc_nlp_get(struct lpfc_nodelist *);
58int  lpfc_nlp_put(struct lpfc_nodelist *);
59struct lpfc_nodelist *lpfc_setup_disc_node(struct lpfc_hba *, uint32_t);
60void lpfc_disc_list_loopmap(struct lpfc_hba *);
61void lpfc_disc_start(struct lpfc_hba *);
62void lpfc_disc_flush_list(struct lpfc_hba *);
63void lpfc_disc_timeout(unsigned long);
64
65struct lpfc_nodelist *__lpfc_findnode_rpi(struct lpfc_hba * phba, uint16_t rpi);
66struct lpfc_nodelist *lpfc_findnode_rpi(struct lpfc_hba * phba, uint16_t rpi);
67
68int lpfc_workq_post_event(struct lpfc_hba *, void *, void *, uint32_t);
69int lpfc_do_work(void *);
70int lpfc_disc_state_machine(struct lpfc_hba *, struct lpfc_nodelist *, void *,
71			    uint32_t);
72
73int lpfc_check_sparm(struct lpfc_hba *, struct lpfc_nodelist *,
74		     struct serv_parm *, uint32_t);
75int lpfc_els_abort(struct lpfc_hba *, struct lpfc_nodelist * ndlp);
76int lpfc_els_abort_flogi(struct lpfc_hba *);
77int lpfc_initial_flogi(struct lpfc_hba *);
78int lpfc_issue_els_plogi(struct lpfc_hba *, uint32_t, uint8_t);
79int lpfc_issue_els_prli(struct lpfc_hba *, struct lpfc_nodelist *, uint8_t);
80int lpfc_issue_els_adisc(struct lpfc_hba *, struct lpfc_nodelist *, uint8_t);
81int lpfc_issue_els_logo(struct lpfc_hba *, struct lpfc_nodelist *, uint8_t);
82int lpfc_issue_els_scr(struct lpfc_hba *, uint32_t, uint8_t);
83int lpfc_els_free_iocb(struct lpfc_hba *, struct lpfc_iocbq *);
84int lpfc_els_rsp_acc(struct lpfc_hba *, uint32_t, struct lpfc_iocbq *,
85		     struct lpfc_nodelist *, LPFC_MBOXQ_t *, uint8_t);
86int lpfc_els_rsp_reject(struct lpfc_hba *, uint32_t, struct lpfc_iocbq *,
87			struct lpfc_nodelist *);
88int lpfc_els_rsp_adisc_acc(struct lpfc_hba *, struct lpfc_iocbq *,
89			   struct lpfc_nodelist *);
90int lpfc_els_rsp_prli_acc(struct lpfc_hba *, struct lpfc_iocbq *,
91			  struct lpfc_nodelist *);
92void lpfc_cancel_retry_delay_tmo(struct lpfc_hba *, struct lpfc_nodelist *);
93void lpfc_els_retry_delay(unsigned long);
94void lpfc_els_retry_delay_handler(struct lpfc_nodelist *);
95void lpfc_els_unsol_event(struct lpfc_hba *, struct lpfc_sli_ring *,
96			  struct lpfc_iocbq *);
97int lpfc_els_handle_rscn(struct lpfc_hba *);
98int lpfc_els_flush_rscn(struct lpfc_hba *);
99int lpfc_rscn_payload_check(struct lpfc_hba *, uint32_t);
100void lpfc_els_flush_cmd(struct lpfc_hba *);
101int lpfc_els_disc_adisc(struct lpfc_hba *);
102int lpfc_els_disc_plogi(struct lpfc_hba *);
103void lpfc_els_timeout(unsigned long);
104void lpfc_els_timeout_handler(struct lpfc_hba *);
105
106void lpfc_ct_unsol_event(struct lpfc_hba *, struct lpfc_sli_ring *,
107			 struct lpfc_iocbq *);
108int lpfc_ns_cmd(struct lpfc_hba *, struct lpfc_nodelist *, int);
109int lpfc_fdmi_cmd(struct lpfc_hba *, struct lpfc_nodelist *, int);
110void lpfc_fdmi_tmo(unsigned long);
111void lpfc_fdmi_tmo_handler(struct lpfc_hba *);
112
113int lpfc_config_port_prep(struct lpfc_hba *);
114int lpfc_config_port_post(struct lpfc_hba *);
115int lpfc_hba_down_prep(struct lpfc_hba *);
116int lpfc_hba_down_post(struct lpfc_hba *);
117void lpfc_hba_init(struct lpfc_hba *, uint32_t *);
118int lpfc_post_buffer(struct lpfc_hba *, struct lpfc_sli_ring *, int, int);
119void lpfc_decode_firmware_rev(struct lpfc_hba *, char *, int);
120int lpfc_online(struct lpfc_hba *);
121void lpfc_block_mgmt_io(struct lpfc_hba *);
122void lpfc_unblock_mgmt_io(struct lpfc_hba *);
123void lpfc_offline_prep(struct lpfc_hba *);
124void lpfc_offline(struct lpfc_hba *);
125
126int lpfc_sli_setup(struct lpfc_hba *);
127int lpfc_sli_queue_setup(struct lpfc_hba *);
128
129void lpfc_handle_eratt(struct lpfc_hba *);
130void lpfc_handle_latt(struct lpfc_hba *);
131irqreturn_t lpfc_intr_handler(int, void *);
132
133void lpfc_read_rev(struct lpfc_hba *, LPFC_MBOXQ_t *);
134void lpfc_config_ring(struct lpfc_hba *, int, LPFC_MBOXQ_t *);
135void lpfc_config_port(struct lpfc_hba *, LPFC_MBOXQ_t *);
136void lpfc_kill_board(struct lpfc_hba *, LPFC_MBOXQ_t *);
137void lpfc_mbox_put(struct lpfc_hba *, LPFC_MBOXQ_t *);
138LPFC_MBOXQ_t *lpfc_mbox_get(struct lpfc_hba *);
139int lpfc_mbox_tmo_val(struct lpfc_hba *, int);
140
141int lpfc_mem_alloc(struct lpfc_hba *);
142void lpfc_mem_free(struct lpfc_hba *);
143
144void lpfc_poll_timeout(unsigned long ptr);
145void lpfc_poll_start_timer(struct lpfc_hba * phba);
146void lpfc_sli_poll_fcp_ring(struct lpfc_hba * hba);
147struct lpfc_iocbq * lpfc_sli_get_iocbq(struct lpfc_hba *);
148void lpfc_sli_release_iocbq(struct lpfc_hba * phba, struct lpfc_iocbq * iocb);
149uint16_t lpfc_sli_next_iotag(struct lpfc_hba * phba, struct lpfc_iocbq * iocb);
150
151void lpfc_reset_barrier(struct lpfc_hba * phba);
152int lpfc_sli_brdready(struct lpfc_hba *, uint32_t);
153int lpfc_sli_brdkill(struct lpfc_hba *);
154int lpfc_sli_brdreset(struct lpfc_hba *);
155int lpfc_sli_brdrestart(struct lpfc_hba *);
156int lpfc_sli_hba_setup(struct lpfc_hba *);
157int lpfc_sli_hba_down(struct lpfc_hba *);
158int lpfc_sli_issue_mbox(struct lpfc_hba *, LPFC_MBOXQ_t *, uint32_t);
159int lpfc_sli_handle_mb_event(struct lpfc_hba *);
160int lpfc_sli_flush_mbox_queue(struct lpfc_hba *);
161int lpfc_sli_handle_slow_ring_event(struct lpfc_hba *,
162				    struct lpfc_sli_ring *, uint32_t);
163void lpfc_sli_def_mbox_cmpl(struct lpfc_hba *, LPFC_MBOXQ_t *);
164int lpfc_sli_issue_iocb(struct lpfc_hba *, struct lpfc_sli_ring *,
165			struct lpfc_iocbq *, uint32_t);
166void lpfc_sli_pcimem_bcopy(void *, void *, uint32_t);
167int lpfc_sli_abort_iocb_ring(struct lpfc_hba *, struct lpfc_sli_ring *);
168int lpfc_sli_ringpostbuf_put(struct lpfc_hba *, struct lpfc_sli_ring *,
169			     struct lpfc_dmabuf *);
170struct lpfc_dmabuf *lpfc_sli_ringpostbuf_get(struct lpfc_hba *,
171					     struct lpfc_sli_ring *,
172					     dma_addr_t);
173int lpfc_sli_issue_abort_iotag(struct lpfc_hba *, struct lpfc_sli_ring *,
174			       struct lpfc_iocbq *);
175int lpfc_sli_sum_iocb(struct lpfc_hba *, struct lpfc_sli_ring *, uint16_t,
176			  uint64_t, lpfc_ctx_cmd);
177int lpfc_sli_abort_iocb(struct lpfc_hba *, struct lpfc_sli_ring *, uint16_t,
178			    uint64_t, uint32_t, lpfc_ctx_cmd);
179
180void lpfc_mbox_timeout(unsigned long);
181void lpfc_mbox_timeout_handler(struct lpfc_hba *);
182
183struct lpfc_nodelist *lpfc_findnode_did(struct lpfc_hba *, uint32_t);
184struct lpfc_nodelist *lpfc_findnode_wwpn(struct lpfc_hba *, struct lpfc_name *);
185
186int lpfc_sli_issue_mbox_wait(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq,
187			 uint32_t timeout);
188
189int lpfc_sli_issue_iocb_wait(struct lpfc_hba * phba,
190			     struct lpfc_sli_ring * pring,
191			     struct lpfc_iocbq * piocb,
192			     struct lpfc_iocbq * prspiocbq,
193			     uint32_t timeout);
194void lpfc_sli_abort_fcp_cmpl(struct lpfc_hba * phba,
195			     struct lpfc_iocbq * cmdiocb,
196			     struct lpfc_iocbq * rspiocb);
197
198void *lpfc_mbuf_alloc(struct lpfc_hba *, int, dma_addr_t *);
199void lpfc_mbuf_free(struct lpfc_hba *, void *, dma_addr_t);
200
201/* Function prototypes. */
202const char* lpfc_info(struct Scsi_Host *);
203void lpfc_scan_start(struct Scsi_Host *);
204int lpfc_scan_finished(struct Scsi_Host *, unsigned long);
205
206void lpfc_get_cfgparam(struct lpfc_hba *);
207int lpfc_alloc_sysfs_attr(struct lpfc_hba *);
208void lpfc_free_sysfs_attr(struct lpfc_hba *);
209extern struct class_device_attribute *lpfc_host_attrs[];
210extern struct scsi_host_template lpfc_template;
211extern struct fc_function_template lpfc_transport_functions;
212
213void lpfc_get_hba_sym_node_name(struct lpfc_hba * phba, uint8_t * symbp);
214void lpfc_terminate_rport_io(struct fc_rport *);
215void lpfc_dev_loss_tmo_callbk(struct fc_rport *rport);
216
217#define ScsiResult(host_code, scsi_code) (((host_code) << 16) | scsi_code)
218#define HBA_EVENT_RSCN                   5
219#define HBA_EVENT_LINK_UP                2
220#define HBA_EVENT_LINK_DOWN              3
221