[SCSI] bfa: Add pbc port disable check and fix LPS message name
[pandora-kernel.git] / drivers / scsi / bfa / bfi.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 __BFI_H__
19 #define __BFI_H__
20
21 #include "bfa_defs.h"
22 #include "bfa_defs_svc.h"
23
24 #pragma pack(1)
25
26 /*
27  * BFI FW image type
28  */
29 #define BFI_FLASH_CHUNK_SZ                      256     /*  Flash chunk size */
30 #define BFI_FLASH_CHUNK_SZ_WORDS        (BFI_FLASH_CHUNK_SZ/sizeof(u32))
31 enum {
32         BFI_IMAGE_CB_FC,
33         BFI_IMAGE_CT_FC,
34         BFI_IMAGE_CT_CNA,
35         BFI_IMAGE_MAX,
36 };
37
38 /*
39  * Msg header common to all msgs
40  */
41 struct bfi_mhdr_s {
42         u8              msg_class;      /*  @ref bfi_mclass_t               */
43         u8              msg_id;         /*  msg opcode with in the class   */
44         union {
45                 struct {
46                         u8      qid;
47                         u8      lpu_id; /*  msg destination                 */
48                 } h2i;
49                 u16     i2htok; /*  token in msgs to host           */
50         } mtag;
51 };
52
53 #define bfi_mhdr_2_qid(_mh)     ((_mh)->mtag.h2i.qid)
54
55 #define bfi_h2i_set(_mh, _mc, _op, _lpuid) do {         \
56         (_mh).msg_class         = (_mc);      \
57         (_mh).msg_id            = (_op);      \
58         (_mh).mtag.h2i.lpu_id   = (_lpuid);      \
59 } while (0)
60
61 #define bfi_i2h_set(_mh, _mc, _op, _i2htok) do {                \
62         (_mh).msg_class         = (_mc);      \
63         (_mh).msg_id            = (_op);      \
64         (_mh).mtag.i2htok       = (_i2htok);      \
65 } while (0)
66
67 /*
68  * Message opcodes: 0-127 to firmware, 128-255 to host
69  */
70 #define BFI_I2H_OPCODE_BASE     128
71 #define BFA_I2HM(_x)            ((_x) + BFI_I2H_OPCODE_BASE)
72
73 /*
74  ****************************************************************************
75  *
76  * Scatter Gather Element and Page definition
77  *
78  ****************************************************************************
79  */
80
81 #define BFI_SGE_INLINE  1
82 #define BFI_SGE_INLINE_MAX      (BFI_SGE_INLINE + 1)
83
84 /*
85  * SG Flags
86  */
87 enum {
88         BFI_SGE_DATA            = 0,    /*  data address, not last           */
89         BFI_SGE_DATA_CPL        = 1,    /*  data addr, last in current page */
90         BFI_SGE_DATA_LAST       = 3,    /*  data address, last               */
91         BFI_SGE_LINK            = 2,    /*  link address                     */
92         BFI_SGE_PGDLEN          = 2,    /*  cumulative data length for page */
93 };
94
95 /*
96  * DMA addresses
97  */
98 union bfi_addr_u {
99         struct {
100                 __be32  addr_lo;
101                 __be32  addr_hi;
102         } a32;
103 };
104
105 /*
106  * Scatter Gather Element used for fast-path IO requests
107  */
108 struct bfi_sge_s {
109 #ifdef __BIG_ENDIAN
110         u32     flags:2,
111                         rsvd:2,
112                         sg_len:28;
113 #else
114         u32     sg_len:28,
115                         rsvd:2,
116                         flags:2;
117 #endif
118         union bfi_addr_u sga;
119 };
120
121 /**
122  * Generic DMA addr-len pair.
123  */
124 struct bfi_alen_s {
125         union bfi_addr_u        al_addr;        /* DMA addr of buffer   */
126         u32                     al_len;         /* length of buffer     */
127 };
128
129 /*
130  * Scatter Gather Page
131  */
132 #define BFI_SGPG_DATA_SGES              7
133 #define BFI_SGPG_SGES_MAX               (BFI_SGPG_DATA_SGES + 1)
134 #define BFI_SGPG_RSVD_WD_LEN    8
135 struct bfi_sgpg_s {
136         struct bfi_sge_s sges[BFI_SGPG_SGES_MAX];
137         u32     rsvd[BFI_SGPG_RSVD_WD_LEN];
138 };
139
140 /*
141  * Large Message structure - 128 Bytes size Msgs
142  */
143 #define BFI_LMSG_SZ             128
144 #define BFI_LMSG_PL_WSZ \
145                         ((BFI_LMSG_SZ - sizeof(struct bfi_mhdr_s)) / 4)
146
147 struct bfi_msg_s {
148         struct bfi_mhdr_s mhdr;
149         u32     pl[BFI_LMSG_PL_WSZ];
150 };
151
152 /*
153  * Mailbox message structure
154  */
155 #define BFI_MBMSG_SZ            7
156 struct bfi_mbmsg_s {
157         struct bfi_mhdr_s       mh;
158         u32             pl[BFI_MBMSG_SZ];
159 };
160
161 /*
162  * Supported PCI function class codes (personality)
163  */
164 enum bfi_pcifn_class {
165         BFI_PCIFN_CLASS_FC  = 0x0c04,
166         BFI_PCIFN_CLASS_ETH = 0x0200,
167 };
168
169 /*
170  * Message Classes
171  */
172 enum bfi_mclass {
173         BFI_MC_IOC              = 1,    /*  IO Controller (IOC)     */
174         BFI_MC_FCPORT           = 5,    /*  FC port                         */
175         BFI_MC_IOCFC            = 6,    /*  FC - IO Controller (IOC)        */
176         BFI_MC_LL               = 7,    /*  Link Layer                      */
177         BFI_MC_UF               = 8,    /*  Unsolicited frame receive       */
178         BFI_MC_FCXP             = 9,    /*  FC Transport                    */
179         BFI_MC_LPS              = 10,   /*  lport fc login services         */
180         BFI_MC_RPORT            = 11,   /*  Remote port             */
181         BFI_MC_ITNIM            = 12,   /*  I-T nexus (Initiator mode)      */
182         BFI_MC_IOIM_READ        = 13,   /*  read IO (Initiator mode)        */
183         BFI_MC_IOIM_WRITE       = 14,   /*  write IO (Initiator mode)       */
184         BFI_MC_IOIM_IO          = 15,   /*  IO (Initiator mode)     */
185         BFI_MC_IOIM             = 16,   /*  IO (Initiator mode)     */
186         BFI_MC_IOIM_IOCOM       = 17,   /*  good IO completion              */
187         BFI_MC_TSKIM            = 18,   /*  Initiator Task management       */
188         BFI_MC_PORT             = 21,   /*  Physical port                   */
189         BFI_MC_MAX              = 32
190 };
191
192 #define BFI_IOC_MAX_CQS         4
193 #define BFI_IOC_MAX_CQS_ASIC    8
194 #define BFI_IOC_MSGLEN_MAX      32      /* 32 bytes */
195
196 #define BFI_BOOT_TYPE_OFF               8
197 #define BFI_BOOT_LOADER_OFF             12
198
199 #define BFI_BOOT_TYPE_NORMAL            0
200 #define BFI_BOOT_TYPE_FLASH             1
201 #define BFI_BOOT_TYPE_MEMTEST           2
202
203 #define BFI_BOOT_LOADER_OS              0
204 #define BFI_BOOT_LOADER_BIOS            1
205 #define BFI_BOOT_LOADER_UEFI            2
206
207 /*
208  *----------------------------------------------------------------------
209  *                              IOC
210  *----------------------------------------------------------------------
211  */
212
213 enum bfi_ioc_h2i_msgs {
214         BFI_IOC_H2I_ENABLE_REQ          = 1,
215         BFI_IOC_H2I_DISABLE_REQ         = 2,
216         BFI_IOC_H2I_GETATTR_REQ         = 3,
217         BFI_IOC_H2I_DBG_SYNC            = 4,
218         BFI_IOC_H2I_DBG_DUMP            = 5,
219 };
220
221 enum bfi_ioc_i2h_msgs {
222         BFI_IOC_I2H_ENABLE_REPLY        = BFA_I2HM(1),
223         BFI_IOC_I2H_DISABLE_REPLY       = BFA_I2HM(2),
224         BFI_IOC_I2H_GETATTR_REPLY       = BFA_I2HM(3),
225         BFI_IOC_I2H_READY_EVENT         = BFA_I2HM(4),
226         BFI_IOC_I2H_HBEAT               = BFA_I2HM(5),
227 };
228
229 /*
230  * BFI_IOC_H2I_GETATTR_REQ message
231  */
232 struct bfi_ioc_getattr_req_s {
233         struct bfi_mhdr_s       mh;
234         union bfi_addr_u        attr_addr;
235 };
236
237 struct bfi_ioc_attr_s {
238         wwn_t           mfg_pwwn;       /*  Mfg port wwn           */
239         wwn_t           mfg_nwwn;       /*  Mfg node wwn           */
240         mac_t           mfg_mac;        /*  Mfg mac                */
241         u16     rsvd_a;
242         wwn_t           pwwn;
243         wwn_t           nwwn;
244         mac_t           mac;            /*  PBC or Mfg mac         */
245         u16     rsvd_b;
246         mac_t           fcoe_mac;
247         u16     rsvd_c;
248         char            brcd_serialnum[STRSZ(BFA_MFG_SERIALNUM_SIZE)];
249         u8              pcie_gen;
250         u8              pcie_lanes_orig;
251         u8              pcie_lanes;
252         u8              rx_bbcredit;    /*  receive buffer credits */
253         u32     adapter_prop;   /*  adapter properties     */
254         u16     maxfrsize;      /*  max receive frame size */
255         char            asic_rev;
256         u8              rsvd_d;
257         char            fw_version[BFA_VERSION_LEN];
258         char            optrom_version[BFA_VERSION_LEN];
259         struct          bfa_mfg_vpd_s   vpd;
260         u32     card_type;      /*  card type                   */
261 };
262
263 /*
264  * BFI_IOC_I2H_GETATTR_REPLY message
265  */
266 struct bfi_ioc_getattr_reply_s {
267         struct  bfi_mhdr_s      mh;     /*  Common msg header           */
268         u8                      status; /*  cfg reply status            */
269         u8                      rsvd[3];
270 };
271
272 /*
273  * Firmware memory page offsets
274  */
275 #define BFI_IOC_SMEM_PG0_CB     (0x40)
276 #define BFI_IOC_SMEM_PG0_CT     (0x180)
277
278 /*
279  * Firmware statistic offset
280  */
281 #define BFI_IOC_FWSTATS_OFF     (0x6B40)
282 #define BFI_IOC_FWSTATS_SZ      (4096)
283
284 /*
285  * Firmware trace offset
286  */
287 #define BFI_IOC_TRC_OFF         (0x4b00)
288 #define BFI_IOC_TRC_ENTS        256
289
290 #define BFI_IOC_FW_SIGNATURE    (0xbfadbfad)
291 #define BFI_IOC_MD5SUM_SZ       4
292 struct bfi_ioc_image_hdr_s {
293         u32     signature;      /*  constant signature */
294         u32     rsvd_a;
295         u32     exec;           /*  exec vector */
296         u32     param;          /*  parameters          */
297         u32     rsvd_b[4];
298         u32     md5sum[BFI_IOC_MD5SUM_SZ];
299 };
300
301 /*
302  *  BFI_IOC_I2H_READY_EVENT message
303  */
304 struct bfi_ioc_rdy_event_s {
305         struct bfi_mhdr_s       mh;             /*  common msg header */
306         u8                      init_status;    /*  init event status */
307         u8                      rsvd[3];
308 };
309
310 struct bfi_ioc_hbeat_s {
311         struct bfi_mhdr_s  mh;          /*  common msg header           */
312         u32        hb_count;    /*  current heart beat count    */
313 };
314
315 /*
316  * IOC hardware/firmware state
317  */
318 enum bfi_ioc_state {
319         BFI_IOC_UNINIT          = 0,    /*  not initialized                  */
320         BFI_IOC_INITING         = 1,    /*  h/w is being initialized         */
321         BFI_IOC_HWINIT          = 2,    /*  h/w is initialized               */
322         BFI_IOC_CFG             = 3,    /*  IOC configuration in progress   */
323         BFI_IOC_OP              = 4,    /*  IOC is operational               */
324         BFI_IOC_DISABLING       = 5,    /*  IOC is being disabled            */
325         BFI_IOC_DISABLED        = 6,    /*  IOC is disabled                  */
326         BFI_IOC_CFG_DISABLED    = 7,    /*  IOC is being disabled;transient */
327         BFI_IOC_FAIL            = 8,    /*  IOC heart-beat failure           */
328         BFI_IOC_MEMTEST         = 9,    /*  IOC is doing memtest             */
329 };
330
331 #define BFI_IOC_ENDIAN_SIG  0x12345678
332
333 enum {
334         BFI_ADAPTER_TYPE_FC     = 0x01,         /*  FC adapters    */
335         BFI_ADAPTER_TYPE_MK     = 0x0f0000,     /*  adapter type mask     */
336         BFI_ADAPTER_TYPE_SH     = 16,           /*  adapter type shift    */
337         BFI_ADAPTER_NPORTS_MK   = 0xff00,       /*  number of ports mask  */
338         BFI_ADAPTER_NPORTS_SH   = 8,            /*  number of ports shift */
339         BFI_ADAPTER_SPEED_MK    = 0xff,         /*  adapter speed mask    */
340         BFI_ADAPTER_SPEED_SH    = 0,            /*  adapter speed shift   */
341         BFI_ADAPTER_PROTO       = 0x100000,     /*  prototype adapaters   */
342         BFI_ADAPTER_TTV         = 0x200000,     /*  TTV debug capable     */
343         BFI_ADAPTER_UNSUPP      = 0x400000,     /*  unknown adapter type  */
344 };
345
346 #define BFI_ADAPTER_GETP(__prop, __adap_prop)                   \
347         (((__adap_prop) & BFI_ADAPTER_ ## __prop ## _MK) >>     \
348                 BFI_ADAPTER_ ## __prop ## _SH)
349 #define BFI_ADAPTER_SETP(__prop, __val)                         \
350         ((__val) << BFI_ADAPTER_ ## __prop ## _SH)
351 #define BFI_ADAPTER_IS_PROTO(__adap_type)                       \
352         ((__adap_type) & BFI_ADAPTER_PROTO)
353 #define BFI_ADAPTER_IS_TTV(__adap_type)                         \
354         ((__adap_type) & BFI_ADAPTER_TTV)
355 #define BFI_ADAPTER_IS_UNSUPP(__adap_type)                      \
356         ((__adap_type) & BFI_ADAPTER_UNSUPP)
357 #define BFI_ADAPTER_IS_SPECIAL(__adap_type)                     \
358         ((__adap_type) & (BFI_ADAPTER_TTV | BFI_ADAPTER_PROTO | \
359                         BFI_ADAPTER_UNSUPP))
360
361 /*
362  * BFI_IOC_H2I_ENABLE_REQ & BFI_IOC_H2I_DISABLE_REQ messages
363  */
364 struct bfi_ioc_ctrl_req_s {
365         struct bfi_mhdr_s       mh;
366         u16                     clscode;
367         u16                     rsvd;
368         u32             tv_sec;
369 };
370 #define bfi_ioc_enable_req_t struct bfi_ioc_ctrl_req_s;
371 #define bfi_ioc_disable_req_t struct bfi_ioc_ctrl_req_s;
372
373 /*
374  * BFI_IOC_I2H_ENABLE_REPLY & BFI_IOC_I2H_DISABLE_REPLY messages
375  */
376 struct bfi_ioc_ctrl_reply_s {
377         struct bfi_mhdr_s       mh;             /*  Common msg header     */
378         u8                      status;         /*  enable/disable status */
379         u8                      rsvd[3];
380 };
381 #define bfi_ioc_enable_reply_t struct bfi_ioc_ctrl_reply_s;
382 #define bfi_ioc_disable_reply_t struct bfi_ioc_ctrl_reply_s;
383
384 #define BFI_IOC_MSGSZ   8
385 /*
386  * H2I Messages
387  */
388 union bfi_ioc_h2i_msg_u {
389         struct bfi_mhdr_s               mh;
390         struct bfi_ioc_ctrl_req_s       enable_req;
391         struct bfi_ioc_ctrl_req_s       disable_req;
392         struct bfi_ioc_getattr_req_s    getattr_req;
393         u32                     mboxmsg[BFI_IOC_MSGSZ];
394 };
395
396 /*
397  * I2H Messages
398  */
399 union bfi_ioc_i2h_msg_u {
400         struct bfi_mhdr_s               mh;
401         struct bfi_ioc_rdy_event_s      rdy_event;
402         u32                     mboxmsg[BFI_IOC_MSGSZ];
403 };
404
405
406 /*
407  *----------------------------------------------------------------------
408  *                              PBC
409  *----------------------------------------------------------------------
410  */
411
412 #define BFI_PBC_MAX_BLUNS       8
413 #define BFI_PBC_MAX_VPORTS      16
414 #define BFI_PBC_PORT_DISABLED   2
415
416 /*
417  * PBC boot lun configuration
418  */
419 struct bfi_pbc_blun_s {
420         wwn_t           tgt_pwwn;
421         struct scsi_lun tgt_lun;
422 };
423
424 /*
425  * PBC virtual port configuration
426  */
427 struct bfi_pbc_vport_s {
428         wwn_t           vp_pwwn;
429         wwn_t           vp_nwwn;
430 };
431
432 /*
433  * BFI pre-boot configuration information
434  */
435 struct bfi_pbc_s {
436         u8              port_enabled;
437         u8              boot_enabled;
438         u8              nbluns;
439         u8              nvports;
440         u8              port_speed;
441         u8              rsvd_a;
442         u16     hss;
443         wwn_t           pbc_pwwn;
444         wwn_t           pbc_nwwn;
445         struct bfi_pbc_blun_s blun[BFI_PBC_MAX_BLUNS];
446         struct bfi_pbc_vport_s vport[BFI_PBC_MAX_VPORTS];
447 };
448
449 /*
450  *----------------------------------------------------------------------
451  *                              MSGQ
452  *----------------------------------------------------------------------
453  */
454 #define BFI_MSGQ_FULL(_q)       (((_q->pi + 1) % _q->q_depth) == _q->ci)
455 #define BFI_MSGQ_EMPTY(_q)      (_q->pi == _q->ci)
456 #define BFI_MSGQ_UPDATE_CI(_q)  (_q->ci = (_q->ci + 1) % _q->q_depth)
457 #define BFI_MSGQ_UPDATE_PI(_q)  (_q->pi = (_q->pi + 1) % _q->q_depth)
458
459 /* q_depth must be power of 2 */
460 #define BFI_MSGQ_FREE_CNT(_q)   ((_q->ci - _q->pi - 1) & (_q->q_depth - 1))
461
462 enum bfi_msgq_h2i_msgs_e {
463         BFI_MSGQ_H2I_INIT_REQ   = 1,
464         BFI_MSGQ_H2I_DOORBELL   = 2,
465         BFI_MSGQ_H2I_SHUTDOWN   = 3,
466 };
467
468 enum bfi_msgq_i2h_msgs_e {
469         BFI_MSGQ_I2H_INIT_RSP   = 1,
470         BFI_MSGQ_I2H_DOORBELL   = 2,
471 };
472
473
474 /* Messages(commands/responsed/AENS will have the following header */
475 struct bfi_msgq_mhdr_s {
476         u8              msg_class;
477         u8              msg_id;
478         u16     msg_token;
479         u16     num_entries;
480         u8              enet_id;
481         u8              rsvd[1];
482 };
483
484 #define bfi_msgq_mhdr_set(_mh, _mc, _mid, _tok, _enet_id) do {        \
485         (_mh).msg_class         = (_mc);      \
486         (_mh).msg_id            = (_mid);      \
487         (_mh).msg_token         = (_tok);      \
488         (_mh).enet_id           = (_enet_id);      \
489 } while (0)
490
491 /*
492  * Mailbox  for messaging interface
493  *
494 */
495 #define BFI_MSGQ_CMD_ENTRY_SIZE         (64)    /* TBD */
496 #define BFI_MSGQ_RSP_ENTRY_SIZE         (64)    /* TBD */
497 #define BFI_MSGQ_MSG_SIZE_MAX           (2048)  /* TBD */
498
499 struct bfi_msgq_s {
500         union bfi_addr_u addr;
501         u16 q_depth;     /* Total num of entries in the queue */
502         u8 rsvd[2];
503 };
504
505 /* BFI_ENET_MSGQ_CFG_REQ TBD init or cfg? */
506 struct bfi_msgq_cfg_req_s {
507         struct bfi_mhdr_s mh;
508         struct bfi_msgq_s cmdq;
509         struct bfi_msgq_s rspq;
510 };
511
512 /* BFI_ENET_MSGQ_CFG_RSP */
513 struct bfi_msgq_cfg_rsp_s {
514         struct bfi_mhdr_s mh;
515         u8 cmd_status;
516         u8 rsvd[3];
517 };
518
519
520 /* BFI_MSGQ_H2I_DOORBELL */
521 struct bfi_msgq_h2i_db_s {
522         struct bfi_mhdr_s mh;
523         u16 cmdq_pi;
524         u16 rspq_ci;
525 };
526
527 /* BFI_MSGQ_I2H_DOORBELL */
528 struct bfi_msgq_i2h_db_s {
529         struct bfi_mhdr_s mh;
530         u16 rspq_pi;
531         u16 cmdq_ci;
532 };
533
534 #pragma pack()
535
536 /* BFI port specific */
537 #pragma pack(1)
538
539 enum bfi_port_h2i {
540         BFI_PORT_H2I_ENABLE_REQ         = (1),
541         BFI_PORT_H2I_DISABLE_REQ        = (2),
542         BFI_PORT_H2I_GET_STATS_REQ      = (3),
543         BFI_PORT_H2I_CLEAR_STATS_REQ    = (4),
544 };
545
546 enum bfi_port_i2h {
547         BFI_PORT_I2H_ENABLE_RSP         = BFA_I2HM(1),
548         BFI_PORT_I2H_DISABLE_RSP        = BFA_I2HM(2),
549         BFI_PORT_I2H_GET_STATS_RSP      = BFA_I2HM(3),
550         BFI_PORT_I2H_CLEAR_STATS_RSP    = BFA_I2HM(4),
551 };
552
553 /*
554  * Generic REQ type
555  */
556 struct bfi_port_generic_req_s {
557         struct bfi_mhdr_s  mh;          /*  msg header          */
558         u32     msgtag;         /*  msgtag for reply                */
559         u32     rsvd;
560 };
561
562 /*
563  * Generic RSP type
564  */
565 struct bfi_port_generic_rsp_s {
566         struct bfi_mhdr_s  mh;          /*  common msg header               */
567         u8              status;         /*  port enable status              */
568         u8              rsvd[3];
569         u32     msgtag;         /*  msgtag for reply                */
570 };
571
572 /*
573  * BFI_PORT_H2I_GET_STATS_REQ
574  */
575 struct bfi_port_get_stats_req_s {
576         struct bfi_mhdr_s  mh;          /*  common msg header               */
577         union bfi_addr_u   dma_addr;
578 };
579
580 union bfi_port_h2i_msg_u {
581         struct bfi_mhdr_s               mh;
582         struct bfi_port_generic_req_s   enable_req;
583         struct bfi_port_generic_req_s   disable_req;
584         struct bfi_port_get_stats_req_s getstats_req;
585         struct bfi_port_generic_req_s   clearstats_req;
586 };
587
588 union bfi_port_i2h_msg_u {
589         struct bfi_mhdr_s               mh;
590         struct bfi_port_generic_rsp_s   enable_rsp;
591         struct bfi_port_generic_rsp_s   disable_rsp;
592         struct bfi_port_generic_rsp_s   getstats_rsp;
593         struct bfi_port_generic_rsp_s   clearstats_rsp;
594 };
595
596 #pragma pack()
597
598 #endif /* __BFI_H__ */