Back to home page

OSCL-LXR

 
 

    


0001 #ifndef _QIB_KERNEL_H
0002 #define _QIB_KERNEL_H
0003 /*
0004  * Copyright (c) 2012 - 2017 Intel Corporation.  All rights reserved.
0005  * Copyright (c) 2006 - 2012 QLogic Corporation. All rights reserved.
0006  * Copyright (c) 2003, 2004, 2005, 2006 PathScale, Inc. All rights reserved.
0007  *
0008  * This software is available to you under a choice of one of two
0009  * licenses.  You may choose to be licensed under the terms of the GNU
0010  * General Public License (GPL) Version 2, available from the file
0011  * COPYING in the main directory of this source tree, or the
0012  * OpenIB.org BSD license below:
0013  *
0014  *     Redistribution and use in source and binary forms, with or
0015  *     without modification, are permitted provided that the following
0016  *     conditions are met:
0017  *
0018  *      - Redistributions of source code must retain the above
0019  *        copyright notice, this list of conditions and the following
0020  *        disclaimer.
0021  *
0022  *      - Redistributions in binary form must reproduce the above
0023  *        copyright notice, this list of conditions and the following
0024  *        disclaimer in the documentation and/or other materials
0025  *        provided with the distribution.
0026  *
0027  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
0028  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
0029  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
0030  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
0031  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
0032  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
0033  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
0034  * SOFTWARE.
0035  */
0036 
0037 /*
0038  * This header file is the base header file for qlogic_ib kernel code
0039  * qib_user.h serves a similar purpose for user code.
0040  */
0041 
0042 #include <linux/interrupt.h>
0043 #include <linux/pci.h>
0044 #include <linux/dma-mapping.h>
0045 #include <linux/mutex.h>
0046 #include <linux/list.h>
0047 #include <linux/scatterlist.h>
0048 #include <linux/slab.h>
0049 #include <linux/io.h>
0050 #include <linux/fs.h>
0051 #include <linux/completion.h>
0052 #include <linux/kref.h>
0053 #include <linux/sched.h>
0054 #include <linux/kthread.h>
0055 #include <linux/xarray.h>
0056 #include <rdma/ib_hdrs.h>
0057 #include <rdma/rdma_vt.h>
0058 
0059 #include "qib_common.h"
0060 #include "qib_verbs.h"
0061 
0062 /* only s/w major version of QLogic_IB we can handle */
0063 #define QIB_CHIP_VERS_MAJ 2U
0064 
0065 /* don't care about this except printing */
0066 #define QIB_CHIP_VERS_MIN 0U
0067 
0068 /* The Organization Unique Identifier (Mfg code), and its position in GUID */
0069 #define QIB_OUI 0x001175
0070 #define QIB_OUI_LSB 40
0071 
0072 /*
0073  * per driver stats, either not device nor port-specific, or
0074  * summed over all of the devices and ports.
0075  * They are described by name via ipathfs filesystem, so layout
0076  * and number of elements can change without breaking compatibility.
0077  * If members are added or deleted qib_statnames[] in qib_fs.c must
0078  * change to match.
0079  */
0080 struct qlogic_ib_stats {
0081     __u64 sps_ints; /* number of interrupts handled */
0082     __u64 sps_errints; /* number of error interrupts */
0083     __u64 sps_txerrs; /* tx-related packet errors */
0084     __u64 sps_rcverrs; /* non-crc rcv packet errors */
0085     __u64 sps_hwerrs; /* hardware errors reported (parity, etc.) */
0086     __u64 sps_nopiobufs; /* no pio bufs avail from kernel */
0087     __u64 sps_ctxts; /* number of contexts currently open */
0088     __u64 sps_lenerrs; /* number of kernel packets where RHF != LRH len */
0089     __u64 sps_buffull;
0090     __u64 sps_hdrfull;
0091 };
0092 
0093 extern struct qlogic_ib_stats qib_stats;
0094 extern const struct pci_error_handlers qib_pci_err_handler;
0095 
0096 #define QIB_CHIP_SWVERSION QIB_CHIP_VERS_MAJ
0097 /*
0098  * First-cut critierion for "device is active" is
0099  * two thousand dwords combined Tx, Rx traffic per
0100  * 5-second interval. SMA packets are 64 dwords,
0101  * and occur "a few per second", presumably each way.
0102  */
0103 #define QIB_TRAFFIC_ACTIVE_THRESHOLD (2000)
0104 
0105 /*
0106  * Below contains all data related to a single context (formerly called port).
0107  */
0108 
0109 #ifdef CONFIG_DEBUG_FS
0110 struct qib_opcode_stats_perctx;
0111 #endif
0112 
0113 struct qib_ctxtdata {
0114     void **rcvegrbuf;
0115     dma_addr_t *rcvegrbuf_phys;
0116     /* rcvhdrq base, needs mmap before useful */
0117     void *rcvhdrq;
0118     /* kernel virtual address where hdrqtail is updated */
0119     void *rcvhdrtail_kvaddr;
0120     /*
0121      * temp buffer for expected send setup, allocated at open, instead
0122      * of each setup call
0123      */
0124     void *tid_pg_list;
0125     /*
0126      * Shared page for kernel to signal user processes that send buffers
0127      * need disarming.  The process should call QIB_CMD_DISARM_BUFS
0128      * or QIB_CMD_ACK_EVENT with IPATH_EVENT_DISARM_BUFS set.
0129      */
0130     unsigned long *user_event_mask;
0131     /* when waiting for rcv or pioavail */
0132     wait_queue_head_t wait;
0133     /*
0134      * rcvegr bufs base, physical, must fit
0135      * in 44 bits so 32 bit programs mmap64 44 bit works)
0136      */
0137     dma_addr_t rcvegr_phys;
0138     /* mmap of hdrq, must fit in 44 bits */
0139     dma_addr_t rcvhdrq_phys;
0140     dma_addr_t rcvhdrqtailaddr_phys;
0141 
0142     /*
0143      * number of opens (including slave sub-contexts) on this instance
0144      * (ignoring forks, dup, etc. for now)
0145      */
0146     int cnt;
0147     /*
0148      * how much space to leave at start of eager TID entries for
0149      * protocol use, on each TID
0150      */
0151     /* instead of calculating it */
0152     unsigned ctxt;
0153     /* local node of context */
0154     int node_id;
0155     /* non-zero if ctxt is being shared. */
0156     u16 subctxt_cnt;
0157     /* non-zero if ctxt is being shared. */
0158     u16 subctxt_id;
0159     /* number of eager TID entries. */
0160     u16 rcvegrcnt;
0161     /* index of first eager TID entry. */
0162     u16 rcvegr_tid_base;
0163     /* number of pio bufs for this ctxt (all procs, if shared) */
0164     u32 piocnt;
0165     /* first pio buffer for this ctxt */
0166     u32 pio_base;
0167     /* chip offset of PIO buffers for this ctxt */
0168     u32 piobufs;
0169     /* how many alloc_pages() chunks in rcvegrbuf_pages */
0170     u32 rcvegrbuf_chunks;
0171     /* how many egrbufs per chunk */
0172     u16 rcvegrbufs_perchunk;
0173     /* ilog2 of above */
0174     u16 rcvegrbufs_perchunk_shift;
0175     /* order for rcvegrbuf_pages */
0176     size_t rcvegrbuf_size;
0177     /* rcvhdrq size (for freeing) */
0178     size_t rcvhdrq_size;
0179     /* per-context flags for fileops/intr communication */
0180     unsigned long flag;
0181     /* next expected TID to check when looking for free */
0182     u32 tidcursor;
0183     /* WAIT_RCV that timed out, no interrupt */
0184     u32 rcvwait_to;
0185     /* WAIT_PIO that timed out, no interrupt */
0186     u32 piowait_to;
0187     /* WAIT_RCV already happened, no wait */
0188     u32 rcvnowait;
0189     /* WAIT_PIO already happened, no wait */
0190     u32 pionowait;
0191     /* total number of polled urgent packets */
0192     u32 urgent;
0193     /* saved total number of polled urgent packets for poll edge trigger */
0194     u32 urgent_poll;
0195     /* pid of process using this ctxt */
0196     pid_t pid;
0197     pid_t subpid[QLOGIC_IB_MAX_SUBCTXT];
0198     /* same size as task_struct .comm[], command that opened context */
0199     char comm[TASK_COMM_LEN];
0200     /* pkeys set by this use of this ctxt */
0201     u16 pkeys[4];
0202     /* so file ops can get at unit */
0203     struct qib_devdata *dd;
0204     /* so funcs that need physical port can get it easily */
0205     struct qib_pportdata *ppd;
0206     /* A page of memory for rcvhdrhead, rcvegrhead, rcvegrtail * N */
0207     void *subctxt_uregbase;
0208     /* An array of pages for the eager receive buffers * N */
0209     void *subctxt_rcvegrbuf;
0210     /* An array of pages for the eager header queue entries * N */
0211     void *subctxt_rcvhdr_base;
0212     /* The version of the library which opened this ctxt */
0213     u32 userversion;
0214     /* Bitmask of active slaves */
0215     u32 active_slaves;
0216     /* Type of packets or conditions we want to poll for */
0217     u16 poll_type;
0218     /* receive packet sequence counter */
0219     u8 seq_cnt;
0220     u8 redirect_seq_cnt;
0221     /* ctxt rcvhdrq head offset */
0222     u32 head;
0223     /* QPs waiting for context processing */
0224     struct list_head qp_wait_list;
0225 #ifdef CONFIG_DEBUG_FS
0226     /* verbs stats per CTX */
0227     struct qib_opcode_stats_perctx *opstats;
0228 #endif
0229 };
0230 
0231 struct rvt_sge_state;
0232 
0233 struct qib_sdma_txreq {
0234     int                 flags;
0235     int                 sg_count;
0236     dma_addr_t          addr;
0237     void              (*callback)(struct qib_sdma_txreq *, int);
0238     u16                 start_idx;  /* sdma private */
0239     u16                 next_descq_idx;  /* sdma private */
0240     struct list_head    list;       /* sdma private */
0241 };
0242 
0243 struct qib_sdma_desc {
0244     __le64 qw[2];
0245 };
0246 
0247 struct qib_verbs_txreq {
0248     struct qib_sdma_txreq   txreq;
0249     struct rvt_qp           *qp;
0250     struct rvt_swqe         *wqe;
0251     u32                     dwords;
0252     u16                     hdr_dwords;
0253     u16                     hdr_inx;
0254     struct qib_pio_header   *align_buf;
0255     struct rvt_mregion  *mr;
0256     struct rvt_sge_state    *ss;
0257 };
0258 
0259 #define QIB_SDMA_TXREQ_F_USELARGEBUF  0x1
0260 #define QIB_SDMA_TXREQ_F_HEADTOHOST   0x2
0261 #define QIB_SDMA_TXREQ_F_INTREQ       0x4
0262 #define QIB_SDMA_TXREQ_F_FREEBUF      0x8
0263 #define QIB_SDMA_TXREQ_F_FREEDESC     0x10
0264 
0265 #define QIB_SDMA_TXREQ_S_OK        0
0266 #define QIB_SDMA_TXREQ_S_SENDERROR 1
0267 #define QIB_SDMA_TXREQ_S_ABORTED   2
0268 #define QIB_SDMA_TXREQ_S_SHUTDOWN  3
0269 
0270 /*
0271  * Get/Set IB link-level config parameters for f_get/set_ib_cfg()
0272  * Mostly for MADs that set or query link parameters, also ipath
0273  * config interfaces
0274  */
0275 #define QIB_IB_CFG_LIDLMC 0 /* LID (LS16b) and Mask (MS16b) */
0276 #define QIB_IB_CFG_LWID_ENB 2 /* allowed Link-width */
0277 #define QIB_IB_CFG_LWID 3 /* currently active Link-width */
0278 #define QIB_IB_CFG_SPD_ENB 4 /* allowed Link speeds */
0279 #define QIB_IB_CFG_SPD 5 /* current Link spd */
0280 #define QIB_IB_CFG_RXPOL_ENB 6 /* Auto-RX-polarity enable */
0281 #define QIB_IB_CFG_LREV_ENB 7 /* Auto-Lane-reversal enable */
0282 #define QIB_IB_CFG_LINKLATENCY 8 /* Link Latency (IB1.2 only) */
0283 #define QIB_IB_CFG_HRTBT 9 /* IB heartbeat off/enable/auto; DDR/QDR only */
0284 #define QIB_IB_CFG_OP_VLS 10 /* operational VLs */
0285 #define QIB_IB_CFG_VL_HIGH_CAP 11 /* num of VL high priority weights */
0286 #define QIB_IB_CFG_VL_LOW_CAP 12 /* num of VL low priority weights */
0287 #define QIB_IB_CFG_OVERRUN_THRESH 13 /* IB overrun threshold */
0288 #define QIB_IB_CFG_PHYERR_THRESH 14 /* IB PHY error threshold */
0289 #define QIB_IB_CFG_LINKDEFAULT 15 /* IB link default (sleep/poll) */
0290 #define QIB_IB_CFG_PKEYS 16 /* update partition keys */
0291 #define QIB_IB_CFG_MTU 17 /* update MTU in IBC */
0292 #define QIB_IB_CFG_LSTATE 18 /* update linkcmd and linkinitcmd in IBC */
0293 #define QIB_IB_CFG_VL_HIGH_LIMIT 19
0294 #define QIB_IB_CFG_PMA_TICKS 20 /* PMA sample tick resolution */
0295 #define QIB_IB_CFG_PORT 21 /* switch port we are connected to */
0296 
0297 /*
0298  * for CFG_LSTATE: LINKCMD in upper 16 bits, LINKINITCMD in lower 16
0299  * IB_LINKINITCMD_POLL and SLEEP are also used as set/get values for
0300  * QIB_IB_CFG_LINKDEFAULT cmd
0301  */
0302 #define   IB_LINKCMD_DOWN   (0 << 16)
0303 #define   IB_LINKCMD_ARMED  (1 << 16)
0304 #define   IB_LINKCMD_ACTIVE (2 << 16)
0305 #define   IB_LINKINITCMD_NOP     0
0306 #define   IB_LINKINITCMD_POLL    1
0307 #define   IB_LINKINITCMD_SLEEP   2
0308 #define   IB_LINKINITCMD_DISABLE 3
0309 
0310 /*
0311  * valid states passed to qib_set_linkstate() user call
0312  */
0313 #define QIB_IB_LINKDOWN         0
0314 #define QIB_IB_LINKARM          1
0315 #define QIB_IB_LINKACTIVE       2
0316 #define QIB_IB_LINKDOWN_ONLY    3
0317 #define QIB_IB_LINKDOWN_SLEEP   4
0318 #define QIB_IB_LINKDOWN_DISABLE 5
0319 
0320 /*
0321  * These 7 values (SDR, DDR, and QDR may be ORed for auto-speed
0322  * negotiation) are used for the 3rd argument to path_f_set_ib_cfg
0323  * with cmd QIB_IB_CFG_SPD_ENB, by direct calls or via sysfs.  They
0324  * are also the possible values for qib_link_speed_enabled and active
0325  * The values were chosen to match values used within the IB spec.
0326  */
0327 #define QIB_IB_SDR 1
0328 #define QIB_IB_DDR 2
0329 #define QIB_IB_QDR 4
0330 
0331 #define QIB_DEFAULT_MTU 4096
0332 
0333 /* max number of IB ports supported per HCA */
0334 #define QIB_MAX_IB_PORTS 2
0335 
0336 /*
0337  * Possible IB config parameters for f_get/set_ib_table()
0338  */
0339 #define QIB_IB_TBL_VL_HIGH_ARB 1 /* Get/set VL high priority weights */
0340 #define QIB_IB_TBL_VL_LOW_ARB 2 /* Get/set VL low priority weights */
0341 
0342 /*
0343  * Possible "operations" for f_rcvctrl(ppd, op, ctxt)
0344  * these are bits so they can be combined, e.g.
0345  * QIB_RCVCTRL_INTRAVAIL_ENB | QIB_RCVCTRL_CTXT_ENB
0346  */
0347 #define QIB_RCVCTRL_TAILUPD_ENB 0x01
0348 #define QIB_RCVCTRL_TAILUPD_DIS 0x02
0349 #define QIB_RCVCTRL_CTXT_ENB 0x04
0350 #define QIB_RCVCTRL_CTXT_DIS 0x08
0351 #define QIB_RCVCTRL_INTRAVAIL_ENB 0x10
0352 #define QIB_RCVCTRL_INTRAVAIL_DIS 0x20
0353 #define QIB_RCVCTRL_PKEY_ENB 0x40  /* Note, default is enabled */
0354 #define QIB_RCVCTRL_PKEY_DIS 0x80
0355 #define QIB_RCVCTRL_BP_ENB 0x0100
0356 #define QIB_RCVCTRL_BP_DIS 0x0200
0357 #define QIB_RCVCTRL_TIDFLOW_ENB 0x0400
0358 #define QIB_RCVCTRL_TIDFLOW_DIS 0x0800
0359 
0360 /*
0361  * Possible "operations" for f_sendctrl(ppd, op, var)
0362  * these are bits so they can be combined, e.g.
0363  * QIB_SENDCTRL_BUFAVAIL_ENB | QIB_SENDCTRL_ENB
0364  * Some operations (e.g. DISARM, ABORT) are known to
0365  * be "one-shot", so do not modify shadow.
0366  */
0367 #define QIB_SENDCTRL_DISARM       (0x1000)
0368 #define QIB_SENDCTRL_DISARM_BUF(bufn) ((bufn) | QIB_SENDCTRL_DISARM)
0369     /* available (0x2000) */
0370 #define QIB_SENDCTRL_AVAIL_DIS    (0x4000)
0371 #define QIB_SENDCTRL_AVAIL_ENB    (0x8000)
0372 #define QIB_SENDCTRL_AVAIL_BLIP  (0x10000)
0373 #define QIB_SENDCTRL_SEND_DIS    (0x20000)
0374 #define QIB_SENDCTRL_SEND_ENB    (0x40000)
0375 #define QIB_SENDCTRL_FLUSH       (0x80000)
0376 #define QIB_SENDCTRL_CLEAR      (0x100000)
0377 #define QIB_SENDCTRL_DISARM_ALL (0x200000)
0378 
0379 /*
0380  * These are the generic indices for requesting per-port
0381  * counter values via the f_portcntr function.  They
0382  * are always returned as 64 bit values, although most
0383  * are 32 bit counters.
0384  */
0385 /* send-related counters */
0386 #define QIBPORTCNTR_PKTSEND         0U
0387 #define QIBPORTCNTR_WORDSEND        1U
0388 #define QIBPORTCNTR_PSXMITDATA      2U
0389 #define QIBPORTCNTR_PSXMITPKTS      3U
0390 #define QIBPORTCNTR_PSXMITWAIT      4U
0391 #define QIBPORTCNTR_SENDSTALL       5U
0392 /* receive-related counters */
0393 #define QIBPORTCNTR_PKTRCV          6U
0394 #define QIBPORTCNTR_PSRCVDATA       7U
0395 #define QIBPORTCNTR_PSRCVPKTS       8U
0396 #define QIBPORTCNTR_RCVEBP          9U
0397 #define QIBPORTCNTR_RCVOVFL         10U
0398 #define QIBPORTCNTR_WORDRCV         11U
0399 /* IB link related error counters */
0400 #define QIBPORTCNTR_RXLOCALPHYERR   12U
0401 #define QIBPORTCNTR_RXVLERR         13U
0402 #define QIBPORTCNTR_ERRICRC         14U
0403 #define QIBPORTCNTR_ERRVCRC         15U
0404 #define QIBPORTCNTR_ERRLPCRC        16U
0405 #define QIBPORTCNTR_BADFORMAT       17U
0406 #define QIBPORTCNTR_ERR_RLEN        18U
0407 #define QIBPORTCNTR_IBSYMBOLERR     19U
0408 #define QIBPORTCNTR_INVALIDRLEN     20U
0409 #define QIBPORTCNTR_UNSUPVL         21U
0410 #define QIBPORTCNTR_EXCESSBUFOVFL   22U
0411 #define QIBPORTCNTR_ERRLINK         23U
0412 #define QIBPORTCNTR_IBLINKDOWN      24U
0413 #define QIBPORTCNTR_IBLINKERRRECOV  25U
0414 #define QIBPORTCNTR_LLI             26U
0415 /* other error counters */
0416 #define QIBPORTCNTR_RXDROPPKT       27U
0417 #define QIBPORTCNTR_VL15PKTDROP     28U
0418 #define QIBPORTCNTR_ERRPKEY         29U
0419 #define QIBPORTCNTR_KHDROVFL        30U
0420 /* sampling counters (these are actually control registers) */
0421 #define QIBPORTCNTR_PSINTERVAL      31U
0422 #define QIBPORTCNTR_PSSTART         32U
0423 #define QIBPORTCNTR_PSSTAT          33U
0424 
0425 /* how often we check for packet activity for "power on hours (in seconds) */
0426 #define ACTIVITY_TIMER 5
0427 
0428 #define MAX_NAME_SIZE 64
0429 
0430 #ifdef CONFIG_INFINIBAND_QIB_DCA
0431 struct qib_irq_notify;
0432 #endif
0433 
0434 struct qib_msix_entry {
0435     void *arg;
0436 #ifdef CONFIG_INFINIBAND_QIB_DCA
0437     int dca;
0438     int rcv;
0439     struct qib_irq_notify *notifier;
0440 #endif
0441     cpumask_var_t mask;
0442 };
0443 
0444 /* Below is an opaque struct. Each chip (device) can maintain
0445  * private data needed for its operation, but not germane to the
0446  * rest of the driver.  For convenience, we define another that
0447  * is chip-specific, per-port
0448  */
0449 struct qib_chip_specific;
0450 struct qib_chipport_specific;
0451 
0452 enum qib_sdma_states {
0453     qib_sdma_state_s00_hw_down,
0454     qib_sdma_state_s10_hw_start_up_wait,
0455     qib_sdma_state_s20_idle,
0456     qib_sdma_state_s30_sw_clean_up_wait,
0457     qib_sdma_state_s40_hw_clean_up_wait,
0458     qib_sdma_state_s50_hw_halt_wait,
0459     qib_sdma_state_s99_running,
0460 };
0461 
0462 enum qib_sdma_events {
0463     qib_sdma_event_e00_go_hw_down,
0464     qib_sdma_event_e10_go_hw_start,
0465     qib_sdma_event_e20_hw_started,
0466     qib_sdma_event_e30_go_running,
0467     qib_sdma_event_e40_sw_cleaned,
0468     qib_sdma_event_e50_hw_cleaned,
0469     qib_sdma_event_e60_hw_halted,
0470     qib_sdma_event_e70_go_idle,
0471     qib_sdma_event_e7220_err_halted,
0472     qib_sdma_event_e7322_err_halted,
0473     qib_sdma_event_e90_timer_tick,
0474 };
0475 
0476 struct sdma_set_state_action {
0477     unsigned op_enable:1;
0478     unsigned op_intenable:1;
0479     unsigned op_halt:1;
0480     unsigned op_drain:1;
0481     unsigned go_s99_running_tofalse:1;
0482     unsigned go_s99_running_totrue:1;
0483 };
0484 
0485 struct qib_sdma_state {
0486     struct kref          kref;
0487     struct completion    comp;
0488     enum qib_sdma_states current_state;
0489     struct sdma_set_state_action *set_state_action;
0490     unsigned             current_op;
0491     unsigned             go_s99_running;
0492     unsigned             first_sendbuf;
0493     unsigned             last_sendbuf; /* really last +1 */
0494     /* debugging/devel */
0495     enum qib_sdma_states previous_state;
0496     unsigned             previous_op;
0497     enum qib_sdma_events last_event;
0498 };
0499 
0500 struct xmit_wait {
0501     struct timer_list timer;
0502     u64 counter;
0503     u8 flags;
0504     struct cache {
0505         u64 psxmitdata;
0506         u64 psrcvdata;
0507         u64 psxmitpkts;
0508         u64 psrcvpkts;
0509         u64 psxmitwait;
0510     } counter_cache;
0511 };
0512 
0513 /*
0514  * The structure below encapsulates data relevant to a physical IB Port.
0515  * Current chips support only one such port, but the separation
0516  * clarifies things a bit. Note that to conform to IB conventions,
0517  * port-numbers are one-based. The first or only port is port1.
0518  */
0519 struct qib_pportdata {
0520     struct qib_ibport ibport_data;
0521 
0522     struct qib_devdata *dd;
0523     struct qib_chippport_specific *cpspec; /* chip-specific per-port */
0524 
0525     /* GUID for this interface, in network order */
0526     __be64 guid;
0527 
0528     /* QIB_POLL, etc. link-state specific flags, per port */
0529     u32 lflags;
0530     /* qib_lflags driver is waiting for */
0531     u32 state_wanted;
0532     spinlock_t lflags_lock;
0533 
0534     /* ref count for each pkey */
0535     atomic_t pkeyrefs[4];
0536 
0537     /*
0538      * this address is mapped readonly into user processes so they can
0539      * get status cheaply, whenever they want.  One qword of status per port
0540      */
0541     u64 *statusp;
0542 
0543     /* SendDMA related entries */
0544 
0545     /* read mostly */
0546     struct qib_sdma_desc *sdma_descq;
0547     struct workqueue_struct *qib_wq;
0548     struct qib_sdma_state sdma_state;
0549     dma_addr_t       sdma_descq_phys;
0550     volatile __le64 *sdma_head_dma; /* DMA'ed by chip */
0551     dma_addr_t       sdma_head_phys;
0552     u16                   sdma_descq_cnt;
0553 
0554     /* read/write using lock */
0555     spinlock_t            sdma_lock ____cacheline_aligned_in_smp;
0556     struct list_head      sdma_activelist;
0557     struct list_head      sdma_userpending;
0558     u64                   sdma_descq_added;
0559     u64                   sdma_descq_removed;
0560     u16                   sdma_descq_tail;
0561     u16                   sdma_descq_head;
0562     u8                    sdma_generation;
0563     u8                    sdma_intrequest;
0564 
0565     struct tasklet_struct sdma_sw_clean_up_task
0566         ____cacheline_aligned_in_smp;
0567 
0568     wait_queue_head_t state_wait; /* for state_wanted */
0569 
0570     /* HoL blocking for SMP replies */
0571     unsigned          hol_state;
0572     struct timer_list hol_timer;
0573 
0574     /*
0575      * Shadow copies of registers; size indicates read access size.
0576      * Most of them are readonly, but some are write-only register,
0577      * where we manipulate the bits in the shadow copy, and then write
0578      * the shadow copy to qlogic_ib.
0579      *
0580      * We deliberately make most of these 32 bits, since they have
0581      * restricted range.  For any that we read, we won't to generate 32
0582      * bit accesses, since Opteron will generate 2 separate 32 bit HT
0583      * transactions for a 64 bit read, and we want to avoid unnecessary
0584      * bus transactions.
0585      */
0586 
0587     /* This is the 64 bit group */
0588     /* last ibcstatus.  opaque outside chip-specific code */
0589     u64 lastibcstat;
0590 
0591     /* these are the "32 bit" regs */
0592 
0593     /*
0594      * the following two are 32-bit bitmasks, but {test,clear,set}_bit
0595      * all expect bit fields to be "unsigned long"
0596      */
0597     unsigned long p_rcvctrl; /* shadow per-port rcvctrl */
0598     unsigned long p_sendctrl; /* shadow per-port sendctrl */
0599 
0600     u32 ibmtu; /* The MTU programmed for this unit */
0601     /*
0602      * Current max size IB packet (in bytes) including IB headers, that
0603      * we can send. Changes when ibmtu changes.
0604      */
0605     u32 ibmaxlen;
0606     /*
0607      * ibmaxlen at init time, limited by chip and by receive buffer
0608      * size.  Not changed after init.
0609      */
0610     u32 init_ibmaxlen;
0611     /* LID programmed for this instance */
0612     u16 lid;
0613     /* list of pkeys programmed; 0 if not set */
0614     u16 pkeys[4];
0615     /* LID mask control */
0616     u8 lmc;
0617     u8 link_width_supported;
0618     u16 link_speed_supported;
0619     u8 link_width_enabled;
0620     u16 link_speed_enabled;
0621     u8 link_width_active;
0622     u16 link_speed_active;
0623     u8 vls_supported;
0624     u8 vls_operational;
0625     /* Rx Polarity inversion (compensate for ~tx on partner) */
0626     u8 rx_pol_inv;
0627 
0628     u8 hw_pidx;     /* physical port index */
0629     u32 port;        /* IB port number and index into dd->pports - 1 */
0630 
0631     u8 delay_mult;
0632 
0633     /* used to override LED behavior */
0634     u8 led_override;  /* Substituted for normal value, if non-zero */
0635     u16 led_override_timeoff; /* delta to next timer event */
0636     u8 led_override_vals[2]; /* Alternates per blink-frame */
0637     u8 led_override_phase; /* Just counts, LSB picks from vals[] */
0638     atomic_t led_override_timer_active;
0639     /* Used to flash LEDs in override mode */
0640     struct timer_list led_override_timer;
0641     struct xmit_wait cong_stats;
0642     struct timer_list symerr_clear_timer;
0643 
0644     /* Synchronize access between driver writes and sysfs reads */
0645     spinlock_t cc_shadow_lock
0646         ____cacheline_aligned_in_smp;
0647 
0648     /* Shadow copy of the congestion control table */
0649     struct cc_table_shadow *ccti_entries_shadow;
0650 
0651     /* Shadow copy of the congestion control entries */
0652     struct ib_cc_congestion_setting_attr_shadow *congestion_entries_shadow;
0653 
0654     /* List of congestion control table entries */
0655     struct ib_cc_table_entry_shadow *ccti_entries;
0656 
0657     /* 16 congestion entries with each entry corresponding to a SL */
0658     struct ib_cc_congestion_entry_shadow *congestion_entries;
0659 
0660     /* Maximum number of congestion control entries that the agent expects
0661      * the manager to send.
0662      */
0663     u16 cc_supported_table_entries;
0664 
0665     /* Total number of congestion control table entries */
0666     u16 total_cct_entry;
0667 
0668     /* Bit map identifying service level */
0669     u16 cc_sl_control_map;
0670 
0671     /* maximum congestion control table index */
0672     u16 ccti_limit;
0673 
0674     /* CA's max number of 64 entry units in the congestion control table */
0675     u8 cc_max_table_entries;
0676 };
0677 
0678 /* Observers. Not to be taken lightly, possibly not to ship. */
0679 /*
0680  * If a diag read or write is to (bottom <= offset <= top),
0681  * the "hook" is called, allowing, e.g. shadows to be
0682  * updated in sync with the driver. struct diag_observer
0683  * is the "visible" part.
0684  */
0685 struct diag_observer;
0686 
0687 typedef int (*diag_hook) (struct qib_devdata *dd,
0688     const struct diag_observer *op,
0689     u32 offs, u64 *data, u64 mask, int only_32);
0690 
0691 struct diag_observer {
0692     diag_hook hook;
0693     u32 bottom;
0694     u32 top;
0695 };
0696 
0697 extern int qib_register_observer(struct qib_devdata *dd,
0698     const struct diag_observer *op);
0699 
0700 /* Only declared here, not defined. Private to diags */
0701 struct diag_observer_list_elt;
0702 
0703 /* device data struct now contains only "general per-device" info.
0704  * fields related to a physical IB port are in a qib_pportdata struct,
0705  * described above) while fields only used by a particular chip-type are in
0706  * a qib_chipdata struct, whose contents are opaque to this file.
0707  */
0708 struct qib_devdata {
0709     struct qib_ibdev verbs_dev;     /* must be first */
0710     struct list_head list;
0711     /* pointers to related structs for this device */
0712     /* pci access data structure */
0713     struct pci_dev *pcidev;
0714     struct cdev *user_cdev;
0715     struct cdev *diag_cdev;
0716     struct device *user_device;
0717     struct device *diag_device;
0718 
0719     /* mem-mapped pointer to base of chip regs */
0720     u64 __iomem *kregbase;
0721     /* end of mem-mapped chip space excluding sendbuf and user regs */
0722     u64 __iomem *kregend;
0723     /* physical address of chip for io_remap, etc. */
0724     resource_size_t physaddr;
0725     /* qib_cfgctxts pointers */
0726     struct qib_ctxtdata **rcd; /* Receive Context Data */
0727 
0728     /* qib_pportdata, points to array of (physical) port-specific
0729      * data structs, indexed by pidx (0..n-1)
0730      */
0731     struct qib_pportdata *pport;
0732     struct qib_chip_specific *cspec; /* chip-specific */
0733 
0734     /* kvirt address of 1st 2k pio buffer */
0735     void __iomem *pio2kbase;
0736     /* kvirt address of 1st 4k pio buffer */
0737     void __iomem *pio4kbase;
0738     /* mem-mapped pointer to base of PIO buffers (if using WC PAT) */
0739     void __iomem *piobase;
0740     /* mem-mapped pointer to base of user chip regs (if using WC PAT) */
0741     u64 __iomem *userbase;
0742     void __iomem *piovl15base; /* base of VL15 buffers, if not WC */
0743     /*
0744      * points to area where PIOavail registers will be DMA'ed.
0745      * Has to be on a page of it's own, because the page will be
0746      * mapped into user program space.  This copy is *ONLY* ever
0747      * written by DMA, not by the driver!  Need a copy per device
0748      * when we get to multiple devices
0749      */
0750     volatile __le64 *pioavailregs_dma; /* DMA'ed by chip */
0751     /* physical address where updates occur */
0752     dma_addr_t pioavailregs_phys;
0753 
0754     /* device-specific implementations of functions needed by
0755      * common code. Contrary to previous consensus, we can't
0756      * really just point to a device-specific table, because we
0757      * may need to "bend", e.g. *_f_put_tid
0758      */
0759     /* fallback to alternate interrupt type if possible */
0760     int (*f_intr_fallback)(struct qib_devdata *);
0761     /* hard reset chip */
0762     int (*f_reset)(struct qib_devdata *);
0763     void (*f_quiet_serdes)(struct qib_pportdata *);
0764     int (*f_bringup_serdes)(struct qib_pportdata *);
0765     int (*f_early_init)(struct qib_devdata *);
0766     void (*f_clear_tids)(struct qib_devdata *, struct qib_ctxtdata *);
0767     void (*f_put_tid)(struct qib_devdata *, u64 __iomem*,
0768                 u32, unsigned long);
0769     void (*f_cleanup)(struct qib_devdata *);
0770     void (*f_setextled)(struct qib_pportdata *, u32);
0771     /* fill out chip-specific fields */
0772     int (*f_get_base_info)(struct qib_ctxtdata *, struct qib_base_info *);
0773     /* free irq */
0774     void (*f_free_irq)(struct qib_devdata *);
0775     struct qib_message_header *(*f_get_msgheader)
0776                     (struct qib_devdata *, __le32 *);
0777     void (*f_config_ctxts)(struct qib_devdata *);
0778     int (*f_get_ib_cfg)(struct qib_pportdata *, int);
0779     int (*f_set_ib_cfg)(struct qib_pportdata *, int, u32);
0780     int (*f_set_ib_loopback)(struct qib_pportdata *, const char *);
0781     int (*f_get_ib_table)(struct qib_pportdata *, int, void *);
0782     int (*f_set_ib_table)(struct qib_pportdata *, int, void *);
0783     u32 (*f_iblink_state)(u64);
0784     u8 (*f_ibphys_portstate)(u64);
0785     void (*f_xgxs_reset)(struct qib_pportdata *);
0786     /* per chip actions needed for IB Link up/down changes */
0787     int (*f_ib_updown)(struct qib_pportdata *, int, u64);
0788     u32 __iomem *(*f_getsendbuf)(struct qib_pportdata *, u64, u32 *);
0789     /* Read/modify/write of GPIO pins (potentially chip-specific */
0790     int (*f_gpio_mod)(struct qib_devdata *dd, u32 out, u32 dir,
0791         u32 mask);
0792     /* Enable writes to config EEPROM (if supported) */
0793     int (*f_eeprom_wen)(struct qib_devdata *dd, int wen);
0794     /*
0795      * modify rcvctrl shadow[s] and write to appropriate chip-regs.
0796      * see above QIB_RCVCTRL_xxx_ENB/DIS for operations.
0797      * (ctxt == -1) means "all contexts", only meaningful for
0798      * clearing. Could remove if chip_spec shutdown properly done.
0799      */
0800     void (*f_rcvctrl)(struct qib_pportdata *, unsigned int op,
0801         int ctxt);
0802     /* Read/modify/write sendctrl appropriately for op and port. */
0803     void (*f_sendctrl)(struct qib_pportdata *, u32 op);
0804     void (*f_set_intr_state)(struct qib_devdata *, u32);
0805     void (*f_set_armlaunch)(struct qib_devdata *, u32);
0806     void (*f_wantpiobuf_intr)(struct qib_devdata *, u32);
0807     int (*f_late_initreg)(struct qib_devdata *);
0808     int (*f_init_sdma_regs)(struct qib_pportdata *);
0809     u16 (*f_sdma_gethead)(struct qib_pportdata *);
0810     int (*f_sdma_busy)(struct qib_pportdata *);
0811     void (*f_sdma_update_tail)(struct qib_pportdata *, u16);
0812     void (*f_sdma_set_desc_cnt)(struct qib_pportdata *, unsigned);
0813     void (*f_sdma_sendctrl)(struct qib_pportdata *, unsigned);
0814     void (*f_sdma_hw_clean_up)(struct qib_pportdata *);
0815     void (*f_sdma_hw_start_up)(struct qib_pportdata *);
0816     void (*f_sdma_init_early)(struct qib_pportdata *);
0817     void (*f_set_cntr_sample)(struct qib_pportdata *, u32, u32);
0818     void (*f_update_usrhead)(struct qib_ctxtdata *, u64, u32, u32, u32);
0819     u32 (*f_hdrqempty)(struct qib_ctxtdata *);
0820     u64 (*f_portcntr)(struct qib_pportdata *, u32);
0821     u32 (*f_read_cntrs)(struct qib_devdata *, loff_t, char **,
0822         u64 **);
0823     u32 (*f_read_portcntrs)(struct qib_devdata *, loff_t, u32,
0824         char **, u64 **);
0825     u32 (*f_setpbc_control)(struct qib_pportdata *, u32, u8, u8);
0826     void (*f_initvl15_bufs)(struct qib_devdata *);
0827     void (*f_init_ctxt)(struct qib_ctxtdata *);
0828     void (*f_txchk_change)(struct qib_devdata *, u32, u32, u32,
0829         struct qib_ctxtdata *);
0830     void (*f_writescratch)(struct qib_devdata *, u32);
0831     int (*f_tempsense_rd)(struct qib_devdata *, int regnum);
0832 #ifdef CONFIG_INFINIBAND_QIB_DCA
0833     int (*f_notify_dca)(struct qib_devdata *, unsigned long event);
0834 #endif
0835 
0836     char *boardname; /* human readable board info */
0837 
0838     /* template for writing TIDs  */
0839     u64 tidtemplate;
0840     /* value to write to free TIDs */
0841     u64 tidinvalid;
0842 
0843     /* number of registers used for pioavail */
0844     u32 pioavregs;
0845     /* device (not port) flags, basically device capabilities */
0846     u32 flags;
0847     /* last buffer for user use */
0848     u32 lastctxt_piobuf;
0849 
0850     /* reset value */
0851     u64 z_int_counter;
0852     /* percpu intcounter */
0853     u64 __percpu *int_counter;
0854 
0855     /* pio bufs allocated per ctxt */
0856     u32 pbufsctxt;
0857     /* if remainder on bufs/ctxt, ctxts < extrabuf get 1 extra */
0858     u32 ctxts_extrabuf;
0859     /*
0860      * number of ctxts configured as max; zero is set to number chip
0861      * supports, less gives more pio bufs/ctxt, etc.
0862      */
0863     u32 cfgctxts;
0864     /*
0865      * number of ctxts available for PSM open
0866      */
0867     u32 freectxts;
0868 
0869     /*
0870      * hint that we should update pioavailshadow before
0871      * looking for a PIO buffer
0872      */
0873     u32 upd_pio_shadow;
0874 
0875     /* internal debugging stats */
0876     u32 maxpkts_call;
0877     u32 avgpkts_call;
0878     u64 nopiobufs;
0879 
0880     /* PCI Vendor ID (here for NodeInfo) */
0881     u16 vendorid;
0882     /* PCI Device ID (here for NodeInfo) */
0883     u16 deviceid;
0884     /* for write combining settings */
0885     int wc_cookie;
0886     unsigned long wc_base;
0887     unsigned long wc_len;
0888 
0889     /* shadow copy of struct page *'s for exp tid pages */
0890     struct page **pageshadow;
0891     /* shadow copy of dma handles for exp tid pages */
0892     dma_addr_t *physshadow;
0893     u64 __iomem *egrtidbase;
0894     spinlock_t sendctrl_lock; /* protect changes to sendctrl shadow */
0895     /* around rcd and (user ctxts) ctxt_cnt use (intr vs free) */
0896     spinlock_t uctxt_lock; /* rcd and user context changes */
0897     /*
0898      * per unit status, see also portdata statusp
0899      * mapped readonly into user processes so they can get unit and
0900      * IB link status cheaply
0901      */
0902     u64 *devstatusp;
0903     char *freezemsg; /* freeze msg if hw error put chip in freeze */
0904     u32 freezelen; /* max length of freezemsg */
0905     /* timer used to prevent stats overflow, error throttling, etc. */
0906     struct timer_list stats_timer;
0907 
0908     /* timer to verify interrupts work, and fallback if possible */
0909     struct timer_list intrchk_timer;
0910     unsigned long ureg_align; /* user register alignment */
0911 
0912     /*
0913      * Protects pioavailshadow, pioavailkernel, pio_need_disarm, and
0914      * pio_writing.
0915      */
0916     spinlock_t pioavail_lock;
0917     /*
0918      * index of last buffer to optimize search for next
0919      */
0920     u32 last_pio;
0921     /*
0922      * min kernel pio buffer to optimize search
0923      */
0924     u32 min_kernel_pio;
0925     /*
0926      * Shadow copies of registers; size indicates read access size.
0927      * Most of them are readonly, but some are write-only register,
0928      * where we manipulate the bits in the shadow copy, and then write
0929      * the shadow copy to qlogic_ib.
0930      *
0931      * We deliberately make most of these 32 bits, since they have
0932      * restricted range.  For any that we read, we won't to generate 32
0933      * bit accesses, since Opteron will generate 2 separate 32 bit HT
0934      * transactions for a 64 bit read, and we want to avoid unnecessary
0935      * bus transactions.
0936      */
0937 
0938     /* This is the 64 bit group */
0939 
0940     unsigned long pioavailshadow[6];
0941     /* bitmap of send buffers available for the kernel to use with PIO. */
0942     unsigned long pioavailkernel[6];
0943     /* bitmap of send buffers which need to be disarmed. */
0944     unsigned long pio_need_disarm[3];
0945     /* bitmap of send buffers which are being written to. */
0946     unsigned long pio_writing[3];
0947     /* kr_revision shadow */
0948     u64 revision;
0949     /* Base GUID for device (from eeprom, network order) */
0950     __be64 base_guid;
0951 
0952     /*
0953      * kr_sendpiobufbase value (chip offset of pio buffers), and the
0954      * base of the 2KB buffer s(user processes only use 2K)
0955      */
0956     u64 piobufbase;
0957     u32 pio2k_bufbase;
0958 
0959     /* these are the "32 bit" regs */
0960 
0961     /* number of GUIDs in the flash for this interface */
0962     u32 nguid;
0963     /*
0964      * the following two are 32-bit bitmasks, but {test,clear,set}_bit
0965      * all expect bit fields to be "unsigned long"
0966      */
0967     unsigned long rcvctrl; /* shadow per device rcvctrl */
0968     unsigned long sendctrl; /* shadow per device sendctrl */
0969 
0970     /* value we put in kr_rcvhdrcnt */
0971     u32 rcvhdrcnt;
0972     /* value we put in kr_rcvhdrsize */
0973     u32 rcvhdrsize;
0974     /* value we put in kr_rcvhdrentsize */
0975     u32 rcvhdrentsize;
0976     /* kr_ctxtcnt value */
0977     u32 ctxtcnt;
0978     /* kr_pagealign value */
0979     u32 palign;
0980     /* number of "2KB" PIO buffers */
0981     u32 piobcnt2k;
0982     /* size in bytes of "2KB" PIO buffers */
0983     u32 piosize2k;
0984     /* max usable size in dwords of a "2KB" PIO buffer before going "4KB" */
0985     u32 piosize2kmax_dwords;
0986     /* number of "4KB" PIO buffers */
0987     u32 piobcnt4k;
0988     /* size in bytes of "4KB" PIO buffers */
0989     u32 piosize4k;
0990     /* kr_rcvegrbase value */
0991     u32 rcvegrbase;
0992     /* kr_rcvtidbase value */
0993     u32 rcvtidbase;
0994     /* kr_rcvtidcnt value */
0995     u32 rcvtidcnt;
0996     /* kr_userregbase */
0997     u32 uregbase;
0998     /* shadow the control register contents */
0999     u32 control;
1000 
1001     /* chip address space used by 4k pio buffers */
1002     u32 align4k;
1003     /* size of each rcvegrbuffer */
1004     u16 rcvegrbufsize;
1005     /* log2 of above */
1006     u16 rcvegrbufsize_shift;
1007     /* localbus width (1, 2,4,8,16,32) from config space  */
1008     u32 lbus_width;
1009     /* localbus speed in MHz */
1010     u32 lbus_speed;
1011     int unit; /* unit # of this chip */
1012 
1013     /* start of CHIP_SPEC move to chipspec, but need code changes */
1014     /* low and high portions of MSI capability/vector */
1015     u32 msi_lo;
1016     /* saved after PCIe init for restore after reset */
1017     u32 msi_hi;
1018     /* MSI data (vector) saved for restore */
1019     u16 msi_data;
1020     /* so we can rewrite it after a chip reset */
1021     u32 pcibar0;
1022     /* so we can rewrite it after a chip reset */
1023     u32 pcibar1;
1024     u64 rhdrhead_intr_off;
1025 
1026     /*
1027      * ASCII serial number, from flash, large enough for original
1028      * all digit strings, and longer QLogic serial number format
1029      */
1030     u8 serial[16];
1031     /* human readable board version */
1032     u8 boardversion[96];
1033     u8 lbus_info[32]; /* human readable localbus info */
1034     /* chip major rev, from qib_revision */
1035     u8 majrev;
1036     /* chip minor rev, from qib_revision */
1037     u8 minrev;
1038 
1039     /* Misc small ints */
1040     /* Number of physical ports available */
1041     u8 num_pports;
1042     /* Lowest context number which can be used by user processes */
1043     u8 first_user_ctxt;
1044     u8 n_krcv_queues;
1045     u8 qpn_mask;
1046     u8 skip_kctxt_mask;
1047 
1048     u16 rhf_offset; /* offset of RHF within receive header entry */
1049 
1050     /*
1051      * GPIO pins for twsi-connected devices, and device code for eeprom
1052      */
1053     u8 gpio_sda_num;
1054     u8 gpio_scl_num;
1055     u8 twsi_eeprom_dev;
1056     u8 board_atten;
1057 
1058     /* Support (including locks) for EEPROM logging of errors and time */
1059     /* control access to actual counters, timer */
1060     spinlock_t eep_st_lock;
1061     /* control high-level access to EEPROM */
1062     struct mutex eep_lock;
1063     uint64_t traffic_wds;
1064     struct qib_diag_client *diag_client;
1065     spinlock_t qib_diag_trans_lock; /* protect diag observer ops */
1066     struct diag_observer_list_elt *diag_observer_list;
1067 
1068     u8 psxmitwait_supported;
1069     /* cycle length of PS* counters in HW (in picoseconds) */
1070     u16 psxmitwait_check_rate;
1071     /* high volume overflow errors defered to tasklet */
1072     struct tasklet_struct error_tasklet;
1073 
1074     int assigned_node_id; /* NUMA node closest to HCA */
1075 };
1076 
1077 /* hol_state values */
1078 #define QIB_HOL_UP       0
1079 #define QIB_HOL_INIT     1
1080 
1081 #define QIB_SDMA_SENDCTRL_OP_ENABLE    (1U << 0)
1082 #define QIB_SDMA_SENDCTRL_OP_INTENABLE (1U << 1)
1083 #define QIB_SDMA_SENDCTRL_OP_HALT      (1U << 2)
1084 #define QIB_SDMA_SENDCTRL_OP_CLEANUP   (1U << 3)
1085 #define QIB_SDMA_SENDCTRL_OP_DRAIN     (1U << 4)
1086 
1087 /* operation types for f_txchk_change() */
1088 #define TXCHK_CHG_TYPE_DIS1  3
1089 #define TXCHK_CHG_TYPE_ENAB1 2
1090 #define TXCHK_CHG_TYPE_KERN  1
1091 #define TXCHK_CHG_TYPE_USER  0
1092 
1093 #define QIB_CHASE_TIME msecs_to_jiffies(145)
1094 #define QIB_CHASE_DIS_TIME msecs_to_jiffies(160)
1095 
1096 /* Private data for file operations */
1097 struct qib_filedata {
1098     struct qib_ctxtdata *rcd;
1099     unsigned subctxt;
1100     unsigned tidcursor;
1101     struct qib_user_sdma_queue *pq;
1102     int rec_cpu_num; /* for cpu affinity; -1 if none */
1103 };
1104 
1105 extern struct xarray qib_dev_table;
1106 extern struct qib_devdata *qib_lookup(int unit);
1107 extern u32 qib_cpulist_count;
1108 extern unsigned long *qib_cpulist;
1109 extern unsigned qib_cc_table_size;
1110 
1111 int qib_init(struct qib_devdata *, int);
1112 int init_chip_wc_pat(struct qib_devdata *dd, u32);
1113 int qib_enable_wc(struct qib_devdata *dd);
1114 void qib_disable_wc(struct qib_devdata *dd);
1115 int qib_count_units(int *npresentp, int *nupp);
1116 int qib_count_active_units(void);
1117 
1118 int qib_cdev_init(int minor, const char *name,
1119           const struct file_operations *fops,
1120           struct cdev **cdevp, struct device **devp);
1121 void qib_cdev_cleanup(struct cdev **cdevp, struct device **devp);
1122 int qib_dev_init(void);
1123 void qib_dev_cleanup(void);
1124 
1125 int qib_diag_add(struct qib_devdata *);
1126 void qib_diag_remove(struct qib_devdata *);
1127 void qib_handle_e_ibstatuschanged(struct qib_pportdata *, u64);
1128 void qib_sdma_update_tail(struct qib_pportdata *, u16); /* hold sdma_lock */
1129 
1130 int qib_decode_err(struct qib_devdata *dd, char *buf, size_t blen, u64 err);
1131 void qib_bad_intrstatus(struct qib_devdata *);
1132 void qib_handle_urcv(struct qib_devdata *, u64);
1133 
1134 /* clean up any per-chip chip-specific stuff */
1135 void qib_chip_cleanup(struct qib_devdata *);
1136 /* clean up any chip type-specific stuff */
1137 void qib_chip_done(void);
1138 
1139 /* check to see if we have to force ordering for write combining */
1140 int qib_unordered_wc(void);
1141 void qib_pio_copy(void __iomem *to, const void *from, size_t count);
1142 
1143 void qib_disarm_piobufs(struct qib_devdata *, unsigned, unsigned);
1144 int qib_disarm_piobufs_ifneeded(struct qib_ctxtdata *);
1145 void qib_disarm_piobufs_set(struct qib_devdata *, unsigned long *, unsigned);
1146 void qib_cancel_sends(struct qib_pportdata *);
1147 
1148 int qib_create_rcvhdrq(struct qib_devdata *, struct qib_ctxtdata *);
1149 int qib_setup_eagerbufs(struct qib_ctxtdata *);
1150 void qib_set_ctxtcnt(struct qib_devdata *);
1151 int qib_create_ctxts(struct qib_devdata *dd);
1152 struct qib_ctxtdata *qib_create_ctxtdata(struct qib_pportdata *, u32, int);
1153 int qib_init_pportdata(struct qib_pportdata *, struct qib_devdata *, u8, u8);
1154 void qib_free_ctxtdata(struct qib_devdata *, struct qib_ctxtdata *);
1155 
1156 u32 qib_kreceive(struct qib_ctxtdata *, u32 *, u32 *);
1157 int qib_reset_device(int);
1158 int qib_wait_linkstate(struct qib_pportdata *, u32, int);
1159 int qib_set_linkstate(struct qib_pportdata *, u8);
1160 int qib_set_mtu(struct qib_pportdata *, u16);
1161 int qib_set_lid(struct qib_pportdata *, u32, u8);
1162 void qib_hol_down(struct qib_pportdata *);
1163 void qib_hol_init(struct qib_pportdata *);
1164 void qib_hol_up(struct qib_pportdata *);
1165 void qib_hol_event(struct timer_list *);
1166 void qib_disable_after_error(struct qib_devdata *);
1167 int qib_set_uevent_bits(struct qib_pportdata *, const int);
1168 
1169 /* for use in system calls, where we want to know device type, etc. */
1170 #define ctxt_fp(fp) \
1171     (((struct qib_filedata *)(fp)->private_data)->rcd)
1172 #define subctxt_fp(fp) \
1173     (((struct qib_filedata *)(fp)->private_data)->subctxt)
1174 #define tidcursor_fp(fp) \
1175     (((struct qib_filedata *)(fp)->private_data)->tidcursor)
1176 #define user_sdma_queue_fp(fp) \
1177     (((struct qib_filedata *)(fp)->private_data)->pq)
1178 
1179 static inline struct qib_devdata *dd_from_ppd(struct qib_pportdata *ppd)
1180 {
1181     return ppd->dd;
1182 }
1183 
1184 static inline struct qib_devdata *dd_from_dev(struct qib_ibdev *dev)
1185 {
1186     return container_of(dev, struct qib_devdata, verbs_dev);
1187 }
1188 
1189 static inline struct qib_devdata *dd_from_ibdev(struct ib_device *ibdev)
1190 {
1191     return dd_from_dev(to_idev(ibdev));
1192 }
1193 
1194 static inline struct qib_pportdata *ppd_from_ibp(struct qib_ibport *ibp)
1195 {
1196     return container_of(ibp, struct qib_pportdata, ibport_data);
1197 }
1198 
1199 static inline struct qib_ibport *to_iport(struct ib_device *ibdev, u32 port)
1200 {
1201     struct qib_devdata *dd = dd_from_ibdev(ibdev);
1202     u32 pidx = port - 1; /* IB number port from 1, hdw from 0 */
1203 
1204     WARN_ON(pidx >= dd->num_pports);
1205     return &dd->pport[pidx].ibport_data;
1206 }
1207 
1208 /*
1209  * values for dd->flags (_device_ related flags) and
1210  */
1211 #define QIB_HAS_LINK_LATENCY  0x1 /* supports link latency (IB 1.2) */
1212 #define QIB_INITTED           0x2 /* chip and driver up and initted */
1213 #define QIB_DOING_RESET       0x4  /* in the middle of doing chip reset */
1214 #define QIB_PRESENT           0x8  /* chip accesses can be done */
1215 #define QIB_PIO_FLUSH_WC      0x10 /* Needs Write combining flush for PIO */
1216 #define QIB_HAS_THRESH_UPDATE 0x40
1217 #define QIB_HAS_SDMA_TIMEOUT  0x80
1218 #define QIB_USE_SPCL_TRIG     0x100 /* SpecialTrigger launch enabled */
1219 #define QIB_NODMA_RTAIL       0x200 /* rcvhdrtail register DMA enabled */
1220 #define QIB_HAS_INTX          0x800 /* Supports INTx interrupts */
1221 #define QIB_HAS_SEND_DMA      0x1000 /* Supports Send DMA */
1222 #define QIB_HAS_VLSUPP        0x2000 /* Supports multiple VLs; PBC different */
1223 #define QIB_HAS_HDRSUPP       0x4000 /* Supports header suppression */
1224 #define QIB_BADINTR           0x8000 /* severe interrupt problems */
1225 #define QIB_DCA_ENABLED       0x10000 /* Direct Cache Access enabled */
1226 #define QIB_HAS_QSFP          0x20000 /* device (card instance) has QSFP */
1227 #define QIB_SHUTDOWN          0x40000 /* device is shutting down */
1228 
1229 /*
1230  * values for ppd->lflags (_ib_port_ related flags)
1231  */
1232 #define QIBL_LINKV             0x1 /* IB link state valid */
1233 #define QIBL_LINKDOWN          0x8 /* IB link is down */
1234 #define QIBL_LINKINIT          0x10 /* IB link level is up */
1235 #define QIBL_LINKARMED         0x20 /* IB link is ARMED */
1236 #define QIBL_LINKACTIVE        0x40 /* IB link is ACTIVE */
1237 /* leave a gap for more IB-link state */
1238 #define QIBL_IB_AUTONEG_INPROG 0x1000 /* non-IBTA DDR/QDR neg active */
1239 #define QIBL_IB_AUTONEG_FAILED 0x2000 /* non-IBTA DDR/QDR neg failed */
1240 #define QIBL_IB_LINK_DISABLED  0x4000 /* Linkdown-disable forced,
1241                        * Do not try to bring up */
1242 #define QIBL_IB_FORCE_NOTIFY   0x8000 /* force notify on next ib change */
1243 
1244 /* IB dword length mask in PBC (lower 11 bits); same for all chips */
1245 #define QIB_PBC_LENGTH_MASK                     ((1 << 11) - 1)
1246 
1247 
1248 /* ctxt_flag bit offsets */
1249         /* waiting for a packet to arrive */
1250 #define QIB_CTXT_WAITING_RCV   2
1251         /* master has not finished initializing */
1252 #define QIB_CTXT_MASTER_UNINIT 4
1253         /* waiting for an urgent packet to arrive */
1254 #define QIB_CTXT_WAITING_URG 5
1255 
1256 /* free up any allocated data at closes */
1257 void qib_free_data(struct qib_ctxtdata *dd);
1258 void qib_chg_pioavailkernel(struct qib_devdata *, unsigned, unsigned,
1259                 u32, struct qib_ctxtdata *);
1260 struct qib_devdata *qib_init_iba7322_funcs(struct pci_dev *,
1261                        const struct pci_device_id *);
1262 struct qib_devdata *qib_init_iba7220_funcs(struct pci_dev *,
1263                        const struct pci_device_id *);
1264 struct qib_devdata *qib_init_iba6120_funcs(struct pci_dev *,
1265                        const struct pci_device_id *);
1266 void qib_free_devdata(struct qib_devdata *);
1267 struct qib_devdata *qib_alloc_devdata(struct pci_dev *pdev, size_t extra);
1268 
1269 #define QIB_TWSI_NO_DEV 0xFF
1270 /* Below qib_twsi_ functions must be called with eep_lock held */
1271 int qib_twsi_reset(struct qib_devdata *dd);
1272 int qib_twsi_blk_rd(struct qib_devdata *dd, int dev, int addr, void *buffer,
1273             int len);
1274 int qib_twsi_blk_wr(struct qib_devdata *dd, int dev, int addr,
1275             const void *buffer, int len);
1276 void qib_get_eeprom_info(struct qib_devdata *);
1277 void qib_dump_lookup_output_queue(struct qib_devdata *);
1278 void qib_force_pio_avail_update(struct qib_devdata *);
1279 void qib_clear_symerror_on_linkup(struct timer_list *t);
1280 
1281 /*
1282  * Set LED override, only the two LSBs have "public" meaning, but
1283  * any non-zero value substitutes them for the Link and LinkTrain
1284  * LED states.
1285  */
1286 #define QIB_LED_PHYS 1 /* Physical (linktraining) GREEN LED */
1287 #define QIB_LED_LOG 2  /* Logical (link) YELLOW LED */
1288 void qib_set_led_override(struct qib_pportdata *ppd, unsigned int val);
1289 
1290 /* send dma routines */
1291 int qib_setup_sdma(struct qib_pportdata *);
1292 void qib_teardown_sdma(struct qib_pportdata *);
1293 void __qib_sdma_intr(struct qib_pportdata *);
1294 void qib_sdma_intr(struct qib_pportdata *);
1295 void qib_user_sdma_send_desc(struct qib_pportdata *dd,
1296             struct list_head *pktlist);
1297 int qib_sdma_verbs_send(struct qib_pportdata *, struct rvt_sge_state *,
1298             u32, struct qib_verbs_txreq *);
1299 /* ppd->sdma_lock should be locked before calling this. */
1300 int qib_sdma_make_progress(struct qib_pportdata *dd);
1301 
1302 /* must be called under qib_sdma_lock */
1303 static inline u16 qib_sdma_descq_freecnt(const struct qib_pportdata *ppd)
1304 {
1305     return ppd->sdma_descq_cnt -
1306         (ppd->sdma_descq_added - ppd->sdma_descq_removed) - 1;
1307 }
1308 
1309 static inline int __qib_sdma_running(struct qib_pportdata *ppd)
1310 {
1311     return ppd->sdma_state.current_state == qib_sdma_state_s99_running;
1312 }
1313 int qib_sdma_running(struct qib_pportdata *);
1314 void dump_sdma_state(struct qib_pportdata *ppd);
1315 void __qib_sdma_process_event(struct qib_pportdata *, enum qib_sdma_events);
1316 void qib_sdma_process_event(struct qib_pportdata *, enum qib_sdma_events);
1317 
1318 /*
1319  * number of words used for protocol header if not set by qib_userinit();
1320  */
1321 #define QIB_DFLT_RCVHDRSIZE 9
1322 
1323 /*
1324  * We need to be able to handle an IB header of at least 24 dwords.
1325  * We need the rcvhdrq large enough to handle largest IB header, but
1326  * still have room for a 2KB MTU standard IB packet.
1327  * Additionally, some processor/memory controller combinations
1328  * benefit quite strongly from having the DMA'ed data be cacheline
1329  * aligned and a cacheline multiple, so we set the size to 32 dwords
1330  * (2 64-byte primary cachelines for pretty much all processors of
1331  * interest).  The alignment hurts nothing, other than using somewhat
1332  * more memory.
1333  */
1334 #define QIB_RCVHDR_ENTSIZE 32
1335 
1336 int qib_get_user_pages(unsigned long, size_t, struct page **);
1337 void qib_release_user_pages(struct page **, size_t);
1338 int qib_eeprom_read(struct qib_devdata *, u8, void *, int);
1339 int qib_eeprom_write(struct qib_devdata *, u8, const void *, int);
1340 u32 __iomem *qib_getsendbuf_range(struct qib_devdata *, u32 *, u32, u32);
1341 void qib_sendbuf_done(struct qib_devdata *, unsigned);
1342 
1343 static inline void qib_clear_rcvhdrtail(const struct qib_ctxtdata *rcd)
1344 {
1345     *((u64 *) rcd->rcvhdrtail_kvaddr) = 0ULL;
1346 }
1347 
1348 static inline u32 qib_get_rcvhdrtail(const struct qib_ctxtdata *rcd)
1349 {
1350     /*
1351      * volatile because it's a DMA target from the chip, routine is
1352      * inlined, and don't want register caching or reordering.
1353      */
1354     return (u32) le64_to_cpu(
1355         *((volatile __le64 *)rcd->rcvhdrtail_kvaddr)); /* DMA'ed */
1356 }
1357 
1358 /*
1359  * sysfs interface.
1360  */
1361 
1362 extern const char ib_qib_version[];
1363 extern const struct attribute_group qib_attr_group;
1364 extern const struct attribute_group *qib_attr_port_groups[];
1365 
1366 int qib_device_create(struct qib_devdata *);
1367 void qib_device_remove(struct qib_devdata *);
1368 
1369 /* Hook for sysfs read of QSFP */
1370 extern int qib_qsfp_dump(struct qib_pportdata *ppd, char *buf, int len);
1371 
1372 int __init qib_init_qibfs(void);
1373 int __exit qib_exit_qibfs(void);
1374 
1375 int qibfs_add(struct qib_devdata *);
1376 int qibfs_remove(struct qib_devdata *);
1377 
1378 int qib_pcie_init(struct pci_dev *, const struct pci_device_id *);
1379 int qib_pcie_ddinit(struct qib_devdata *, struct pci_dev *,
1380             const struct pci_device_id *);
1381 void qib_pcie_ddcleanup(struct qib_devdata *);
1382 int qib_pcie_params(struct qib_devdata *dd, u32 minw, u32 *nent);
1383 void qib_free_irq(struct qib_devdata *dd);
1384 int qib_reinit_intr(struct qib_devdata *dd);
1385 void qib_pcie_getcmd(struct qib_devdata *, u16 *, u8 *, u8 *);
1386 void qib_pcie_reenable(struct qib_devdata *, u16, u8, u8);
1387 /* interrupts for device */
1388 u64 qib_int_counter(struct qib_devdata *);
1389 /* interrupt for all devices */
1390 u64 qib_sps_ints(void);
1391 
1392 /*
1393  * dma_addr wrappers - all 0's invalid for hw
1394  */
1395 int qib_map_page(struct pci_dev *d, struct page *p, dma_addr_t *daddr);
1396 struct pci_dev *qib_get_pci_dev(struct rvt_dev_info *rdi);
1397 
1398 /*
1399  * Flush write combining store buffers (if present) and perform a write
1400  * barrier.
1401  */
1402 static inline void qib_flush_wc(void)
1403 {
1404 #if defined(CONFIG_X86_64)
1405     asm volatile("sfence" : : : "memory");
1406 #else
1407     wmb(); /* no reorder around wc flush */
1408 #endif
1409 }
1410 
1411 /* global module parameter variables */
1412 extern unsigned qib_ibmtu;
1413 extern ushort qib_cfgctxts;
1414 extern ushort qib_num_cfg_vls;
1415 extern ushort qib_mini_init; /* If set, do few (ideally 0) writes to chip */
1416 extern unsigned qib_n_krcv_queues;
1417 extern unsigned qib_sdma_fetch_arb;
1418 extern unsigned qib_compat_ddr_negotiate;
1419 extern int qib_special_trigger;
1420 extern unsigned qib_numa_aware;
1421 
1422 extern struct mutex qib_mutex;
1423 
1424 /* Number of seconds before our card status check...  */
1425 #define STATUS_TIMEOUT 60
1426 
1427 #define QIB_DRV_NAME            "ib_qib"
1428 #define QIB_USER_MINOR_BASE     0
1429 #define QIB_TRACE_MINOR         127
1430 #define QIB_DIAGPKT_MINOR       128
1431 #define QIB_DIAG_MINOR_BASE     129
1432 #define QIB_NMINORS             255
1433 
1434 #define PCI_VENDOR_ID_PATHSCALE 0x1fc1
1435 #define PCI_VENDOR_ID_QLOGIC 0x1077
1436 #define PCI_DEVICE_ID_QLOGIC_IB_6120 0x10
1437 #define PCI_DEVICE_ID_QLOGIC_IB_7220 0x7220
1438 #define PCI_DEVICE_ID_QLOGIC_IB_7322 0x7322
1439 
1440 /*
1441  * qib_early_err is used (only!) to print early errors before devdata is
1442  * allocated, or when dd->pcidev may not be valid, and at the tail end of
1443  * cleanup when devdata may have been freed, etc.  qib_dev_porterr is
1444  * the same as qib_dev_err, but is used when the message really needs
1445  * the IB port# to be definitive as to what's happening..
1446  * All of these go to the trace log, and the trace log entry is done
1447  * first to avoid possible serial port delays from printk.
1448  */
1449 #define qib_early_err(dev, fmt, ...) \
1450     dev_err(dev, fmt, ##__VA_ARGS__)
1451 
1452 #define qib_dev_err(dd, fmt, ...) \
1453     dev_err(&(dd)->pcidev->dev, "%s: " fmt, \
1454         rvt_get_ibdev_name(&(dd)->verbs_dev.rdi), ##__VA_ARGS__)
1455 
1456 #define qib_dev_warn(dd, fmt, ...) \
1457     dev_warn(&(dd)->pcidev->dev, "%s: " fmt, \
1458          rvt_get_ibdev_name(&(dd)->verbs_dev.rdi), ##__VA_ARGS__)
1459 
1460 #define qib_dev_porterr(dd, port, fmt, ...) \
1461     dev_err(&(dd)->pcidev->dev, "%s: IB%u:%u " fmt, \
1462         rvt_get_ibdev_name(&(dd)->verbs_dev.rdi), (dd)->unit, (port), \
1463         ##__VA_ARGS__)
1464 
1465 #define qib_devinfo(pcidev, fmt, ...) \
1466     dev_info(&(pcidev)->dev, fmt, ##__VA_ARGS__)
1467 
1468 /*
1469  * this is used for formatting hw error messages...
1470  */
1471 struct qib_hwerror_msgs {
1472     u64 mask;
1473     const char *msg;
1474     size_t sz;
1475 };
1476 
1477 #define QLOGIC_IB_HWE_MSG(a, b) { .mask = a, .msg = b }
1478 
1479 /* in qib_intr.c... */
1480 void qib_format_hwerrors(u64 hwerrs,
1481              const struct qib_hwerror_msgs *hwerrmsgs,
1482              size_t nhwerrmsgs, char *msg, size_t lmsg);
1483 
1484 void qib_stop_send_queue(struct rvt_qp *qp);
1485 void qib_quiesce_qp(struct rvt_qp *qp);
1486 void qib_flush_qp_waiters(struct rvt_qp *qp);
1487 int qib_mtu_to_path_mtu(u32 mtu);
1488 u32 qib_mtu_from_qp(struct rvt_dev_info *rdi, struct rvt_qp *qp, u32 pmtu);
1489 void qib_notify_error_qp(struct rvt_qp *qp);
1490 int qib_get_pmtu_from_attr(struct rvt_dev_info *rdi, struct rvt_qp *qp,
1491                struct ib_qp_attr *attr);
1492 
1493 #endif                          /* _QIB_KERNEL_H */