]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/scsi/bfa/bfa_fcs.h
f0e652b50994a6d14d36bd9eb560bd0176b6cf86
[karo-tx-linux.git] / drivers / scsi / bfa / bfa_fcs.h
1 /*
2  * Copyright (c) 2005-2010 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
18 #ifndef __BFA_FCS_H__
19 #define __BFA_FCS_H__
20
21 #include "bfa_cs.h"
22 #include "bfa_defs.h"
23 #include "bfa_defs_fcs.h"
24 #include "bfa_modules.h"
25 #include "bfa_fc.h"
26
27 #define BFA_FCS_OS_STR_LEN              64
28
29 /*
30  *  lps_pvt BFA LPS private functions
31  */
32
33 enum bfa_lps_event {
34         BFA_LPS_SM_LOGIN        = 1,    /* login request from user      */
35         BFA_LPS_SM_LOGOUT       = 2,    /* logout request from user     */
36         BFA_LPS_SM_FWRSP        = 3,    /* f/w response to login/logout */
37         BFA_LPS_SM_RESUME       = 4,    /* space present in reqq queue  */
38         BFA_LPS_SM_DELETE       = 5,    /* lps delete from user         */
39         BFA_LPS_SM_OFFLINE      = 6,    /* Link is offline              */
40         BFA_LPS_SM_RX_CVL       = 7,    /* Rx clear virtual link        */
41 };
42
43
44 /*
45  * !!! Only append to the enums defined here to avoid any versioning
46  * !!! needed between trace utility and driver version
47  */
48 enum {
49         BFA_TRC_FCS_FCS         = 1,
50         BFA_TRC_FCS_PORT        = 2,
51         BFA_TRC_FCS_RPORT       = 3,
52         BFA_TRC_FCS_FCPIM       = 4,
53 };
54
55
56 struct bfa_fcs_s;
57
58 #define __fcs_min_cfg(__fcs)       ((__fcs)->min_cfg)
59
60 #define BFA_FCS_BRCD_SWITCH_OUI  0x051e
61 #define N2N_LOCAL_PID       0x010000
62 #define N2N_REMOTE_PID          0x020000
63 #define BFA_FCS_RETRY_TIMEOUT 2000
64 #define BFA_FCS_PID_IS_WKA(pid)  ((bfa_ntoh3b(pid) > 0xFFF000) ?  1 : 0)
65
66
67
68 struct bfa_fcs_lport_ns_s {
69         bfa_sm_t        sm;             /*  state machine */
70         struct bfa_timer_s timer;
71         struct bfa_fcs_lport_s *port;   /*  parent port */
72         struct bfa_fcxp_s *fcxp;
73         struct bfa_fcxp_wqe_s fcxp_wqe;
74 };
75
76
77 struct bfa_fcs_lport_scn_s {
78         bfa_sm_t        sm;             /*  state machine */
79         struct bfa_timer_s timer;
80         struct bfa_fcs_lport_s *port;   /*  parent port */
81         struct bfa_fcxp_s *fcxp;
82         struct bfa_fcxp_wqe_s fcxp_wqe;
83 };
84
85
86 struct bfa_fcs_lport_fdmi_s {
87         bfa_sm_t        sm;             /*  state machine */
88         struct bfa_timer_s timer;
89         struct bfa_fcs_lport_ms_s *ms;  /*  parent ms */
90         struct bfa_fcxp_s *fcxp;
91         struct bfa_fcxp_wqe_s fcxp_wqe;
92         u8      retry_cnt;      /*  retry count */
93         u8      rsvd[3];
94 };
95
96
97 struct bfa_fcs_lport_ms_s {
98         bfa_sm_t        sm;             /*  state machine */
99         struct bfa_timer_s timer;
100         struct bfa_fcs_lport_s *port;   /*  parent port */
101         struct bfa_fcxp_s *fcxp;
102         struct bfa_fcxp_wqe_s fcxp_wqe;
103         struct bfa_fcs_lport_fdmi_s fdmi;       /*  FDMI component of MS */
104         u8         retry_cnt;   /*  retry count */
105         u8      rsvd[3];
106 };
107
108
109 struct bfa_fcs_lport_fab_s {
110         struct bfa_fcs_lport_ns_s ns;   /*  NS component of port */
111         struct bfa_fcs_lport_scn_s scn; /*  scn component of port */
112         struct bfa_fcs_lport_ms_s ms;   /*  MS component of port */
113 };
114
115 #define MAX_ALPA_COUNT  127
116
117 struct bfa_fcs_lport_loop_s {
118         u8         num_alpa;    /*  Num of ALPA entries in the map */
119         u8         alpa_pos_map[MAX_ALPA_COUNT];        /*  ALPA Positional
120                                                          *Map */
121         struct bfa_fcs_lport_s *port;   /*  parent port */
122 };
123
124 struct bfa_fcs_lport_n2n_s {
125         u32        rsvd;
126         __be16     reply_oxid;  /*  ox_id from the req flogi to be
127                                          *used in flogi acc */
128         wwn_t           rem_port_wwn;   /*  Attached port's wwn */
129 };
130
131
132 union bfa_fcs_lport_topo_u {
133         struct bfa_fcs_lport_fab_s pfab;
134         struct bfa_fcs_lport_loop_s ploop;
135         struct bfa_fcs_lport_n2n_s pn2n;
136 };
137
138
139 struct bfa_fcs_lport_s {
140         struct list_head         qe;    /*  used by port/vport */
141         bfa_sm_t               sm;      /*  state machine */
142         struct bfa_fcs_fabric_s *fabric;        /*  parent fabric */
143         struct bfa_lport_cfg_s  port_cfg;       /*  port configuration */
144         struct bfa_timer_s link_timer;  /*  timer for link offline */
145         u32        pid:24;      /*  FC address */
146         u8         lp_tag;              /*  lport tag */
147         u16        num_rports;  /*  Num of r-ports */
148         struct list_head         rport_q; /*  queue of discovered r-ports */
149         struct bfa_fcs_s *fcs;  /*  FCS instance */
150         union bfa_fcs_lport_topo_u port_topo;   /*  fabric/loop/n2n details */
151         struct bfad_port_s *bfad_port;  /*  driver peer instance */
152         struct bfa_fcs_vport_s *vport;  /*  NULL for base ports */
153         struct bfa_fcxp_s *fcxp;
154         struct bfa_fcxp_wqe_s fcxp_wqe;
155         struct bfa_lport_stats_s stats;
156         struct bfa_wc_s        wc;      /*  waiting counter for events */
157 };
158 #define BFA_FCS_GET_HAL_FROM_PORT(port)  (port->fcs->bfa)
159 #define BFA_FCS_GET_NS_FROM_PORT(port)  (&port->port_topo.pfab.ns)
160 #define BFA_FCS_GET_SCN_FROM_PORT(port)  (&port->port_topo.pfab.scn)
161 #define BFA_FCS_GET_MS_FROM_PORT(port)  (&port->port_topo.pfab.ms)
162 #define BFA_FCS_GET_FDMI_FROM_PORT(port)  (&port->port_topo.pfab.ms.fdmi)
163 #define BFA_FCS_VPORT_IS_INITIATOR_MODE(port) \
164                 (port->port_cfg.roles & BFA_LPORT_ROLE_FCP_IM)
165
166 /*
167  * forward declaration
168  */
169 struct bfad_vf_s;
170
171 enum bfa_fcs_fabric_type {
172         BFA_FCS_FABRIC_UNKNOWN = 0,
173         BFA_FCS_FABRIC_SWITCHED = 1,
174         BFA_FCS_FABRIC_N2N = 2,
175 };
176
177
178 struct bfa_fcs_fabric_s {
179         struct list_head   qe;          /*  queue element */
180         bfa_sm_t         sm;            /*  state machine */
181         struct bfa_fcs_s *fcs;          /*  FCS instance */
182         struct bfa_fcs_lport_s  bport;  /*  base logical port */
183         enum bfa_fcs_fabric_type fab_type; /*  fabric type */
184         enum bfa_port_type oper_type;   /*  current link topology */
185         u8         is_vf;               /*  is virtual fabric? */
186         u8         is_npiv;     /*  is NPIV supported ? */
187         u8         is_auth;     /*  is Security/Auth supported ? */
188         u16        bb_credit;   /*  BB credit from fabric */
189         u16        vf_id;               /*  virtual fabric ID */
190         u16        num_vports;  /*  num vports */
191         u16        rsvd;
192         struct list_head         vport_q;       /*  queue of virtual ports */
193         struct list_head         vf_q;  /*  queue of virtual fabrics */
194         struct bfad_vf_s      *vf_drv;  /*  driver vf structure */
195         struct bfa_timer_s link_timer;  /*  Link Failure timer. Vport */
196         wwn_t           fabric_name;    /*  attached fabric name */
197         bfa_boolean_t   auth_reqd;      /*  authentication required     */
198         struct bfa_timer_s delay_timer; /*  delay timer         */
199         union {
200                 u16        swp_vfid;/*  switch port VF id               */
201         } event_arg;
202         struct bfa_wc_s        wc;      /*  wait counter for delete     */
203         struct bfa_vf_stats_s   stats;  /*  fabric/vf stats             */
204         struct bfa_lps_s        *lps;   /*  lport login services        */
205         u8      fabric_ip_addr[BFA_FCS_FABRIC_IPADDR_SZ];
206                                         /*  attached fabric's ip addr  */
207 };
208
209 #define bfa_fcs_fabric_npiv_capable(__f)    ((__f)->is_npiv)
210 #define bfa_fcs_fabric_is_switched(__f)                 \
211         ((__f)->fab_type == BFA_FCS_FABRIC_SWITCHED)
212
213 /*
214  *   The design calls for a single implementation of base fabric and vf.
215  */
216 #define bfa_fcs_vf_t struct bfa_fcs_fabric_s
217
218 struct bfa_vf_event_s {
219         u32        undefined;
220 };
221
222 struct bfa_fcs_s;
223 struct bfa_fcs_fabric_s;
224
225 /*
226  * @todo : need to move to a global config file.
227  * Maximum Rports supported per port (physical/logical).
228  */
229 #define BFA_FCS_MAX_RPORTS_SUPP  256    /* @todo : tentative value */
230
231 #define bfa_fcs_lport_t struct bfa_fcs_lport_s
232
233 /*
234  * Symbolic Name related defines
235  *  Total bytes 255.
236  *  Physical Port's symbolic name 128 bytes.
237  *  For Vports, Vport's symbolic name is appended to the Physical port's
238  *  Symbolic Name.
239  *
240  *  Physical Port's symbolic name Format : (Total 128 bytes)
241  *  Adapter Model number/name : 12 bytes
242  *  Driver Version     : 10 bytes
243  *  Host Machine Name  : 30 bytes
244  *  Host OS Info           : 48 bytes
245  *  Host OS PATCH Info : 16 bytes
246  *  ( remaining 12 bytes reserved to be used for separator)
247  */
248 #define BFA_FCS_PORT_SYMBNAME_SEPARATOR                 " | "
249
250 #define BFA_FCS_PORT_SYMBNAME_MODEL_SZ                  12
251 #define BFA_FCS_PORT_SYMBNAME_VERSION_SZ                10
252 #define BFA_FCS_PORT_SYMBNAME_MACHINENAME_SZ            30
253 #define BFA_FCS_PORT_SYMBNAME_OSINFO_SZ                 48
254 #define BFA_FCS_PORT_SYMBNAME_OSPATCH_SZ                16
255
256 /*
257  * Get FC port ID for a logical port.
258  */
259 #define bfa_fcs_lport_get_fcid(_lport)  ((_lport)->pid)
260 #define bfa_fcs_lport_get_pwwn(_lport)  ((_lport)->port_cfg.pwwn)
261 #define bfa_fcs_lport_get_nwwn(_lport)  ((_lport)->port_cfg.nwwn)
262 #define bfa_fcs_lport_get_psym_name(_lport)     ((_lport)->port_cfg.sym_name)
263 #define bfa_fcs_lport_is_initiator(_lport)                      \
264         ((_lport)->port_cfg.roles & BFA_LPORT_ROLE_FCP_IM)
265 #define bfa_fcs_lport_get_nrports(_lport)       \
266         ((_lport) ? (_lport)->num_rports : 0)
267
268 static inline struct bfad_port_s *
269 bfa_fcs_lport_get_drvport(struct bfa_fcs_lport_s *port)
270 {
271         return port->bfad_port;
272 }
273
274 #define bfa_fcs_lport_get_opertype(_lport)      ((_lport)->fabric->oper_type)
275 #define bfa_fcs_lport_get_fabric_name(_lport)   ((_lport)->fabric->fabric_name)
276 #define bfa_fcs_lport_get_fabric_ipaddr(_lport)         \
277                 ((_lport)->fabric->fabric_ip_addr)
278
279 /*
280  * bfa fcs port public functions
281  */
282
283 bfa_boolean_t   bfa_fcs_lport_is_online(struct bfa_fcs_lport_s *port);
284 struct bfa_fcs_lport_s *bfa_fcs_get_base_port(struct bfa_fcs_s *fcs);
285 void bfa_fcs_lport_get_rports(struct bfa_fcs_lport_s *port,
286                               wwn_t rport_wwns[], int *nrports);
287
288 wwn_t bfa_fcs_lport_get_rport(struct bfa_fcs_lport_s *port, wwn_t wwn,
289                               int index, int nrports, bfa_boolean_t bwwn);
290
291 struct bfa_fcs_lport_s *bfa_fcs_lookup_port(struct bfa_fcs_s *fcs,
292                                             u16 vf_id, wwn_t lpwwn);
293
294 void bfa_fcs_lport_get_info(struct bfa_fcs_lport_s *port,
295                             struct bfa_lport_info_s *port_info);
296 void bfa_fcs_lport_get_attr(struct bfa_fcs_lport_s *port,
297                             struct bfa_lport_attr_s *port_attr);
298 void bfa_fcs_lport_get_stats(struct bfa_fcs_lport_s *fcs_port,
299                              struct bfa_lport_stats_s *port_stats);
300 void bfa_fcs_lport_clear_stats(struct bfa_fcs_lport_s *fcs_port);
301 enum bfa_port_speed bfa_fcs_lport_get_rport_max_speed(
302                         struct bfa_fcs_lport_s *port);
303
304 /* MS FCS routines */
305 void bfa_fcs_lport_ms_init(struct bfa_fcs_lport_s *port);
306 void bfa_fcs_lport_ms_offline(struct bfa_fcs_lport_s *port);
307 void bfa_fcs_lport_ms_online(struct bfa_fcs_lport_s *port);
308 void bfa_fcs_lport_ms_fabric_rscn(struct bfa_fcs_lport_s *port);
309
310 /* FDMI FCS routines */
311 void bfa_fcs_lport_fdmi_init(struct bfa_fcs_lport_ms_s *ms);
312 void bfa_fcs_lport_fdmi_offline(struct bfa_fcs_lport_ms_s *ms);
313 void bfa_fcs_lport_fdmi_online(struct bfa_fcs_lport_ms_s *ms);
314 void bfa_fcs_lport_uf_recv(struct bfa_fcs_lport_s *lport, struct fchs_s *fchs,
315                                      u16 len);
316 void bfa_fcs_lport_attach(struct bfa_fcs_lport_s *lport, struct bfa_fcs_s *fcs,
317                         u16 vf_id, struct bfa_fcs_vport_s *vport);
318 void bfa_fcs_lport_init(struct bfa_fcs_lport_s *lport,
319                                 struct bfa_lport_cfg_s *port_cfg);
320 void            bfa_fcs_lport_online(struct bfa_fcs_lport_s *port);
321 void            bfa_fcs_lport_offline(struct bfa_fcs_lport_s *port);
322 void            bfa_fcs_lport_delete(struct bfa_fcs_lport_s *port);
323 struct bfa_fcs_rport_s *bfa_fcs_lport_get_rport_by_pid(
324                 struct bfa_fcs_lport_s *port, u32 pid);
325 struct bfa_fcs_rport_s *bfa_fcs_lport_get_rport_by_pwwn(
326                 struct bfa_fcs_lport_s *port, wwn_t pwwn);
327 struct bfa_fcs_rport_s *bfa_fcs_lport_get_rport_by_nwwn(
328                 struct bfa_fcs_lport_s *port, wwn_t nwwn);
329 void            bfa_fcs_lport_add_rport(struct bfa_fcs_lport_s *port,
330                                        struct bfa_fcs_rport_s *rport);
331 void            bfa_fcs_lport_del_rport(struct bfa_fcs_lport_s *port,
332                                        struct bfa_fcs_rport_s *rport);
333 void            bfa_fcs_lport_ns_init(struct bfa_fcs_lport_s *vport);
334 void            bfa_fcs_lport_ns_offline(struct bfa_fcs_lport_s *vport);
335 void            bfa_fcs_lport_ns_online(struct bfa_fcs_lport_s *vport);
336 void            bfa_fcs_lport_ns_query(struct bfa_fcs_lport_s *port);
337 void            bfa_fcs_lport_scn_init(struct bfa_fcs_lport_s *vport);
338 void            bfa_fcs_lport_scn_offline(struct bfa_fcs_lport_s *vport);
339 void            bfa_fcs_lport_scn_online(struct bfa_fcs_lport_s *vport);
340 void            bfa_fcs_lport_scn_process_rscn(struct bfa_fcs_lport_s *port,
341                                               struct fchs_s *rx_frame, u32 len);
342
343 struct bfa_fcs_vport_s {
344         struct list_head                qe;             /*  queue elem  */
345         bfa_sm_t                sm;             /*  state machine       */
346         bfa_fcs_lport_t         lport;          /*  logical port        */
347         struct bfa_timer_s      timer;
348         struct bfad_vport_s     *vport_drv;     /*  Driver private      */
349         struct bfa_vport_stats_s vport_stats;   /*  vport statistics    */
350         struct bfa_lps_s        *lps;           /*  Lport login service*/
351         int                     fdisc_retries;
352 };
353
354 #define bfa_fcs_vport_get_port(vport)                   \
355         ((struct bfa_fcs_lport_s  *)(&vport->port))
356
357 /*
358  * bfa fcs vport public functions
359  */
360 bfa_status_t bfa_fcs_vport_create(struct bfa_fcs_vport_s *vport,
361                                   struct bfa_fcs_s *fcs, u16 vf_id,
362                                   struct bfa_lport_cfg_s *port_cfg,
363                                   struct bfad_vport_s *vport_drv);
364 bfa_status_t bfa_fcs_pbc_vport_create(struct bfa_fcs_vport_s *vport,
365                                       struct bfa_fcs_s *fcs, u16 vf_id,
366                                       struct bfa_lport_cfg_s *port_cfg,
367                                       struct bfad_vport_s *vport_drv);
368 bfa_boolean_t bfa_fcs_is_pbc_vport(struct bfa_fcs_vport_s *vport);
369 bfa_status_t bfa_fcs_vport_delete(struct bfa_fcs_vport_s *vport);
370 bfa_status_t bfa_fcs_vport_start(struct bfa_fcs_vport_s *vport);
371 bfa_status_t bfa_fcs_vport_stop(struct bfa_fcs_vport_s *vport);
372 void bfa_fcs_vport_get_attr(struct bfa_fcs_vport_s *vport,
373                             struct bfa_vport_attr_s *vport_attr);
374 struct bfa_fcs_vport_s *bfa_fcs_vport_lookup(struct bfa_fcs_s *fcs,
375                                              u16 vf_id, wwn_t vpwwn);
376 void bfa_fcs_vport_cleanup(struct bfa_fcs_vport_s *vport);
377 void bfa_fcs_vport_online(struct bfa_fcs_vport_s *vport);
378 void bfa_fcs_vport_offline(struct bfa_fcs_vport_s *vport);
379 void bfa_fcs_vport_delete_comp(struct bfa_fcs_vport_s *vport);
380 void bfa_fcs_vport_fcs_delete(struct bfa_fcs_vport_s *vport);
381
382 #define BFA_FCS_RPORT_DEF_DEL_TIMEOUT   90      /* in secs */
383 #define BFA_FCS_RPORT_MAX_RETRIES       (5)
384
385 /*
386  * forward declarations
387  */
388 struct bfad_rport_s;
389
390 struct bfa_fcs_itnim_s;
391 struct bfa_fcs_tin_s;
392 struct bfa_fcs_iprp_s;
393
394 /* Rport Features (RPF) */
395 struct bfa_fcs_rpf_s {
396         bfa_sm_t        sm;     /*  state machine */
397         struct bfa_fcs_rport_s *rport;  /*  parent rport */
398         struct bfa_timer_s      timer;  /*  general purpose timer */
399         struct bfa_fcxp_s       *fcxp;  /*  FCXP needed for discarding */
400         struct bfa_fcxp_wqe_s   fcxp_wqe; /*  fcxp wait queue element */
401         int     rpsc_retries;   /*  max RPSC retry attempts */
402         enum bfa_port_speed     rpsc_speed;
403         /*  Current Speed from RPSC. O if RPSC fails */
404         enum bfa_port_speed     assigned_speed;
405         /*
406          * Speed assigned by the user.  will be used if RPSC is
407          * not supported by the rport.
408          */
409 };
410
411 struct bfa_fcs_rport_s {
412         struct list_head        qe;     /*  used by port/vport */
413         struct bfa_fcs_lport_s *port;   /*  parent FCS port */
414         struct bfa_fcs_s        *fcs;   /*  fcs instance */
415         struct bfad_rport_s     *rp_drv;        /*  driver peer instance */
416         u32     pid;    /*  port ID of rport */
417         u16     maxfrsize;      /*  maximum frame size */
418         __be16  reply_oxid;     /*  OX_ID of inbound requests */
419         enum fc_cos     fc_cos; /*  FC classes of service supp */
420         bfa_boolean_t   cisc;   /*  CISC capable device */
421         bfa_boolean_t   prlo;   /*  processing prlo or LOGO */
422         wwn_t   pwwn;   /*  port wwn of rport */
423         wwn_t   nwwn;   /*  node wwn of rport */
424         struct bfa_rport_symname_s psym_name; /*  port symbolic name  */
425         bfa_sm_t        sm;             /*  state machine */
426         struct bfa_timer_s timer;       /*  general purpose timer */
427         struct bfa_fcs_itnim_s *itnim;  /*  ITN initiator mode role */
428         struct bfa_fcs_tin_s *tin;      /*  ITN initiator mode role */
429         struct bfa_fcs_iprp_s *iprp;    /*  IP/FC role */
430         struct bfa_rport_s *bfa_rport;  /*  BFA Rport */
431         struct bfa_fcxp_s *fcxp;        /*  FCXP needed for discarding */
432         int     plogi_retries;  /*  max plogi retry attempts */
433         int     ns_retries;     /*  max NS query retry attempts */
434         struct bfa_fcxp_wqe_s   fcxp_wqe; /*  fcxp wait queue element */
435         struct bfa_rport_stats_s stats; /*  rport stats */
436         enum bfa_rport_function scsi_function;  /*  Initiator/Target */
437         struct bfa_fcs_rpf_s rpf;       /* Rport features module */
438 };
439
440 static inline struct bfa_rport_s *
441 bfa_fcs_rport_get_halrport(struct bfa_fcs_rport_s *rport)
442 {
443         return rport->bfa_rport;
444 }
445
446 /*
447  * bfa fcs rport API functions
448  */
449 struct bfa_fcs_rport_s *bfa_fcs_rport_lookup(struct bfa_fcs_lport_s *port,
450                                              wwn_t rpwwn);
451 struct bfa_fcs_rport_s *bfa_fcs_rport_lookup_by_nwwn(
452         struct bfa_fcs_lport_s *port, wwn_t rnwwn);
453 void bfa_fcs_rport_set_del_timeout(u8 rport_tmo);
454
455 void bfa_fcs_rport_uf_recv(struct bfa_fcs_rport_s *rport,
456          struct fchs_s *fchs, u16 len);
457 void bfa_fcs_rport_scn(struct bfa_fcs_rport_s *rport);
458
459 struct bfa_fcs_rport_s *bfa_fcs_rport_create(struct bfa_fcs_lport_s *port,
460          u32 pid);
461 void bfa_fcs_rport_start(struct bfa_fcs_lport_s *port, struct fchs_s *rx_fchs,
462                          struct fc_logi_s *plogi_rsp);
463 void bfa_fcs_rport_plogi_create(struct bfa_fcs_lport_s *port,
464                                 struct fchs_s *rx_fchs,
465                                 struct fc_logi_s *plogi);
466 void bfa_fcs_rport_plogi(struct bfa_fcs_rport_s *rport, struct fchs_s *fchs,
467                          struct fc_logi_s *plogi);
468 void bfa_fcs_rport_prlo(struct bfa_fcs_rport_s *rport, __be16 ox_id);
469
470 void bfa_fcs_rport_itntm_ack(struct bfa_fcs_rport_s *rport);
471 void bfa_fcs_rport_fcptm_offline_done(struct bfa_fcs_rport_s *rport);
472 int  bfa_fcs_rport_get_state(struct bfa_fcs_rport_s *rport);
473 struct bfa_fcs_rport_s *bfa_fcs_rport_create_by_wwn(
474                         struct bfa_fcs_lport_s *port, wwn_t wwn);
475 void  bfa_fcs_rpf_init(struct bfa_fcs_rport_s *rport);
476 void  bfa_fcs_rpf_rport_online(struct bfa_fcs_rport_s *rport);
477 void  bfa_fcs_rpf_rport_offline(struct bfa_fcs_rport_s *rport);
478
479 /*
480  * forward declarations
481  */
482 struct bfad_itnim_s;
483
484 struct bfa_fcs_itnim_s {
485         bfa_sm_t                sm;             /*  state machine */
486         struct bfa_fcs_rport_s  *rport;         /*  parent remote rport  */
487         struct bfad_itnim_s     *itnim_drv;     /*  driver peer instance */
488         struct bfa_fcs_s        *fcs;           /*  fcs instance        */
489         struct bfa_timer_s      timer;          /*  timer functions     */
490         struct bfa_itnim_s      *bfa_itnim;     /*  BFA itnim struct    */
491         u32             prli_retries;   /*  max prli retry attempts */
492         bfa_boolean_t           seq_rec;        /*  seq recovery support */
493         bfa_boolean_t           rec_support;    /*  REC supported       */
494         bfa_boolean_t           conf_comp;      /*  FCP_CONF    support */
495         bfa_boolean_t           task_retry_id;  /*  task retry id supp  */
496         struct bfa_fcxp_wqe_s   fcxp_wqe;       /*  wait qelem for fcxp  */
497         struct bfa_fcxp_s       *fcxp;          /*  FCXP in use */
498         struct bfa_itnim_stats_s        stats;  /*  itn statistics      */
499 };
500 #define bfa_fcs_fcxp_alloc(__fcs)       \
501         bfa_fcxp_alloc(NULL, (__fcs)->bfa, 0, 0, NULL, NULL, NULL, NULL)
502
503 #define bfa_fcs_fcxp_alloc_wait(__bfa, __wqe, __alloc_cbfn, __alloc_cbarg) \
504         bfa_fcxp_alloc_wait(__bfa, __wqe, __alloc_cbfn, __alloc_cbarg, \
505                                         NULL, 0, 0, NULL, NULL, NULL, NULL)
506
507 static inline struct bfad_port_s *
508 bfa_fcs_itnim_get_drvport(struct bfa_fcs_itnim_s *itnim)
509 {
510         return itnim->rport->port->bfad_port;
511 }
512
513
514 static inline struct bfa_fcs_lport_s *
515 bfa_fcs_itnim_get_port(struct bfa_fcs_itnim_s *itnim)
516 {
517         return itnim->rport->port;
518 }
519
520
521 static inline wwn_t
522 bfa_fcs_itnim_get_nwwn(struct bfa_fcs_itnim_s *itnim)
523 {
524         return itnim->rport->nwwn;
525 }
526
527
528 static inline wwn_t
529 bfa_fcs_itnim_get_pwwn(struct bfa_fcs_itnim_s *itnim)
530 {
531         return itnim->rport->pwwn;
532 }
533
534
535 static inline u32
536 bfa_fcs_itnim_get_fcid(struct bfa_fcs_itnim_s *itnim)
537 {
538         return itnim->rport->pid;
539 }
540
541
542 static inline   u32
543 bfa_fcs_itnim_get_maxfrsize(struct bfa_fcs_itnim_s *itnim)
544 {
545         return itnim->rport->maxfrsize;
546 }
547
548
549 static inline   enum fc_cos
550 bfa_fcs_itnim_get_cos(struct bfa_fcs_itnim_s *itnim)
551 {
552         return itnim->rport->fc_cos;
553 }
554
555
556 static inline struct bfad_itnim_s *
557 bfa_fcs_itnim_get_drvitn(struct bfa_fcs_itnim_s *itnim)
558 {
559         return itnim->itnim_drv;
560 }
561
562
563 static inline struct bfa_itnim_s *
564 bfa_fcs_itnim_get_halitn(struct bfa_fcs_itnim_s *itnim)
565 {
566         return itnim->bfa_itnim;
567 }
568
569 /*
570  * bfa fcs FCP Initiator mode API functions
571  */
572 void bfa_fcs_itnim_get_attr(struct bfa_fcs_itnim_s *itnim,
573                             struct bfa_itnim_attr_s *attr);
574 void bfa_fcs_itnim_get_stats(struct bfa_fcs_itnim_s *itnim,
575                              struct bfa_itnim_stats_s *stats);
576 struct bfa_fcs_itnim_s *bfa_fcs_itnim_lookup(struct bfa_fcs_lport_s *port,
577                                              wwn_t rpwwn);
578 bfa_status_t bfa_fcs_itnim_attr_get(struct bfa_fcs_lport_s *port, wwn_t rpwwn,
579                                     struct bfa_itnim_attr_s *attr);
580 bfa_status_t bfa_fcs_itnim_stats_get(struct bfa_fcs_lport_s *port, wwn_t rpwwn,
581                                      struct bfa_itnim_stats_s *stats);
582 bfa_status_t bfa_fcs_itnim_stats_clear(struct bfa_fcs_lport_s *port,
583                                        wwn_t rpwwn);
584 struct bfa_fcs_itnim_s *bfa_fcs_itnim_create(struct bfa_fcs_rport_s *rport);
585 void bfa_fcs_itnim_delete(struct bfa_fcs_itnim_s *itnim);
586 void bfa_fcs_itnim_rport_offline(struct bfa_fcs_itnim_s *itnim);
587 void bfa_fcs_itnim_rport_online(struct bfa_fcs_itnim_s *itnim);
588 bfa_status_t bfa_fcs_itnim_get_online_state(struct bfa_fcs_itnim_s *itnim);
589 void bfa_fcs_itnim_is_initiator(struct bfa_fcs_itnim_s *itnim);
590 void bfa_fcs_fcpim_uf_recv(struct bfa_fcs_itnim_s *itnim,
591                         struct fchs_s *fchs, u16 len);
592
593 #define BFA_FCS_FDMI_SUPORTED_SPEEDS  (FDMI_TRANS_SPEED_1G  |   \
594                                        FDMI_TRANS_SPEED_2G |    \
595                                        FDMI_TRANS_SPEED_4G |    \
596                                        FDMI_TRANS_SPEED_8G)
597
598 /*
599  * HBA Attribute Block : BFA internal representation. Note : Some variable
600  * sizes have been trimmed to suit BFA For Ex : Model will be "Brocade". Based
601  * on this the size has been reduced to 16 bytes from the standard's 64 bytes.
602  */
603 struct bfa_fcs_fdmi_hba_attr_s {
604         wwn_t           node_name;
605         u8         manufacturer[64];
606         u8         serial_num[64];
607         u8         model[16];
608         u8         model_desc[256];
609         u8         hw_version[8];
610         u8         driver_version[8];
611         u8         option_rom_ver[BFA_VERSION_LEN];
612         u8         fw_version[8];
613         u8         os_name[256];
614         __be32        max_ct_pyld;
615 };
616
617 /*
618  * Port Attribute Block
619  */
620 struct bfa_fcs_fdmi_port_attr_s {
621         u8         supp_fc4_types[32];  /* supported FC4 types */
622         __be32        supp_speed;       /* supported speed */
623         __be32        curr_speed;       /* current Speed */
624         __be32        max_frm_size;     /* max frame size */
625         u8         os_device_name[256]; /* OS device Name */
626         u8         host_name[256];      /* host name */
627 };
628
629 struct bfa_fcs_stats_s {
630         struct {
631                 u32     untagged; /*  untagged receive frames */
632                 u32     tagged; /*  tagged receive frames */
633                 u32     vfid_unknown;   /*  VF id is unknown */
634         } uf;
635 };
636
637 struct bfa_fcs_driver_info_s {
638         u8       version[BFA_VERSION_LEN];              /* Driver Version */
639         u8       host_machine_name[BFA_FCS_OS_STR_LEN];
640         u8       host_os_name[BFA_FCS_OS_STR_LEN]; /* OS name and version */
641         u8       host_os_patch[BFA_FCS_OS_STR_LEN]; /* patch or service pack */
642         u8       os_device_name[BFA_FCS_OS_STR_LEN]; /* Driver Device Name */
643 };
644
645 struct bfa_fcs_s {
646         struct bfa_s      *bfa; /*  corresponding BFA bfa instance */
647         struct bfad_s         *bfad; /*  corresponding BDA driver instance */
648         struct bfa_trc_mod_s  *trcmod;  /*  tracing module */
649         bfa_boolean_t   vf_enabled;     /*  VF mode is enabled */
650         bfa_boolean_t   fdmi_enabled;   /*  FDMI is enabled */
651         bfa_boolean_t min_cfg;          /* min cfg enabled/disabled */
652         u16     port_vfid;      /*  port default VF ID */
653         struct bfa_fcs_driver_info_s driver_info;
654         struct bfa_fcs_fabric_s fabric; /*  base fabric state machine */
655         struct bfa_fcs_stats_s  stats;  /*  FCS statistics */
656         struct bfa_wc_s         wc;     /*  waiting counter */
657 };
658
659 /*
660  *  fcs_fabric_sm fabric state machine functions
661  */
662
663 /*
664  * Fabric state machine events
665  */
666 enum bfa_fcs_fabric_event {
667         BFA_FCS_FABRIC_SM_CREATE        = 1,    /*  create from driver        */
668         BFA_FCS_FABRIC_SM_DELETE        = 2,    /*  delete from driver        */
669         BFA_FCS_FABRIC_SM_LINK_DOWN     = 3,    /*  link down from port      */
670         BFA_FCS_FABRIC_SM_LINK_UP       = 4,    /*  link up from port         */
671         BFA_FCS_FABRIC_SM_CONT_OP       = 5,    /*  flogi/auth continue op   */
672         BFA_FCS_FABRIC_SM_RETRY_OP      = 6,    /*  flogi/auth retry op      */
673         BFA_FCS_FABRIC_SM_NO_FABRIC     = 7,    /*  from flogi/auth           */
674         BFA_FCS_FABRIC_SM_PERF_EVFP     = 8,    /*  from flogi/auth           */
675         BFA_FCS_FABRIC_SM_ISOLATE       = 9,    /*  from EVFP processing     */
676         BFA_FCS_FABRIC_SM_NO_TAGGING    = 10,   /*  no VFT tagging from EVFP */
677         BFA_FCS_FABRIC_SM_DELAYED       = 11,   /*  timeout delay event      */
678         BFA_FCS_FABRIC_SM_AUTH_FAILED   = 12,   /*  auth failed       */
679         BFA_FCS_FABRIC_SM_AUTH_SUCCESS  = 13,   /*  auth successful           */
680         BFA_FCS_FABRIC_SM_DELCOMP       = 14,   /*  all vports deleted event */
681         BFA_FCS_FABRIC_SM_LOOPBACK      = 15,   /*  Received our own FLOGI   */
682         BFA_FCS_FABRIC_SM_START         = 16,   /*  from driver       */
683 };
684
685 /*
686  *  fcs_rport_sm FCS rport state machine events
687  */
688
689 enum rport_event {
690         RPSM_EVENT_PLOGI_SEND   = 1,    /*  new rport; start with PLOGI */
691         RPSM_EVENT_PLOGI_RCVD   = 2,    /*  Inbound PLOGI from remote port */
692         RPSM_EVENT_PLOGI_COMP   = 3,    /*  PLOGI completed to rport    */
693         RPSM_EVENT_LOGO_RCVD    = 4,    /*  LOGO from remote device     */
694         RPSM_EVENT_LOGO_IMP     = 5,    /*  implicit logo for SLER      */
695         RPSM_EVENT_FCXP_SENT    = 6,    /*  Frame from has been sent    */
696         RPSM_EVENT_DELETE       = 7,    /*  RPORT delete request        */
697         RPSM_EVENT_SCN          = 8,    /*  state change notification   */
698         RPSM_EVENT_ACCEPTED     = 9,    /*  Good response from remote device */
699         RPSM_EVENT_FAILED       = 10,   /*  Request to rport failed.    */
700         RPSM_EVENT_TIMEOUT      = 11,   /*  Rport SM timeout event      */
701         RPSM_EVENT_HCB_ONLINE  = 12,    /*  BFA rport online callback   */
702         RPSM_EVENT_HCB_OFFLINE = 13,    /*  BFA rport offline callback  */
703         RPSM_EVENT_FC4_OFFLINE = 14,    /*  FC-4 offline complete       */
704         RPSM_EVENT_ADDRESS_CHANGE = 15, /*  Rport's PID has changed     */
705         RPSM_EVENT_ADDRESS_DISC = 16,   /*  Need to Discover rport's PID */
706         RPSM_EVENT_PRLO_RCVD   = 17,    /*  PRLO from remote device     */
707         RPSM_EVENT_PLOGI_RETRY = 18,    /*  Retry PLOGI continously */
708 };
709
710 /*
711  * bfa fcs API functions
712  */
713 void bfa_fcs_attach(struct bfa_fcs_s *fcs, struct bfa_s *bfa,
714                     struct bfad_s *bfad,
715                     bfa_boolean_t min_cfg);
716 void bfa_fcs_init(struct bfa_fcs_s *fcs);
717 void bfa_fcs_driver_info_init(struct bfa_fcs_s *fcs,
718                               struct bfa_fcs_driver_info_s *driver_info);
719 void bfa_fcs_exit(struct bfa_fcs_s *fcs);
720
721 /*
722  * bfa fcs vf public functions
723  */
724 bfa_fcs_vf_t *bfa_fcs_vf_lookup(struct bfa_fcs_s *fcs, u16 vf_id);
725
726 /*
727  * fabric protected interface functions
728  */
729 void bfa_fcs_fabric_attach(struct bfa_fcs_s *fcs);
730 void bfa_fcs_fabric_modinit(struct bfa_fcs_s *fcs);
731 void bfa_fcs_fabric_modexit(struct bfa_fcs_s *fcs);
732 void bfa_fcs_fabric_link_up(struct bfa_fcs_fabric_s *fabric);
733 void bfa_fcs_fabric_link_down(struct bfa_fcs_fabric_s *fabric);
734 void bfa_fcs_fabric_addvport(struct bfa_fcs_fabric_s *fabric,
735         struct bfa_fcs_vport_s *vport);
736 void bfa_fcs_fabric_delvport(struct bfa_fcs_fabric_s *fabric,
737         struct bfa_fcs_vport_s *vport);
738 struct bfa_fcs_vport_s *bfa_fcs_fabric_vport_lookup(
739                 struct bfa_fcs_fabric_s *fabric, wwn_t pwwn);
740 void bfa_fcs_fabric_modstart(struct bfa_fcs_s *fcs);
741 void bfa_fcs_fabric_uf_recv(struct bfa_fcs_fabric_s *fabric,
742                 struct fchs_s *fchs, u16 len);
743 void    bfa_fcs_fabric_psymb_init(struct bfa_fcs_fabric_s *fabric);
744 void bfa_fcs_fabric_set_fabric_name(struct bfa_fcs_fabric_s *fabric,
745                wwn_t fabric_name);
746 u16 bfa_fcs_fabric_get_switch_oui(struct bfa_fcs_fabric_s *fabric);
747 void bfa_fcs_uf_attach(struct bfa_fcs_s *fcs);
748 void bfa_fcs_port_attach(struct bfa_fcs_s *fcs);
749 void bfa_fcs_fabric_sm_online(struct bfa_fcs_fabric_s *fabric,
750                         enum bfa_fcs_fabric_event event);
751 void bfa_fcs_fabric_sm_loopback(struct bfa_fcs_fabric_s *fabric,
752                         enum bfa_fcs_fabric_event event);
753 void bfa_fcs_fabric_sm_auth_failed(struct bfa_fcs_fabric_s *fabric,
754                         enum bfa_fcs_fabric_event event);
755
756 /*
757  * BFA FCS callback interfaces
758  */
759
760 /*
761  * fcb Main fcs callbacks
762  */
763
764 struct bfad_port_s;
765 struct bfad_vf_s;
766 struct bfad_vport_s;
767 struct bfad_rport_s;
768
769 /*
770  * lport callbacks
771  */
772 struct bfad_port_s *bfa_fcb_lport_new(struct bfad_s *bfad,
773                                       struct bfa_fcs_lport_s *port,
774                                       enum bfa_lport_role roles,
775                                       struct bfad_vf_s *vf_drv,
776                                       struct bfad_vport_s *vp_drv);
777 void bfa_fcb_lport_delete(struct bfad_s *bfad, enum bfa_lport_role roles,
778                           struct bfad_vf_s *vf_drv,
779                           struct bfad_vport_s *vp_drv);
780
781 /*
782  * vport callbacks
783  */
784 void bfa_fcb_pbc_vport_create(struct bfad_s *bfad, struct bfi_pbc_vport_s);
785
786 /*
787  * rport callbacks
788  */
789 bfa_status_t bfa_fcb_rport_alloc(struct bfad_s *bfad,
790                                  struct bfa_fcs_rport_s **rport,
791                                  struct bfad_rport_s **rport_drv);
792
793 /*
794  * itnim callbacks
795  */
796 void bfa_fcb_itnim_alloc(struct bfad_s *bfad, struct bfa_fcs_itnim_s **itnim,
797                          struct bfad_itnim_s **itnim_drv);
798 void bfa_fcb_itnim_free(struct bfad_s *bfad,
799                         struct bfad_itnim_s *itnim_drv);
800 void bfa_fcb_itnim_online(struct bfad_itnim_s *itnim_drv);
801 void bfa_fcb_itnim_offline(struct bfad_itnim_s *itnim_drv);
802
803 #endif /* __BFA_FCS_H__ */