2 * Copyright (c) 2005-2010 Brocade Communications Systems, Inc.
6 * Linux driver for Brocade Fibre Channel Host Bus Adapter.
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
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.
22 #include "bfa_defs_svc.h"
29 #define BFI_FLASH_CHUNK_SZ 256 /* Flash chunk size */
30 #define BFI_FLASH_CHUNK_SZ_WORDS (BFI_FLASH_CHUNK_SZ/sizeof(u32))
39 * Msg header common to all msgs
42 u8 msg_class; /* @ref bfi_mclass_t */
43 u8 msg_id; /* msg opcode with in the class */
47 u8 lpu_id; /* msg destination */
49 u16 i2htok; /* token in msgs to host */
53 #define bfi_mhdr_2_qid(_mh) ((_mh)->mtag.h2i.qid)
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); \
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); \
68 * Message opcodes: 0-127 to firmware, 128-255 to host
70 #define BFI_I2H_OPCODE_BASE 128
71 #define BFA_I2HM(_x) ((_x) + BFI_I2H_OPCODE_BASE)
74 ****************************************************************************
76 * Scatter Gather Element and Page definition
78 ****************************************************************************
81 #define BFI_SGE_INLINE 1
82 #define BFI_SGE_INLINE_MAX (BFI_SGE_INLINE + 1)
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 */
106 * Scatter Gather Element used for fast-path IO requests
118 union bfi_addr_u sga;
122 * Generic DMA addr-len pair.
125 union bfi_addr_u al_addr; /* DMA addr of buffer */
126 u32 al_len; /* length of buffer */
130 * Scatter Gather Page
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
136 struct bfi_sge_s sges[BFI_SGPG_SGES_MAX];
137 u32 rsvd[BFI_SGPG_RSVD_WD_LEN];
141 * Large Message structure - 128 Bytes size Msgs
143 #define BFI_LMSG_SZ 128
144 #define BFI_LMSG_PL_WSZ \
145 ((BFI_LMSG_SZ - sizeof(struct bfi_mhdr_s)) / 4)
148 struct bfi_mhdr_s mhdr;
149 u32 pl[BFI_LMSG_PL_WSZ];
153 * Mailbox message structure
155 #define BFI_MBMSG_SZ 7
157 struct bfi_mhdr_s mh;
158 u32 pl[BFI_MBMSG_SZ];
162 * Supported PCI function class codes (personality)
164 enum bfi_pcifn_class {
165 BFI_PCIFN_CLASS_FC = 0x0c04,
166 BFI_PCIFN_CLASS_ETH = 0x0200,
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 */
192 #define BFI_IOC_MAX_CQS 4
193 #define BFI_IOC_MAX_CQS_ASIC 8
194 #define BFI_IOC_MSGLEN_MAX 32 /* 32 bytes */
196 #define BFI_BOOT_TYPE_OFF 8
197 #define BFI_BOOT_LOADER_OFF 12
199 #define BFI_BOOT_TYPE_NORMAL 0
200 #define BFI_BOOT_TYPE_FLASH 1
201 #define BFI_BOOT_TYPE_MEMTEST 2
203 #define BFI_BOOT_LOADER_OS 0
204 #define BFI_BOOT_LOADER_BIOS 1
205 #define BFI_BOOT_LOADER_UEFI 2
208 *----------------------------------------------------------------------
210 *----------------------------------------------------------------------
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,
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),
230 * BFI_IOC_H2I_GETATTR_REQ message
232 struct bfi_ioc_getattr_req_s {
233 struct bfi_mhdr_s mh;
234 union bfi_addr_u attr_addr;
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 */
244 mac_t mac; /* PBC or Mfg mac */
248 char brcd_serialnum[STRSZ(BFA_MFG_SERIALNUM_SIZE)];
252 u8 rx_bbcredit; /* receive buffer credits */
253 u32 adapter_prop; /* adapter properties */
254 u16 maxfrsize; /* max receive frame size */
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 */
264 * BFI_IOC_I2H_GETATTR_REPLY message
266 struct bfi_ioc_getattr_reply_s {
267 struct bfi_mhdr_s mh; /* Common msg header */
268 u8 status; /* cfg reply status */
273 * Firmware memory page offsets
275 #define BFI_IOC_SMEM_PG0_CB (0x40)
276 #define BFI_IOC_SMEM_PG0_CT (0x180)
279 * Firmware statistic offset
281 #define BFI_IOC_FWSTATS_OFF (0x6B40)
282 #define BFI_IOC_FWSTATS_SZ (4096)
285 * Firmware trace offset
287 #define BFI_IOC_TRC_OFF (0x4b00)
288 #define BFI_IOC_TRC_ENTS 256
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 */
295 u32 exec; /* exec vector */
296 u32 param; /* parameters */
298 u32 md5sum[BFI_IOC_MD5SUM_SZ];
302 * BFI_IOC_I2H_READY_EVENT message
304 struct bfi_ioc_rdy_event_s {
305 struct bfi_mhdr_s mh; /* common msg header */
306 u8 init_status; /* init event status */
310 struct bfi_ioc_hbeat_s {
311 struct bfi_mhdr_s mh; /* common msg header */
312 u32 hb_count; /* current heart beat count */
316 * IOC hardware/firmware 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 */
331 #define BFI_IOC_ENDIAN_SIG 0x12345678
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 */
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 | \
362 * BFI_IOC_H2I_ENABLE_REQ & BFI_IOC_H2I_DISABLE_REQ messages
364 struct bfi_ioc_ctrl_req_s {
365 struct bfi_mhdr_s mh;
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;
374 * BFI_IOC_I2H_ENABLE_REPLY & BFI_IOC_I2H_DISABLE_REPLY messages
376 struct bfi_ioc_ctrl_reply_s {
377 struct bfi_mhdr_s mh; /* Common msg header */
378 u8 status; /* enable/disable status */
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;
384 #define BFI_IOC_MSGSZ 8
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];
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];
407 *----------------------------------------------------------------------
409 *----------------------------------------------------------------------
412 #define BFI_PBC_MAX_BLUNS 8
413 #define BFI_PBC_MAX_VPORTS 16
414 #define BFI_PBC_PORT_DISABLED 2
417 * PBC boot lun configuration
419 struct bfi_pbc_blun_s {
421 struct scsi_lun tgt_lun;
425 * PBC virtual port configuration
427 struct bfi_pbc_vport_s {
433 * BFI pre-boot configuration information
445 struct bfi_pbc_blun_s blun[BFI_PBC_MAX_BLUNS];
446 struct bfi_pbc_vport_s vport[BFI_PBC_MAX_VPORTS];
450 *----------------------------------------------------------------------
452 *----------------------------------------------------------------------
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)
459 /* q_depth must be power of 2 */
460 #define BFI_MSGQ_FREE_CNT(_q) ((_q->ci - _q->pi - 1) & (_q->q_depth - 1))
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,
468 enum bfi_msgq_i2h_msgs_e {
469 BFI_MSGQ_I2H_INIT_RSP = 1,
470 BFI_MSGQ_I2H_DOORBELL = 2,
474 /* Messages(commands/responsed/AENS will have the following header */
475 struct bfi_msgq_mhdr_s {
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); \
492 * Mailbox for messaging interface
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 */
500 union bfi_addr_u addr;
501 u16 q_depth; /* Total num of entries in the queue */
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;
512 /* BFI_ENET_MSGQ_CFG_RSP */
513 struct bfi_msgq_cfg_rsp_s {
514 struct bfi_mhdr_s mh;
520 /* BFI_MSGQ_H2I_DOORBELL */
521 struct bfi_msgq_h2i_db_s {
522 struct bfi_mhdr_s mh;
527 /* BFI_MSGQ_I2H_DOORBELL */
528 struct bfi_msgq_i2h_db_s {
529 struct bfi_mhdr_s mh;
536 /* BFI port specific */
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),
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),
556 struct bfi_port_generic_req_s {
557 struct bfi_mhdr_s mh; /* msg header */
558 u32 msgtag; /* msgtag for reply */
565 struct bfi_port_generic_rsp_s {
566 struct bfi_mhdr_s mh; /* common msg header */
567 u8 status; /* port enable status */
569 u32 msgtag; /* msgtag for reply */
573 * BFI_PORT_H2I_GET_STATS_REQ
575 struct bfi_port_get_stats_req_s {
576 struct bfi_mhdr_s mh; /* common msg header */
577 union bfi_addr_u dma_addr;
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;
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;
598 #endif /* __BFI_H__ */