f2c30858900bb36d1be0f4960103dcf9657c27be
[safe/jmp/linux-2.6] / drivers / scsi / bfa / include / bfa_svc.h
1 /*
2  * Copyright (c) 2005-2009 Brocade Communications Systems, Inc.
3  * All rights reserved
4  * www.brocade.com
5  *
6  * Linux driver for Brocade Fibre Channel Host Bus Adapter.
7  *
8  * This program is free software; you can redistribute it and/or modify it
9  * under the terms of the GNU General Public License (GPL) Version 2 as
10  * published by the Free Software Foundation
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License for more details.
16  */
17 #ifndef __BFA_SVC_H__
18 #define __BFA_SVC_H__
19
20 /*
21  * forward declarations
22  */
23 struct bfa_fcxp_s;
24
25 #include <defs/bfa_defs_status.h>
26 #include <defs/bfa_defs_pport.h>
27 #include <defs/bfa_defs_rport.h>
28 #include <defs/bfa_defs_qos.h>
29 #include <defs/bfa_defs_fcport.h>
30 #include <cs/bfa_sm.h>
31 #include <bfa.h>
32
33 /**
34  *              BFA rport information.
35  */
36 struct bfa_rport_info_s {
37         u16        max_frmsz;   /*  max rcv pdu size               */
38         u32        pid:24,              /*  remote port ID                 */
39                         lp_tag:8;
40         u32        local_pid:24,        /*  local port ID                   */
41                         cisc:8;         /*  CIRO supported                  */
42         u8         fc_class;    /*  supported FC classes. enum fc_cos */
43         u8         vf_en;               /*  virtual fabric enable          */
44         u16        vf_id;               /*  virtual fabric ID              */
45         enum bfa_pport_speed speed;     /*  Rport's current speed           */
46 };
47
48 /**
49  * BFA rport data structure
50  */
51 struct bfa_rport_s {
52         struct list_head        qe;       /*  queue element */
53         bfa_sm_t              sm;         /*  state machine */
54         struct bfa_s          *bfa;       /*  backpointer to BFA */
55         void                  *rport_drv; /*  fcs/driver rport object */
56         u16              fw_handle; /*  firmware rport handle */
57         u16              rport_tag; /*  BFA rport tag */
58         struct bfa_rport_info_s rport_info; /*  rport info from *fcs/driver */
59         struct bfa_reqq_wait_s reqq_wait; /*  to wait for room in reqq */
60         struct bfa_cb_qe_s    hcb_qe;    /*  BFA callback qelem */
61         struct bfa_rport_hal_stats_s stats; /*  BFA rport statistics  */
62         struct bfa_rport_qos_attr_s  qos_attr;
63         union a {
64                 bfa_status_t    status;  /*  f/w status */
65                 void            *fw_msg; /*  QoS scn event */
66         } event_arg;
67 };
68 #define BFA_RPORT_FC_COS(_rport)        ((_rport)->rport_info.fc_class)
69
70 /**
71  * Send completion callback.
72  */
73 typedef void (*bfa_cb_fcxp_send_t) (void *bfad_fcxp, struct bfa_fcxp_s *fcxp,
74                         void *cbarg, enum bfa_status req_status,
75                         u32 rsp_len, u32 resid_len,
76                         struct fchs_s *rsp_fchs);
77
78 /**
79  * BFA fcxp allocation (asynchronous)
80  */
81 typedef void (*bfa_fcxp_alloc_cbfn_t) (void *cbarg, struct bfa_fcxp_s *fcxp);
82
83 struct bfa_fcxp_wqe_s {
84         struct list_head         qe;
85         bfa_fcxp_alloc_cbfn_t  alloc_cbfn;
86         void           *alloc_cbarg;
87 };
88
89 typedef u64 (*bfa_fcxp_get_sgaddr_t) (void *bfad_fcxp, int sgeid);
90 typedef u32 (*bfa_fcxp_get_sglen_t) (void *bfad_fcxp, int sgeid);
91
92 #define BFA_UF_BUFSZ    (2 * 1024 + 256)
93
94 /**
95  * @todo private
96  */
97 struct bfa_uf_buf_s {
98         u8         d[BFA_UF_BUFSZ];
99 };
100
101
102 struct bfa_uf_s {
103         struct list_head        qe;             /*  queue element         */
104         struct bfa_s    *bfa;           /*  bfa instance          */
105         u16        uf_tag;              /*  identifying tag f/w messages */
106         u16        vf_id;
107         u16        src_rport_handle;
108         u16        rsvd;
109         u8              *data_ptr;
110         u16        data_len;    /*  actual receive length         */
111         u16        pb_len;              /*  posted buffer length          */
112         void            *buf_kva;       /*  buffer virtual address        */
113         u64        buf_pa;              /*  buffer physical address       */
114         struct bfa_cb_qe_s    hcb_qe;   /*  comp: BFA comp qelem          */
115         struct bfa_sge_s        sges[BFI_SGE_INLINE_MAX];
116 };
117
118 typedef void (*bfa_cb_pport_t) (void *cbarg, enum bfa_status status);
119
120 /**
121  * bfa lport login/logout service interface
122  */
123 struct bfa_lps_s {
124         struct list_head        qe;             /*  queue element */
125         struct bfa_s    *bfa;           /*  parent bfa instance */
126         bfa_sm_t        sm;             /*  finite state machine        */
127         u8              lp_tag;         /*  lport tag                   */
128         u8              reqq;           /*  lport request queue */
129         u8              alpa;           /*  ALPA for loop topologies    */
130         u32     lp_pid;         /*  lport port ID               */
131         bfa_boolean_t   fdisc;          /*  send FDISC instead of FLOGI*/
132         bfa_boolean_t   auth_en;        /*  enable authentication       */
133         bfa_boolean_t   auth_req;       /*  authentication required     */
134         bfa_boolean_t   npiv_en;        /*  NPIV is allowed by peer     */
135         bfa_boolean_t   fport;          /*  attached peer is F_PORT     */
136         bfa_boolean_t   brcd_switch;/*  attached peer is brcd switch    */
137         bfa_status_t    status;         /*  login status                */
138         u16     pdusz;          /*  max receive PDU size        */
139         u16     pr_bbcred;      /*  BB_CREDIT from peer         */
140         u8              lsrjt_rsn;      /*  LSRJT reason                */
141         u8              lsrjt_expl;     /*  LSRJT explanation           */
142         wwn_t           pwwn;           /*  port wwn of lport           */
143         wwn_t           nwwn;           /*  node wwn of lport           */
144         wwn_t           pr_pwwn;        /*  port wwn of lport peer      */
145         wwn_t           pr_nwwn;        /*  node wwn of lport peer      */
146         mac_t           lp_mac;         /*  fpma/spma MAC for lport     */
147         mac_t           fcf_mac;        /*  FCF MAC of lport            */
148         struct bfa_reqq_wait_s  wqe;    /*  request wait queue element  */
149         void            *uarg;          /*  user callback arg           */
150         struct bfa_cb_qe_s hcb_qe;      /*  comp: callback qelem        */
151         struct bfi_lps_login_rsp_s *loginrsp;
152         bfa_eproto_status_t     ext_status;
153 };
154
155 #define BFA_FCPORT(_bfa)        (&((_bfa)->modules.port))
156
157 /*
158  * bfa pport API functions
159  */
160 bfa_status_t bfa_fcport_enable(struct bfa_s *bfa);
161 bfa_status_t bfa_fcport_disable(struct bfa_s *bfa);
162 bfa_status_t bfa_fcport_cfg_speed(struct bfa_s *bfa,
163                         enum bfa_pport_speed speed);
164 enum bfa_pport_speed bfa_fcport_get_speed(struct bfa_s *bfa);
165 bfa_status_t bfa_fcport_cfg_topology(struct bfa_s *bfa,
166                         enum bfa_pport_topology topo);
167 enum bfa_pport_topology bfa_fcport_get_topology(struct bfa_s *bfa);
168 bfa_status_t bfa_fcport_cfg_hardalpa(struct bfa_s *bfa, u8 alpa);
169 bfa_boolean_t bfa_fcport_get_hardalpa(struct bfa_s *bfa, u8 *alpa);
170 u8 bfa_fcport_get_myalpa(struct bfa_s *bfa);
171 bfa_status_t bfa_fcport_clr_hardalpa(struct bfa_s *bfa);
172 bfa_status_t bfa_fcport_cfg_maxfrsize(struct bfa_s *bfa, u16 maxsize);
173 u16 bfa_fcport_get_maxfrsize(struct bfa_s *bfa);
174 u32 bfa_fcport_mypid(struct bfa_s *bfa);
175 u8 bfa_fcport_get_rx_bbcredit(struct bfa_s *bfa);
176 bfa_status_t bfa_fcport_trunk_enable(struct bfa_s *bfa, u8 bitmap);
177 bfa_status_t bfa_fcport_trunk_disable(struct bfa_s *bfa);
178 bfa_boolean_t bfa_fcport_trunk_query(struct bfa_s *bfa, u32 *bitmap);
179 void bfa_fcport_get_attr(struct bfa_s *bfa, struct bfa_pport_attr_s *attr);
180 wwn_t bfa_fcport_get_wwn(struct bfa_s *bfa, bfa_boolean_t node);
181 bfa_status_t bfa_pport_get_stats(struct bfa_s *bfa,
182                         union bfa_pport_stats_u *stats,
183                         bfa_cb_pport_t cbfn, void *cbarg);
184 bfa_status_t bfa_pport_clear_stats(struct bfa_s *bfa, bfa_cb_pport_t cbfn,
185                         void *cbarg);
186 void bfa_fcport_event_register(struct bfa_s *bfa,
187                         void (*event_cbfn) (void *cbarg,
188                         bfa_pport_event_t event), void *event_cbarg);
189 bfa_boolean_t bfa_fcport_is_disabled(struct bfa_s *bfa);
190 void bfa_fcport_cfg_qos(struct bfa_s *bfa, bfa_boolean_t on_off);
191 void bfa_fcport_cfg_ratelim(struct bfa_s *bfa, bfa_boolean_t on_off);
192 bfa_status_t bfa_fcport_cfg_ratelim_speed(struct bfa_s *bfa,
193                         enum bfa_pport_speed speed);
194 enum bfa_pport_speed bfa_fcport_get_ratelim_speed(struct bfa_s *bfa);
195
196 void bfa_fcport_set_tx_bbcredit(struct bfa_s *bfa, u16 tx_bbcredit);
197 void bfa_fcport_busy(struct bfa_s *bfa, bfa_boolean_t status);
198 void bfa_fcport_beacon(struct bfa_s *bfa, bfa_boolean_t beacon,
199                         bfa_boolean_t link_e2e_beacon);
200 void bfa_cb_pport_event(void *cbarg, bfa_pport_event_t event);
201 void bfa_fcport_qos_get_attr(struct bfa_s *bfa, struct bfa_qos_attr_s *qos_attr);
202 void bfa_fcport_qos_get_vc_attr(struct bfa_s *bfa,
203                         struct bfa_qos_vc_attr_s *qos_vc_attr);
204 bfa_status_t bfa_fcport_get_qos_stats(struct bfa_s *bfa,
205                         union bfa_pport_stats_u *stats,
206                         bfa_cb_pport_t cbfn, void *cbarg);
207 bfa_status_t bfa_fcport_clear_qos_stats(struct bfa_s *bfa, bfa_cb_pport_t cbfn,
208                         void *cbarg);
209 bfa_boolean_t     bfa_fcport_is_ratelim(struct bfa_s *bfa);
210 bfa_boolean_t   bfa_fcport_is_linkup(struct bfa_s *bfa);
211 bfa_status_t bfa_fcport_get_stats(struct bfa_s *bfa,
212                 union bfa_fcport_stats_u *stats,
213                 bfa_cb_pport_t cbfn, void *cbarg);
214 bfa_status_t bfa_fcport_clear_stats(struct bfa_s *bfa, bfa_cb_pport_t cbfn,
215                 void *cbarg);
216
217 /*
218  * bfa rport API functions
219  */
220 struct bfa_rport_s *bfa_rport_create(struct bfa_s *bfa, void *rport_drv);
221 void bfa_rport_delete(struct bfa_rport_s *rport);
222 void bfa_rport_online(struct bfa_rport_s *rport,
223                         struct bfa_rport_info_s *rport_info);
224 void bfa_rport_offline(struct bfa_rport_s *rport);
225 void bfa_rport_speed(struct bfa_rport_s *rport, enum bfa_pport_speed speed);
226 void bfa_rport_get_stats(struct bfa_rport_s *rport,
227                         struct bfa_rport_hal_stats_s *stats);
228 void bfa_rport_clear_stats(struct bfa_rport_s *rport);
229 void bfa_cb_rport_online(void *rport);
230 void bfa_cb_rport_offline(void *rport);
231 void bfa_cb_rport_qos_scn_flowid(void *rport,
232                         struct bfa_rport_qos_attr_s old_qos_attr,
233                         struct bfa_rport_qos_attr_s new_qos_attr);
234 void bfa_cb_rport_qos_scn_prio(void *rport,
235                         struct bfa_rport_qos_attr_s old_qos_attr,
236                         struct bfa_rport_qos_attr_s new_qos_attr);
237 void bfa_rport_get_qos_attr(struct bfa_rport_s *rport,
238                         struct bfa_rport_qos_attr_s *qos_attr);
239
240 /*
241  * bfa fcxp API functions
242  */
243 struct bfa_fcxp_s *bfa_fcxp_alloc(void *bfad_fcxp, struct bfa_s *bfa,
244                         int nreq_sgles, int nrsp_sgles,
245                         bfa_fcxp_get_sgaddr_t get_req_sga,
246                         bfa_fcxp_get_sglen_t get_req_sglen,
247                         bfa_fcxp_get_sgaddr_t get_rsp_sga,
248                         bfa_fcxp_get_sglen_t get_rsp_sglen);
249 void bfa_fcxp_alloc_wait(struct bfa_s *bfa, struct bfa_fcxp_wqe_s *wqe,
250                         bfa_fcxp_alloc_cbfn_t alloc_cbfn, void *cbarg);
251 void bfa_fcxp_walloc_cancel(struct bfa_s *bfa,
252                         struct bfa_fcxp_wqe_s *wqe);
253 void bfa_fcxp_discard(struct bfa_fcxp_s *fcxp);
254
255 void *bfa_fcxp_get_reqbuf(struct bfa_fcxp_s *fcxp);
256 void *bfa_fcxp_get_rspbuf(struct bfa_fcxp_s *fcxp);
257
258 void bfa_fcxp_free(struct bfa_fcxp_s *fcxp);
259
260 void bfa_fcxp_send(struct bfa_fcxp_s *fcxp,
261                         struct bfa_rport_s *rport, u16 vf_id, u8 lp_tag,
262                         bfa_boolean_t cts, enum fc_cos cos,
263                         u32 reqlen, struct fchs_s *fchs,
264                         bfa_cb_fcxp_send_t cbfn,
265                         void *cbarg,
266                         u32 rsp_maxlen, u8 rsp_timeout);
267 bfa_status_t bfa_fcxp_abort(struct bfa_fcxp_s *fcxp);
268 u32        bfa_fcxp_get_reqbufsz(struct bfa_fcxp_s *fcxp);
269 u32     bfa_fcxp_get_maxrsp(struct bfa_s *bfa);
270
271 static inline void *
272 bfa_uf_get_frmbuf(struct bfa_uf_s *uf)
273 {
274         return uf->data_ptr;
275 }
276
277 static inline   u16
278 bfa_uf_get_frmlen(struct bfa_uf_s *uf)
279 {
280         return uf->data_len;
281 }
282
283 /**
284  *      Callback prototype for unsolicited frame receive handler.
285  *
286  * @param[in]           cbarg           callback arg for receive handler
287  * @param[in]           uf              unsolicited frame descriptor
288  *
289  * @return None
290  */
291 typedef void (*bfa_cb_uf_recv_t) (void *cbarg, struct bfa_uf_s *uf);
292
293 /*
294  * bfa uf API functions
295  */
296 void bfa_uf_recv_register(struct bfa_s *bfa, bfa_cb_uf_recv_t ufrecv,
297                         void *cbarg);
298 void bfa_uf_free(struct bfa_uf_s *uf);
299
300 /**
301  * bfa lport service api
302  */
303
304 u32     bfa_lps_get_max_vport(struct bfa_s *bfa);
305 struct bfa_lps_s *bfa_lps_alloc(struct bfa_s *bfa);
306 void bfa_lps_delete(struct bfa_lps_s *lps);
307 void bfa_lps_discard(struct bfa_lps_s *lps);
308 void bfa_lps_flogi(struct bfa_lps_s *lps, void *uarg, u8 alpa, u16 pdusz,
309                    wwn_t pwwn, wwn_t nwwn, bfa_boolean_t auth_en);
310 void bfa_lps_fdisc(struct bfa_lps_s *lps, void *uarg, u16 pdusz, wwn_t pwwn,
311                    wwn_t nwwn);
312 void bfa_lps_flogo(struct bfa_lps_s *lps);
313 void bfa_lps_fdisclogo(struct bfa_lps_s *lps);
314 u8 bfa_lps_get_tag(struct bfa_lps_s *lps);
315 bfa_boolean_t bfa_lps_is_npiv_en(struct bfa_lps_s *lps);
316 bfa_boolean_t bfa_lps_is_fport(struct bfa_lps_s *lps);
317 bfa_boolean_t bfa_lps_is_brcd_fabric(struct bfa_lps_s *lps);
318 bfa_boolean_t bfa_lps_is_authreq(struct bfa_lps_s *lps);
319 bfa_eproto_status_t bfa_lps_get_extstatus(struct bfa_lps_s *lps);
320 u32 bfa_lps_get_pid(struct bfa_lps_s *lps);
321 u8 bfa_lps_get_tag_from_pid(struct bfa_s *bfa, u32 pid);
322 u16 bfa_lps_get_peer_bbcredit(struct bfa_lps_s *lps);
323 wwn_t bfa_lps_get_peer_pwwn(struct bfa_lps_s *lps);
324 wwn_t bfa_lps_get_peer_nwwn(struct bfa_lps_s *lps);
325 u8 bfa_lps_get_lsrjt_rsn(struct bfa_lps_s *lps);
326 u8 bfa_lps_get_lsrjt_expl(struct bfa_lps_s *lps);
327 mac_t bfa_lps_get_lp_mac(struct bfa_lps_s *lps);
328 void bfa_cb_lps_flogi_comp(void *bfad, void *uarg, bfa_status_t status);
329 void bfa_cb_lps_flogo_comp(void *bfad, void *uarg);
330 void bfa_cb_lps_fdisc_comp(void *bfad, void *uarg, bfa_status_t status);
331 void bfa_cb_lps_fdisclogo_comp(void *bfad, void *uarg);
332 void bfa_cb_lps_cvl_event(void *bfad, void *uarg);
333
334 #endif /* __BFA_SVC_H__ */
335