#ifndef _QIB_KERNEL_H1#define _QIB_KERNEL_H2/*3* Copyright (c) 2006, 2007, 2008, 2009, 2010 QLogic Corporation.4* All rights reserved.5* Copyright (c) 2003, 2004, 2005, 2006 PathScale, Inc. All rights reserved.6*7* This software is available to you under a choice of one of two8* licenses. You may choose to be licensed under the terms of the GNU9* General Public License (GPL) Version 2, available from the file10* COPYING in the main directory of this source tree, or the11* OpenIB.org BSD license below:12*13* Redistribution and use in source and binary forms, with or14* without modification, are permitted provided that the following15* conditions are met:16*17* - Redistributions of source code must retain the above18* copyright notice, this list of conditions and the following19* disclaimer.20*21* - Redistributions in binary form must reproduce the above22* copyright notice, this list of conditions and the following23* disclaimer in the documentation and/or other materials24* provided with the distribution.25*26* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,27* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF28* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND29* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS30* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN31* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN32* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE33* SOFTWARE.34*/3536/*37* This header file is the base header file for qlogic_ib kernel code38* qib_user.h serves a similar purpose for user code.39*/4041#include <linux/interrupt.h>42#include <linux/pci.h>43#include <linux/dma-mapping.h>44#include <linux/mutex.h>45#include <linux/list.h>46#include <linux/scatterlist.h>47#include <linux/slab.h>48#include <linux/io.h>49#include <linux/fs.h>50#include <linux/completion.h>51#include <linux/kref.h>52#include <linux/sched.h>5354#include "qib_common.h"55#include "qib_verbs.h"5657/* only s/w major version of QLogic_IB we can handle */58#define QIB_CHIP_VERS_MAJ 2U5960/* don't care about this except printing */61#define QIB_CHIP_VERS_MIN 0U6263/* The Organization Unique Identifier (Mfg code), and its position in GUID */64#define QIB_OUI 0x00117565#define QIB_OUI_LSB 406667/*68* per driver stats, either not device nor port-specific, or69* summed over all of the devices and ports.70* They are described by name via ipathfs filesystem, so layout71* and number of elements can change without breaking compatibility.72* If members are added or deleted qib_statnames[] in qib_fs.c must73* change to match.74*/75struct qlogic_ib_stats {76__u64 sps_ints; /* number of interrupts handled */77__u64 sps_errints; /* number of error interrupts */78__u64 sps_txerrs; /* tx-related packet errors */79__u64 sps_rcverrs; /* non-crc rcv packet errors */80__u64 sps_hwerrs; /* hardware errors reported (parity, etc.) */81__u64 sps_nopiobufs; /* no pio bufs avail from kernel */82__u64 sps_ctxts; /* number of contexts currently open */83__u64 sps_lenerrs; /* number of kernel packets where RHF != LRH len */84__u64 sps_buffull;85__u64 sps_hdrfull;86};8788extern struct qlogic_ib_stats qib_stats;89extern struct pci_error_handlers qib_pci_err_handler;90extern struct pci_driver qib_driver;9192#define QIB_CHIP_SWVERSION QIB_CHIP_VERS_MAJ93/*94* First-cut critierion for "device is active" is95* two thousand dwords combined Tx, Rx traffic per96* 5-second interval. SMA packets are 64 dwords,97* and occur "a few per second", presumably each way.98*/99#define QIB_TRAFFIC_ACTIVE_THRESHOLD (2000)100101/*102* Struct used to indicate which errors are logged in each of the103* error-counters that are logged to EEPROM. A counter is incremented104* _once_ (saturating at 255) for each event with any bits set in105* the error or hwerror register masks below.106*/107#define QIB_EEP_LOG_CNT (4)108struct qib_eep_log_mask {109u64 errs_to_log;110u64 hwerrs_to_log;111};112113/*114* Below contains all data related to a single context (formerly called port).115*/116struct qib_ctxtdata {117void **rcvegrbuf;118dma_addr_t *rcvegrbuf_phys;119/* rcvhdrq base, needs mmap before useful */120void *rcvhdrq;121/* kernel virtual address where hdrqtail is updated */122void *rcvhdrtail_kvaddr;123/*124* temp buffer for expected send setup, allocated at open, instead125* of each setup call126*/127void *tid_pg_list;128/*129* Shared page for kernel to signal user processes that send buffers130* need disarming. The process should call QIB_CMD_DISARM_BUFS131* or QIB_CMD_ACK_EVENT with IPATH_EVENT_DISARM_BUFS set.132*/133unsigned long *user_event_mask;134/* when waiting for rcv or pioavail */135wait_queue_head_t wait;136/*137* rcvegr bufs base, physical, must fit138* in 44 bits so 32 bit programs mmap64 44 bit works)139*/140dma_addr_t rcvegr_phys;141/* mmap of hdrq, must fit in 44 bits */142dma_addr_t rcvhdrq_phys;143dma_addr_t rcvhdrqtailaddr_phys;144145/*146* number of opens (including slave sub-contexts) on this instance147* (ignoring forks, dup, etc. for now)148*/149int cnt;150/*151* how much space to leave at start of eager TID entries for152* protocol use, on each TID153*/154/* instead of calculating it */155unsigned ctxt;156/* non-zero if ctxt is being shared. */157u16 subctxt_cnt;158/* non-zero if ctxt is being shared. */159u16 subctxt_id;160/* number of eager TID entries. */161u16 rcvegrcnt;162/* index of first eager TID entry. */163u16 rcvegr_tid_base;164/* number of pio bufs for this ctxt (all procs, if shared) */165u32 piocnt;166/* first pio buffer for this ctxt */167u32 pio_base;168/* chip offset of PIO buffers for this ctxt */169u32 piobufs;170/* how many alloc_pages() chunks in rcvegrbuf_pages */171u32 rcvegrbuf_chunks;172/* how many egrbufs per chunk */173u32 rcvegrbufs_perchunk;174/* order for rcvegrbuf_pages */175size_t rcvegrbuf_size;176/* rcvhdrq size (for freeing) */177size_t rcvhdrq_size;178/* per-context flags for fileops/intr communication */179unsigned long flag;180/* next expected TID to check when looking for free */181u32 tidcursor;182/* WAIT_RCV that timed out, no interrupt */183u32 rcvwait_to;184/* WAIT_PIO that timed out, no interrupt */185u32 piowait_to;186/* WAIT_RCV already happened, no wait */187u32 rcvnowait;188/* WAIT_PIO already happened, no wait */189u32 pionowait;190/* total number of polled urgent packets */191u32 urgent;192/* saved total number of polled urgent packets for poll edge trigger */193u32 urgent_poll;194/* pid of process using this ctxt */195pid_t pid;196pid_t subpid[QLOGIC_IB_MAX_SUBCTXT];197/* same size as task_struct .comm[], command that opened context */198char comm[16];199/* pkeys set by this use of this ctxt */200u16 pkeys[4];201/* so file ops can get at unit */202struct qib_devdata *dd;203/* so funcs that need physical port can get it easily */204struct qib_pportdata *ppd;205/* A page of memory for rcvhdrhead, rcvegrhead, rcvegrtail * N */206void *subctxt_uregbase;207/* An array of pages for the eager receive buffers * N */208void *subctxt_rcvegrbuf;209/* An array of pages for the eager header queue entries * N */210void *subctxt_rcvhdr_base;211/* The version of the library which opened this ctxt */212u32 userversion;213/* Bitmask of active slaves */214u32 active_slaves;215/* Type of packets or conditions we want to poll for */216u16 poll_type;217/* receive packet sequence counter */218u8 seq_cnt;219u8 redirect_seq_cnt;220/* ctxt rcvhdrq head offset */221u32 head;222u32 pkt_count;223/* QPs waiting for context processing */224struct list_head qp_wait_list;225};226227struct qib_sge_state;228229struct qib_sdma_txreq {230int flags;231int sg_count;232dma_addr_t addr;233void (*callback)(struct qib_sdma_txreq *, int);234u16 start_idx; /* sdma private */235u16 next_descq_idx; /* sdma private */236struct list_head list; /* sdma private */237};238239struct qib_sdma_desc {240__le64 qw[2];241};242243struct qib_verbs_txreq {244struct qib_sdma_txreq txreq;245struct qib_qp *qp;246struct qib_swqe *wqe;247u32 dwords;248u16 hdr_dwords;249u16 hdr_inx;250struct qib_pio_header *align_buf;251struct qib_mregion *mr;252struct qib_sge_state *ss;253};254255#define QIB_SDMA_TXREQ_F_USELARGEBUF 0x1256#define QIB_SDMA_TXREQ_F_HEADTOHOST 0x2257#define QIB_SDMA_TXREQ_F_INTREQ 0x4258#define QIB_SDMA_TXREQ_F_FREEBUF 0x8259#define QIB_SDMA_TXREQ_F_FREEDESC 0x10260261#define QIB_SDMA_TXREQ_S_OK 0262#define QIB_SDMA_TXREQ_S_SENDERROR 1263#define QIB_SDMA_TXREQ_S_ABORTED 2264#define QIB_SDMA_TXREQ_S_SHUTDOWN 3265266/*267* Get/Set IB link-level config parameters for f_get/set_ib_cfg()268* Mostly for MADs that set or query link parameters, also ipath269* config interfaces270*/271#define QIB_IB_CFG_LIDLMC 0 /* LID (LS16b) and Mask (MS16b) */272#define QIB_IB_CFG_LWID_ENB 2 /* allowed Link-width */273#define QIB_IB_CFG_LWID 3 /* currently active Link-width */274#define QIB_IB_CFG_SPD_ENB 4 /* allowed Link speeds */275#define QIB_IB_CFG_SPD 5 /* current Link spd */276#define QIB_IB_CFG_RXPOL_ENB 6 /* Auto-RX-polarity enable */277#define QIB_IB_CFG_LREV_ENB 7 /* Auto-Lane-reversal enable */278#define QIB_IB_CFG_LINKLATENCY 8 /* Link Latency (IB1.2 only) */279#define QIB_IB_CFG_HRTBT 9 /* IB heartbeat off/enable/auto; DDR/QDR only */280#define QIB_IB_CFG_OP_VLS 10 /* operational VLs */281#define QIB_IB_CFG_VL_HIGH_CAP 11 /* num of VL high priority weights */282#define QIB_IB_CFG_VL_LOW_CAP 12 /* num of VL low priority weights */283#define QIB_IB_CFG_OVERRUN_THRESH 13 /* IB overrun threshold */284#define QIB_IB_CFG_PHYERR_THRESH 14 /* IB PHY error threshold */285#define QIB_IB_CFG_LINKDEFAULT 15 /* IB link default (sleep/poll) */286#define QIB_IB_CFG_PKEYS 16 /* update partition keys */287#define QIB_IB_CFG_MTU 17 /* update MTU in IBC */288#define QIB_IB_CFG_LSTATE 18 /* update linkcmd and linkinitcmd in IBC */289#define QIB_IB_CFG_VL_HIGH_LIMIT 19290#define QIB_IB_CFG_PMA_TICKS 20 /* PMA sample tick resolution */291#define QIB_IB_CFG_PORT 21 /* switch port we are connected to */292293/*294* for CFG_LSTATE: LINKCMD in upper 16 bits, LINKINITCMD in lower 16295* IB_LINKINITCMD_POLL and SLEEP are also used as set/get values for296* QIB_IB_CFG_LINKDEFAULT cmd297*/298#define IB_LINKCMD_DOWN (0 << 16)299#define IB_LINKCMD_ARMED (1 << 16)300#define IB_LINKCMD_ACTIVE (2 << 16)301#define IB_LINKINITCMD_NOP 0302#define IB_LINKINITCMD_POLL 1303#define IB_LINKINITCMD_SLEEP 2304#define IB_LINKINITCMD_DISABLE 3305306/*307* valid states passed to qib_set_linkstate() user call308*/309#define QIB_IB_LINKDOWN 0310#define QIB_IB_LINKARM 1311#define QIB_IB_LINKACTIVE 2312#define QIB_IB_LINKDOWN_ONLY 3313#define QIB_IB_LINKDOWN_SLEEP 4314#define QIB_IB_LINKDOWN_DISABLE 5315316/*317* These 7 values (SDR, DDR, and QDR may be ORed for auto-speed318* negotiation) are used for the 3rd argument to path_f_set_ib_cfg319* with cmd QIB_IB_CFG_SPD_ENB, by direct calls or via sysfs. They320* are also the the possible values for qib_link_speed_enabled and active321* The values were chosen to match values used within the IB spec.322*/323#define QIB_IB_SDR 1324#define QIB_IB_DDR 2325#define QIB_IB_QDR 4326327#define QIB_DEFAULT_MTU 4096328329/* max number of IB ports supported per HCA */330#define QIB_MAX_IB_PORTS 2331332/*333* Possible IB config parameters for f_get/set_ib_table()334*/335#define QIB_IB_TBL_VL_HIGH_ARB 1 /* Get/set VL high priority weights */336#define QIB_IB_TBL_VL_LOW_ARB 2 /* Get/set VL low priority weights */337338/*339* Possible "operations" for f_rcvctrl(ppd, op, ctxt)340* these are bits so they can be combined, e.g.341* QIB_RCVCTRL_INTRAVAIL_ENB | QIB_RCVCTRL_CTXT_ENB342*/343#define QIB_RCVCTRL_TAILUPD_ENB 0x01344#define QIB_RCVCTRL_TAILUPD_DIS 0x02345#define QIB_RCVCTRL_CTXT_ENB 0x04346#define QIB_RCVCTRL_CTXT_DIS 0x08347#define QIB_RCVCTRL_INTRAVAIL_ENB 0x10348#define QIB_RCVCTRL_INTRAVAIL_DIS 0x20349#define QIB_RCVCTRL_PKEY_ENB 0x40 /* Note, default is enabled */350#define QIB_RCVCTRL_PKEY_DIS 0x80351#define QIB_RCVCTRL_BP_ENB 0x0100352#define QIB_RCVCTRL_BP_DIS 0x0200353#define QIB_RCVCTRL_TIDFLOW_ENB 0x0400354#define QIB_RCVCTRL_TIDFLOW_DIS 0x0800355356/*357* Possible "operations" for f_sendctrl(ppd, op, var)358* these are bits so they can be combined, e.g.359* QIB_SENDCTRL_BUFAVAIL_ENB | QIB_SENDCTRL_ENB360* Some operations (e.g. DISARM, ABORT) are known to361* be "one-shot", so do not modify shadow.362*/363#define QIB_SENDCTRL_DISARM (0x1000)364#define QIB_SENDCTRL_DISARM_BUF(bufn) ((bufn) | QIB_SENDCTRL_DISARM)365/* available (0x2000) */366#define QIB_SENDCTRL_AVAIL_DIS (0x4000)367#define QIB_SENDCTRL_AVAIL_ENB (0x8000)368#define QIB_SENDCTRL_AVAIL_BLIP (0x10000)369#define QIB_SENDCTRL_SEND_DIS (0x20000)370#define QIB_SENDCTRL_SEND_ENB (0x40000)371#define QIB_SENDCTRL_FLUSH (0x80000)372#define QIB_SENDCTRL_CLEAR (0x100000)373#define QIB_SENDCTRL_DISARM_ALL (0x200000)374375/*376* These are the generic indices for requesting per-port377* counter values via the f_portcntr function. They378* are always returned as 64 bit values, although most379* are 32 bit counters.380*/381/* send-related counters */382#define QIBPORTCNTR_PKTSEND 0U383#define QIBPORTCNTR_WORDSEND 1U384#define QIBPORTCNTR_PSXMITDATA 2U385#define QIBPORTCNTR_PSXMITPKTS 3U386#define QIBPORTCNTR_PSXMITWAIT 4U387#define QIBPORTCNTR_SENDSTALL 5U388/* receive-related counters */389#define QIBPORTCNTR_PKTRCV 6U390#define QIBPORTCNTR_PSRCVDATA 7U391#define QIBPORTCNTR_PSRCVPKTS 8U392#define QIBPORTCNTR_RCVEBP 9U393#define QIBPORTCNTR_RCVOVFL 10U394#define QIBPORTCNTR_WORDRCV 11U395/* IB link related error counters */396#define QIBPORTCNTR_RXLOCALPHYERR 12U397#define QIBPORTCNTR_RXVLERR 13U398#define QIBPORTCNTR_ERRICRC 14U399#define QIBPORTCNTR_ERRVCRC 15U400#define QIBPORTCNTR_ERRLPCRC 16U401#define QIBPORTCNTR_BADFORMAT 17U402#define QIBPORTCNTR_ERR_RLEN 18U403#define QIBPORTCNTR_IBSYMBOLERR 19U404#define QIBPORTCNTR_INVALIDRLEN 20U405#define QIBPORTCNTR_UNSUPVL 21U406#define QIBPORTCNTR_EXCESSBUFOVFL 22U407#define QIBPORTCNTR_ERRLINK 23U408#define QIBPORTCNTR_IBLINKDOWN 24U409#define QIBPORTCNTR_IBLINKERRRECOV 25U410#define QIBPORTCNTR_LLI 26U411/* other error counters */412#define QIBPORTCNTR_RXDROPPKT 27U413#define QIBPORTCNTR_VL15PKTDROP 28U414#define QIBPORTCNTR_ERRPKEY 29U415#define QIBPORTCNTR_KHDROVFL 30U416/* sampling counters (these are actually control registers) */417#define QIBPORTCNTR_PSINTERVAL 31U418#define QIBPORTCNTR_PSSTART 32U419#define QIBPORTCNTR_PSSTAT 33U420421/* how often we check for packet activity for "power on hours (in seconds) */422#define ACTIVITY_TIMER 5423424/* Below is an opaque struct. Each chip (device) can maintain425* private data needed for its operation, but not germane to the426* rest of the driver. For convenience, we define another that427* is chip-specific, per-port428*/429struct qib_chip_specific;430struct qib_chipport_specific;431432enum qib_sdma_states {433qib_sdma_state_s00_hw_down,434qib_sdma_state_s10_hw_start_up_wait,435qib_sdma_state_s20_idle,436qib_sdma_state_s30_sw_clean_up_wait,437qib_sdma_state_s40_hw_clean_up_wait,438qib_sdma_state_s50_hw_halt_wait,439qib_sdma_state_s99_running,440};441442enum qib_sdma_events {443qib_sdma_event_e00_go_hw_down,444qib_sdma_event_e10_go_hw_start,445qib_sdma_event_e20_hw_started,446qib_sdma_event_e30_go_running,447qib_sdma_event_e40_sw_cleaned,448qib_sdma_event_e50_hw_cleaned,449qib_sdma_event_e60_hw_halted,450qib_sdma_event_e70_go_idle,451qib_sdma_event_e7220_err_halted,452qib_sdma_event_e7322_err_halted,453qib_sdma_event_e90_timer_tick,454};455456extern char *qib_sdma_state_names[];457extern char *qib_sdma_event_names[];458459struct sdma_set_state_action {460unsigned op_enable:1;461unsigned op_intenable:1;462unsigned op_halt:1;463unsigned op_drain:1;464unsigned go_s99_running_tofalse:1;465unsigned go_s99_running_totrue:1;466};467468struct qib_sdma_state {469struct kref kref;470struct completion comp;471enum qib_sdma_states current_state;472struct sdma_set_state_action *set_state_action;473unsigned current_op;474unsigned go_s99_running;475unsigned first_sendbuf;476unsigned last_sendbuf; /* really last +1 */477/* debugging/devel */478enum qib_sdma_states previous_state;479unsigned previous_op;480enum qib_sdma_events last_event;481};482483struct xmit_wait {484struct timer_list timer;485u64 counter;486u8 flags;487struct cache {488u64 psxmitdata;489u64 psrcvdata;490u64 psxmitpkts;491u64 psrcvpkts;492u64 psxmitwait;493} counter_cache;494};495496/*497* The structure below encapsulates data relevant to a physical IB Port.498* Current chips support only one such port, but the separation499* clarifies things a bit. Note that to conform to IB conventions,500* port-numbers are one-based. The first or only port is port1.501*/502struct qib_pportdata {503struct qib_ibport ibport_data;504505struct qib_devdata *dd;506struct qib_chippport_specific *cpspec; /* chip-specific per-port */507struct kobject pport_kobj;508struct kobject sl2vl_kobj;509struct kobject diagc_kobj;510511/* GUID for this interface, in network order */512__be64 guid;513514/* QIB_POLL, etc. link-state specific flags, per port */515u32 lflags;516/* qib_lflags driver is waiting for */517u32 state_wanted;518spinlock_t lflags_lock;519/* number of (port-specific) interrupts for this port -- saturates... */520u32 int_counter;521522/* ref count for each pkey */523atomic_t pkeyrefs[4];524525/*526* this address is mapped readonly into user processes so they can527* get status cheaply, whenever they want. One qword of status per port528*/529u64 *statusp;530531/* SendDMA related entries */532spinlock_t sdma_lock;533struct qib_sdma_state sdma_state;534unsigned long sdma_buf_jiffies;535struct qib_sdma_desc *sdma_descq;536u64 sdma_descq_added;537u64 sdma_descq_removed;538u16 sdma_descq_cnt;539u16 sdma_descq_tail;540u16 sdma_descq_head;541u16 sdma_next_intr;542u16 sdma_reset_wait;543u8 sdma_generation;544struct tasklet_struct sdma_sw_clean_up_task;545struct list_head sdma_activelist;546547dma_addr_t sdma_descq_phys;548volatile __le64 *sdma_head_dma; /* DMA'ed by chip */549dma_addr_t sdma_head_phys;550551wait_queue_head_t state_wait; /* for state_wanted */552553/* HoL blocking for SMP replies */554unsigned hol_state;555struct timer_list hol_timer;556557/*558* Shadow copies of registers; size indicates read access size.559* Most of them are readonly, but some are write-only register,560* where we manipulate the bits in the shadow copy, and then write561* the shadow copy to qlogic_ib.562*563* We deliberately make most of these 32 bits, since they have564* restricted range. For any that we read, we won't to generate 32565* bit accesses, since Opteron will generate 2 separate 32 bit HT566* transactions for a 64 bit read, and we want to avoid unnecessary567* bus transactions.568*/569570/* This is the 64 bit group */571/* last ibcstatus. opaque outside chip-specific code */572u64 lastibcstat;573574/* these are the "32 bit" regs */575576/*577* the following two are 32-bit bitmasks, but {test,clear,set}_bit578* all expect bit fields to be "unsigned long"579*/580unsigned long p_rcvctrl; /* shadow per-port rcvctrl */581unsigned long p_sendctrl; /* shadow per-port sendctrl */582583u32 ibmtu; /* The MTU programmed for this unit */584/*585* Current max size IB packet (in bytes) including IB headers, that586* we can send. Changes when ibmtu changes.587*/588u32 ibmaxlen;589/*590* ibmaxlen at init time, limited by chip and by receive buffer591* size. Not changed after init.592*/593u32 init_ibmaxlen;594/* LID programmed for this instance */595u16 lid;596/* list of pkeys programmed; 0 if not set */597u16 pkeys[4];598/* LID mask control */599u8 lmc;600u8 link_width_supported;601u8 link_speed_supported;602u8 link_width_enabled;603u8 link_speed_enabled;604u8 link_width_active;605u8 link_speed_active;606u8 vls_supported;607u8 vls_operational;608/* Rx Polarity inversion (compensate for ~tx on partner) */609u8 rx_pol_inv;610611u8 hw_pidx; /* physical port index */612u8 port; /* IB port number and index into dd->pports - 1 */613614u8 delay_mult;615616/* used to override LED behavior */617u8 led_override; /* Substituted for normal value, if non-zero */618u16 led_override_timeoff; /* delta to next timer event */619u8 led_override_vals[2]; /* Alternates per blink-frame */620u8 led_override_phase; /* Just counts, LSB picks from vals[] */621atomic_t led_override_timer_active;622/* Used to flash LEDs in override mode */623struct timer_list led_override_timer;624struct xmit_wait cong_stats;625struct timer_list symerr_clear_timer;626};627628/* Observers. Not to be taken lightly, possibly not to ship. */629/*630* If a diag read or write is to (bottom <= offset <= top),631* the "hoook" is called, allowing, e.g. shadows to be632* updated in sync with the driver. struct diag_observer633* is the "visible" part.634*/635struct diag_observer;636637typedef int (*diag_hook) (struct qib_devdata *dd,638const struct diag_observer *op,639u32 offs, u64 *data, u64 mask, int only_32);640641struct diag_observer {642diag_hook hook;643u32 bottom;644u32 top;645};646647extern int qib_register_observer(struct qib_devdata *dd,648const struct diag_observer *op);649650/* Only declared here, not defined. Private to diags */651struct diag_observer_list_elt;652653/* device data struct now contains only "general per-device" info.654* fields related to a physical IB port are in a qib_pportdata struct,655* described above) while fields only used by a particular chip-type are in656* a qib_chipdata struct, whose contents are opaque to this file.657*/658struct qib_devdata {659struct qib_ibdev verbs_dev; /* must be first */660struct list_head list;661/* pointers to related structs for this device */662/* pci access data structure */663struct pci_dev *pcidev;664struct cdev *user_cdev;665struct cdev *diag_cdev;666struct device *user_device;667struct device *diag_device;668669/* mem-mapped pointer to base of chip regs */670u64 __iomem *kregbase;671/* end of mem-mapped chip space excluding sendbuf and user regs */672u64 __iomem *kregend;673/* physical address of chip for io_remap, etc. */674resource_size_t physaddr;675/* qib_cfgctxts pointers */676struct qib_ctxtdata **rcd; /* Receive Context Data */677678/* qib_pportdata, points to array of (physical) port-specific679* data structs, indexed by pidx (0..n-1)680*/681struct qib_pportdata *pport;682struct qib_chip_specific *cspec; /* chip-specific */683684/* kvirt address of 1st 2k pio buffer */685void __iomem *pio2kbase;686/* kvirt address of 1st 4k pio buffer */687void __iomem *pio4kbase;688/* mem-mapped pointer to base of PIO buffers (if using WC PAT) */689void __iomem *piobase;690/* mem-mapped pointer to base of user chip regs (if using WC PAT) */691u64 __iomem *userbase;692void __iomem *piovl15base; /* base of VL15 buffers, if not WC */693/*694* points to area where PIOavail registers will be DMA'ed.695* Has to be on a page of it's own, because the page will be696* mapped into user program space. This copy is *ONLY* ever697* written by DMA, not by the driver! Need a copy per device698* when we get to multiple devices699*/700volatile __le64 *pioavailregs_dma; /* DMA'ed by chip */701/* physical address where updates occur */702dma_addr_t pioavailregs_phys;703704/* device-specific implementations of functions needed by705* common code. Contrary to previous consensus, we can't706* really just point to a device-specific table, because we707* may need to "bend", e.g. *_f_put_tid708*/709/* fallback to alternate interrupt type if possible */710int (*f_intr_fallback)(struct qib_devdata *);711/* hard reset chip */712int (*f_reset)(struct qib_devdata *);713void (*f_quiet_serdes)(struct qib_pportdata *);714int (*f_bringup_serdes)(struct qib_pportdata *);715int (*f_early_init)(struct qib_devdata *);716void (*f_clear_tids)(struct qib_devdata *, struct qib_ctxtdata *);717void (*f_put_tid)(struct qib_devdata *, u64 __iomem*,718u32, unsigned long);719void (*f_cleanup)(struct qib_devdata *);720void (*f_setextled)(struct qib_pportdata *, u32);721/* fill out chip-specific fields */722int (*f_get_base_info)(struct qib_ctxtdata *, struct qib_base_info *);723/* free irq */724void (*f_free_irq)(struct qib_devdata *);725struct qib_message_header *(*f_get_msgheader)726(struct qib_devdata *, __le32 *);727void (*f_config_ctxts)(struct qib_devdata *);728int (*f_get_ib_cfg)(struct qib_pportdata *, int);729int (*f_set_ib_cfg)(struct qib_pportdata *, int, u32);730int (*f_set_ib_loopback)(struct qib_pportdata *, const char *);731int (*f_get_ib_table)(struct qib_pportdata *, int, void *);732int (*f_set_ib_table)(struct qib_pportdata *, int, void *);733u32 (*f_iblink_state)(u64);734u8 (*f_ibphys_portstate)(u64);735void (*f_xgxs_reset)(struct qib_pportdata *);736/* per chip actions needed for IB Link up/down changes */737int (*f_ib_updown)(struct qib_pportdata *, int, u64);738u32 __iomem *(*f_getsendbuf)(struct qib_pportdata *, u64, u32 *);739/* Read/modify/write of GPIO pins (potentially chip-specific */740int (*f_gpio_mod)(struct qib_devdata *dd, u32 out, u32 dir,741u32 mask);742/* Enable writes to config EEPROM (if supported) */743int (*f_eeprom_wen)(struct qib_devdata *dd, int wen);744/*745* modify rcvctrl shadow[s] and write to appropriate chip-regs.746* see above QIB_RCVCTRL_xxx_ENB/DIS for operations.747* (ctxt == -1) means "all contexts", only meaningful for748* clearing. Could remove if chip_spec shutdown properly done.749*/750void (*f_rcvctrl)(struct qib_pportdata *, unsigned int op,751int ctxt);752/* Read/modify/write sendctrl appropriately for op and port. */753void (*f_sendctrl)(struct qib_pportdata *, u32 op);754void (*f_set_intr_state)(struct qib_devdata *, u32);755void (*f_set_armlaunch)(struct qib_devdata *, u32);756void (*f_wantpiobuf_intr)(struct qib_devdata *, u32);757int (*f_late_initreg)(struct qib_devdata *);758int (*f_init_sdma_regs)(struct qib_pportdata *);759u16 (*f_sdma_gethead)(struct qib_pportdata *);760int (*f_sdma_busy)(struct qib_pportdata *);761void (*f_sdma_update_tail)(struct qib_pportdata *, u16);762void (*f_sdma_set_desc_cnt)(struct qib_pportdata *, unsigned);763void (*f_sdma_sendctrl)(struct qib_pportdata *, unsigned);764void (*f_sdma_hw_clean_up)(struct qib_pportdata *);765void (*f_sdma_hw_start_up)(struct qib_pportdata *);766void (*f_sdma_init_early)(struct qib_pportdata *);767void (*f_set_cntr_sample)(struct qib_pportdata *, u32, u32);768void (*f_update_usrhead)(struct qib_ctxtdata *, u64, u32, u32, u32);769u32 (*f_hdrqempty)(struct qib_ctxtdata *);770u64 (*f_portcntr)(struct qib_pportdata *, u32);771u32 (*f_read_cntrs)(struct qib_devdata *, loff_t, char **,772u64 **);773u32 (*f_read_portcntrs)(struct qib_devdata *, loff_t, u32,774char **, u64 **);775u32 (*f_setpbc_control)(struct qib_pportdata *, u32, u8, u8);776void (*f_initvl15_bufs)(struct qib_devdata *);777void (*f_init_ctxt)(struct qib_ctxtdata *);778void (*f_txchk_change)(struct qib_devdata *, u32, u32, u32,779struct qib_ctxtdata *);780void (*f_writescratch)(struct qib_devdata *, u32);781int (*f_tempsense_rd)(struct qib_devdata *, int regnum);782783char *boardname; /* human readable board info */784785/* template for writing TIDs */786u64 tidtemplate;787/* value to write to free TIDs */788u64 tidinvalid;789790/* number of registers used for pioavail */791u32 pioavregs;792/* device (not port) flags, basically device capabilities */793u32 flags;794/* last buffer for user use */795u32 lastctxt_piobuf;796797/* saturating counter of (non-port-specific) device interrupts */798u32 int_counter;799800/* pio bufs allocated per ctxt */801u32 pbufsctxt;802/* if remainder on bufs/ctxt, ctxts < extrabuf get 1 extra */803u32 ctxts_extrabuf;804/*805* number of ctxts configured as max; zero is set to number chip806* supports, less gives more pio bufs/ctxt, etc.807*/808u32 cfgctxts;809810/*811* hint that we should update pioavailshadow before812* looking for a PIO buffer813*/814u32 upd_pio_shadow;815816/* internal debugging stats */817u32 maxpkts_call;818u32 avgpkts_call;819u64 nopiobufs;820821/* PCI Vendor ID (here for NodeInfo) */822u16 vendorid;823/* PCI Device ID (here for NodeInfo) */824u16 deviceid;825/* for write combining settings */826unsigned long wc_cookie;827unsigned long wc_base;828unsigned long wc_len;829830/* shadow copy of struct page *'s for exp tid pages */831struct page **pageshadow;832/* shadow copy of dma handles for exp tid pages */833dma_addr_t *physshadow;834u64 __iomem *egrtidbase;835spinlock_t sendctrl_lock; /* protect changes to sendctrl shadow */836/* around rcd and (user ctxts) ctxt_cnt use (intr vs free) */837spinlock_t uctxt_lock; /* rcd and user context changes */838/*839* per unit status, see also portdata statusp840* mapped readonly into user processes so they can get unit and841* IB link status cheaply842*/843u64 *devstatusp;844char *freezemsg; /* freeze msg if hw error put chip in freeze */845u32 freezelen; /* max length of freezemsg */846/* timer used to prevent stats overflow, error throttling, etc. */847struct timer_list stats_timer;848849/* timer to verify interrupts work, and fallback if possible */850struct timer_list intrchk_timer;851unsigned long ureg_align; /* user register alignment */852853/*854* Protects pioavailshadow, pioavailkernel, pio_need_disarm, and855* pio_writing.856*/857spinlock_t pioavail_lock;858859/*860* Shadow copies of registers; size indicates read access size.861* Most of them are readonly, but some are write-only register,862* where we manipulate the bits in the shadow copy, and then write863* the shadow copy to qlogic_ib.864*865* We deliberately make most of these 32 bits, since they have866* restricted range. For any that we read, we won't to generate 32867* bit accesses, since Opteron will generate 2 separate 32 bit HT868* transactions for a 64 bit read, and we want to avoid unnecessary869* bus transactions.870*/871872/* This is the 64 bit group */873874unsigned long pioavailshadow[6];875/* bitmap of send buffers available for the kernel to use with PIO. */876unsigned long pioavailkernel[6];877/* bitmap of send buffers which need to be disarmed. */878unsigned long pio_need_disarm[3];879/* bitmap of send buffers which are being written to. */880unsigned long pio_writing[3];881/* kr_revision shadow */882u64 revision;883/* Base GUID for device (from eeprom, network order) */884__be64 base_guid;885886/*887* kr_sendpiobufbase value (chip offset of pio buffers), and the888* base of the 2KB buffer s(user processes only use 2K)889*/890u64 piobufbase;891u32 pio2k_bufbase;892893/* these are the "32 bit" regs */894895/* number of GUIDs in the flash for this interface */896u32 nguid;897/*898* the following two are 32-bit bitmasks, but {test,clear,set}_bit899* all expect bit fields to be "unsigned long"900*/901unsigned long rcvctrl; /* shadow per device rcvctrl */902unsigned long sendctrl; /* shadow per device sendctrl */903904/* value we put in kr_rcvhdrcnt */905u32 rcvhdrcnt;906/* value we put in kr_rcvhdrsize */907u32 rcvhdrsize;908/* value we put in kr_rcvhdrentsize */909u32 rcvhdrentsize;910/* kr_ctxtcnt value */911u32 ctxtcnt;912/* kr_pagealign value */913u32 palign;914/* number of "2KB" PIO buffers */915u32 piobcnt2k;916/* size in bytes of "2KB" PIO buffers */917u32 piosize2k;918/* max usable size in dwords of a "2KB" PIO buffer before going "4KB" */919u32 piosize2kmax_dwords;920/* number of "4KB" PIO buffers */921u32 piobcnt4k;922/* size in bytes of "4KB" PIO buffers */923u32 piosize4k;924/* kr_rcvegrbase value */925u32 rcvegrbase;926/* kr_rcvtidbase value */927u32 rcvtidbase;928/* kr_rcvtidcnt value */929u32 rcvtidcnt;930/* kr_userregbase */931u32 uregbase;932/* shadow the control register contents */933u32 control;934935/* chip address space used by 4k pio buffers */936u32 align4k;937/* size of each rcvegrbuffer */938u32 rcvegrbufsize;939/* localbus width (1, 2,4,8,16,32) from config space */940u32 lbus_width;941/* localbus speed in MHz */942u32 lbus_speed;943int unit; /* unit # of this chip */944945/* start of CHIP_SPEC move to chipspec, but need code changes */946/* low and high portions of MSI capability/vector */947u32 msi_lo;948/* saved after PCIe init for restore after reset */949u32 msi_hi;950/* MSI data (vector) saved for restore */951u16 msi_data;952/* so we can rewrite it after a chip reset */953u32 pcibar0;954/* so we can rewrite it after a chip reset */955u32 pcibar1;956u64 rhdrhead_intr_off;957958/*959* ASCII serial number, from flash, large enough for original960* all digit strings, and longer QLogic serial number format961*/962u8 serial[16];963/* human readable board version */964u8 boardversion[96];965u8 lbus_info[32]; /* human readable localbus info */966/* chip major rev, from qib_revision */967u8 majrev;968/* chip minor rev, from qib_revision */969u8 minrev;970971/* Misc small ints */972/* Number of physical ports available */973u8 num_pports;974/* Lowest context number which can be used by user processes */975u8 first_user_ctxt;976u8 n_krcv_queues;977u8 qpn_mask;978u8 skip_kctxt_mask;979980u16 rhf_offset; /* offset of RHF within receive header entry */981982/*983* GPIO pins for twsi-connected devices, and device code for eeprom984*/985u8 gpio_sda_num;986u8 gpio_scl_num;987u8 twsi_eeprom_dev;988u8 board_atten;989990/* Support (including locks) for EEPROM logging of errors and time */991/* control access to actual counters, timer */992spinlock_t eep_st_lock;993/* control high-level access to EEPROM */994struct mutex eep_lock;995uint64_t traffic_wds;996/* active time is kept in seconds, but logged in hours */997atomic_t active_time;998/* Below are nominal shadow of EEPROM, new since last EEPROM update */999uint8_t eep_st_errs[QIB_EEP_LOG_CNT];1000uint8_t eep_st_new_errs[QIB_EEP_LOG_CNT];1001uint16_t eep_hrs;1002/*1003* masks for which bits of errs, hwerrs that cause1004* each of the counters to increment.1005*/1006struct qib_eep_log_mask eep_st_masks[QIB_EEP_LOG_CNT];1007struct qib_diag_client *diag_client;1008spinlock_t qib_diag_trans_lock; /* protect diag observer ops */1009struct diag_observer_list_elt *diag_observer_list;10101011u8 psxmitwait_supported;1012/* cycle length of PS* counters in HW (in picoseconds) */1013u16 psxmitwait_check_rate;1014};10151016/* hol_state values */1017#define QIB_HOL_UP 01018#define QIB_HOL_INIT 110191020#define QIB_SDMA_SENDCTRL_OP_ENABLE (1U << 0)1021#define QIB_SDMA_SENDCTRL_OP_INTENABLE (1U << 1)1022#define QIB_SDMA_SENDCTRL_OP_HALT (1U << 2)1023#define QIB_SDMA_SENDCTRL_OP_CLEANUP (1U << 3)1024#define QIB_SDMA_SENDCTRL_OP_DRAIN (1U << 4)10251026/* operation types for f_txchk_change() */1027#define TXCHK_CHG_TYPE_DIS1 31028#define TXCHK_CHG_TYPE_ENAB1 21029#define TXCHK_CHG_TYPE_KERN 11030#define TXCHK_CHG_TYPE_USER 010311032#define QIB_CHASE_TIME msecs_to_jiffies(145)1033#define QIB_CHASE_DIS_TIME msecs_to_jiffies(160)10341035/* Private data for file operations */1036struct qib_filedata {1037struct qib_ctxtdata *rcd;1038unsigned subctxt;1039unsigned tidcursor;1040struct qib_user_sdma_queue *pq;1041int rec_cpu_num; /* for cpu affinity; -1 if none */1042};10431044extern struct list_head qib_dev_list;1045extern spinlock_t qib_devs_lock;1046extern struct qib_devdata *qib_lookup(int unit);1047extern u32 qib_cpulist_count;1048extern unsigned long *qib_cpulist;10491050extern unsigned qib_wc_pat;1051int qib_init(struct qib_devdata *, int);1052int init_chip_wc_pat(struct qib_devdata *dd, u32);1053int qib_enable_wc(struct qib_devdata *dd);1054void qib_disable_wc(struct qib_devdata *dd);1055int qib_count_units(int *npresentp, int *nupp);1056int qib_count_active_units(void);10571058int qib_cdev_init(int minor, const char *name,1059const struct file_operations *fops,1060struct cdev **cdevp, struct device **devp);1061void qib_cdev_cleanup(struct cdev **cdevp, struct device **devp);1062int qib_dev_init(void);1063void qib_dev_cleanup(void);10641065int qib_diag_add(struct qib_devdata *);1066void qib_diag_remove(struct qib_devdata *);1067void qib_handle_e_ibstatuschanged(struct qib_pportdata *, u64);1068void qib_sdma_update_tail(struct qib_pportdata *, u16); /* hold sdma_lock */10691070int qib_decode_err(struct qib_devdata *dd, char *buf, size_t blen, u64 err);1071void qib_bad_intrstatus(struct qib_devdata *);1072void qib_handle_urcv(struct qib_devdata *, u64);10731074/* clean up any per-chip chip-specific stuff */1075void qib_chip_cleanup(struct qib_devdata *);1076/* clean up any chip type-specific stuff */1077void qib_chip_done(void);10781079/* check to see if we have to force ordering for write combining */1080int qib_unordered_wc(void);1081void qib_pio_copy(void __iomem *to, const void *from, size_t count);10821083void qib_disarm_piobufs(struct qib_devdata *, unsigned, unsigned);1084int qib_disarm_piobufs_ifneeded(struct qib_ctxtdata *);1085void qib_disarm_piobufs_set(struct qib_devdata *, unsigned long *, unsigned);1086void qib_cancel_sends(struct qib_pportdata *);10871088int qib_create_rcvhdrq(struct qib_devdata *, struct qib_ctxtdata *);1089int qib_setup_eagerbufs(struct qib_ctxtdata *);1090void qib_set_ctxtcnt(struct qib_devdata *);1091int qib_create_ctxts(struct qib_devdata *dd);1092struct qib_ctxtdata *qib_create_ctxtdata(struct qib_pportdata *, u32);1093void qib_init_pportdata(struct qib_pportdata *, struct qib_devdata *, u8, u8);1094void qib_free_ctxtdata(struct qib_devdata *, struct qib_ctxtdata *);10951096u32 qib_kreceive(struct qib_ctxtdata *, u32 *, u32 *);1097int qib_reset_device(int);1098int qib_wait_linkstate(struct qib_pportdata *, u32, int);1099int qib_set_linkstate(struct qib_pportdata *, u8);1100int qib_set_mtu(struct qib_pportdata *, u16);1101int qib_set_lid(struct qib_pportdata *, u32, u8);1102void qib_hol_down(struct qib_pportdata *);1103void qib_hol_init(struct qib_pportdata *);1104void qib_hol_up(struct qib_pportdata *);1105void qib_hol_event(unsigned long);1106void qib_disable_after_error(struct qib_devdata *);1107int qib_set_uevent_bits(struct qib_pportdata *, const int);11081109/* for use in system calls, where we want to know device type, etc. */1110#define ctxt_fp(fp) \1111(((struct qib_filedata *)(fp)->private_data)->rcd)1112#define subctxt_fp(fp) \1113(((struct qib_filedata *)(fp)->private_data)->subctxt)1114#define tidcursor_fp(fp) \1115(((struct qib_filedata *)(fp)->private_data)->tidcursor)1116#define user_sdma_queue_fp(fp) \1117(((struct qib_filedata *)(fp)->private_data)->pq)11181119static inline struct qib_devdata *dd_from_ppd(struct qib_pportdata *ppd)1120{1121return ppd->dd;1122}11231124static inline struct qib_devdata *dd_from_dev(struct qib_ibdev *dev)1125{1126return container_of(dev, struct qib_devdata, verbs_dev);1127}11281129static inline struct qib_devdata *dd_from_ibdev(struct ib_device *ibdev)1130{1131return dd_from_dev(to_idev(ibdev));1132}11331134static inline struct qib_pportdata *ppd_from_ibp(struct qib_ibport *ibp)1135{1136return container_of(ibp, struct qib_pportdata, ibport_data);1137}11381139static inline struct qib_ibport *to_iport(struct ib_device *ibdev, u8 port)1140{1141struct qib_devdata *dd = dd_from_ibdev(ibdev);1142unsigned pidx = port - 1; /* IB number port from 1, hdw from 0 */11431144WARN_ON(pidx >= dd->num_pports);1145return &dd->pport[pidx].ibport_data;1146}11471148/*1149* values for dd->flags (_device_ related flags) and1150*/1151#define QIB_HAS_LINK_LATENCY 0x1 /* supports link latency (IB 1.2) */1152#define QIB_INITTED 0x2 /* chip and driver up and initted */1153#define QIB_DOING_RESET 0x4 /* in the middle of doing chip reset */1154#define QIB_PRESENT 0x8 /* chip accesses can be done */1155#define QIB_PIO_FLUSH_WC 0x10 /* Needs Write combining flush for PIO */1156#define QIB_HAS_THRESH_UPDATE 0x401157#define QIB_HAS_SDMA_TIMEOUT 0x801158#define QIB_USE_SPCL_TRIG 0x100 /* SpecialTrigger launch enabled */1159#define QIB_NODMA_RTAIL 0x200 /* rcvhdrtail register DMA enabled */1160#define QIB_HAS_INTX 0x800 /* Supports INTx interrupts */1161#define QIB_HAS_SEND_DMA 0x1000 /* Supports Send DMA */1162#define QIB_HAS_VLSUPP 0x2000 /* Supports multiple VLs; PBC different */1163#define QIB_HAS_HDRSUPP 0x4000 /* Supports header suppression */1164#define QIB_BADINTR 0x8000 /* severe interrupt problems */1165#define QIB_DCA_ENABLED 0x10000 /* Direct Cache Access enabled */1166#define QIB_HAS_QSFP 0x20000 /* device (card instance) has QSFP */11671168/*1169* values for ppd->lflags (_ib_port_ related flags)1170*/1171#define QIBL_LINKV 0x1 /* IB link state valid */1172#define QIBL_LINKDOWN 0x8 /* IB link is down */1173#define QIBL_LINKINIT 0x10 /* IB link level is up */1174#define QIBL_LINKARMED 0x20 /* IB link is ARMED */1175#define QIBL_LINKACTIVE 0x40 /* IB link is ACTIVE */1176/* leave a gap for more IB-link state */1177#define QIBL_IB_AUTONEG_INPROG 0x1000 /* non-IBTA DDR/QDR neg active */1178#define QIBL_IB_AUTONEG_FAILED 0x2000 /* non-IBTA DDR/QDR neg failed */1179#define QIBL_IB_LINK_DISABLED 0x4000 /* Linkdown-disable forced,1180* Do not try to bring up */1181#define QIBL_IB_FORCE_NOTIFY 0x8000 /* force notify on next ib change */11821183/* IB dword length mask in PBC (lower 11 bits); same for all chips */1184#define QIB_PBC_LENGTH_MASK ((1 << 11) - 1)118511861187/* ctxt_flag bit offsets */1188/* waiting for a packet to arrive */1189#define QIB_CTXT_WAITING_RCV 21190/* master has not finished initializing */1191#define QIB_CTXT_MASTER_UNINIT 41192/* waiting for an urgent packet to arrive */1193#define QIB_CTXT_WAITING_URG 511941195/* free up any allocated data at closes */1196void qib_free_data(struct qib_ctxtdata *dd);1197void qib_chg_pioavailkernel(struct qib_devdata *, unsigned, unsigned,1198u32, struct qib_ctxtdata *);1199struct qib_devdata *qib_init_iba7322_funcs(struct pci_dev *,1200const struct pci_device_id *);1201struct qib_devdata *qib_init_iba7220_funcs(struct pci_dev *,1202const struct pci_device_id *);1203struct qib_devdata *qib_init_iba6120_funcs(struct pci_dev *,1204const struct pci_device_id *);1205void qib_free_devdata(struct qib_devdata *);1206struct qib_devdata *qib_alloc_devdata(struct pci_dev *pdev, size_t extra);12071208#define QIB_TWSI_NO_DEV 0xFF1209/* Below qib_twsi_ functions must be called with eep_lock held */1210int qib_twsi_reset(struct qib_devdata *dd);1211int qib_twsi_blk_rd(struct qib_devdata *dd, int dev, int addr, void *buffer,1212int len);1213int qib_twsi_blk_wr(struct qib_devdata *dd, int dev, int addr,1214const void *buffer, int len);1215void qib_get_eeprom_info(struct qib_devdata *);1216int qib_update_eeprom_log(struct qib_devdata *dd);1217void qib_inc_eeprom_err(struct qib_devdata *dd, u32 eidx, u32 incr);1218void qib_dump_lookup_output_queue(struct qib_devdata *);1219void qib_force_pio_avail_update(struct qib_devdata *);1220void qib_clear_symerror_on_linkup(unsigned long opaque);12211222/*1223* Set LED override, only the two LSBs have "public" meaning, but1224* any non-zero value substitutes them for the Link and LinkTrain1225* LED states.1226*/1227#define QIB_LED_PHYS 1 /* Physical (linktraining) GREEN LED */1228#define QIB_LED_LOG 2 /* Logical (link) YELLOW LED */1229void qib_set_led_override(struct qib_pportdata *ppd, unsigned int val);12301231/* send dma routines */1232int qib_setup_sdma(struct qib_pportdata *);1233void qib_teardown_sdma(struct qib_pportdata *);1234void __qib_sdma_intr(struct qib_pportdata *);1235void qib_sdma_intr(struct qib_pportdata *);1236int qib_sdma_verbs_send(struct qib_pportdata *, struct qib_sge_state *,1237u32, struct qib_verbs_txreq *);1238/* ppd->sdma_lock should be locked before calling this. */1239int qib_sdma_make_progress(struct qib_pportdata *dd);12401241/* must be called under qib_sdma_lock */1242static inline u16 qib_sdma_descq_freecnt(const struct qib_pportdata *ppd)1243{1244return ppd->sdma_descq_cnt -1245(ppd->sdma_descq_added - ppd->sdma_descq_removed) - 1;1246}12471248static inline int __qib_sdma_running(struct qib_pportdata *ppd)1249{1250return ppd->sdma_state.current_state == qib_sdma_state_s99_running;1251}1252int qib_sdma_running(struct qib_pportdata *);12531254void __qib_sdma_process_event(struct qib_pportdata *, enum qib_sdma_events);1255void qib_sdma_process_event(struct qib_pportdata *, enum qib_sdma_events);12561257/*1258* number of words used for protocol header if not set by qib_userinit();1259*/1260#define QIB_DFLT_RCVHDRSIZE 912611262/*1263* We need to be able to handle an IB header of at least 24 dwords.1264* We need the rcvhdrq large enough to handle largest IB header, but1265* still have room for a 2KB MTU standard IB packet.1266* Additionally, some processor/memory controller combinations1267* benefit quite strongly from having the DMA'ed data be cacheline1268* aligned and a cacheline multiple, so we set the size to 32 dwords1269* (2 64-byte primary cachelines for pretty much all processors of1270* interest). The alignment hurts nothing, other than using somewhat1271* more memory.1272*/1273#define QIB_RCVHDR_ENTSIZE 3212741275int qib_get_user_pages(unsigned long, size_t, struct page **);1276void qib_release_user_pages(struct page **, size_t);1277int qib_eeprom_read(struct qib_devdata *, u8, void *, int);1278int qib_eeprom_write(struct qib_devdata *, u8, const void *, int);1279u32 __iomem *qib_getsendbuf_range(struct qib_devdata *, u32 *, u32, u32);1280void qib_sendbuf_done(struct qib_devdata *, unsigned);12811282static inline void qib_clear_rcvhdrtail(const struct qib_ctxtdata *rcd)1283{1284*((u64 *) rcd->rcvhdrtail_kvaddr) = 0ULL;1285}12861287static inline u32 qib_get_rcvhdrtail(const struct qib_ctxtdata *rcd)1288{1289/*1290* volatile because it's a DMA target from the chip, routine is1291* inlined, and don't want register caching or reordering.1292*/1293return (u32) le64_to_cpu(1294*((volatile __le64 *)rcd->rcvhdrtail_kvaddr)); /* DMA'ed */1295}12961297static inline u32 qib_get_hdrqtail(const struct qib_ctxtdata *rcd)1298{1299const struct qib_devdata *dd = rcd->dd;1300u32 hdrqtail;13011302if (dd->flags & QIB_NODMA_RTAIL) {1303__le32 *rhf_addr;1304u32 seq;13051306rhf_addr = (__le32 *) rcd->rcvhdrq +1307rcd->head + dd->rhf_offset;1308seq = qib_hdrget_seq(rhf_addr);1309hdrqtail = rcd->head;1310if (seq == rcd->seq_cnt)1311hdrqtail++;1312} else1313hdrqtail = qib_get_rcvhdrtail(rcd);13141315return hdrqtail;1316}13171318/*1319* sysfs interface.1320*/13211322extern const char ib_qib_version[];13231324int qib_device_create(struct qib_devdata *);1325void qib_device_remove(struct qib_devdata *);13261327int qib_create_port_files(struct ib_device *ibdev, u8 port_num,1328struct kobject *kobj);1329int qib_verbs_register_sysfs(struct qib_devdata *);1330void qib_verbs_unregister_sysfs(struct qib_devdata *);1331/* Hook for sysfs read of QSFP */1332extern int qib_qsfp_dump(struct qib_pportdata *ppd, char *buf, int len);13331334int __init qib_init_qibfs(void);1335int __exit qib_exit_qibfs(void);13361337int qibfs_add(struct qib_devdata *);1338int qibfs_remove(struct qib_devdata *);13391340int qib_pcie_init(struct pci_dev *, const struct pci_device_id *);1341int qib_pcie_ddinit(struct qib_devdata *, struct pci_dev *,1342const struct pci_device_id *);1343void qib_pcie_ddcleanup(struct qib_devdata *);1344int qib_pcie_params(struct qib_devdata *, u32, u32 *, struct msix_entry *);1345int qib_reinit_intr(struct qib_devdata *);1346void qib_enable_intx(struct pci_dev *);1347void qib_nomsi(struct qib_devdata *);1348void qib_nomsix(struct qib_devdata *);1349void qib_pcie_getcmd(struct qib_devdata *, u16 *, u8 *, u8 *);1350void qib_pcie_reenable(struct qib_devdata *, u16, u8, u8);13511352/*1353* dma_addr wrappers - all 0's invalid for hw1354*/1355dma_addr_t qib_map_page(struct pci_dev *, struct page *, unsigned long,1356size_t, int);1357const char *qib_get_unit_name(int unit);13581359/*1360* Flush write combining store buffers (if present) and perform a write1361* barrier.1362*/1363#if defined(CONFIG_X86_64)1364#define qib_flush_wc() asm volatile("sfence" : : : "memory")1365#else1366#define qib_flush_wc() wmb() /* no reorder around wc flush */1367#endif13681369/* global module parameter variables */1370extern unsigned qib_ibmtu;1371extern ushort qib_cfgctxts;1372extern ushort qib_num_cfg_vls;1373extern ushort qib_mini_init; /* If set, do few (ideally 0) writes to chip */1374extern unsigned qib_n_krcv_queues;1375extern unsigned qib_sdma_fetch_arb;1376extern unsigned qib_compat_ddr_negotiate;1377extern int qib_special_trigger;13781379extern struct mutex qib_mutex;13801381/* Number of seconds before our card status check... */1382#define STATUS_TIMEOUT 6013831384#define QIB_DRV_NAME "ib_qib"1385#define QIB_USER_MINOR_BASE 01386#define QIB_TRACE_MINOR 1271387#define QIB_DIAGPKT_MINOR 1281388#define QIB_DIAG_MINOR_BASE 1291389#define QIB_NMINORS 25513901391#define PCI_VENDOR_ID_PATHSCALE 0x1fc11392#define PCI_VENDOR_ID_QLOGIC 0x10771393#define PCI_DEVICE_ID_QLOGIC_IB_6120 0x101394#define PCI_DEVICE_ID_QLOGIC_IB_7220 0x72201395#define PCI_DEVICE_ID_QLOGIC_IB_7322 0x732213961397/*1398* qib_early_err is used (only!) to print early errors before devdata is1399* allocated, or when dd->pcidev may not be valid, and at the tail end of1400* cleanup when devdata may have been freed, etc. qib_dev_porterr is1401* the same as qib_dev_err, but is used when the message really needs1402* the IB port# to be definitive as to what's happening..1403* All of these go to the trace log, and the trace log entry is done1404* first to avoid possible serial port delays from printk.1405*/1406#define qib_early_err(dev, fmt, ...) \1407do { \1408dev_err(dev, fmt, ##__VA_ARGS__); \1409} while (0)14101411#define qib_dev_err(dd, fmt, ...) \1412do { \1413dev_err(&(dd)->pcidev->dev, "%s: " fmt, \1414qib_get_unit_name((dd)->unit), ##__VA_ARGS__); \1415} while (0)14161417#define qib_dev_porterr(dd, port, fmt, ...) \1418do { \1419dev_err(&(dd)->pcidev->dev, "%s: IB%u:%u " fmt, \1420qib_get_unit_name((dd)->unit), (dd)->unit, (port), \1421##__VA_ARGS__); \1422} while (0)14231424#define qib_devinfo(pcidev, fmt, ...) \1425do { \1426dev_info(&(pcidev)->dev, fmt, ##__VA_ARGS__); \1427} while (0)14281429/*1430* this is used for formatting hw error messages...1431*/1432struct qib_hwerror_msgs {1433u64 mask;1434const char *msg;1435};14361437#define QLOGIC_IB_HWE_MSG(a, b) { .mask = a, .msg = b }14381439/* in qib_intr.c... */1440void qib_format_hwerrors(u64 hwerrs,1441const struct qib_hwerror_msgs *hwerrmsgs,1442size_t nhwerrmsgs, char *msg, size_t lmsg);1443#endif /* _QIB_KERNEL_H */144414451446