blob: 4a9af795b88f3bf5ba2fc8a8d44aaf637a318029 [file] [log] [blame]
Ralph Campbellf9315512010-05-23 21:44:54 -07001#ifndef _QIB_KERNEL_H
2#define _QIB_KERNEL_H
3/*
Mike Marciniszyn85caafe2013-06-04 15:05:37 -04004 * Copyright (c) 2012, 2013 Intel Corporation. All rights reserved.
Mike Marciniszyn551ace12012-07-19 13:03:56 +00005 * Copyright (c) 2006 - 2012 QLogic Corporation. All rights reserved.
Ralph Campbellf9315512010-05-23 21:44:54 -07006 * Copyright (c) 2003, 2004, 2005, 2006 PathScale, Inc. All rights reserved.
7 *
8 * This software is available to you under a choice of one of two
9 * licenses. You may choose to be licensed under the terms of the GNU
10 * General Public License (GPL) Version 2, available from the file
11 * COPYING in the main directory of this source tree, or the
12 * OpenIB.org BSD license below:
13 *
14 * Redistribution and use in source and binary forms, with or
15 * without modification, are permitted provided that the following
16 * conditions are met:
17 *
18 * - Redistributions of source code must retain the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer.
21 *
22 * - Redistributions in binary form must reproduce the above
23 * copyright notice, this list of conditions and the following
24 * disclaimer in the documentation and/or other materials
25 * provided with the distribution.
26 *
27 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
28 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
29 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
30 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
31 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
32 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
33 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
34 * SOFTWARE.
35 */
36
37/*
38 * This header file is the base header file for qlogic_ib kernel code
39 * qib_user.h serves a similar purpose for user code.
40 */
41
42#include <linux/interrupt.h>
43#include <linux/pci.h>
44#include <linux/dma-mapping.h>
45#include <linux/mutex.h>
46#include <linux/list.h>
47#include <linux/scatterlist.h>
David Millerba818af2010-08-05 05:55:52 +000048#include <linux/slab.h>
Ralph Campbellf9315512010-05-23 21:44:54 -070049#include <linux/io.h>
50#include <linux/fs.h>
51#include <linux/completion.h>
52#include <linux/kref.h>
53#include <linux/sched.h>
Mike Marciniszyn85caafe2013-06-04 15:05:37 -040054#include <linux/kthread.h>
Ralph Campbellf9315512010-05-23 21:44:54 -070055
56#include "qib_common.h"
57#include "qib_verbs.h"
58
59/* only s/w major version of QLogic_IB we can handle */
60#define QIB_CHIP_VERS_MAJ 2U
61
62/* don't care about this except printing */
63#define QIB_CHIP_VERS_MIN 0U
64
65/* The Organization Unique Identifier (Mfg code), and its position in GUID */
66#define QIB_OUI 0x001175
67#define QIB_OUI_LSB 40
68
69/*
70 * per driver stats, either not device nor port-specific, or
71 * summed over all of the devices and ports.
72 * They are described by name via ipathfs filesystem, so layout
73 * and number of elements can change without breaking compatibility.
74 * If members are added or deleted qib_statnames[] in qib_fs.c must
75 * change to match.
76 */
77struct qlogic_ib_stats {
78 __u64 sps_ints; /* number of interrupts handled */
79 __u64 sps_errints; /* number of error interrupts */
80 __u64 sps_txerrs; /* tx-related packet errors */
81 __u64 sps_rcverrs; /* non-crc rcv packet errors */
82 __u64 sps_hwerrs; /* hardware errors reported (parity, etc.) */
83 __u64 sps_nopiobufs; /* no pio bufs avail from kernel */
84 __u64 sps_ctxts; /* number of contexts currently open */
85 __u64 sps_lenerrs; /* number of kernel packets where RHF != LRH len */
86 __u64 sps_buffull;
87 __u64 sps_hdrfull;
88};
89
90extern struct qlogic_ib_stats qib_stats;
Stephen Hemminger1d352032012-09-07 09:33:17 -070091extern const struct pci_error_handlers qib_pci_err_handler;
Ralph Campbellf9315512010-05-23 21:44:54 -070092extern struct pci_driver qib_driver;
93
94#define QIB_CHIP_SWVERSION QIB_CHIP_VERS_MAJ
95/*
96 * First-cut critierion for "device is active" is
97 * two thousand dwords combined Tx, Rx traffic per
98 * 5-second interval. SMA packets are 64 dwords,
99 * and occur "a few per second", presumably each way.
100 */
101#define QIB_TRAFFIC_ACTIVE_THRESHOLD (2000)
102
103/*
104 * Struct used to indicate which errors are logged in each of the
105 * error-counters that are logged to EEPROM. A counter is incremented
106 * _once_ (saturating at 255) for each event with any bits set in
107 * the error or hwerror register masks below.
108 */
109#define QIB_EEP_LOG_CNT (4)
110struct qib_eep_log_mask {
111 u64 errs_to_log;
112 u64 hwerrs_to_log;
113};
114
115/*
116 * Below contains all data related to a single context (formerly called port).
117 */
Mike Marciniszynddb88762013-06-15 17:07:03 -0400118
119#ifdef CONFIG_DEBUG_FS
120struct qib_opcode_stats_perctx;
121#endif
122
Ralph Campbellf9315512010-05-23 21:44:54 -0700123struct qib_ctxtdata {
124 void **rcvegrbuf;
125 dma_addr_t *rcvegrbuf_phys;
126 /* rcvhdrq base, needs mmap before useful */
127 void *rcvhdrq;
128 /* kernel virtual address where hdrqtail is updated */
129 void *rcvhdrtail_kvaddr;
130 /*
131 * temp buffer for expected send setup, allocated at open, instead
132 * of each setup call
133 */
134 void *tid_pg_list;
135 /*
136 * Shared page for kernel to signal user processes that send buffers
137 * need disarming. The process should call QIB_CMD_DISARM_BUFS
138 * or QIB_CMD_ACK_EVENT with IPATH_EVENT_DISARM_BUFS set.
139 */
140 unsigned long *user_event_mask;
141 /* when waiting for rcv or pioavail */
142 wait_queue_head_t wait;
143 /*
144 * rcvegr bufs base, physical, must fit
145 * in 44 bits so 32 bit programs mmap64 44 bit works)
146 */
147 dma_addr_t rcvegr_phys;
148 /* mmap of hdrq, must fit in 44 bits */
149 dma_addr_t rcvhdrq_phys;
150 dma_addr_t rcvhdrqtailaddr_phys;
151
152 /*
153 * number of opens (including slave sub-contexts) on this instance
154 * (ignoring forks, dup, etc. for now)
155 */
156 int cnt;
157 /*
158 * how much space to leave at start of eager TID entries for
159 * protocol use, on each TID
160 */
161 /* instead of calculating it */
162 unsigned ctxt;
Ramkrishna Vepae0f30ba2013-05-28 12:57:33 -0400163 /* local node of context */
164 int node_id;
Ralph Campbellf9315512010-05-23 21:44:54 -0700165 /* non-zero if ctxt is being shared. */
166 u16 subctxt_cnt;
167 /* non-zero if ctxt is being shared. */
168 u16 subctxt_id;
169 /* number of eager TID entries. */
170 u16 rcvegrcnt;
171 /* index of first eager TID entry. */
172 u16 rcvegr_tid_base;
173 /* number of pio bufs for this ctxt (all procs, if shared) */
174 u32 piocnt;
175 /* first pio buffer for this ctxt */
176 u32 pio_base;
177 /* chip offset of PIO buffers for this ctxt */
178 u32 piobufs;
179 /* how many alloc_pages() chunks in rcvegrbuf_pages */
180 u32 rcvegrbuf_chunks;
181 /* how many egrbufs per chunk */
Mike Marciniszyn9e1c0e42011-09-23 13:16:39 -0400182 u16 rcvegrbufs_perchunk;
183 /* ilog2 of above */
184 u16 rcvegrbufs_perchunk_shift;
Ralph Campbellf9315512010-05-23 21:44:54 -0700185 /* order for rcvegrbuf_pages */
186 size_t rcvegrbuf_size;
187 /* rcvhdrq size (for freeing) */
188 size_t rcvhdrq_size;
189 /* per-context flags for fileops/intr communication */
190 unsigned long flag;
191 /* next expected TID to check when looking for free */
192 u32 tidcursor;
193 /* WAIT_RCV that timed out, no interrupt */
194 u32 rcvwait_to;
195 /* WAIT_PIO that timed out, no interrupt */
196 u32 piowait_to;
197 /* WAIT_RCV already happened, no wait */
198 u32 rcvnowait;
199 /* WAIT_PIO already happened, no wait */
200 u32 pionowait;
201 /* total number of polled urgent packets */
202 u32 urgent;
203 /* saved total number of polled urgent packets for poll edge trigger */
204 u32 urgent_poll;
205 /* pid of process using this ctxt */
206 pid_t pid;
207 pid_t subpid[QLOGIC_IB_MAX_SUBCTXT];
208 /* same size as task_struct .comm[], command that opened context */
209 char comm[16];
210 /* pkeys set by this use of this ctxt */
211 u16 pkeys[4];
212 /* so file ops can get at unit */
213 struct qib_devdata *dd;
214 /* so funcs that need physical port can get it easily */
215 struct qib_pportdata *ppd;
216 /* A page of memory for rcvhdrhead, rcvegrhead, rcvegrtail * N */
217 void *subctxt_uregbase;
218 /* An array of pages for the eager receive buffers * N */
219 void *subctxt_rcvegrbuf;
220 /* An array of pages for the eager header queue entries * N */
221 void *subctxt_rcvhdr_base;
222 /* The version of the library which opened this ctxt */
223 u32 userversion;
224 /* Bitmask of active slaves */
225 u32 active_slaves;
226 /* Type of packets or conditions we want to poll for */
227 u16 poll_type;
228 /* receive packet sequence counter */
229 u8 seq_cnt;
230 u8 redirect_seq_cnt;
231 /* ctxt rcvhdrq head offset */
232 u32 head;
Mike Marciniszynaf061a62011-09-23 13:16:44 -0400233 /* lookaside fields */
234 struct qib_qp *lookaside_qp;
235 u32 lookaside_qpn;
Ralph Campbellf9315512010-05-23 21:44:54 -0700236 /* QPs waiting for context processing */
237 struct list_head qp_wait_list;
Mike Marciniszynddb88762013-06-15 17:07:03 -0400238#ifdef CONFIG_DEBUG_FS
239 /* verbs stats per CTX */
240 struct qib_opcode_stats_perctx *opstats;
241#endif
Ralph Campbellf9315512010-05-23 21:44:54 -0700242};
243
244struct qib_sge_state;
245
246struct qib_sdma_txreq {
247 int flags;
248 int sg_count;
249 dma_addr_t addr;
250 void (*callback)(struct qib_sdma_txreq *, int);
251 u16 start_idx; /* sdma private */
252 u16 next_descq_idx; /* sdma private */
253 struct list_head list; /* sdma private */
254};
255
256struct qib_sdma_desc {
257 __le64 qw[2];
258};
259
260struct qib_verbs_txreq {
261 struct qib_sdma_txreq txreq;
262 struct qib_qp *qp;
263 struct qib_swqe *wqe;
264 u32 dwords;
265 u16 hdr_dwords;
266 u16 hdr_inx;
267 struct qib_pio_header *align_buf;
268 struct qib_mregion *mr;
269 struct qib_sge_state *ss;
270};
271
272#define QIB_SDMA_TXREQ_F_USELARGEBUF 0x1
273#define QIB_SDMA_TXREQ_F_HEADTOHOST 0x2
274#define QIB_SDMA_TXREQ_F_INTREQ 0x4
275#define QIB_SDMA_TXREQ_F_FREEBUF 0x8
276#define QIB_SDMA_TXREQ_F_FREEDESC 0x10
277
278#define QIB_SDMA_TXREQ_S_OK 0
279#define QIB_SDMA_TXREQ_S_SENDERROR 1
280#define QIB_SDMA_TXREQ_S_ABORTED 2
281#define QIB_SDMA_TXREQ_S_SHUTDOWN 3
282
283/*
284 * Get/Set IB link-level config parameters for f_get/set_ib_cfg()
285 * Mostly for MADs that set or query link parameters, also ipath
286 * config interfaces
287 */
288#define QIB_IB_CFG_LIDLMC 0 /* LID (LS16b) and Mask (MS16b) */
289#define QIB_IB_CFG_LWID_ENB 2 /* allowed Link-width */
290#define QIB_IB_CFG_LWID 3 /* currently active Link-width */
291#define QIB_IB_CFG_SPD_ENB 4 /* allowed Link speeds */
292#define QIB_IB_CFG_SPD 5 /* current Link spd */
293#define QIB_IB_CFG_RXPOL_ENB 6 /* Auto-RX-polarity enable */
294#define QIB_IB_CFG_LREV_ENB 7 /* Auto-Lane-reversal enable */
295#define QIB_IB_CFG_LINKLATENCY 8 /* Link Latency (IB1.2 only) */
296#define QIB_IB_CFG_HRTBT 9 /* IB heartbeat off/enable/auto; DDR/QDR only */
297#define QIB_IB_CFG_OP_VLS 10 /* operational VLs */
298#define QIB_IB_CFG_VL_HIGH_CAP 11 /* num of VL high priority weights */
299#define QIB_IB_CFG_VL_LOW_CAP 12 /* num of VL low priority weights */
300#define QIB_IB_CFG_OVERRUN_THRESH 13 /* IB overrun threshold */
301#define QIB_IB_CFG_PHYERR_THRESH 14 /* IB PHY error threshold */
302#define QIB_IB_CFG_LINKDEFAULT 15 /* IB link default (sleep/poll) */
303#define QIB_IB_CFG_PKEYS 16 /* update partition keys */
304#define QIB_IB_CFG_MTU 17 /* update MTU in IBC */
305#define QIB_IB_CFG_LSTATE 18 /* update linkcmd and linkinitcmd in IBC */
306#define QIB_IB_CFG_VL_HIGH_LIMIT 19
307#define QIB_IB_CFG_PMA_TICKS 20 /* PMA sample tick resolution */
308#define QIB_IB_CFG_PORT 21 /* switch port we are connected to */
309
310/*
311 * for CFG_LSTATE: LINKCMD in upper 16 bits, LINKINITCMD in lower 16
312 * IB_LINKINITCMD_POLL and SLEEP are also used as set/get values for
313 * QIB_IB_CFG_LINKDEFAULT cmd
314 */
315#define IB_LINKCMD_DOWN (0 << 16)
316#define IB_LINKCMD_ARMED (1 << 16)
317#define IB_LINKCMD_ACTIVE (2 << 16)
318#define IB_LINKINITCMD_NOP 0
319#define IB_LINKINITCMD_POLL 1
320#define IB_LINKINITCMD_SLEEP 2
321#define IB_LINKINITCMD_DISABLE 3
322
323/*
324 * valid states passed to qib_set_linkstate() user call
325 */
326#define QIB_IB_LINKDOWN 0
327#define QIB_IB_LINKARM 1
328#define QIB_IB_LINKACTIVE 2
329#define QIB_IB_LINKDOWN_ONLY 3
330#define QIB_IB_LINKDOWN_SLEEP 4
331#define QIB_IB_LINKDOWN_DISABLE 5
332
333/*
334 * These 7 values (SDR, DDR, and QDR may be ORed for auto-speed
335 * negotiation) are used for the 3rd argument to path_f_set_ib_cfg
336 * with cmd QIB_IB_CFG_SPD_ENB, by direct calls or via sysfs. They
337 * are also the the possible values for qib_link_speed_enabled and active
338 * The values were chosen to match values used within the IB spec.
339 */
340#define QIB_IB_SDR 1
341#define QIB_IB_DDR 2
342#define QIB_IB_QDR 4
343
344#define QIB_DEFAULT_MTU 4096
345
Ralph Campbellcc323b22010-06-03 00:21:07 +0000346/* max number of IB ports supported per HCA */
347#define QIB_MAX_IB_PORTS 2
348
Ralph Campbellf9315512010-05-23 21:44:54 -0700349/*
350 * Possible IB config parameters for f_get/set_ib_table()
351 */
352#define QIB_IB_TBL_VL_HIGH_ARB 1 /* Get/set VL high priority weights */
353#define QIB_IB_TBL_VL_LOW_ARB 2 /* Get/set VL low priority weights */
354
355/*
356 * Possible "operations" for f_rcvctrl(ppd, op, ctxt)
357 * these are bits so they can be combined, e.g.
358 * QIB_RCVCTRL_INTRAVAIL_ENB | QIB_RCVCTRL_CTXT_ENB
359 */
360#define QIB_RCVCTRL_TAILUPD_ENB 0x01
361#define QIB_RCVCTRL_TAILUPD_DIS 0x02
362#define QIB_RCVCTRL_CTXT_ENB 0x04
363#define QIB_RCVCTRL_CTXT_DIS 0x08
364#define QIB_RCVCTRL_INTRAVAIL_ENB 0x10
365#define QIB_RCVCTRL_INTRAVAIL_DIS 0x20
366#define QIB_RCVCTRL_PKEY_ENB 0x40 /* Note, default is enabled */
367#define QIB_RCVCTRL_PKEY_DIS 0x80
368#define QIB_RCVCTRL_BP_ENB 0x0100
369#define QIB_RCVCTRL_BP_DIS 0x0200
370#define QIB_RCVCTRL_TIDFLOW_ENB 0x0400
371#define QIB_RCVCTRL_TIDFLOW_DIS 0x0800
372
373/*
374 * Possible "operations" for f_sendctrl(ppd, op, var)
375 * these are bits so they can be combined, e.g.
376 * QIB_SENDCTRL_BUFAVAIL_ENB | QIB_SENDCTRL_ENB
377 * Some operations (e.g. DISARM, ABORT) are known to
378 * be "one-shot", so do not modify shadow.
379 */
380#define QIB_SENDCTRL_DISARM (0x1000)
381#define QIB_SENDCTRL_DISARM_BUF(bufn) ((bufn) | QIB_SENDCTRL_DISARM)
382 /* available (0x2000) */
383#define QIB_SENDCTRL_AVAIL_DIS (0x4000)
384#define QIB_SENDCTRL_AVAIL_ENB (0x8000)
385#define QIB_SENDCTRL_AVAIL_BLIP (0x10000)
386#define QIB_SENDCTRL_SEND_DIS (0x20000)
387#define QIB_SENDCTRL_SEND_ENB (0x40000)
388#define QIB_SENDCTRL_FLUSH (0x80000)
389#define QIB_SENDCTRL_CLEAR (0x100000)
390#define QIB_SENDCTRL_DISARM_ALL (0x200000)
391
392/*
393 * These are the generic indices for requesting per-port
394 * counter values via the f_portcntr function. They
395 * are always returned as 64 bit values, although most
396 * are 32 bit counters.
397 */
398/* send-related counters */
399#define QIBPORTCNTR_PKTSEND 0U
400#define QIBPORTCNTR_WORDSEND 1U
401#define QIBPORTCNTR_PSXMITDATA 2U
402#define QIBPORTCNTR_PSXMITPKTS 3U
403#define QIBPORTCNTR_PSXMITWAIT 4U
404#define QIBPORTCNTR_SENDSTALL 5U
405/* receive-related counters */
406#define QIBPORTCNTR_PKTRCV 6U
407#define QIBPORTCNTR_PSRCVDATA 7U
408#define QIBPORTCNTR_PSRCVPKTS 8U
409#define QIBPORTCNTR_RCVEBP 9U
410#define QIBPORTCNTR_RCVOVFL 10U
411#define QIBPORTCNTR_WORDRCV 11U
412/* IB link related error counters */
413#define QIBPORTCNTR_RXLOCALPHYERR 12U
414#define QIBPORTCNTR_RXVLERR 13U
415#define QIBPORTCNTR_ERRICRC 14U
416#define QIBPORTCNTR_ERRVCRC 15U
417#define QIBPORTCNTR_ERRLPCRC 16U
418#define QIBPORTCNTR_BADFORMAT 17U
419#define QIBPORTCNTR_ERR_RLEN 18U
420#define QIBPORTCNTR_IBSYMBOLERR 19U
421#define QIBPORTCNTR_INVALIDRLEN 20U
422#define QIBPORTCNTR_UNSUPVL 21U
423#define QIBPORTCNTR_EXCESSBUFOVFL 22U
424#define QIBPORTCNTR_ERRLINK 23U
425#define QIBPORTCNTR_IBLINKDOWN 24U
426#define QIBPORTCNTR_IBLINKERRRECOV 25U
427#define QIBPORTCNTR_LLI 26U
428/* other error counters */
429#define QIBPORTCNTR_RXDROPPKT 27U
430#define QIBPORTCNTR_VL15PKTDROP 28U
431#define QIBPORTCNTR_ERRPKEY 29U
432#define QIBPORTCNTR_KHDROVFL 30U
433/* sampling counters (these are actually control registers) */
434#define QIBPORTCNTR_PSINTERVAL 31U
435#define QIBPORTCNTR_PSSTART 32U
436#define QIBPORTCNTR_PSSTAT 33U
437
438/* how often we check for packet activity for "power on hours (in seconds) */
439#define ACTIVITY_TIMER 5
440
Mike Marciniszyna778f3f2012-02-25 17:45:49 -0800441#define MAX_NAME_SIZE 64
Mike Marciniszyn8469ba32013-05-30 18:25:25 -0400442
443#ifdef CONFIG_INFINIBAND_QIB_DCA
444struct qib_irq_notify;
445#endif
446
Mike Marciniszyna778f3f2012-02-25 17:45:49 -0800447struct qib_msix_entry {
448 struct msix_entry msix;
449 void *arg;
Mike Marciniszyn8469ba32013-05-30 18:25:25 -0400450#ifdef CONFIG_INFINIBAND_QIB_DCA
451 int dca;
452 int rcv;
453 struct qib_irq_notify *notifier;
454#endif
Mike Marciniszyna778f3f2012-02-25 17:45:49 -0800455 char name[MAX_NAME_SIZE];
456 cpumask_var_t mask;
457};
458
Ralph Campbellf9315512010-05-23 21:44:54 -0700459/* Below is an opaque struct. Each chip (device) can maintain
460 * private data needed for its operation, but not germane to the
461 * rest of the driver. For convenience, we define another that
462 * is chip-specific, per-port
463 */
464struct qib_chip_specific;
465struct qib_chipport_specific;
466
467enum qib_sdma_states {
468 qib_sdma_state_s00_hw_down,
469 qib_sdma_state_s10_hw_start_up_wait,
470 qib_sdma_state_s20_idle,
471 qib_sdma_state_s30_sw_clean_up_wait,
472 qib_sdma_state_s40_hw_clean_up_wait,
473 qib_sdma_state_s50_hw_halt_wait,
474 qib_sdma_state_s99_running,
475};
476
477enum qib_sdma_events {
478 qib_sdma_event_e00_go_hw_down,
479 qib_sdma_event_e10_go_hw_start,
480 qib_sdma_event_e20_hw_started,
481 qib_sdma_event_e30_go_running,
482 qib_sdma_event_e40_sw_cleaned,
483 qib_sdma_event_e50_hw_cleaned,
484 qib_sdma_event_e60_hw_halted,
485 qib_sdma_event_e70_go_idle,
486 qib_sdma_event_e7220_err_halted,
487 qib_sdma_event_e7322_err_halted,
488 qib_sdma_event_e90_timer_tick,
489};
490
491extern char *qib_sdma_state_names[];
492extern char *qib_sdma_event_names[];
493
494struct sdma_set_state_action {
495 unsigned op_enable:1;
496 unsigned op_intenable:1;
497 unsigned op_halt:1;
498 unsigned op_drain:1;
499 unsigned go_s99_running_tofalse:1;
500 unsigned go_s99_running_totrue:1;
501};
502
503struct qib_sdma_state {
504 struct kref kref;
505 struct completion comp;
506 enum qib_sdma_states current_state;
507 struct sdma_set_state_action *set_state_action;
508 unsigned current_op;
509 unsigned go_s99_running;
510 unsigned first_sendbuf;
511 unsigned last_sendbuf; /* really last +1 */
512 /* debugging/devel */
513 enum qib_sdma_states previous_state;
514 unsigned previous_op;
515 enum qib_sdma_events last_event;
516};
517
518struct xmit_wait {
519 struct timer_list timer;
520 u64 counter;
521 u8 flags;
522 struct cache {
523 u64 psxmitdata;
524 u64 psrcvdata;
525 u64 psxmitpkts;
526 u64 psrcvpkts;
527 u64 psxmitwait;
528 } counter_cache;
529};
530
531/*
532 * The structure below encapsulates data relevant to a physical IB Port.
533 * Current chips support only one such port, but the separation
534 * clarifies things a bit. Note that to conform to IB conventions,
535 * port-numbers are one-based. The first or only port is port1.
536 */
537struct qib_pportdata {
538 struct qib_ibport ibport_data;
539
540 struct qib_devdata *dd;
541 struct qib_chippport_specific *cpspec; /* chip-specific per-port */
542 struct kobject pport_kobj;
Mike Marciniszyn36a8f012012-07-19 13:04:04 +0000543 struct kobject pport_cc_kobj;
Ralph Campbellf9315512010-05-23 21:44:54 -0700544 struct kobject sl2vl_kobj;
545 struct kobject diagc_kobj;
546
547 /* GUID for this interface, in network order */
548 __be64 guid;
549
550 /* QIB_POLL, etc. link-state specific flags, per port */
551 u32 lflags;
552 /* qib_lflags driver is waiting for */
553 u32 state_wanted;
554 spinlock_t lflags_lock;
Ralph Campbellf9315512010-05-23 21:44:54 -0700555
556 /* ref count for each pkey */
557 atomic_t pkeyrefs[4];
558
559 /*
560 * this address is mapped readonly into user processes so they can
561 * get status cheaply, whenever they want. One qword of status per port
562 */
563 u64 *statusp;
564
565 /* SendDMA related entries */
Ralph Campbellf9315512010-05-23 21:44:54 -0700566
Mike Marciniszyn1c942832012-05-07 14:02:31 -0400567 /* read mostly */
568 struct qib_sdma_desc *sdma_descq;
Mike Marciniszyn551ace12012-07-19 13:03:56 +0000569 struct workqueue_struct *qib_wq;
Mike Marciniszyn1c942832012-05-07 14:02:31 -0400570 struct qib_sdma_state sdma_state;
Ralph Campbellf9315512010-05-23 21:44:54 -0700571 dma_addr_t sdma_descq_phys;
572 volatile __le64 *sdma_head_dma; /* DMA'ed by chip */
573 dma_addr_t sdma_head_phys;
Mike Marciniszyn1c942832012-05-07 14:02:31 -0400574 u16 sdma_descq_cnt;
575
576 /* read/write using lock */
577 spinlock_t sdma_lock ____cacheline_aligned_in_smp;
578 struct list_head sdma_activelist;
579 u64 sdma_descq_added;
580 u64 sdma_descq_removed;
581 u16 sdma_descq_tail;
582 u16 sdma_descq_head;
583 u8 sdma_generation;
584
585 struct tasklet_struct sdma_sw_clean_up_task
586 ____cacheline_aligned_in_smp;
Ralph Campbellf9315512010-05-23 21:44:54 -0700587
588 wait_queue_head_t state_wait; /* for state_wanted */
589
590 /* HoL blocking for SMP replies */
591 unsigned hol_state;
592 struct timer_list hol_timer;
593
594 /*
595 * Shadow copies of registers; size indicates read access size.
596 * Most of them are readonly, but some are write-only register,
597 * where we manipulate the bits in the shadow copy, and then write
598 * the shadow copy to qlogic_ib.
599 *
600 * We deliberately make most of these 32 bits, since they have
601 * restricted range. For any that we read, we won't to generate 32
602 * bit accesses, since Opteron will generate 2 separate 32 bit HT
603 * transactions for a 64 bit read, and we want to avoid unnecessary
604 * bus transactions.
605 */
606
607 /* This is the 64 bit group */
608 /* last ibcstatus. opaque outside chip-specific code */
609 u64 lastibcstat;
610
611 /* these are the "32 bit" regs */
612
613 /*
614 * the following two are 32-bit bitmasks, but {test,clear,set}_bit
615 * all expect bit fields to be "unsigned long"
616 */
617 unsigned long p_rcvctrl; /* shadow per-port rcvctrl */
618 unsigned long p_sendctrl; /* shadow per-port sendctrl */
619
620 u32 ibmtu; /* The MTU programmed for this unit */
621 /*
622 * Current max size IB packet (in bytes) including IB headers, that
623 * we can send. Changes when ibmtu changes.
624 */
625 u32 ibmaxlen;
626 /*
627 * ibmaxlen at init time, limited by chip and by receive buffer
628 * size. Not changed after init.
629 */
630 u32 init_ibmaxlen;
631 /* LID programmed for this instance */
632 u16 lid;
633 /* list of pkeys programmed; 0 if not set */
634 u16 pkeys[4];
635 /* LID mask control */
636 u8 lmc;
637 u8 link_width_supported;
638 u8 link_speed_supported;
639 u8 link_width_enabled;
640 u8 link_speed_enabled;
641 u8 link_width_active;
642 u8 link_speed_active;
643 u8 vls_supported;
644 u8 vls_operational;
645 /* Rx Polarity inversion (compensate for ~tx on partner) */
646 u8 rx_pol_inv;
647
648 u8 hw_pidx; /* physical port index */
649 u8 port; /* IB port number and index into dd->pports - 1 */
650
651 u8 delay_mult;
652
653 /* used to override LED behavior */
654 u8 led_override; /* Substituted for normal value, if non-zero */
655 u16 led_override_timeoff; /* delta to next timer event */
656 u8 led_override_vals[2]; /* Alternates per blink-frame */
657 u8 led_override_phase; /* Just counts, LSB picks from vals[] */
658 atomic_t led_override_timer_active;
659 /* Used to flash LEDs in override mode */
660 struct timer_list led_override_timer;
661 struct xmit_wait cong_stats;
662 struct timer_list symerr_clear_timer;
Mike Marciniszyn36a8f012012-07-19 13:04:04 +0000663
664 /* Synchronize access between driver writes and sysfs reads */
665 spinlock_t cc_shadow_lock
666 ____cacheline_aligned_in_smp;
667
668 /* Shadow copy of the congestion control table */
669 struct cc_table_shadow *ccti_entries_shadow;
670
671 /* Shadow copy of the congestion control entries */
672 struct ib_cc_congestion_setting_attr_shadow *congestion_entries_shadow;
673
674 /* List of congestion control table entries */
675 struct ib_cc_table_entry_shadow *ccti_entries;
676
677 /* 16 congestion entries with each entry corresponding to a SL */
678 struct ib_cc_congestion_entry_shadow *congestion_entries;
679
Mike Marciniszyn5d7fe4e2012-07-23 16:38:15 +0000680 /* Maximum number of congestion control entries that the agent expects
681 * the manager to send.
682 */
683 u16 cc_supported_table_entries;
684
Mike Marciniszyn36a8f012012-07-19 13:04:04 +0000685 /* Total number of congestion control table entries */
686 u16 total_cct_entry;
687
688 /* Bit map identifying service level */
689 u16 cc_sl_control_map;
690
691 /* maximum congestion control table index */
692 u16 ccti_limit;
693
694 /* CA's max number of 64 entry units in the congestion control table */
695 u8 cc_max_table_entries;
Ralph Campbellf9315512010-05-23 21:44:54 -0700696};
697
698/* Observers. Not to be taken lightly, possibly not to ship. */
699/*
700 * If a diag read or write is to (bottom <= offset <= top),
701 * the "hoook" is called, allowing, e.g. shadows to be
702 * updated in sync with the driver. struct diag_observer
703 * is the "visible" part.
704 */
705struct diag_observer;
706
707typedef int (*diag_hook) (struct qib_devdata *dd,
708 const struct diag_observer *op,
709 u32 offs, u64 *data, u64 mask, int only_32);
710
711struct diag_observer {
712 diag_hook hook;
713 u32 bottom;
714 u32 top;
715};
716
717extern int qib_register_observer(struct qib_devdata *dd,
718 const struct diag_observer *op);
719
720/* Only declared here, not defined. Private to diags */
721struct diag_observer_list_elt;
722
723/* device data struct now contains only "general per-device" info.
724 * fields related to a physical IB port are in a qib_pportdata struct,
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300725 * described above) while fields only used by a particular chip-type are in
Ralph Campbellf9315512010-05-23 21:44:54 -0700726 * a qib_chipdata struct, whose contents are opaque to this file.
727 */
728struct qib_devdata {
729 struct qib_ibdev verbs_dev; /* must be first */
730 struct list_head list;
731 /* pointers to related structs for this device */
732 /* pci access data structure */
733 struct pci_dev *pcidev;
734 struct cdev *user_cdev;
735 struct cdev *diag_cdev;
736 struct device *user_device;
737 struct device *diag_device;
738
739 /* mem-mapped pointer to base of chip regs */
740 u64 __iomem *kregbase;
741 /* end of mem-mapped chip space excluding sendbuf and user regs */
742 u64 __iomem *kregend;
743 /* physical address of chip for io_remap, etc. */
744 resource_size_t physaddr;
745 /* qib_cfgctxts pointers */
746 struct qib_ctxtdata **rcd; /* Receive Context Data */
747
748 /* qib_pportdata, points to array of (physical) port-specific
749 * data structs, indexed by pidx (0..n-1)
750 */
751 struct qib_pportdata *pport;
752 struct qib_chip_specific *cspec; /* chip-specific */
753
754 /* kvirt address of 1st 2k pio buffer */
755 void __iomem *pio2kbase;
756 /* kvirt address of 1st 4k pio buffer */
757 void __iomem *pio4kbase;
758 /* mem-mapped pointer to base of PIO buffers (if using WC PAT) */
759 void __iomem *piobase;
760 /* mem-mapped pointer to base of user chip regs (if using WC PAT) */
761 u64 __iomem *userbase;
Dave Olsonfce24a92010-06-17 23:13:44 +0000762 void __iomem *piovl15base; /* base of VL15 buffers, if not WC */
Ralph Campbellf9315512010-05-23 21:44:54 -0700763 /*
764 * points to area where PIOavail registers will be DMA'ed.
765 * Has to be on a page of it's own, because the page will be
766 * mapped into user program space. This copy is *ONLY* ever
767 * written by DMA, not by the driver! Need a copy per device
768 * when we get to multiple devices
769 */
770 volatile __le64 *pioavailregs_dma; /* DMA'ed by chip */
771 /* physical address where updates occur */
772 dma_addr_t pioavailregs_phys;
773
774 /* device-specific implementations of functions needed by
775 * common code. Contrary to previous consensus, we can't
776 * really just point to a device-specific table, because we
777 * may need to "bend", e.g. *_f_put_tid
778 */
779 /* fallback to alternate interrupt type if possible */
780 int (*f_intr_fallback)(struct qib_devdata *);
781 /* hard reset chip */
782 int (*f_reset)(struct qib_devdata *);
783 void (*f_quiet_serdes)(struct qib_pportdata *);
784 int (*f_bringup_serdes)(struct qib_pportdata *);
785 int (*f_early_init)(struct qib_devdata *);
786 void (*f_clear_tids)(struct qib_devdata *, struct qib_ctxtdata *);
787 void (*f_put_tid)(struct qib_devdata *, u64 __iomem*,
788 u32, unsigned long);
789 void (*f_cleanup)(struct qib_devdata *);
790 void (*f_setextled)(struct qib_pportdata *, u32);
791 /* fill out chip-specific fields */
792 int (*f_get_base_info)(struct qib_ctxtdata *, struct qib_base_info *);
793 /* free irq */
794 void (*f_free_irq)(struct qib_devdata *);
795 struct qib_message_header *(*f_get_msgheader)
796 (struct qib_devdata *, __le32 *);
797 void (*f_config_ctxts)(struct qib_devdata *);
798 int (*f_get_ib_cfg)(struct qib_pportdata *, int);
799 int (*f_set_ib_cfg)(struct qib_pportdata *, int, u32);
800 int (*f_set_ib_loopback)(struct qib_pportdata *, const char *);
801 int (*f_get_ib_table)(struct qib_pportdata *, int, void *);
802 int (*f_set_ib_table)(struct qib_pportdata *, int, void *);
803 u32 (*f_iblink_state)(u64);
804 u8 (*f_ibphys_portstate)(u64);
805 void (*f_xgxs_reset)(struct qib_pportdata *);
806 /* per chip actions needed for IB Link up/down changes */
807 int (*f_ib_updown)(struct qib_pportdata *, int, u64);
808 u32 __iomem *(*f_getsendbuf)(struct qib_pportdata *, u64, u32 *);
809 /* Read/modify/write of GPIO pins (potentially chip-specific */
810 int (*f_gpio_mod)(struct qib_devdata *dd, u32 out, u32 dir,
811 u32 mask);
812 /* Enable writes to config EEPROM (if supported) */
813 int (*f_eeprom_wen)(struct qib_devdata *dd, int wen);
814 /*
815 * modify rcvctrl shadow[s] and write to appropriate chip-regs.
816 * see above QIB_RCVCTRL_xxx_ENB/DIS for operations.
817 * (ctxt == -1) means "all contexts", only meaningful for
818 * clearing. Could remove if chip_spec shutdown properly done.
819 */
820 void (*f_rcvctrl)(struct qib_pportdata *, unsigned int op,
821 int ctxt);
822 /* Read/modify/write sendctrl appropriately for op and port. */
823 void (*f_sendctrl)(struct qib_pportdata *, u32 op);
824 void (*f_set_intr_state)(struct qib_devdata *, u32);
825 void (*f_set_armlaunch)(struct qib_devdata *, u32);
826 void (*f_wantpiobuf_intr)(struct qib_devdata *, u32);
827 int (*f_late_initreg)(struct qib_devdata *);
828 int (*f_init_sdma_regs)(struct qib_pportdata *);
829 u16 (*f_sdma_gethead)(struct qib_pportdata *);
830 int (*f_sdma_busy)(struct qib_pportdata *);
831 void (*f_sdma_update_tail)(struct qib_pportdata *, u16);
832 void (*f_sdma_set_desc_cnt)(struct qib_pportdata *, unsigned);
833 void (*f_sdma_sendctrl)(struct qib_pportdata *, unsigned);
834 void (*f_sdma_hw_clean_up)(struct qib_pportdata *);
835 void (*f_sdma_hw_start_up)(struct qib_pportdata *);
836 void (*f_sdma_init_early)(struct qib_pportdata *);
837 void (*f_set_cntr_sample)(struct qib_pportdata *, u32, u32);
Mike Marciniszyn19ede2e2011-01-10 17:42:21 -0800838 void (*f_update_usrhead)(struct qib_ctxtdata *, u64, u32, u32, u32);
Ralph Campbellf9315512010-05-23 21:44:54 -0700839 u32 (*f_hdrqempty)(struct qib_ctxtdata *);
840 u64 (*f_portcntr)(struct qib_pportdata *, u32);
841 u32 (*f_read_cntrs)(struct qib_devdata *, loff_t, char **,
842 u64 **);
843 u32 (*f_read_portcntrs)(struct qib_devdata *, loff_t, u32,
844 char **, u64 **);
845 u32 (*f_setpbc_control)(struct qib_pportdata *, u32, u8, u8);
846 void (*f_initvl15_bufs)(struct qib_devdata *);
847 void (*f_init_ctxt)(struct qib_ctxtdata *);
848 void (*f_txchk_change)(struct qib_devdata *, u32, u32, u32,
849 struct qib_ctxtdata *);
850 void (*f_writescratch)(struct qib_devdata *, u32);
851 int (*f_tempsense_rd)(struct qib_devdata *, int regnum);
Mike Marciniszyn8469ba32013-05-30 18:25:25 -0400852#ifdef CONFIG_INFINIBAND_QIB_DCA
853 int (*f_notify_dca)(struct qib_devdata *, unsigned long event);
854#endif
Ralph Campbellf9315512010-05-23 21:44:54 -0700855
856 char *boardname; /* human readable board info */
857
858 /* template for writing TIDs */
859 u64 tidtemplate;
860 /* value to write to free TIDs */
861 u64 tidinvalid;
862
863 /* number of registers used for pioavail */
864 u32 pioavregs;
865 /* device (not port) flags, basically device capabilities */
866 u32 flags;
867 /* last buffer for user use */
868 u32 lastctxt_piobuf;
869
870 /* saturating counter of (non-port-specific) device interrupts */
871 u32 int_counter;
872
873 /* pio bufs allocated per ctxt */
874 u32 pbufsctxt;
875 /* if remainder on bufs/ctxt, ctxts < extrabuf get 1 extra */
876 u32 ctxts_extrabuf;
877 /*
878 * number of ctxts configured as max; zero is set to number chip
879 * supports, less gives more pio bufs/ctxt, etc.
880 */
881 u32 cfgctxts;
Mike Marciniszyn53ab1c62011-10-06 09:33:35 -0700882 /*
883 * number of ctxts available for PSM open
884 */
885 u32 freectxts;
Ralph Campbellf9315512010-05-23 21:44:54 -0700886
887 /*
888 * hint that we should update pioavailshadow before
889 * looking for a PIO buffer
890 */
891 u32 upd_pio_shadow;
892
893 /* internal debugging stats */
894 u32 maxpkts_call;
895 u32 avgpkts_call;
896 u64 nopiobufs;
897
898 /* PCI Vendor ID (here for NodeInfo) */
899 u16 vendorid;
900 /* PCI Device ID (here for NodeInfo) */
901 u16 deviceid;
902 /* for write combining settings */
903 unsigned long wc_cookie;
904 unsigned long wc_base;
905 unsigned long wc_len;
906
907 /* shadow copy of struct page *'s for exp tid pages */
908 struct page **pageshadow;
909 /* shadow copy of dma handles for exp tid pages */
910 dma_addr_t *physshadow;
911 u64 __iomem *egrtidbase;
912 spinlock_t sendctrl_lock; /* protect changes to sendctrl shadow */
913 /* around rcd and (user ctxts) ctxt_cnt use (intr vs free) */
914 spinlock_t uctxt_lock; /* rcd and user context changes */
915 /*
916 * per unit status, see also portdata statusp
917 * mapped readonly into user processes so they can get unit and
918 * IB link status cheaply
919 */
920 u64 *devstatusp;
921 char *freezemsg; /* freeze msg if hw error put chip in freeze */
922 u32 freezelen; /* max length of freezemsg */
923 /* timer used to prevent stats overflow, error throttling, etc. */
924 struct timer_list stats_timer;
925
926 /* timer to verify interrupts work, and fallback if possible */
927 struct timer_list intrchk_timer;
928 unsigned long ureg_align; /* user register alignment */
929
930 /*
931 * Protects pioavailshadow, pioavailkernel, pio_need_disarm, and
932 * pio_writing.
933 */
934 spinlock_t pioavail_lock;
Mike Marciniszynbb77a072012-05-07 14:02:42 -0400935 /*
936 * index of last buffer to optimize search for next
937 */
938 u32 last_pio;
939 /*
940 * min kernel pio buffer to optimize search
941 */
942 u32 min_kernel_pio;
Ralph Campbellf9315512010-05-23 21:44:54 -0700943 /*
944 * Shadow copies of registers; size indicates read access size.
945 * Most of them are readonly, but some are write-only register,
946 * where we manipulate the bits in the shadow copy, and then write
947 * the shadow copy to qlogic_ib.
948 *
949 * We deliberately make most of these 32 bits, since they have
950 * restricted range. For any that we read, we won't to generate 32
951 * bit accesses, since Opteron will generate 2 separate 32 bit HT
952 * transactions for a 64 bit read, and we want to avoid unnecessary
953 * bus transactions.
954 */
955
956 /* This is the 64 bit group */
957
958 unsigned long pioavailshadow[6];
959 /* bitmap of send buffers available for the kernel to use with PIO. */
960 unsigned long pioavailkernel[6];
961 /* bitmap of send buffers which need to be disarmed. */
962 unsigned long pio_need_disarm[3];
963 /* bitmap of send buffers which are being written to. */
964 unsigned long pio_writing[3];
965 /* kr_revision shadow */
966 u64 revision;
967 /* Base GUID for device (from eeprom, network order) */
968 __be64 base_guid;
969
970 /*
971 * kr_sendpiobufbase value (chip offset of pio buffers), and the
972 * base of the 2KB buffer s(user processes only use 2K)
973 */
974 u64 piobufbase;
975 u32 pio2k_bufbase;
976
977 /* these are the "32 bit" regs */
978
979 /* number of GUIDs in the flash for this interface */
980 u32 nguid;
981 /*
982 * the following two are 32-bit bitmasks, but {test,clear,set}_bit
983 * all expect bit fields to be "unsigned long"
984 */
985 unsigned long rcvctrl; /* shadow per device rcvctrl */
986 unsigned long sendctrl; /* shadow per device sendctrl */
987
988 /* value we put in kr_rcvhdrcnt */
989 u32 rcvhdrcnt;
990 /* value we put in kr_rcvhdrsize */
991 u32 rcvhdrsize;
992 /* value we put in kr_rcvhdrentsize */
993 u32 rcvhdrentsize;
994 /* kr_ctxtcnt value */
995 u32 ctxtcnt;
996 /* kr_pagealign value */
997 u32 palign;
998 /* number of "2KB" PIO buffers */
999 u32 piobcnt2k;
1000 /* size in bytes of "2KB" PIO buffers */
1001 u32 piosize2k;
1002 /* max usable size in dwords of a "2KB" PIO buffer before going "4KB" */
1003 u32 piosize2kmax_dwords;
1004 /* number of "4KB" PIO buffers */
1005 u32 piobcnt4k;
1006 /* size in bytes of "4KB" PIO buffers */
1007 u32 piosize4k;
1008 /* kr_rcvegrbase value */
1009 u32 rcvegrbase;
1010 /* kr_rcvtidbase value */
1011 u32 rcvtidbase;
1012 /* kr_rcvtidcnt value */
1013 u32 rcvtidcnt;
1014 /* kr_userregbase */
1015 u32 uregbase;
1016 /* shadow the control register contents */
1017 u32 control;
1018
1019 /* chip address space used by 4k pio buffers */
1020 u32 align4k;
1021 /* size of each rcvegrbuffer */
Mike Marciniszyn9e1c0e42011-09-23 13:16:39 -04001022 u16 rcvegrbufsize;
1023 /* log2 of above */
1024 u16 rcvegrbufsize_shift;
Ralph Campbellf9315512010-05-23 21:44:54 -07001025 /* localbus width (1, 2,4,8,16,32) from config space */
1026 u32 lbus_width;
1027 /* localbus speed in MHz */
1028 u32 lbus_speed;
1029 int unit; /* unit # of this chip */
1030
1031 /* start of CHIP_SPEC move to chipspec, but need code changes */
1032 /* low and high portions of MSI capability/vector */
1033 u32 msi_lo;
1034 /* saved after PCIe init for restore after reset */
1035 u32 msi_hi;
1036 /* MSI data (vector) saved for restore */
1037 u16 msi_data;
1038 /* so we can rewrite it after a chip reset */
1039 u32 pcibar0;
1040 /* so we can rewrite it after a chip reset */
1041 u32 pcibar1;
1042 u64 rhdrhead_intr_off;
1043
1044 /*
1045 * ASCII serial number, from flash, large enough for original
1046 * all digit strings, and longer QLogic serial number format
1047 */
1048 u8 serial[16];
1049 /* human readable board version */
1050 u8 boardversion[96];
1051 u8 lbus_info[32]; /* human readable localbus info */
1052 /* chip major rev, from qib_revision */
1053 u8 majrev;
1054 /* chip minor rev, from qib_revision */
1055 u8 minrev;
1056
1057 /* Misc small ints */
1058 /* Number of physical ports available */
1059 u8 num_pports;
1060 /* Lowest context number which can be used by user processes */
1061 u8 first_user_ctxt;
1062 u8 n_krcv_queues;
1063 u8 qpn_mask;
1064 u8 skip_kctxt_mask;
1065
1066 u16 rhf_offset; /* offset of RHF within receive header entry */
1067
1068 /*
1069 * GPIO pins for twsi-connected devices, and device code for eeprom
1070 */
1071 u8 gpio_sda_num;
1072 u8 gpio_scl_num;
1073 u8 twsi_eeprom_dev;
1074 u8 board_atten;
1075
1076 /* Support (including locks) for EEPROM logging of errors and time */
1077 /* control access to actual counters, timer */
1078 spinlock_t eep_st_lock;
1079 /* control high-level access to EEPROM */
1080 struct mutex eep_lock;
1081 uint64_t traffic_wds;
1082 /* active time is kept in seconds, but logged in hours */
1083 atomic_t active_time;
1084 /* Below are nominal shadow of EEPROM, new since last EEPROM update */
1085 uint8_t eep_st_errs[QIB_EEP_LOG_CNT];
1086 uint8_t eep_st_new_errs[QIB_EEP_LOG_CNT];
1087 uint16_t eep_hrs;
1088 /*
1089 * masks for which bits of errs, hwerrs that cause
1090 * each of the counters to increment.
1091 */
1092 struct qib_eep_log_mask eep_st_masks[QIB_EEP_LOG_CNT];
1093 struct qib_diag_client *diag_client;
1094 spinlock_t qib_diag_trans_lock; /* protect diag observer ops */
1095 struct diag_observer_list_elt *diag_observer_list;
1096
1097 u8 psxmitwait_supported;
1098 /* cycle length of PS* counters in HW (in picoseconds) */
1099 u16 psxmitwait_check_rate;
Mike Marciniszyne67306a2011-07-21 13:21:16 +00001100 /* high volume overflow errors defered to tasklet */
1101 struct tasklet_struct error_tasklet;
Mike Marciniszyn85caafe2013-06-04 15:05:37 -04001102 /* per device cq worker */
1103 struct kthread_worker *worker;
Ramkrishna Vepae0f30ba2013-05-28 12:57:33 -04001104
1105 int assigned_node_id; /* NUMA node closest to HCA */
Ralph Campbellf9315512010-05-23 21:44:54 -07001106};
1107
1108/* hol_state values */
1109#define QIB_HOL_UP 0
1110#define QIB_HOL_INIT 1
1111
1112#define QIB_SDMA_SENDCTRL_OP_ENABLE (1U << 0)
1113#define QIB_SDMA_SENDCTRL_OP_INTENABLE (1U << 1)
1114#define QIB_SDMA_SENDCTRL_OP_HALT (1U << 2)
1115#define QIB_SDMA_SENDCTRL_OP_CLEANUP (1U << 3)
1116#define QIB_SDMA_SENDCTRL_OP_DRAIN (1U << 4)
1117
1118/* operation types for f_txchk_change() */
1119#define TXCHK_CHG_TYPE_DIS1 3
1120#define TXCHK_CHG_TYPE_ENAB1 2
1121#define TXCHK_CHG_TYPE_KERN 1
1122#define TXCHK_CHG_TYPE_USER 0
1123
1124#define QIB_CHASE_TIME msecs_to_jiffies(145)
1125#define QIB_CHASE_DIS_TIME msecs_to_jiffies(160)
1126
1127/* Private data for file operations */
1128struct qib_filedata {
1129 struct qib_ctxtdata *rcd;
1130 unsigned subctxt;
1131 unsigned tidcursor;
1132 struct qib_user_sdma_queue *pq;
1133 int rec_cpu_num; /* for cpu affinity; -1 if none */
1134};
1135
1136extern struct list_head qib_dev_list;
1137extern spinlock_t qib_devs_lock;
1138extern struct qib_devdata *qib_lookup(int unit);
1139extern u32 qib_cpulist_count;
1140extern unsigned long *qib_cpulist;
1141
1142extern unsigned qib_wc_pat;
Mike Marciniszyn36a8f012012-07-19 13:04:04 +00001143extern unsigned qib_cc_table_size;
Ralph Campbellf9315512010-05-23 21:44:54 -07001144int qib_init(struct qib_devdata *, int);
1145int init_chip_wc_pat(struct qib_devdata *dd, u32);
1146int qib_enable_wc(struct qib_devdata *dd);
1147void qib_disable_wc(struct qib_devdata *dd);
1148int qib_count_units(int *npresentp, int *nupp);
1149int qib_count_active_units(void);
1150
1151int qib_cdev_init(int minor, const char *name,
1152 const struct file_operations *fops,
1153 struct cdev **cdevp, struct device **devp);
1154void qib_cdev_cleanup(struct cdev **cdevp, struct device **devp);
1155int qib_dev_init(void);
1156void qib_dev_cleanup(void);
1157
1158int qib_diag_add(struct qib_devdata *);
1159void qib_diag_remove(struct qib_devdata *);
1160void qib_handle_e_ibstatuschanged(struct qib_pportdata *, u64);
1161void qib_sdma_update_tail(struct qib_pportdata *, u16); /* hold sdma_lock */
1162
1163int qib_decode_err(struct qib_devdata *dd, char *buf, size_t blen, u64 err);
1164void qib_bad_intrstatus(struct qib_devdata *);
1165void qib_handle_urcv(struct qib_devdata *, u64);
1166
1167/* clean up any per-chip chip-specific stuff */
1168void qib_chip_cleanup(struct qib_devdata *);
1169/* clean up any chip type-specific stuff */
1170void qib_chip_done(void);
1171
1172/* check to see if we have to force ordering for write combining */
1173int qib_unordered_wc(void);
1174void qib_pio_copy(void __iomem *to, const void *from, size_t count);
1175
1176void qib_disarm_piobufs(struct qib_devdata *, unsigned, unsigned);
1177int qib_disarm_piobufs_ifneeded(struct qib_ctxtdata *);
1178void qib_disarm_piobufs_set(struct qib_devdata *, unsigned long *, unsigned);
1179void qib_cancel_sends(struct qib_pportdata *);
1180
1181int qib_create_rcvhdrq(struct qib_devdata *, struct qib_ctxtdata *);
1182int qib_setup_eagerbufs(struct qib_ctxtdata *);
1183void qib_set_ctxtcnt(struct qib_devdata *);
1184int qib_create_ctxts(struct qib_devdata *dd);
Ramkrishna Vepae0f30ba2013-05-28 12:57:33 -04001185struct qib_ctxtdata *qib_create_ctxtdata(struct qib_pportdata *, u32, int);
Ralph Campbellf9315512010-05-23 21:44:54 -07001186void qib_init_pportdata(struct qib_pportdata *, struct qib_devdata *, u8, u8);
1187void qib_free_ctxtdata(struct qib_devdata *, struct qib_ctxtdata *);
1188
1189u32 qib_kreceive(struct qib_ctxtdata *, u32 *, u32 *);
1190int qib_reset_device(int);
1191int qib_wait_linkstate(struct qib_pportdata *, u32, int);
1192int qib_set_linkstate(struct qib_pportdata *, u8);
1193int qib_set_mtu(struct qib_pportdata *, u16);
1194int qib_set_lid(struct qib_pportdata *, u32, u8);
1195void qib_hol_down(struct qib_pportdata *);
1196void qib_hol_init(struct qib_pportdata *);
1197void qib_hol_up(struct qib_pportdata *);
1198void qib_hol_event(unsigned long);
1199void qib_disable_after_error(struct qib_devdata *);
1200int qib_set_uevent_bits(struct qib_pportdata *, const int);
1201
1202/* for use in system calls, where we want to know device type, etc. */
1203#define ctxt_fp(fp) \
1204 (((struct qib_filedata *)(fp)->private_data)->rcd)
1205#define subctxt_fp(fp) \
1206 (((struct qib_filedata *)(fp)->private_data)->subctxt)
1207#define tidcursor_fp(fp) \
1208 (((struct qib_filedata *)(fp)->private_data)->tidcursor)
1209#define user_sdma_queue_fp(fp) \
1210 (((struct qib_filedata *)(fp)->private_data)->pq)
1211
1212static inline struct qib_devdata *dd_from_ppd(struct qib_pportdata *ppd)
1213{
1214 return ppd->dd;
1215}
1216
1217static inline struct qib_devdata *dd_from_dev(struct qib_ibdev *dev)
1218{
1219 return container_of(dev, struct qib_devdata, verbs_dev);
1220}
1221
1222static inline struct qib_devdata *dd_from_ibdev(struct ib_device *ibdev)
1223{
1224 return dd_from_dev(to_idev(ibdev));
1225}
1226
1227static inline struct qib_pportdata *ppd_from_ibp(struct qib_ibport *ibp)
1228{
1229 return container_of(ibp, struct qib_pportdata, ibport_data);
1230}
1231
1232static inline struct qib_ibport *to_iport(struct ib_device *ibdev, u8 port)
1233{
1234 struct qib_devdata *dd = dd_from_ibdev(ibdev);
1235 unsigned pidx = port - 1; /* IB number port from 1, hdw from 0 */
1236
1237 WARN_ON(pidx >= dd->num_pports);
1238 return &dd->pport[pidx].ibport_data;
1239}
1240
1241/*
1242 * values for dd->flags (_device_ related flags) and
1243 */
1244#define QIB_HAS_LINK_LATENCY 0x1 /* supports link latency (IB 1.2) */
1245#define QIB_INITTED 0x2 /* chip and driver up and initted */
1246#define QIB_DOING_RESET 0x4 /* in the middle of doing chip reset */
1247#define QIB_PRESENT 0x8 /* chip accesses can be done */
1248#define QIB_PIO_FLUSH_WC 0x10 /* Needs Write combining flush for PIO */
1249#define QIB_HAS_THRESH_UPDATE 0x40
1250#define QIB_HAS_SDMA_TIMEOUT 0x80
1251#define QIB_USE_SPCL_TRIG 0x100 /* SpecialTrigger launch enabled */
1252#define QIB_NODMA_RTAIL 0x200 /* rcvhdrtail register DMA enabled */
1253#define QIB_HAS_INTX 0x800 /* Supports INTx interrupts */
1254#define QIB_HAS_SEND_DMA 0x1000 /* Supports Send DMA */
1255#define QIB_HAS_VLSUPP 0x2000 /* Supports multiple VLs; PBC different */
1256#define QIB_HAS_HDRSUPP 0x4000 /* Supports header suppression */
1257#define QIB_BADINTR 0x8000 /* severe interrupt problems */
1258#define QIB_DCA_ENABLED 0x10000 /* Direct Cache Access enabled */
1259#define QIB_HAS_QSFP 0x20000 /* device (card instance) has QSFP */
1260
1261/*
1262 * values for ppd->lflags (_ib_port_ related flags)
1263 */
1264#define QIBL_LINKV 0x1 /* IB link state valid */
1265#define QIBL_LINKDOWN 0x8 /* IB link is down */
1266#define QIBL_LINKINIT 0x10 /* IB link level is up */
1267#define QIBL_LINKARMED 0x20 /* IB link is ARMED */
1268#define QIBL_LINKACTIVE 0x40 /* IB link is ACTIVE */
1269/* leave a gap for more IB-link state */
1270#define QIBL_IB_AUTONEG_INPROG 0x1000 /* non-IBTA DDR/QDR neg active */
1271#define QIBL_IB_AUTONEG_FAILED 0x2000 /* non-IBTA DDR/QDR neg failed */
1272#define QIBL_IB_LINK_DISABLED 0x4000 /* Linkdown-disable forced,
1273 * Do not try to bring up */
1274#define QIBL_IB_FORCE_NOTIFY 0x8000 /* force notify on next ib change */
1275
1276/* IB dword length mask in PBC (lower 11 bits); same for all chips */
1277#define QIB_PBC_LENGTH_MASK ((1 << 11) - 1)
1278
1279
1280/* ctxt_flag bit offsets */
1281 /* waiting for a packet to arrive */
1282#define QIB_CTXT_WAITING_RCV 2
1283 /* master has not finished initializing */
1284#define QIB_CTXT_MASTER_UNINIT 4
1285 /* waiting for an urgent packet to arrive */
1286#define QIB_CTXT_WAITING_URG 5
1287
1288/* free up any allocated data at closes */
1289void qib_free_data(struct qib_ctxtdata *dd);
1290void qib_chg_pioavailkernel(struct qib_devdata *, unsigned, unsigned,
1291 u32, struct qib_ctxtdata *);
1292struct qib_devdata *qib_init_iba7322_funcs(struct pci_dev *,
1293 const struct pci_device_id *);
1294struct qib_devdata *qib_init_iba7220_funcs(struct pci_dev *,
1295 const struct pci_device_id *);
1296struct qib_devdata *qib_init_iba6120_funcs(struct pci_dev *,
1297 const struct pci_device_id *);
1298void qib_free_devdata(struct qib_devdata *);
1299struct qib_devdata *qib_alloc_devdata(struct pci_dev *pdev, size_t extra);
1300
1301#define QIB_TWSI_NO_DEV 0xFF
1302/* Below qib_twsi_ functions must be called with eep_lock held */
1303int qib_twsi_reset(struct qib_devdata *dd);
1304int qib_twsi_blk_rd(struct qib_devdata *dd, int dev, int addr, void *buffer,
1305 int len);
1306int qib_twsi_blk_wr(struct qib_devdata *dd, int dev, int addr,
1307 const void *buffer, int len);
1308void qib_get_eeprom_info(struct qib_devdata *);
1309int qib_update_eeprom_log(struct qib_devdata *dd);
1310void qib_inc_eeprom_err(struct qib_devdata *dd, u32 eidx, u32 incr);
1311void qib_dump_lookup_output_queue(struct qib_devdata *);
1312void qib_force_pio_avail_update(struct qib_devdata *);
1313void qib_clear_symerror_on_linkup(unsigned long opaque);
1314
1315/*
1316 * Set LED override, only the two LSBs have "public" meaning, but
1317 * any non-zero value substitutes them for the Link and LinkTrain
1318 * LED states.
1319 */
1320#define QIB_LED_PHYS 1 /* Physical (linktraining) GREEN LED */
1321#define QIB_LED_LOG 2 /* Logical (link) YELLOW LED */
1322void qib_set_led_override(struct qib_pportdata *ppd, unsigned int val);
1323
1324/* send dma routines */
1325int qib_setup_sdma(struct qib_pportdata *);
1326void qib_teardown_sdma(struct qib_pportdata *);
1327void __qib_sdma_intr(struct qib_pportdata *);
1328void qib_sdma_intr(struct qib_pportdata *);
1329int qib_sdma_verbs_send(struct qib_pportdata *, struct qib_sge_state *,
1330 u32, struct qib_verbs_txreq *);
1331/* ppd->sdma_lock should be locked before calling this. */
1332int qib_sdma_make_progress(struct qib_pportdata *dd);
1333
Mike Marciniszyn551ace12012-07-19 13:03:56 +00001334static inline int qib_sdma_empty(const struct qib_pportdata *ppd)
1335{
1336 return ppd->sdma_descq_added == ppd->sdma_descq_removed;
1337}
1338
Ralph Campbellf9315512010-05-23 21:44:54 -07001339/* must be called under qib_sdma_lock */
1340static inline u16 qib_sdma_descq_freecnt(const struct qib_pportdata *ppd)
1341{
1342 return ppd->sdma_descq_cnt -
1343 (ppd->sdma_descq_added - ppd->sdma_descq_removed) - 1;
1344}
1345
1346static inline int __qib_sdma_running(struct qib_pportdata *ppd)
1347{
1348 return ppd->sdma_state.current_state == qib_sdma_state_s99_running;
1349}
1350int qib_sdma_running(struct qib_pportdata *);
Dean Luick0b3ddf32013-07-11 15:32:14 -04001351void dump_sdma_state(struct qib_pportdata *ppd);
Ralph Campbellf9315512010-05-23 21:44:54 -07001352void __qib_sdma_process_event(struct qib_pportdata *, enum qib_sdma_events);
1353void qib_sdma_process_event(struct qib_pportdata *, enum qib_sdma_events);
1354
1355/*
1356 * number of words used for protocol header if not set by qib_userinit();
1357 */
1358#define QIB_DFLT_RCVHDRSIZE 9
1359
1360/*
1361 * We need to be able to handle an IB header of at least 24 dwords.
1362 * We need the rcvhdrq large enough to handle largest IB header, but
1363 * still have room for a 2KB MTU standard IB packet.
1364 * Additionally, some processor/memory controller combinations
1365 * benefit quite strongly from having the DMA'ed data be cacheline
1366 * aligned and a cacheline multiple, so we set the size to 32 dwords
1367 * (2 64-byte primary cachelines for pretty much all processors of
1368 * interest). The alignment hurts nothing, other than using somewhat
1369 * more memory.
1370 */
1371#define QIB_RCVHDR_ENTSIZE 32
1372
1373int qib_get_user_pages(unsigned long, size_t, struct page **);
1374void qib_release_user_pages(struct page **, size_t);
1375int qib_eeprom_read(struct qib_devdata *, u8, void *, int);
1376int qib_eeprom_write(struct qib_devdata *, u8, const void *, int);
1377u32 __iomem *qib_getsendbuf_range(struct qib_devdata *, u32 *, u32, u32);
1378void qib_sendbuf_done(struct qib_devdata *, unsigned);
1379
1380static inline void qib_clear_rcvhdrtail(const struct qib_ctxtdata *rcd)
1381{
1382 *((u64 *) rcd->rcvhdrtail_kvaddr) = 0ULL;
1383}
1384
1385static inline u32 qib_get_rcvhdrtail(const struct qib_ctxtdata *rcd)
1386{
1387 /*
1388 * volatile because it's a DMA target from the chip, routine is
1389 * inlined, and don't want register caching or reordering.
1390 */
1391 return (u32) le64_to_cpu(
1392 *((volatile __le64 *)rcd->rcvhdrtail_kvaddr)); /* DMA'ed */
1393}
1394
1395static inline u32 qib_get_hdrqtail(const struct qib_ctxtdata *rcd)
1396{
1397 const struct qib_devdata *dd = rcd->dd;
1398 u32 hdrqtail;
1399
1400 if (dd->flags & QIB_NODMA_RTAIL) {
1401 __le32 *rhf_addr;
1402 u32 seq;
1403
1404 rhf_addr = (__le32 *) rcd->rcvhdrq +
1405 rcd->head + dd->rhf_offset;
1406 seq = qib_hdrget_seq(rhf_addr);
1407 hdrqtail = rcd->head;
1408 if (seq == rcd->seq_cnt)
1409 hdrqtail++;
1410 } else
1411 hdrqtail = qib_get_rcvhdrtail(rcd);
1412
1413 return hdrqtail;
1414}
1415
1416/*
1417 * sysfs interface.
1418 */
1419
1420extern const char ib_qib_version[];
1421
1422int qib_device_create(struct qib_devdata *);
1423void qib_device_remove(struct qib_devdata *);
1424
1425int qib_create_port_files(struct ib_device *ibdev, u8 port_num,
1426 struct kobject *kobj);
1427int qib_verbs_register_sysfs(struct qib_devdata *);
1428void qib_verbs_unregister_sysfs(struct qib_devdata *);
1429/* Hook for sysfs read of QSFP */
1430extern int qib_qsfp_dump(struct qib_pportdata *ppd, char *buf, int len);
1431
1432int __init qib_init_qibfs(void);
1433int __exit qib_exit_qibfs(void);
1434
1435int qibfs_add(struct qib_devdata *);
1436int qibfs_remove(struct qib_devdata *);
1437
1438int qib_pcie_init(struct pci_dev *, const struct pci_device_id *);
1439int qib_pcie_ddinit(struct qib_devdata *, struct pci_dev *,
1440 const struct pci_device_id *);
1441void qib_pcie_ddcleanup(struct qib_devdata *);
Mike Marciniszyna778f3f2012-02-25 17:45:49 -08001442int qib_pcie_params(struct qib_devdata *, u32, u32 *, struct qib_msix_entry *);
Ralph Campbellf9315512010-05-23 21:44:54 -07001443int qib_reinit_intr(struct qib_devdata *);
1444void qib_enable_intx(struct pci_dev *);
1445void qib_nomsi(struct qib_devdata *);
1446void qib_nomsix(struct qib_devdata *);
1447void qib_pcie_getcmd(struct qib_devdata *, u16 *, u8 *, u8 *);
1448void qib_pcie_reenable(struct qib_devdata *, u16, u8, u8);
1449
1450/*
1451 * dma_addr wrappers - all 0's invalid for hw
1452 */
1453dma_addr_t qib_map_page(struct pci_dev *, struct page *, unsigned long,
1454 size_t, int);
1455const char *qib_get_unit_name(int unit);
1456
1457/*
1458 * Flush write combining store buffers (if present) and perform a write
1459 * barrier.
1460 */
1461#if defined(CONFIG_X86_64)
1462#define qib_flush_wc() asm volatile("sfence" : : : "memory")
1463#else
1464#define qib_flush_wc() wmb() /* no reorder around wc flush */
1465#endif
1466
1467/* global module parameter variables */
1468extern unsigned qib_ibmtu;
1469extern ushort qib_cfgctxts;
1470extern ushort qib_num_cfg_vls;
1471extern ushort qib_mini_init; /* If set, do few (ideally 0) writes to chip */
1472extern unsigned qib_n_krcv_queues;
1473extern unsigned qib_sdma_fetch_arb;
1474extern unsigned qib_compat_ddr_negotiate;
1475extern int qib_special_trigger;
Ramkrishna Vepae0f30ba2013-05-28 12:57:33 -04001476extern unsigned qib_numa_aware;
Ralph Campbellf9315512010-05-23 21:44:54 -07001477
1478extern struct mutex qib_mutex;
1479
1480/* Number of seconds before our card status check... */
1481#define STATUS_TIMEOUT 60
1482
1483#define QIB_DRV_NAME "ib_qib"
1484#define QIB_USER_MINOR_BASE 0
1485#define QIB_TRACE_MINOR 127
1486#define QIB_DIAGPKT_MINOR 128
1487#define QIB_DIAG_MINOR_BASE 129
1488#define QIB_NMINORS 255
1489
1490#define PCI_VENDOR_ID_PATHSCALE 0x1fc1
1491#define PCI_VENDOR_ID_QLOGIC 0x1077
1492#define PCI_DEVICE_ID_QLOGIC_IB_6120 0x10
1493#define PCI_DEVICE_ID_QLOGIC_IB_7220 0x7220
1494#define PCI_DEVICE_ID_QLOGIC_IB_7322 0x7322
1495
1496/*
1497 * qib_early_err is used (only!) to print early errors before devdata is
1498 * allocated, or when dd->pcidev may not be valid, and at the tail end of
1499 * cleanup when devdata may have been freed, etc. qib_dev_porterr is
1500 * the same as qib_dev_err, but is used when the message really needs
1501 * the IB port# to be definitive as to what's happening..
1502 * All of these go to the trace log, and the trace log entry is done
1503 * first to avoid possible serial port delays from printk.
1504 */
1505#define qib_early_err(dev, fmt, ...) \
Mike Marciniszynddb88762013-06-15 17:07:03 -04001506 dev_err(dev, fmt, ##__VA_ARGS__)
Ralph Campbellf9315512010-05-23 21:44:54 -07001507
1508#define qib_dev_err(dd, fmt, ...) \
Mike Marciniszynddb88762013-06-15 17:07:03 -04001509 dev_err(&(dd)->pcidev->dev, "%s: " fmt, \
1510 qib_get_unit_name((dd)->unit), ##__VA_ARGS__)
1511
1512#define qib_dev_warn(dd, fmt, ...) \
1513 dev_warn(&(dd)->pcidev->dev, "%s: " fmt, \
1514 qib_get_unit_name((dd)->unit), ##__VA_ARGS__)
Ralph Campbellf9315512010-05-23 21:44:54 -07001515
1516#define qib_dev_porterr(dd, port, fmt, ...) \
Mike Marciniszynddb88762013-06-15 17:07:03 -04001517 dev_err(&(dd)->pcidev->dev, "%s: IB%u:%u " fmt, \
1518 qib_get_unit_name((dd)->unit), (dd)->unit, (port), \
1519 ##__VA_ARGS__)
Ralph Campbellf9315512010-05-23 21:44:54 -07001520
1521#define qib_devinfo(pcidev, fmt, ...) \
Mike Marciniszynddb88762013-06-15 17:07:03 -04001522 dev_info(&(pcidev)->dev, fmt, ##__VA_ARGS__)
Ralph Campbellf9315512010-05-23 21:44:54 -07001523
1524/*
1525 * this is used for formatting hw error messages...
1526 */
1527struct qib_hwerror_msgs {
1528 u64 mask;
1529 const char *msg;
Mike Marciniszyne67306a2011-07-21 13:21:16 +00001530 size_t sz;
Ralph Campbellf9315512010-05-23 21:44:54 -07001531};
1532
1533#define QLOGIC_IB_HWE_MSG(a, b) { .mask = a, .msg = b }
1534
1535/* in qib_intr.c... */
1536void qib_format_hwerrors(u64 hwerrs,
1537 const struct qib_hwerror_msgs *hwerrmsgs,
1538 size_t nhwerrmsgs, char *msg, size_t lmsg);
1539#endif /* _QIB_KERNEL_H */