/* bnx2i.h: QLogic NetXtreme II iSCSI driver. * * Copyright (c) 2006 - 2013 Broadcom Corporation * Copyright (c) 2007, 2008 Red Hat, Inc. All rights reserved. * Copyright (c) 2007, 2008 Mike Christie * Copyright (c) 2014, QLogic Corporation * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation. * * Written by: Anil Veerabhadrappa ([email protected]) * Previously Maintained by: Eddie Wai ([email protected]) * Maintained by: [email protected] */ #ifndef _BNX2I_H_ #define _BNX2I_H_ #include <linux/module.h> #include <linux/moduleparam.h> #include <linux/errno.h> #include <linux/pci.h> #include <linux/spinlock.h> #include <linux/interrupt.h> #include <linux/delay.h> #include <linux/sched/signal.h> #include <linux/in.h> #include <linux/kfifo.h> #include <linux/netdevice.h> #include <linux/completion.h> #include <linux/kthread.h> #include <linux/cpu.h> #include <scsi/scsi_cmnd.h> #include <scsi/scsi_device.h> #include <scsi/scsi_eh.h> #include <scsi/scsi_host.h> #include <scsi/scsi.h> #include <scsi/iscsi_proto.h> #include <scsi/libiscsi.h> #include <scsi/scsi_transport_iscsi.h> #include "../../net/ethernet/broadcom/cnic_if.h" #include "57xx_iscsi_hsi.h" #include "57xx_iscsi_constants.h" #include "../../net/ethernet/broadcom/bnx2x/bnx2x_mfw_req.h" #define BNX2_ISCSI_DRIVER_NAME … #define BNX2I_MAX_ADAPTERS … #define ISCSI_MAX_CONNS_PER_HBA … #define ISCSI_MAX_SESS_PER_HBA … #define ISCSI_MAX_CMDS_PER_SESS … /* Total active commands across all connections supported by devices */ #define ISCSI_MAX_CMDS_PER_HBA_5708 … #define ISCSI_MAX_CMDS_PER_HBA_5709 … #define ISCSI_MAX_CMDS_PER_HBA_57710 … #define ISCSI_MAX_BDS_PER_CMD … #define MAX_PAGES_PER_CTRL_STRUCT_POOL … #define BNX2I_RESERVED_SLOW_PATH_CMD_SLOTS … #define BNX2X_DB_SHIFT … /* 5706/08 hardware has limit on maximum buffer size per BD it can handle */ #define MAX_BD_LENGTH … #define BD_SPLIT_SIZE … /* min, max & default values for SQ/RQ/CQ size, configurable via' modparam */ #define BNX2I_SQ_WQES_MIN … #define BNX2I_570X_SQ_WQES_MAX … #define BNX2I_5770X_SQ_WQES_MAX … #define BNX2I_570X_SQ_WQES_DEFAULT … #define BNX2I_5770X_SQ_WQES_DEFAULT … #define BNX2I_570X_CQ_WQES_MAX … #define BNX2I_5770X_CQ_WQES_MAX … #define BNX2I_RQ_WQES_MIN … #define BNX2I_RQ_WQES_MAX … #define BNX2I_RQ_WQES_DEFAULT … /* CCELLs per conn */ #define BNX2I_CCELLS_MIN … #define BNX2I_CCELLS_MAX … #define BNX2I_CCELLS_DEFAULT … #define ITT_INVALID_SIGNATURE … #define ISCSI_CMD_CLEANUP_TIMEOUT … #define BNX2I_CONN_CTX_BUF_SIZE … #define BNX2I_SQ_WQE_SIZE … #define BNX2I_RQ_WQE_SIZE … #define BNX2I_CQE_SIZE … #define MB_KERNEL_CTX_SHIFT … #define MB_KERNEL_CTX_SIZE … #define CTX_SHIFT … #define GET_CID_NUM(cid_addr) … #define CTX_OFFSET … #define MAX_CID_CNT … #define BNX2I_570X_PAGE_SIZE_DEFAULT … /* 5709 context registers */ #define BNX2_MQ_CONFIG2 … #define BNX2_MQ_CONFIG2_CONT_SZ … #define BNX2_MQ_CONFIG2_FIRST_L4L5 … /* 57710's BAR2 is mapped to doorbell registers */ #define BNX2X_DOORBELL_PCI_BAR … #define BNX2X_MAX_CQS … #define CNIC_ARM_CQE … #define CNIC_ARM_CQE_FP … #define CNIC_DISARM_CQE … #define REG_RD(__hba, offset) … #define REG_WR(__hba, offset, val) … #ifdef CONFIG_32BIT #define GET_STATS_64 … #define ADD_STATS_64 … #else #define GET_STATS_64(__hba, dst, field) … #define ADD_STATS_64(__hba, field, len) … #endif /** * struct generic_pdu_resc - login pdu resource structure * * @req_buf: driver buffer used to stage payload associated with * the login request * @req_dma_addr: dma address for iscsi login request payload buffer * @req_buf_size: actual login request payload length * @req_wr_ptr: pointer into login request buffer when next data is * to be written * @resp_hdr: iscsi header where iscsi login response header is to * be recreated * @resp_buf: buffer to stage login response payload * @resp_dma_addr: login response payload buffer dma address * @resp_buf_size: login response paylod length * @resp_wr_ptr: pointer into login response buffer when next data is * to be written * @req_bd_tbl: iscsi login request payload BD table * @req_bd_dma: login request BD table dma address * @resp_bd_tbl: iscsi login response payload BD table * @resp_bd_dma: login request BD table dma address * * following structure defines buffer info for generic pdus such as iSCSI Login, * Logout and NOP */ struct generic_pdu_resc { … }; /** * struct bd_resc_page - tracks DMA'able memory allocated for BD tables * * @link: list head to link elements * @max_ptrs: maximun pointers that can be stored in this page * @num_valid: number of pointer valid in this page * @page: base addess for page pointer array * * structure to track DMA'able memory allocated for command BD tables */ struct bd_resc_page { … }; /** * struct io_bdt - I/O buffer destricptor table * * @bd_tbl: BD table's virtual address * @bd_tbl_dma: BD table's dma address * @bd_valid: num valid BD entries * * IO BD table */ struct io_bdt { … }; /** * bnx2i_cmd - iscsi command structure * * @hdr: iSCSI header * @conn: iscsi_conn pointer * @scsi_cmd: SCSI-ML task pointer corresponding to this iscsi cmd * @sg: SG list * @io_tbl: buffer descriptor (BD) table * @bd_tbl_dma: buffer descriptor (BD) table's dma address * @req: bnx2i specific command request struct */ struct bnx2i_cmd { … }; /** * struct bnx2i_conn - iscsi connection structure * * @cls_conn: pointer to iscsi cls conn * @hba: adapter structure pointer * @iscsi_conn_cid: iscsi conn id * @fw_cid: firmware iscsi context id * @ep: endpoint structure pointer * @gen_pdu: login/nopout/logout pdu resources * @violation_notified: bit mask used to track iscsi error/warning messages * already printed out * @work_cnt: keeps track of the number of outstanding work * * iSCSI connection structure */ struct bnx2i_conn { … }; /** * struct iscsi_cid_queue - Per adapter iscsi cid queue * * @cid_que_base: queue base memory * @cid_que: queue memory pointer * @cid_q_prod_idx: produce index * @cid_q_cons_idx: consumer index * @cid_q_max_idx: max index. used to detect wrap around condition * @cid_free_cnt: queue size * @conn_cid_tbl: iscsi cid to conn structure mapping table * * Per adapter iSCSI CID Queue */ struct iscsi_cid_queue { … }; struct bnx2i_stats_info { … }; /** * struct bnx2i_hba - bnx2i adapter structure * * @link: list head to link elements * @cnic: pointer to cnic device * @pcidev: pointer to pci dev * @netdev: pointer to netdev structure * @regview: mapped PCI register space * @age: age, incremented by every recovery * @cnic_dev_type: cnic device type, 5706/5708/5709/57710 * @mail_queue_access: mailbox queue access mode, applicable to 5709 only * @reg_with_cnic: indicates whether the device is register with CNIC * @adapter_state: adapter state, UP, GOING_DOWN, LINK_DOWN * @mtu_supported: Ethernet MTU supported * @shost: scsi host pointer * @max_sqes: SQ size * @max_rqes: RQ size * @max_cqes: CQ size * @num_ccell: number of command cells per connection * @ofld_conns_active: active connection list * @eh_wait: wait queue for the endpoint to shutdown * @max_active_conns: max offload connections supported by this device * @cid_que: iscsi cid queue * @ep_rdwr_lock: read / write lock to synchronize various ep lists * @ep_ofld_list: connection list for pending offload completion * @ep_active_list: connection list for active offload endpoints * @ep_destroy_list: connection list for pending offload completion * @mp_bd_tbl: BD table to be used with middle path requests * @mp_bd_dma: DMA address of 'mp_bd_tbl' memory buffer * @dummy_buffer: Dummy buffer to be used with zero length scsicmd reqs * @dummy_buf_dma: DMA address of 'dummy_buffer' memory buffer * @lock: lock to synchonize access to hba structure * @hba_shutdown_tmo: Timeout value to shutdown each connection * @conn_teardown_tmo: Timeout value to tear down each connection * @conn_ctx_destroy_tmo: Timeout value to destroy context of each connection * @pci_did: PCI device ID * @pci_vid: PCI vendor ID * @pci_sdid: PCI subsystem device ID * @pci_svid: PCI subsystem vendor ID * @pci_func: PCI function number in system pci tree * @pci_devno: PCI device number in system pci tree * @num_wqe_sent: statistic counter, total wqe's sent * @num_cqe_rcvd: statistic counter, total cqe's received * @num_intr_claimed: statistic counter, total interrupts claimed * @link_changed_count: statistic counter, num of link change notifications * received * @ipaddr_changed_count: statistic counter, num times IP address changed while * at least one connection is offloaded * @num_sess_opened: statistic counter, total num sessions opened * @num_conn_opened: statistic counter, total num conns opened on this hba * @ctx_ccell_tasks: captures number of ccells and tasks supported by * currently offloaded connection, used to decode * context memory * @stat_lock: spin lock used by the statistic collector (32 bit) * @stats: local iSCSI statistic collection place holder * * Adapter Data Structure */ struct bnx2i_hba { … }; /******************************************************************************* * QP [ SQ / RQ / CQ ] info. ******************************************************************************/ /* * SQ/RQ/CQ generic structure definition */ struct sqe { … }; struct rqe { … }; struct cqe { … }; enum { … }; /* * CQ DB */ struct bnx2x_iscsi_cq_pend_cmpl { … }; struct bnx2i_5771x_cq_db { … }; struct bnx2i_5771x_sq_rq_db { … }; struct bnx2i_5771x_dbell_hdr { … }; struct bnx2i_5771x_dbell { … }; /** * struct qp_info - QP (share queue region) atrributes structure * * @ctx_base: ioremapped pci register base to access doorbell register * pertaining to this offloaded connection * @sq_virt: virtual address of send queue (SQ) region * @sq_phys: DMA address of SQ memory region * @sq_mem_size: SQ size * @sq_prod_qe: SQ producer entry pointer * @sq_cons_qe: SQ consumer entry pointer * @sq_first_qe: virtual address of first entry in SQ * @sq_last_qe: virtual address of last entry in SQ * @sq_prod_idx: SQ producer index * @sq_cons_idx: SQ consumer index * @sqe_left: number sq entry left * @sq_pgtbl_virt: page table describing buffer consituting SQ region * @sq_pgtbl_phys: dma address of 'sq_pgtbl_virt' * @sq_pgtbl_size: SQ page table size * @cq_virt: virtual address of completion queue (CQ) region * @cq_phys: DMA address of RQ memory region * @cq_mem_size: CQ size * @cq_prod_qe: CQ producer entry pointer * @cq_cons_qe: CQ consumer entry pointer * @cq_first_qe: virtual address of first entry in CQ * @cq_last_qe: virtual address of last entry in CQ * @cq_prod_idx: CQ producer index * @cq_cons_idx: CQ consumer index * @cqe_left: number cq entry left * @cqe_size: size of each CQ entry * @cqe_exp_seq_sn: next expected CQE sequence number * @cq_pgtbl_virt: page table describing buffer consituting CQ region * @cq_pgtbl_phys: dma address of 'cq_pgtbl_virt' * @cq_pgtbl_size: CQ page table size * @rq_virt: virtual address of receive queue (RQ) region * @rq_phys: DMA address of RQ memory region * @rq_mem_size: RQ size * @rq_prod_qe: RQ producer entry pointer * @rq_cons_qe: RQ consumer entry pointer * @rq_first_qe: virtual address of first entry in RQ * @rq_last_qe: virtual address of last entry in RQ * @rq_prod_idx: RQ producer index * @rq_cons_idx: RQ consumer index * @rqe_left: number rq entry left * @rq_pgtbl_virt: page table describing buffer consituting RQ region * @rq_pgtbl_phys: dma address of 'rq_pgtbl_virt' * @rq_pgtbl_size: RQ page table size * * queue pair (QP) is a per connection shared data structure which is used * to send work requests (SQ), receive completion notifications (CQ) * and receive asynchoronous / scsi sense info (RQ). 'qp_info' structure * below holds queue memory, consumer/producer indexes and page table * information */ struct qp_info { … }; /* * CID handles */ struct ep_handles { … }; enum { … }; /** * struct bnx2i_endpoint - representation of tcp connection in NX2 world * * @link: list head to link elements * @hba: adapter to which this connection belongs * @conn: iscsi connection this EP is linked to * @cls_ep: associated iSCSI endpoint pointer * @cm_sk: cnic sock struct * @hba_age: age to detect if 'iscsid' issues ep_disconnect() * after HBA reset is completed by bnx2i/cnic/bnx2 * modules * @state: tracks offload connection state machine * @timestamp: tracks the start time when the ep begins to connect * @num_active_cmds: tracks the number of outstanding commands for this ep * @ec_shift: the amount of shift as part of the event coal calc * @qp: QP information * @ids: contains chip allocated *context id* & driver assigned * *iscsi cid* * @ofld_timer: offload timer to detect timeout * @ofld_wait: wait queue * * Endpoint Structure - equivalent of tcp socket structure */ struct bnx2i_endpoint { … }; struct bnx2i_work { … }; struct bnx2i_percpu_s { … }; /* Global variables */ extern unsigned int error_mask1, error_mask2; extern u64 iscsi_error_mask; extern unsigned int en_tcp_dack; extern unsigned int event_coal_div; extern unsigned int event_coal_min; extern struct scsi_transport_template *bnx2i_scsi_xport_template; extern struct iscsi_transport bnx2i_iscsi_transport; extern struct cnic_ulp_ops bnx2i_cnic_cb; extern unsigned int sq_size; extern unsigned int rq_size; extern const struct attribute_group *bnx2i_dev_groups[]; /* * Function Prototypes */ extern void bnx2i_identify_device(struct bnx2i_hba *hba, struct cnic_dev *dev); extern void bnx2i_ulp_init(struct cnic_dev *dev); extern void bnx2i_ulp_exit(struct cnic_dev *dev); extern void bnx2i_start(void *handle); extern void bnx2i_stop(void *handle); extern int bnx2i_get_stats(void *handle); extern struct bnx2i_hba *get_adapter_list_head(void); struct bnx2i_conn *bnx2i_get_conn_from_id(struct bnx2i_hba *hba, u16 iscsi_cid); struct bnx2i_hba *bnx2i_find_hba_for_cnic(struct cnic_dev *cnic); struct bnx2i_hba *bnx2i_alloc_hba(struct cnic_dev *cnic); void bnx2i_free_hba(struct bnx2i_hba *hba); void bnx2i_get_rq_buf(struct bnx2i_conn *conn, char *ptr, int len); void bnx2i_put_rq_buf(struct bnx2i_conn *conn, int count); void bnx2i_iscsi_unmap_sg_list(struct bnx2i_cmd *cmd); void bnx2i_drop_session(struct iscsi_cls_session *session); extern int bnx2i_send_fw_iscsi_init_msg(struct bnx2i_hba *hba); extern int bnx2i_send_iscsi_login(struct bnx2i_conn *conn, struct iscsi_task *mtask); extern int bnx2i_send_iscsi_tmf(struct bnx2i_conn *conn, struct iscsi_task *mtask); extern int bnx2i_send_iscsi_text(struct bnx2i_conn *conn, struct iscsi_task *mtask); extern int bnx2i_send_iscsi_scsicmd(struct bnx2i_conn *conn, struct bnx2i_cmd *cmnd); extern int bnx2i_send_iscsi_nopout(struct bnx2i_conn *conn, struct iscsi_task *mtask, char *datap, int data_len, int unsol); extern int bnx2i_send_iscsi_logout(struct bnx2i_conn *conn, struct iscsi_task *mtask); extern void bnx2i_send_cmd_cleanup_req(struct bnx2i_hba *hba, struct bnx2i_cmd *cmd); extern int bnx2i_send_conn_ofld_req(struct bnx2i_hba *hba, struct bnx2i_endpoint *ep); extern void bnx2i_update_iscsi_conn(struct iscsi_conn *conn); extern int bnx2i_send_conn_destroy(struct bnx2i_hba *hba, struct bnx2i_endpoint *ep); extern int bnx2i_alloc_qp_resc(struct bnx2i_hba *hba, struct bnx2i_endpoint *ep); extern void bnx2i_free_qp_resc(struct bnx2i_hba *hba, struct bnx2i_endpoint *ep); extern void bnx2i_ep_ofld_timer(struct timer_list *t); extern struct bnx2i_endpoint *bnx2i_find_ep_in_ofld_list( struct bnx2i_hba *hba, u32 iscsi_cid); extern struct bnx2i_endpoint *bnx2i_find_ep_in_destroy_list( struct bnx2i_hba *hba, u32 iscsi_cid); extern int bnx2i_map_ep_dbell_regs(struct bnx2i_endpoint *ep); extern int bnx2i_arm_cq_event_coalescing(struct bnx2i_endpoint *ep, u8 action); extern int bnx2i_hw_ep_disconnect(struct bnx2i_endpoint *bnx2i_ep); extern int bnx2i_percpu_io_thread(void *arg); extern int bnx2i_process_scsi_cmd_resp(struct iscsi_session *session, struct bnx2i_conn *bnx2i_conn, struct cqe *cqe); #endif