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