]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - drivers/staging/rdma/hfi1/hfi.h
staging/rdma/hfi1: Reduce number of parameters passed to send handlers
[mirror_ubuntu-jammy-kernel.git] / drivers / staging / rdma / hfi1 / hfi.h
CommitLineData
77241056
MM
1#ifndef _HFI1_KERNEL_H
2#define _HFI1_KERNEL_H
3/*
4 *
5 * This file is provided under a dual BSD/GPLv2 license. When using or
6 * redistributing this file, you may do so under either license.
7 *
8 * GPL LICENSE SUMMARY
9 *
10 * Copyright(c) 2015 Intel Corporation.
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of version 2 of the GNU General Public License as
14 * published by the Free Software Foundation.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 *
21 * BSD LICENSE
22 *
23 * Copyright(c) 2015 Intel Corporation.
24 *
25 * Redistribution and use in source and binary forms, with or without
26 * modification, are permitted provided that the following conditions
27 * are met:
28 *
29 * - Redistributions of source code must retain the above copyright
30 * notice, this list of conditions and the following disclaimer.
31 * - Redistributions in binary form must reproduce the above copyright
32 * notice, this list of conditions and the following disclaimer in
33 * the documentation and/or other materials provided with the
34 * distribution.
35 * - Neither the name of Intel Corporation nor the names of its
36 * contributors may be used to endorse or promote products derived
37 * from this software without specific prior written permission.
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
40 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
41 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
42 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
43 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
45 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
46 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
47 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
48 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
49 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
50 *
51 */
52
53#include <linux/interrupt.h>
54#include <linux/pci.h>
55#include <linux/dma-mapping.h>
56#include <linux/mutex.h>
57#include <linux/list.h>
58#include <linux/scatterlist.h>
59#include <linux/slab.h>
60#include <linux/io.h>
61#include <linux/fs.h>
62#include <linux/completion.h>
63#include <linux/kref.h>
64#include <linux/sched.h>
65#include <linux/cdev.h>
66#include <linux/delay.h>
67#include <linux/kthread.h>
68
69#include "chip_registers.h"
70#include "common.h"
71#include "verbs.h"
72#include "pio.h"
73#include "chip.h"
74#include "mad.h"
75#include "qsfp.h"
76#include "platform_config.h"
77
78/* bumped 1 from s/w major version of TrueScale */
79#define HFI1_CHIP_VERS_MAJ 3U
80
81/* don't care about this except printing */
82#define HFI1_CHIP_VERS_MIN 0U
83
84/* The Organization Unique Identifier (Mfg code), and its position in GUID */
85#define HFI1_OUI 0x001175
86#define HFI1_OUI_LSB 40
87
88#define DROP_PACKET_OFF 0
89#define DROP_PACKET_ON 1
90
91extern unsigned long hfi1_cap_mask;
92#define HFI1_CAP_KGET_MASK(mask, cap) ((mask) & HFI1_CAP_##cap)
93#define HFI1_CAP_UGET_MASK(mask, cap) \
94 (((mask) >> HFI1_CAP_USER_SHIFT) & HFI1_CAP_##cap)
95#define HFI1_CAP_KGET(cap) (HFI1_CAP_KGET_MASK(hfi1_cap_mask, cap))
96#define HFI1_CAP_UGET(cap) (HFI1_CAP_UGET_MASK(hfi1_cap_mask, cap))
97#define HFI1_CAP_IS_KSET(cap) (!!HFI1_CAP_KGET(cap))
98#define HFI1_CAP_IS_USET(cap) (!!HFI1_CAP_UGET(cap))
99#define HFI1_MISC_GET() ((hfi1_cap_mask >> HFI1_CAP_MISC_SHIFT) & \
100 HFI1_CAP_MISC_MASK)
101
102/*
103 * per driver stats, either not device nor port-specific, or
104 * summed over all of the devices and ports.
105 * They are described by name via ipathfs filesystem, so layout
106 * and number of elements can change without breaking compatibility.
107 * If members are added or deleted hfi1_statnames[] in debugfs.c must
108 * change to match.
109 */
110struct hfi1_ib_stats {
111 __u64 sps_ints; /* number of interrupts handled */
112 __u64 sps_errints; /* number of error interrupts */
113 __u64 sps_txerrs; /* tx-related packet errors */
114 __u64 sps_rcverrs; /* non-crc rcv packet errors */
115 __u64 sps_hwerrs; /* hardware errors reported (parity, etc.) */
116 __u64 sps_nopiobufs; /* no pio bufs avail from kernel */
117 __u64 sps_ctxts; /* number of contexts currently open */
118 __u64 sps_lenerrs; /* number of kernel packets where RHF != LRH len */
119 __u64 sps_buffull;
120 __u64 sps_hdrfull;
121};
122
123extern struct hfi1_ib_stats hfi1_stats;
124extern const struct pci_error_handlers hfi1_pci_err_handler;
125
126/*
127 * First-cut criterion for "device is active" is
128 * two thousand dwords combined Tx, Rx traffic per
129 * 5-second interval. SMA packets are 64 dwords,
130 * and occur "a few per second", presumably each way.
131 */
132#define HFI1_TRAFFIC_ACTIVE_THRESHOLD (2000)
133
134/*
135 * Below contains all data related to a single context (formerly called port).
136 */
137
138#ifdef CONFIG_DEBUG_FS
139struct hfi1_opcode_stats_perctx;
140#endif
141
77241056
MM
142struct ctxt_eager_bufs {
143 ssize_t size; /* total size of eager buffers */
144 u32 count; /* size of buffers array */
145 u32 numbufs; /* number of buffers allocated */
146 u32 alloced; /* number of rcvarray entries used */
147 u32 rcvtid_size; /* size of each eager rcv tid */
148 u32 threshold; /* head update threshold */
149 struct eager_buffer {
150 void *addr;
151 dma_addr_t phys;
152 ssize_t len;
153 } *buffers;
154 struct {
155 void *addr;
156 dma_addr_t phys;
157 } *rcvtids;
158};
159
160struct hfi1_ctxtdata {
161 /* shadow the ctxt's RcvCtrl register */
162 u64 rcvctrl;
163 /* rcvhdrq base, needs mmap before useful */
164 void *rcvhdrq;
165 /* kernel virtual address where hdrqtail is updated */
166 volatile __le64 *rcvhdrtail_kvaddr;
167 /*
168 * Shared page for kernel to signal user processes that send buffers
169 * need disarming. The process should call HFI1_CMD_DISARM_BUFS
170 * or HFI1_CMD_ACK_EVENT with IPATH_EVENT_DISARM_BUFS set.
171 */
172 unsigned long *user_event_mask;
173 /* when waiting for rcv or pioavail */
174 wait_queue_head_t wait;
175 /* rcvhdrq size (for freeing) */
176 size_t rcvhdrq_size;
177 /* number of rcvhdrq entries */
178 u16 rcvhdrq_cnt;
179 /* size of each of the rcvhdrq entries */
180 u16 rcvhdrqentsize;
181 /* mmap of hdrq, must fit in 44 bits */
182 dma_addr_t rcvhdrq_phys;
183 dma_addr_t rcvhdrqtailaddr_phys;
184 struct ctxt_eager_bufs egrbufs;
185 /* this receive context's assigned PIO ACK send context */
186 struct send_context *sc;
187
188 /* dynamic receive available interrupt timeout */
189 u32 rcvavail_timeout;
190 /*
191 * number of opens (including slave sub-contexts) on this instance
192 * (ignoring forks, dup, etc. for now)
193 */
194 int cnt;
195 /*
196 * how much space to leave at start of eager TID entries for
197 * protocol use, on each TID
198 */
199 /* instead of calculating it */
200 unsigned ctxt;
201 /* non-zero if ctxt is being shared. */
202 u16 subctxt_cnt;
203 /* non-zero if ctxt is being shared. */
204 u16 subctxt_id;
205 u8 uuid[16];
206 /* job key */
207 u16 jkey;
208 /* number of RcvArray groups for this context. */
209 u32 rcv_array_groups;
210 /* index of first eager TID entry. */
211 u32 eager_base;
212 /* number of expected TID entries */
213 u32 expected_count;
214 /* index of first expected TID entry. */
215 u32 expected_base;
216 /* cursor into the exp group sets */
217 atomic_t tidcursor;
218 /* number of exp TID groups assigned to the ctxt */
219 u16 numtidgroups;
220 /* size of exp TID group fields in tidusemap */
221 u16 tidmapcnt;
222 /* exp TID group usage bitfield array */
223 unsigned long *tidusemap;
224 /* pinned pages for exp sends, allocated at open */
225 struct page **tid_pg_list;
226 /* dma handles for exp tid pages */
227 dma_addr_t *physshadow;
228 /* lock protecting all Expected TID data */
229 spinlock_t exp_lock;
230 /* number of pio bufs for this ctxt (all procs, if shared) */
231 u32 piocnt;
232 /* first pio buffer for this ctxt */
233 u32 pio_base;
234 /* chip offset of PIO buffers for this ctxt */
235 u32 piobufs;
236 /* per-context configuration flags */
237 u16 flags;
238 /* per-context event flags for fileops/intr communication */
239 unsigned long event_flags;
240 /* WAIT_RCV that timed out, no interrupt */
241 u32 rcvwait_to;
242 /* WAIT_PIO that timed out, no interrupt */
243 u32 piowait_to;
244 /* WAIT_RCV already happened, no wait */
245 u32 rcvnowait;
246 /* WAIT_PIO already happened, no wait */
247 u32 pionowait;
248 /* total number of polled urgent packets */
249 u32 urgent;
250 /* saved total number of polled urgent packets for poll edge trigger */
251 u32 urgent_poll;
252 /* pid of process using this ctxt */
253 pid_t pid;
254 pid_t subpid[HFI1_MAX_SHARED_CTXTS];
255 /* same size as task_struct .comm[], command that opened context */
c3af8a28 256 char comm[TASK_COMM_LEN];
77241056
MM
257 /* so file ops can get at unit */
258 struct hfi1_devdata *dd;
259 /* so functions that need physical port can get it easily */
260 struct hfi1_pportdata *ppd;
261 /* A page of memory for rcvhdrhead, rcvegrhead, rcvegrtail * N */
262 void *subctxt_uregbase;
263 /* An array of pages for the eager receive buffers * N */
264 void *subctxt_rcvegrbuf;
265 /* An array of pages for the eager header queue entries * N */
266 void *subctxt_rcvhdr_base;
267 /* The version of the library which opened this ctxt */
268 u32 userversion;
269 /* Bitmask of active slaves */
270 u32 active_slaves;
271 /* Type of packets or conditions we want to poll for */
272 u16 poll_type;
273 /* receive packet sequence counter */
274 u8 seq_cnt;
275 u8 redirect_seq_cnt;
276 /* ctxt rcvhdrq head offset */
277 u32 head;
278 u32 pkt_count;
279 /* QPs waiting for context processing */
280 struct list_head qp_wait_list;
281 /* interrupt handling */
282 u64 imask; /* clear interrupt mask */
283 int ireg; /* clear interrupt register */
284 unsigned numa_id; /* numa node of this context */
285 /* verbs stats per CTX */
286 struct hfi1_opcode_stats_perctx *opstats;
287 /*
288 * This is the kernel thread that will keep making
289 * progress on the user sdma requests behind the scenes.
290 * There is one per context (shared contexts use the master's).
291 */
292 struct task_struct *progress;
293 struct list_head sdma_queues;
294 spinlock_t sdma_qlock;
295
77241056
MM
296 /*
297 * The interrupt handler for a particular receive context can vary
298 * throughout it's lifetime. This is not a lock protected data member so
299 * it must be updated atomically and the prev and new value must always
300 * be valid. Worst case is we process an extra interrupt and up to 64
301 * packets with the wrong interrupt handler.
302 */
f4f30031 303 int (*do_interrupt)(struct hfi1_ctxtdata *rcd, int threaded);
77241056
MM
304};
305
306/*
307 * Represents a single packet at a high level. Put commonly computed things in
308 * here so we do not have to keep doing them over and over. The rule of thumb is
309 * if something is used one time to derive some value, store that something in
310 * here. If it is used multiple times, then store the result of that derivation
311 * in here.
312 */
313struct hfi1_packet {
314 void *ebuf;
315 void *hdr;
316 struct hfi1_ctxtdata *rcd;
317 __le32 *rhf_addr;
318 struct hfi1_qp *qp;
319 struct hfi1_other_headers *ohdr;
320 u64 rhf;
321 u32 maxcnt;
322 u32 rhqoff;
323 u32 hdrqtail;
324 int numpkt;
325 u16 tlen;
326 u16 hlen;
327 s16 etail;
328 u16 rsize;
329 u8 updegr;
330 u8 rcv_flags;
331 u8 etype;
332};
333
334static inline bool has_sc4_bit(struct hfi1_packet *p)
335{
336 return !!rhf_dc_info(p->rhf);
337}
338
339/*
340 * Private data for snoop/capture support.
341 */
342struct hfi1_snoop_data {
343 int mode_flag;
344 struct cdev cdev;
345 struct device *class_dev;
346 spinlock_t snoop_lock;
347 struct list_head queue;
348 wait_queue_head_t waitq;
349 void *filter_value;
350 int (*filter_callback)(void *hdr, void *data, void *value);
351 u64 dcc_cfg; /* saved value of DCC Cfg register */
352};
353
354/* snoop mode_flag values */
355#define HFI1_PORT_SNOOP_MODE 1U
356#define HFI1_PORT_CAPTURE_MODE 2U
357
358struct hfi1_sge_state;
359
360/*
361 * Get/Set IB link-level config parameters for f_get/set_ib_cfg()
362 * Mostly for MADs that set or query link parameters, also ipath
363 * config interfaces
364 */
365#define HFI1_IB_CFG_LIDLMC 0 /* LID (LS16b) and Mask (MS16b) */
366#define HFI1_IB_CFG_LWID_DG_ENB 1 /* allowed Link-width downgrade */
367#define HFI1_IB_CFG_LWID_ENB 2 /* allowed Link-width */
368#define HFI1_IB_CFG_LWID 3 /* currently active Link-width */
369#define HFI1_IB_CFG_SPD_ENB 4 /* allowed Link speeds */
370#define HFI1_IB_CFG_SPD 5 /* current Link spd */
371#define HFI1_IB_CFG_RXPOL_ENB 6 /* Auto-RX-polarity enable */
372#define HFI1_IB_CFG_LREV_ENB 7 /* Auto-Lane-reversal enable */
373#define HFI1_IB_CFG_LINKLATENCY 8 /* Link Latency (IB1.2 only) */
374#define HFI1_IB_CFG_HRTBT 9 /* IB heartbeat off/enable/auto; DDR/QDR only */
375#define HFI1_IB_CFG_OP_VLS 10 /* operational VLs */
376#define HFI1_IB_CFG_VL_HIGH_CAP 11 /* num of VL high priority weights */
377#define HFI1_IB_CFG_VL_LOW_CAP 12 /* num of VL low priority weights */
378#define HFI1_IB_CFG_OVERRUN_THRESH 13 /* IB overrun threshold */
379#define HFI1_IB_CFG_PHYERR_THRESH 14 /* IB PHY error threshold */
380#define HFI1_IB_CFG_LINKDEFAULT 15 /* IB link default (sleep/poll) */
381#define HFI1_IB_CFG_PKEYS 16 /* update partition keys */
382#define HFI1_IB_CFG_MTU 17 /* update MTU in IBC */
383#define HFI1_IB_CFG_VL_HIGH_LIMIT 19
384#define HFI1_IB_CFG_PMA_TICKS 20 /* PMA sample tick resolution */
385#define HFI1_IB_CFG_PORT 21 /* switch port we are connected to */
386
387/*
388 * HFI or Host Link States
389 *
390 * These describe the states the driver thinks the logical and physical
391 * states are in. Used as an argument to set_link_state(). Implemented
392 * as bits for easy multi-state checking. The actual state can only be
393 * one.
394 */
395#define __HLS_UP_INIT_BP 0
396#define __HLS_UP_ARMED_BP 1
397#define __HLS_UP_ACTIVE_BP 2
398#define __HLS_DN_DOWNDEF_BP 3 /* link down default */
399#define __HLS_DN_POLL_BP 4
400#define __HLS_DN_DISABLE_BP 5
401#define __HLS_DN_OFFLINE_BP 6
402#define __HLS_VERIFY_CAP_BP 7
403#define __HLS_GOING_UP_BP 8
404#define __HLS_GOING_OFFLINE_BP 9
405#define __HLS_LINK_COOLDOWN_BP 10
406
407#define HLS_UP_INIT (1 << __HLS_UP_INIT_BP)
408#define HLS_UP_ARMED (1 << __HLS_UP_ARMED_BP)
409#define HLS_UP_ACTIVE (1 << __HLS_UP_ACTIVE_BP)
410#define HLS_DN_DOWNDEF (1 << __HLS_DN_DOWNDEF_BP) /* link down default */
411#define HLS_DN_POLL (1 << __HLS_DN_POLL_BP)
412#define HLS_DN_DISABLE (1 << __HLS_DN_DISABLE_BP)
413#define HLS_DN_OFFLINE (1 << __HLS_DN_OFFLINE_BP)
414#define HLS_VERIFY_CAP (1 << __HLS_VERIFY_CAP_BP)
415#define HLS_GOING_UP (1 << __HLS_GOING_UP_BP)
416#define HLS_GOING_OFFLINE (1 << __HLS_GOING_OFFLINE_BP)
417#define HLS_LINK_COOLDOWN (1 << __HLS_LINK_COOLDOWN_BP)
418
419#define HLS_UP (HLS_UP_INIT | HLS_UP_ARMED | HLS_UP_ACTIVE)
420
421/* use this MTU size if none other is given */
422#define HFI1_DEFAULT_ACTIVE_MTU 8192
423/* use this MTU size as the default maximum */
424#define HFI1_DEFAULT_MAX_MTU 8192
425/* default partition key */
426#define DEFAULT_PKEY 0xffff
427
428/*
429 * Possible fabric manager config parameters for fm_{get,set}_table()
430 */
431#define FM_TBL_VL_HIGH_ARB 1 /* Get/set VL high prio weights */
432#define FM_TBL_VL_LOW_ARB 2 /* Get/set VL low prio weights */
433#define FM_TBL_BUFFER_CONTROL 3 /* Get/set Buffer Control */
434#define FM_TBL_SC2VLNT 4 /* Get/set SC->VLnt */
435#define FM_TBL_VL_PREEMPT_ELEMS 5 /* Get (no set) VL preempt elems */
436#define FM_TBL_VL_PREEMPT_MATRIX 6 /* Get (no set) VL preempt matrix */
437
438/*
439 * Possible "operations" for f_rcvctrl(ppd, op, ctxt)
440 * these are bits so they can be combined, e.g.
441 * HFI1_RCVCTRL_INTRAVAIL_ENB | HFI1_RCVCTRL_CTXT_ENB
442 */
443#define HFI1_RCVCTRL_TAILUPD_ENB 0x01
444#define HFI1_RCVCTRL_TAILUPD_DIS 0x02
445#define HFI1_RCVCTRL_CTXT_ENB 0x04
446#define HFI1_RCVCTRL_CTXT_DIS 0x08
447#define HFI1_RCVCTRL_INTRAVAIL_ENB 0x10
448#define HFI1_RCVCTRL_INTRAVAIL_DIS 0x20
449#define HFI1_RCVCTRL_PKEY_ENB 0x40 /* Note, default is enabled */
450#define HFI1_RCVCTRL_PKEY_DIS 0x80
451#define HFI1_RCVCTRL_TIDFLOW_ENB 0x0400
452#define HFI1_RCVCTRL_TIDFLOW_DIS 0x0800
453#define HFI1_RCVCTRL_ONE_PKT_EGR_ENB 0x1000
454#define HFI1_RCVCTRL_ONE_PKT_EGR_DIS 0x2000
455#define HFI1_RCVCTRL_NO_RHQ_DROP_ENB 0x4000
456#define HFI1_RCVCTRL_NO_RHQ_DROP_DIS 0x8000
457#define HFI1_RCVCTRL_NO_EGR_DROP_ENB 0x10000
458#define HFI1_RCVCTRL_NO_EGR_DROP_DIS 0x20000
459
460/* partition enforcement flags */
461#define HFI1_PART_ENFORCE_IN 0x1
462#define HFI1_PART_ENFORCE_OUT 0x2
463
464/* how often we check for synthetic counter wrap around */
465#define SYNTH_CNT_TIME 2
466
467/* Counter flags */
468#define CNTR_NORMAL 0x0 /* Normal counters, just read register */
469#define CNTR_SYNTH 0x1 /* Synthetic counters, saturate at all 1s */
470#define CNTR_DISABLED 0x2 /* Disable this counter */
471#define CNTR_32BIT 0x4 /* Simulate 64 bits for this counter */
472#define CNTR_VL 0x8 /* Per VL counter */
473#define CNTR_INVALID_VL -1 /* Specifies invalid VL */
474#define CNTR_MODE_W 0x0
475#define CNTR_MODE_R 0x1
476
477/* VLs Supported/Operational */
478#define HFI1_MIN_VLS_SUPPORTED 1
479#define HFI1_MAX_VLS_SUPPORTED 8
480
481static inline void incr_cntr64(u64 *cntr)
482{
483 if (*cntr < (u64)-1LL)
484 (*cntr)++;
485}
486
487static inline void incr_cntr32(u32 *cntr)
488{
489 if (*cntr < (u32)-1LL)
490 (*cntr)++;
491}
492
493#define MAX_NAME_SIZE 64
494struct hfi1_msix_entry {
495 struct msix_entry msix;
496 void *arg;
497 char name[MAX_NAME_SIZE];
498 cpumask_var_t mask;
499};
500
501/* per-SL CCA information */
502struct cca_timer {
503 struct hrtimer hrtimer;
504 struct hfi1_pportdata *ppd; /* read-only */
505 int sl; /* read-only */
506 u16 ccti; /* read/write - current value of CCTI */
507};
508
509struct link_down_reason {
510 /*
511 * SMA-facing value. Should be set from .latest when
512 * HLS_UP_* -> HLS_DN_* transition actually occurs.
513 */
514 u8 sma;
515 u8 latest;
516};
517
518enum {
519 LO_PRIO_TABLE,
520 HI_PRIO_TABLE,
521 MAX_PRIO_TABLE
522};
523
524struct vl_arb_cache {
525 spinlock_t lock;
526 struct ib_vl_weight_elem table[VL_ARB_TABLE_SIZE];
527};
528
529/*
530 * The structure below encapsulates data relevant to a physical IB Port.
531 * Current chips support only one such port, but the separation
532 * clarifies things a bit. Note that to conform to IB conventions,
533 * port-numbers are one-based. The first or only port is port1.
534 */
535struct hfi1_pportdata {
536 struct hfi1_ibport ibport_data;
537
538 struct hfi1_devdata *dd;
539 struct kobject pport_cc_kobj;
540 struct kobject sc2vl_kobj;
541 struct kobject sl2sc_kobj;
542 struct kobject vl2mtu_kobj;
543
544 /* QSFP support */
545 struct qsfp_data qsfp_info;
546
547 /* GUID for this interface, in host order */
548 u64 guid;
549 /* GUID for peer interface, in host order */
550 u64 neighbor_guid;
551
552 /* up or down physical link state */
553 u32 linkup;
554
555 /*
556 * this address is mapped read-only into user processes so they can
557 * get status cheaply, whenever they want. One qword of status per port
558 */
559 u64 *statusp;
560
561 /* SendDMA related entries */
562
563 struct workqueue_struct *hfi1_wq;
564
565 /* move out of interrupt context */
566 struct work_struct link_vc_work;
567 struct work_struct link_up_work;
568 struct work_struct link_down_work;
569 struct work_struct sma_message_work;
570 struct work_struct freeze_work;
571 struct work_struct link_downgrade_work;
572 struct work_struct link_bounce_work;
573 /* host link state variables */
574 struct mutex hls_lock;
575 u32 host_link_state;
576
577 spinlock_t sdma_alllock ____cacheline_aligned_in_smp;
578
579 u32 lstate; /* logical link state */
580
581 /* these are the "32 bit" regs */
582
583 u32 ibmtu; /* The MTU programmed for this unit */
584 /*
585 * Current max size IB packet (in bytes) including IB headers, that
586 * we can send. Changes when ibmtu changes.
587 */
588 u32 ibmaxlen;
589 u32 current_egress_rate; /* units [10^6 bits/sec] */
590 /* LID programmed for this instance */
591 u16 lid;
592 /* list of pkeys programmed; 0 if not set */
593 u16 pkeys[MAX_PKEY_VALUES];
594 u16 link_width_supported;
595 u16 link_width_downgrade_supported;
596 u16 link_speed_supported;
597 u16 link_width_enabled;
598 u16 link_width_downgrade_enabled;
599 u16 link_speed_enabled;
600 u16 link_width_active;
601 u16 link_width_downgrade_tx_active;
602 u16 link_width_downgrade_rx_active;
603 u16 link_speed_active;
604 u8 vls_supported;
605 u8 vls_operational;
606 /* LID mask control */
607 u8 lmc;
608 /* Rx Polarity inversion (compensate for ~tx on partner) */
609 u8 rx_pol_inv;
610
611 u8 hw_pidx; /* physical port index */
612 u8 port; /* IB port number and index into dd->pports - 1 */
613 /* type of neighbor node */
614 u8 neighbor_type;
615 u8 neighbor_normal;
616 u8 neighbor_fm_security; /* 1 if firmware checking is disabled */
617 u8 neighbor_port_number;
618 u8 is_sm_config_started;
619 u8 offline_disabled_reason;
620 u8 is_active_optimize_enabled;
621 u8 driver_link_ready; /* driver ready for active link */
622 u8 link_enabled; /* link enabled? */
623 u8 linkinit_reason;
624 u8 local_tx_rate; /* rate given to 8051 firmware */
625
626 /* placeholders for IB MAD packet settings */
627 u8 overrun_threshold;
628 u8 phy_error_threshold;
629
630 /* used to override LED behavior */
631 u8 led_override; /* Substituted for normal value, if non-zero */
632 u16 led_override_timeoff; /* delta to next timer event */
633 u8 led_override_vals[2]; /* Alternates per blink-frame */
634 u8 led_override_phase; /* Just counts, LSB picks from vals[] */
635 atomic_t led_override_timer_active;
636 /* Used to flash LEDs in override mode */
637 struct timer_list led_override_timer;
638 u32 sm_trap_qp;
639 u32 sa_qp;
640
641 /*
642 * cca_timer_lock protects access to the per-SL cca_timer
643 * structures (specifically the ccti member).
644 */
645 spinlock_t cca_timer_lock ____cacheline_aligned_in_smp;
646 struct cca_timer cca_timer[OPA_MAX_SLS];
647
648 /* List of congestion control table entries */
649 struct ib_cc_table_entry_shadow ccti_entries[CC_TABLE_SHADOW_MAX];
650
651 /* congestion entries, each entry corresponding to a SL */
652 struct opa_congestion_setting_entry_shadow
653 congestion_entries[OPA_MAX_SLS];
654
655 /*
656 * cc_state_lock protects (write) access to the per-port
657 * struct cc_state.
658 */
659 spinlock_t cc_state_lock ____cacheline_aligned_in_smp;
660
661 struct cc_state __rcu *cc_state;
662
663 /* Total number of congestion control table entries */
664 u16 total_cct_entry;
665
666 /* Bit map identifying service level */
667 u32 cc_sl_control_map;
668
669 /* CA's max number of 64 entry units in the congestion control table */
670 u8 cc_max_table_entries;
671
672 /* begin congestion log related entries
673 * cc_log_lock protects all congestion log related data */
674 spinlock_t cc_log_lock ____cacheline_aligned_in_smp;
675 u8 threshold_cong_event_map[OPA_MAX_SLS/8];
676 u16 threshold_event_counter;
677 struct opa_hfi1_cong_log_event_internal cc_events[OPA_CONG_LOG_ELEMS];
678 int cc_log_idx; /* index for logging events */
679 int cc_mad_idx; /* index for reporting events */
680 /* end congestion log related entries */
681
682 struct vl_arb_cache vl_arb_cache[MAX_PRIO_TABLE];
683
684 /* port relative counter buffer */
685 u64 *cntrs;
686 /* port relative synthetic counter buffer */
687 u64 *scntrs;
688 /* we synthesize port_xmit_discards from several egress errors */
689 u64 port_xmit_discards;
690 u64 port_xmit_constraint_errors;
691 u64 port_rcv_constraint_errors;
692 /* count of 'link_err' interrupts from DC */
693 u64 link_downed;
694 /* number of times link retrained successfully */
695 u64 link_up;
696 /* port_ltp_crc_mode is returned in 'portinfo' MADs */
697 u16 port_ltp_crc_mode;
698 /* port_crc_mode_enabled is the crc we support */
699 u8 port_crc_mode_enabled;
700 /* mgmt_allowed is also returned in 'portinfo' MADs */
701 u8 mgmt_allowed;
702 u8 part_enforce; /* partition enforcement flags */
703 struct link_down_reason local_link_down_reason;
704 struct link_down_reason neigh_link_down_reason;
705 /* Value to be sent to link peer on LinkDown .*/
706 u8 remote_link_down_reason;
707 /* Error events that will cause a port bounce. */
708 u32 port_error_action;
709};
710
711typedef int (*rhf_rcv_function_ptr)(struct hfi1_packet *packet);
712
713typedef void (*opcode_handler)(struct hfi1_packet *packet);
714
715/* return values for the RHF receive functions */
716#define RHF_RCV_CONTINUE 0 /* keep going */
717#define RHF_RCV_DONE 1 /* stop, this packet processed */
718#define RHF_RCV_REPROCESS 2 /* stop. retain this packet */
719
720struct rcv_array_data {
721 u8 group_size;
722 u16 ngroups;
723 u16 nctxt_extra;
724};
725
726struct per_vl_data {
727 u16 mtu;
728 struct send_context *sc;
729};
730
731/* 16 to directly index */
732#define PER_VL_SEND_CONTEXTS 16
733
734struct err_info_rcvport {
735 u8 status_and_code;
736 u64 packet_flit1;
737 u64 packet_flit2;
738};
739
740struct err_info_constraint {
741 u8 status;
742 u16 pkey;
743 u32 slid;
744};
745
746struct hfi1_temp {
747 unsigned int curr; /* current temperature */
748 unsigned int lo_lim; /* low temperature limit */
749 unsigned int hi_lim; /* high temperature limit */
750 unsigned int crit_lim; /* critical temperature limit */
751 u8 triggers; /* temperature triggers */
752};
753
754/* device data struct now contains only "general per-device" info.
755 * fields related to a physical IB port are in a hfi1_pportdata struct.
756 */
757struct sdma_engine;
758struct sdma_vl_map;
759
760#define BOARD_VERS_MAX 96 /* how long the version string can be */
761#define SERIAL_MAX 16 /* length of the serial number */
762
763struct hfi1_devdata {
764 struct hfi1_ibdev verbs_dev; /* must be first */
765 struct list_head list;
766 /* pointers to related structs for this device */
767 /* pci access data structure */
768 struct pci_dev *pcidev;
769 struct cdev user_cdev;
770 struct cdev diag_cdev;
771 struct cdev ui_cdev;
772 struct device *user_device;
773 struct device *diag_device;
774 struct device *ui_device;
775
776 /* mem-mapped pointer to base of chip regs */
777 u8 __iomem *kregbase;
778 /* end of mem-mapped chip space excluding sendbuf and user regs */
779 u8 __iomem *kregend;
780 /* physical address of chip for io_remap, etc. */
781 resource_size_t physaddr;
782 /* receive context data */
783 struct hfi1_ctxtdata **rcd;
784 /* send context data */
785 struct send_context_info *send_contexts;
786 /* map hardware send contexts to software index */
787 u8 *hw_to_sw;
788 /* spinlock for allocating and releasing send context resources */
789 spinlock_t sc_lock;
790 /* Per VL data. Enough for all VLs but not all elements are set/used. */
791 struct per_vl_data vld[PER_VL_SEND_CONTEXTS];
792 /* seqlock for sc2vl */
793 seqlock_t sc2vl_lock;
794 u64 sc2vl[4];
795 /* Send Context initialization lock. */
796 spinlock_t sc_init_lock;
797
798 /* fields common to all SDMA engines */
799
800 /* default flags to last descriptor */
801 u64 default_desc1;
802 volatile __le64 *sdma_heads_dma; /* DMA'ed by chip */
803 dma_addr_t sdma_heads_phys;
804 void *sdma_pad_dma; /* DMA'ed by chip */
805 dma_addr_t sdma_pad_phys;
806 /* for deallocation */
807 size_t sdma_heads_size;
808 /* number from the chip */
809 u32 chip_sdma_engines;
810 /* num used */
811 u32 num_sdma;
812 /* lock for sdma_map */
813 spinlock_t sde_map_lock;
814 /* array of engines sized by num_sdma */
815 struct sdma_engine *per_sdma;
816 /* array of vl maps */
817 struct sdma_vl_map __rcu *sdma_map;
818 /* SPC freeze waitqueue and variable */
819 wait_queue_head_t sdma_unfreeze_wq;
820 atomic_t sdma_unfreeze_count;
821
822
823 /* hfi1_pportdata, points to array of (physical) port-specific
824 * data structs, indexed by pidx (0..n-1)
825 */
826 struct hfi1_pportdata *pport;
827
828 /* mem-mapped pointer to base of PIO buffers */
829 void __iomem *piobase;
830 /*
831 * write-combining mem-mapped pointer to base of RcvArray
832 * memory.
833 */
834 void __iomem *rcvarray_wc;
835 /*
836 * credit return base - a per-NUMA range of DMA address that
837 * the chip will use to update the per-context free counter
838 */
839 struct credit_return_base *cr_base;
840
841 /* send context numbers and sizes for each type */
842 struct sc_config_sizes sc_sizes[SC_MAX];
843
844 u32 lcb_access_count; /* count of LCB users */
845
846 char *boardname; /* human readable board info */
847
848 /* device (not port) flags, basically device capabilities */
849 u32 flags;
850
851 /* reset value */
852 u64 z_int_counter;
853 u64 z_rcv_limit;
854 /* percpu int_counter */
855 u64 __percpu *int_counter;
856 u64 __percpu *rcv_limit;
857
858 /* number of receive contexts in use by the driver */
859 u32 num_rcv_contexts;
860 /* number of pio send contexts in use by the driver */
861 u32 num_send_contexts;
862 /*
863 * number of ctxts available for PSM open
864 */
865 u32 freectxts;
866 /* base receive interrupt timeout, in CSR units */
867 u32 rcv_intr_timeout_csr;
868
869 u64 __iomem *egrtidbase;
870 spinlock_t sendctrl_lock; /* protect changes to SendCtrl */
871 spinlock_t rcvctrl_lock; /* protect changes to RcvCtrl */
872 /* around rcd and (user ctxts) ctxt_cnt use (intr vs free) */
873 spinlock_t uctxt_lock; /* rcd and user context changes */
874 /* exclusive access to 8051 */
875 spinlock_t dc8051_lock;
876 /* exclusive access to 8051 memory */
877 spinlock_t dc8051_memlock;
878 int dc8051_timed_out; /* remember if the 8051 timed out */
879 /*
880 * A page that will hold event notification bitmaps for all
881 * contexts. This page will be mapped into all processes.
882 */
883 unsigned long *events;
884 /*
885 * per unit status, see also portdata statusp
886 * mapped read-only into user processes so they can get unit and
887 * IB link status cheaply
888 */
889 struct hfi1_status *status;
890 u32 freezelen; /* max length of freezemsg */
891
892 /* revision register shadow */
893 u64 revision;
894 /* Base GUID for device (network order) */
895 u64 base_guid;
896
897 /* these are the "32 bit" regs */
898
899 /* value we put in kr_rcvhdrsize */
900 u32 rcvhdrsize;
901 /* number of receive contexts the chip supports */
902 u32 chip_rcv_contexts;
903 /* number of receive array entries */
904 u32 chip_rcv_array_count;
905 /* number of PIO send contexts the chip supports */
906 u32 chip_send_contexts;
907 /* number of bytes in the PIO memory buffer */
908 u32 chip_pio_mem_size;
909 /* number of bytes in the SDMA memory buffer */
910 u32 chip_sdma_mem_size;
911
912 /* size of each rcvegrbuffer */
913 u32 rcvegrbufsize;
914 /* log2 of above */
915 u16 rcvegrbufsize_shift;
916 /* both sides of the PCIe link are gen3 capable */
917 u8 link_gen3_capable;
918 /* localbus width (1, 2,4,8,16,32) from config space */
919 u32 lbus_width;
920 /* localbus speed in MHz */
921 u32 lbus_speed;
922 int unit; /* unit # of this chip */
923 int node; /* home node of this chip */
924
925 /* save these PCI fields to restore after a reset */
926 u32 pcibar0;
927 u32 pcibar1;
928 u32 pci_rom;
929 u16 pci_command;
930 u16 pcie_devctl;
931 u16 pcie_lnkctl;
932 u16 pcie_devctl2;
933 u32 pci_msix0;
934 u32 pci_lnkctl3;
935 u32 pci_tph2;
936
937 /*
938 * ASCII serial number, from flash, large enough for original
939 * all digit strings, and longer serial number format
940 */
941 u8 serial[SERIAL_MAX];
942 /* human readable board version */
943 u8 boardversion[BOARD_VERS_MAX];
944 u8 lbus_info[32]; /* human readable localbus info */
945 /* chip major rev, from CceRevision */
946 u8 majrev;
947 /* chip minor rev, from CceRevision */
948 u8 minrev;
949 /* hardware ID */
950 u8 hfi1_id;
951 /* implementation code */
952 u8 icode;
953 /* default link down value (poll/sleep) */
954 u8 link_default;
955 /* vAU of this device */
956 u8 vau;
957 /* vCU of this device */
958 u8 vcu;
959 /* link credits of this device */
960 u16 link_credits;
961 /* initial vl15 credits to use */
962 u16 vl15_init;
963
964 /* Misc small ints */
965 /* Number of physical ports available */
966 u8 num_pports;
967 /* Lowest context number which can be used by user processes */
968 u8 first_user_ctxt;
969 u8 n_krcv_queues;
970 u8 qos_shift;
971 u8 qpn_mask;
972
973 u16 rhf_offset; /* offset of RHF within receive header entry */
974 u16 irev; /* implementation revision */
975 u16 dc8051_ver; /* 8051 firmware version */
976
977 struct platform_config_cache pcfg_cache;
978 /* control high-level access to qsfp */
979 struct mutex qsfp_i2c_mutex;
980
981 struct diag_client *diag_client;
982 spinlock_t hfi1_diag_trans_lock; /* protect diag observer ops */
983
984 u8 psxmitwait_supported;
985 /* cycle length of PS* counters in HW (in picoseconds) */
986 u16 psxmitwait_check_rate;
987 /* high volume overflow errors deferred to tasklet */
988 struct tasklet_struct error_tasklet;
989 /* per device cq worker */
990 struct kthread_worker *worker;
991
992 /* MSI-X information */
993 struct hfi1_msix_entry *msix_entries;
994 u32 num_msix_entries;
995
996 /* INTx information */
997 u32 requested_intx_irq; /* did we request one? */
998 char intx_name[MAX_NAME_SIZE]; /* INTx name */
999
1000 /* general interrupt: mask of handled interrupts */
1001 u64 gi_mask[CCE_NUM_INT_CSRS];
1002
1003 struct rcv_array_data rcv_entries;
1004
1005 /*
1006 * 64 bit synthetic counters
1007 */
1008 struct timer_list synth_stats_timer;
1009
1010 /*
1011 * device counters
1012 */
1013 char *cntrnames;
1014 size_t cntrnameslen;
1015 size_t ndevcntrs;
1016 u64 *cntrs;
1017 u64 *scntrs;
1018
1019 /*
1020 * remembered values for synthetic counters
1021 */
1022 u64 last_tx;
1023 u64 last_rx;
1024
1025 /*
1026 * per-port counters
1027 */
1028 size_t nportcntrs;
1029 char *portcntrnames;
1030 size_t portcntrnameslen;
1031
1032 struct hfi1_snoop_data hfi1_snoop;
1033
1034 struct err_info_rcvport err_info_rcvport;
1035 struct err_info_constraint err_info_rcv_constraint;
1036 struct err_info_constraint err_info_xmit_constraint;
1037 u8 err_info_uncorrectable;
1038 u8 err_info_fmconfig;
1039
1040 atomic_t drop_packet;
1041 u8 do_drop;
1042
1043 /* receive interrupt functions */
1044 rhf_rcv_function_ptr *rhf_rcv_function_map;
1045 rhf_rcv_function_ptr normal_rhf_rcv_functions[8];
1046
1047 /*
1048 * Handlers for outgoing data so that snoop/capture does not
1049 * have to have its hooks in the send path
1050 */
d46e5144
DD
1051 int (*process_pio_send)(struct hfi1_qp *qp, struct hfi1_pkt_state *ps,
1052 u64 pbc);
1053 int (*process_dma_send)(struct hfi1_qp *qp, struct hfi1_pkt_state *ps,
1054 u64 pbc);
77241056
MM
1055 void (*pio_inline_send)(struct hfi1_devdata *dd, struct pio_buf *pbuf,
1056 u64 pbc, const void *from, size_t count);
1057
1058 /* OUI comes from the HW. Used everywhere as 3 separate bytes. */
1059 u8 oui1;
1060 u8 oui2;
1061 u8 oui3;
1062 /* Timer and counter used to detect RcvBufOvflCnt changes */
1063 struct timer_list rcverr_timer;
1064 u32 rcv_ovfl_cnt;
1065
1066 int assigned_node_id;
1067 wait_queue_head_t event_queue;
1068
1069 /* Save the enabled LCB error bits */
1070 u64 lcb_err_en;
1071 u8 dc_shutdown;
46b010d3
MB
1072
1073 /* receive context tail dummy address */
1074 __le64 *rcvhdrtail_dummy_kvaddr;
1075 dma_addr_t rcvhdrtail_dummy_physaddr;
77241056
MM
1076};
1077
1078/* 8051 firmware version helper */
1079#define dc8051_ver(a, b) ((a) << 8 | (b))
1080
1081/* f_put_tid types */
1082#define PT_EXPECTED 0
1083#define PT_EAGER 1
1084#define PT_INVALID 2
1085
1086/* Private data for file operations */
1087struct hfi1_filedata {
1088 struct hfi1_ctxtdata *uctxt;
1089 unsigned subctxt;
1090 struct hfi1_user_sdma_comp_q *cq;
1091 struct hfi1_user_sdma_pkt_q *pq;
1092 /* for cpu affinity; -1 if none */
1093 int rec_cpu_num;
1094};
1095
1096extern struct list_head hfi1_dev_list;
1097extern spinlock_t hfi1_devs_lock;
1098struct hfi1_devdata *hfi1_lookup(int unit);
1099extern u32 hfi1_cpulist_count;
1100extern unsigned long *hfi1_cpulist;
1101
1102extern unsigned int snoop_drop_send;
1103extern unsigned int snoop_force_capture;
1104int hfi1_init(struct hfi1_devdata *, int);
1105int hfi1_count_units(int *npresentp, int *nupp);
1106int hfi1_count_active_units(void);
1107
1108int hfi1_diag_add(struct hfi1_devdata *);
1109void hfi1_diag_remove(struct hfi1_devdata *);
1110void handle_linkup_change(struct hfi1_devdata *dd, u32 linkup);
1111
1112void handle_user_interrupt(struct hfi1_ctxtdata *rcd);
1113
1114int hfi1_create_rcvhdrq(struct hfi1_devdata *, struct hfi1_ctxtdata *);
1115int hfi1_setup_eagerbufs(struct hfi1_ctxtdata *);
1116int hfi1_create_ctxts(struct hfi1_devdata *dd);
1117struct hfi1_ctxtdata *hfi1_create_ctxtdata(struct hfi1_pportdata *, u32);
1118void hfi1_init_pportdata(struct pci_dev *, struct hfi1_pportdata *,
1119 struct hfi1_devdata *, u8, u8);
1120void hfi1_free_ctxtdata(struct hfi1_devdata *, struct hfi1_ctxtdata *);
1121
f4f30031
DL
1122int handle_receive_interrupt(struct hfi1_ctxtdata *, int);
1123int handle_receive_interrupt_nodma_rtail(struct hfi1_ctxtdata *, int);
1124int handle_receive_interrupt_dma_rtail(struct hfi1_ctxtdata *, int);
1125
1126/* receive packet handler dispositions */
1127#define RCV_PKT_OK 0x0 /* keep going */
1128#define RCV_PKT_LIMIT 0x1 /* stop, hit limit, start thread */
1129#define RCV_PKT_DONE 0x2 /* stop, no more packets detected */
1130
1131/* calculate the current RHF address */
1132static inline __le32 *get_rhf_addr(struct hfi1_ctxtdata *rcd)
1133{
1134 return (__le32 *)rcd->rcvhdrq + rcd->head + rcd->dd->rhf_offset;
1135}
1136
77241056
MM
1137int hfi1_reset_device(int);
1138
1139/* return the driver's idea of the logical OPA port state */
1140static inline u32 driver_lstate(struct hfi1_pportdata *ppd)
1141{
1142 return ppd->lstate; /* use the cached value */
1143}
1144
1145static inline u16 generate_jkey(kuid_t uid)
1146{
1147 return from_kuid(current_user_ns(), uid) & 0xffff;
1148}
1149
1150/*
1151 * active_egress_rate
1152 *
1153 * returns the active egress rate in units of [10^6 bits/sec]
1154 */
1155static inline u32 active_egress_rate(struct hfi1_pportdata *ppd)
1156{
1157 u16 link_speed = ppd->link_speed_active;
1158 u16 link_width = ppd->link_width_active;
1159 u32 egress_rate;
1160
1161 if (link_speed == OPA_LINK_SPEED_25G)
1162 egress_rate = 25000;
1163 else /* assume OPA_LINK_SPEED_12_5G */
1164 egress_rate = 12500;
1165
1166 switch (link_width) {
1167 case OPA_LINK_WIDTH_4X:
1168 egress_rate *= 4;
1169 break;
1170 case OPA_LINK_WIDTH_3X:
1171 egress_rate *= 3;
1172 break;
1173 case OPA_LINK_WIDTH_2X:
1174 egress_rate *= 2;
1175 break;
1176 default:
1177 /* assume IB_WIDTH_1X */
1178 break;
1179 }
1180
1181 return egress_rate;
1182}
1183
1184/*
1185 * egress_cycles
1186 *
1187 * Returns the number of 'fabric clock cycles' to egress a packet
1188 * of length 'len' bytes, at 'rate' Mbit/s. Since the fabric clock
1189 * rate is (approximately) 805 MHz, the units of the returned value
1190 * are (1/805 MHz).
1191 */
1192static inline u32 egress_cycles(u32 len, u32 rate)
1193{
1194 u32 cycles;
1195
1196 /*
1197 * cycles is:
1198 *
1199 * (length) [bits] / (rate) [bits/sec]
1200 * ---------------------------------------------------
1201 * fabric_clock_period == 1 /(805 * 10^6) [cycles/sec]
1202 */
1203
1204 cycles = len * 8; /* bits */
1205 cycles *= 805;
1206 cycles /= rate;
1207
1208 return cycles;
1209}
1210
1211void set_link_ipg(struct hfi1_pportdata *ppd);
1212void process_becn(struct hfi1_pportdata *ppd, u8 sl, u16 rlid, u32 lqpn,
1213 u32 rqpn, u8 svc_type);
1214void return_cnp(struct hfi1_ibport *ibp, struct hfi1_qp *qp, u32 remote_qpn,
1215 u32 pkey, u32 slid, u32 dlid, u8 sc5,
1216 const struct ib_grh *old_grh);
1217
1218#define PACKET_EGRESS_TIMEOUT 350
1219static inline void pause_for_credit_return(struct hfi1_devdata *dd)
1220{
1221 /* Pause at least 1us, to ensure chip returns all credits */
1222 u32 usec = cclock_to_ns(dd, PACKET_EGRESS_TIMEOUT) / 1000;
1223
1224 udelay(usec ? usec : 1);
1225}
1226
1227/**
1228 * sc_to_vlt() reverse lookup sc to vl
1229 * @dd - devdata
1230 * @sc5 - 5 bit sc
1231 */
1232static inline u8 sc_to_vlt(struct hfi1_devdata *dd, u8 sc5)
1233{
1234 unsigned seq;
1235 u8 rval;
1236
1237 if (sc5 >= OPA_MAX_SCS)
1238 return (u8)(0xff);
1239
1240 do {
1241 seq = read_seqbegin(&dd->sc2vl_lock);
1242 rval = *(((u8 *)dd->sc2vl) + sc5);
1243 } while (read_seqretry(&dd->sc2vl_lock, seq));
1244
1245 return rval;
1246}
1247
1248#define PKEY_MEMBER_MASK 0x8000
1249#define PKEY_LOW_15_MASK 0x7fff
1250
1251/*
1252 * ingress_pkey_matches_entry - return 1 if the pkey matches ent (ent
1253 * being an entry from the ingress partition key table), return 0
1254 * otherwise. Use the matching criteria for ingress partition keys
1255 * specified in the OPAv1 spec., section 9.10.14.
1256 */
1257static inline int ingress_pkey_matches_entry(u16 pkey, u16 ent)
1258{
1259 u16 mkey = pkey & PKEY_LOW_15_MASK;
1260 u16 ment = ent & PKEY_LOW_15_MASK;
1261
1262 if (mkey == ment) {
1263 /*
1264 * If pkey[15] is clear (limited partition member),
1265 * is bit 15 in the corresponding table element
1266 * clear (limited member)?
1267 */
1268 if (!(pkey & PKEY_MEMBER_MASK))
1269 return !!(ent & PKEY_MEMBER_MASK);
1270 return 1;
1271 }
1272 return 0;
1273}
1274
1275/*
1276 * ingress_pkey_table_search - search the entire pkey table for
1277 * an entry which matches 'pkey'. return 0 if a match is found,
1278 * and 1 otherwise.
1279 */
1280static int ingress_pkey_table_search(struct hfi1_pportdata *ppd, u16 pkey)
1281{
1282 int i;
1283
1284 for (i = 0; i < MAX_PKEY_VALUES; i++) {
1285 if (ingress_pkey_matches_entry(pkey, ppd->pkeys[i]))
1286 return 0;
1287 }
1288 return 1;
1289}
1290
1291/*
1292 * ingress_pkey_table_fail - record a failure of ingress pkey validation,
1293 * i.e., increment port_rcv_constraint_errors for the port, and record
1294 * the 'error info' for this failure.
1295 */
1296static void ingress_pkey_table_fail(struct hfi1_pportdata *ppd, u16 pkey,
1297 u16 slid)
1298{
1299 struct hfi1_devdata *dd = ppd->dd;
1300
1301 incr_cntr64(&ppd->port_rcv_constraint_errors);
1302 if (!(dd->err_info_rcv_constraint.status & OPA_EI_STATUS_SMASK)) {
1303 dd->err_info_rcv_constraint.status |= OPA_EI_STATUS_SMASK;
1304 dd->err_info_rcv_constraint.slid = slid;
1305 dd->err_info_rcv_constraint.pkey = pkey;
1306 }
1307}
1308
1309/*
1310 * ingress_pkey_check - Return 0 if the ingress pkey is valid, return 1
1311 * otherwise. Use the criteria in the OPAv1 spec, section 9.10.14. idx
1312 * is a hint as to the best place in the partition key table to begin
1313 * searching. This function should not be called on the data path because
1314 * of performance reasons. On datapath pkey check is expected to be done
1315 * by HW and rcv_pkey_check function should be called instead.
1316 */
1317static inline int ingress_pkey_check(struct hfi1_pportdata *ppd, u16 pkey,
1318 u8 sc5, u8 idx, u16 slid)
1319{
1320 if (!(ppd->part_enforce & HFI1_PART_ENFORCE_IN))
1321 return 0;
1322
1323 /* If SC15, pkey[0:14] must be 0x7fff */
1324 if ((sc5 == 0xf) && ((pkey & PKEY_LOW_15_MASK) != PKEY_LOW_15_MASK))
1325 goto bad;
1326
1327 /* Is the pkey = 0x0, or 0x8000? */
1328 if ((pkey & PKEY_LOW_15_MASK) == 0)
1329 goto bad;
1330
1331 /* The most likely matching pkey has index 'idx' */
1332 if (ingress_pkey_matches_entry(pkey, ppd->pkeys[idx]))
1333 return 0;
1334
1335 /* no match - try the whole table */
1336 if (!ingress_pkey_table_search(ppd, pkey))
1337 return 0;
1338
1339bad:
1340 ingress_pkey_table_fail(ppd, pkey, slid);
1341 return 1;
1342}
1343
1344/*
1345 * rcv_pkey_check - Return 0 if the ingress pkey is valid, return 1
1346 * otherwise. It only ensures pkey is vlid for QP0. This function
1347 * should be called on the data path instead of ingress_pkey_check
1348 * as on data path, pkey check is done by HW (except for QP0).
1349 */
1350static inline int rcv_pkey_check(struct hfi1_pportdata *ppd, u16 pkey,
1351 u8 sc5, u16 slid)
1352{
1353 if (!(ppd->part_enforce & HFI1_PART_ENFORCE_IN))
1354 return 0;
1355
1356 /* If SC15, pkey[0:14] must be 0x7fff */
1357 if ((sc5 == 0xf) && ((pkey & PKEY_LOW_15_MASK) != PKEY_LOW_15_MASK))
1358 goto bad;
1359
1360 return 0;
1361bad:
1362 ingress_pkey_table_fail(ppd, pkey, slid);
1363 return 1;
1364}
1365
1366/* MTU handling */
1367
1368/* MTU enumeration, 256-4k match IB */
1369#define OPA_MTU_0 0
1370#define OPA_MTU_256 1
1371#define OPA_MTU_512 2
1372#define OPA_MTU_1024 3
1373#define OPA_MTU_2048 4
1374#define OPA_MTU_4096 5
1375
1376u32 lrh_max_header_bytes(struct hfi1_devdata *dd);
1377int mtu_to_enum(u32 mtu, int default_if_bad);
1378u16 enum_to_mtu(int);
1379static inline int valid_ib_mtu(unsigned int mtu)
1380{
1381 return mtu == 256 || mtu == 512 ||
1382 mtu == 1024 || mtu == 2048 ||
1383 mtu == 4096;
1384}
1385static inline int valid_opa_max_mtu(unsigned int mtu)
1386{
1387 return mtu >= 2048 &&
1388 (valid_ib_mtu(mtu) || mtu == 8192 || mtu == 10240);
1389}
1390
1391int set_mtu(struct hfi1_pportdata *);
1392
1393int hfi1_set_lid(struct hfi1_pportdata *, u32, u8);
1394void hfi1_disable_after_error(struct hfi1_devdata *);
1395int hfi1_set_uevent_bits(struct hfi1_pportdata *, const int);
1396int hfi1_rcvbuf_validate(u32, u8, u16 *);
1397
1398int fm_get_table(struct hfi1_pportdata *, int, void *);
1399int fm_set_table(struct hfi1_pportdata *, int, void *);
1400
1401void set_up_vl15(struct hfi1_devdata *dd, u8 vau, u16 vl15buf);
1402void reset_link_credits(struct hfi1_devdata *dd);
1403void assign_remote_cm_au_table(struct hfi1_devdata *dd, u8 vcu);
1404
1405int snoop_recv_handler(struct hfi1_packet *packet);
d46e5144
DD
1406int snoop_send_dma_handler(struct hfi1_qp *qp, struct hfi1_pkt_state *ps,
1407 u64 pbc);
1408int snoop_send_pio_handler(struct hfi1_qp *qp, struct hfi1_pkt_state *ps,
1409 u64 pbc);
77241056
MM
1410void snoop_inline_pio_send(struct hfi1_devdata *dd, struct pio_buf *pbuf,
1411 u64 pbc, const void *from, size_t count);
1412
77241056
MM
1413static inline struct hfi1_devdata *dd_from_ppd(struct hfi1_pportdata *ppd)
1414{
1415 return ppd->dd;
1416}
1417
1418static inline struct hfi1_devdata *dd_from_dev(struct hfi1_ibdev *dev)
1419{
1420 return container_of(dev, struct hfi1_devdata, verbs_dev);
1421}
1422
1423static inline struct hfi1_devdata *dd_from_ibdev(struct ib_device *ibdev)
1424{
1425 return dd_from_dev(to_idev(ibdev));
1426}
1427
1428static inline struct hfi1_pportdata *ppd_from_ibp(struct hfi1_ibport *ibp)
1429{
1430 return container_of(ibp, struct hfi1_pportdata, ibport_data);
1431}
1432
1433static inline struct hfi1_ibport *to_iport(struct ib_device *ibdev, u8 port)
1434{
1435 struct hfi1_devdata *dd = dd_from_ibdev(ibdev);
1436 unsigned pidx = port - 1; /* IB number port from 1, hdw from 0 */
1437
1438 WARN_ON(pidx >= dd->num_pports);
1439 return &dd->pport[pidx].ibport_data;
1440}
1441
1442/*
1443 * Return the indexed PKEY from the port PKEY table.
1444 */
1445static inline u16 hfi1_get_pkey(struct hfi1_ibport *ibp, unsigned index)
1446{
1447 struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
1448 u16 ret;
1449
1450 if (index >= ARRAY_SIZE(ppd->pkeys))
1451 ret = 0;
1452 else
1453 ret = ppd->pkeys[index];
1454
1455 return ret;
1456}
1457
1458/*
1459 * Readers of cc_state must call get_cc_state() under rcu_read_lock().
1460 * Writers of cc_state must call get_cc_state() under cc_state_lock.
1461 */
1462static inline struct cc_state *get_cc_state(struct hfi1_pportdata *ppd)
1463{
1464 return rcu_dereference(ppd->cc_state);
1465}
1466
1467/*
1468 * values for dd->flags (_device_ related flags)
1469 */
1470#define HFI1_INITTED 0x1 /* chip and driver up and initted */
1471#define HFI1_PRESENT 0x2 /* chip accesses can be done */
1472#define HFI1_FROZEN 0x4 /* chip in SPC freeze */
1473#define HFI1_HAS_SDMA_TIMEOUT 0x8
1474#define HFI1_HAS_SEND_DMA 0x10 /* Supports Send DMA */
1475#define HFI1_FORCED_FREEZE 0x80 /* driver forced freeze mode */
1476#define HFI1_DO_INIT_ASIC 0x100 /* This device will init the ASIC */
1477
1478/* IB dword length mask in PBC (lower 11 bits); same for all chips */
1479#define HFI1_PBC_LENGTH_MASK ((1 << 11) - 1)
1480
1481
1482/* ctxt_flag bit offsets */
1483 /* context has been setup */
1484#define HFI1_CTXT_SETUP_DONE 1
1485 /* waiting for a packet to arrive */
1486#define HFI1_CTXT_WAITING_RCV 2
1487 /* master has not finished initializing */
1488#define HFI1_CTXT_MASTER_UNINIT 4
1489 /* waiting for an urgent packet to arrive */
1490#define HFI1_CTXT_WAITING_URG 5
1491
1492/* free up any allocated data at closes */
1493struct hfi1_devdata *hfi1_init_dd(struct pci_dev *,
1494 const struct pci_device_id *);
1495void hfi1_free_devdata(struct hfi1_devdata *);
1496void cc_state_reclaim(struct rcu_head *rcu);
1497struct hfi1_devdata *hfi1_alloc_devdata(struct pci_dev *pdev, size_t extra);
1498
1499/*
1500 * Set LED override, only the two LSBs have "public" meaning, but
1501 * any non-zero value substitutes them for the Link and LinkTrain
1502 * LED states.
1503 */
1504#define HFI1_LED_PHYS 1 /* Physical (linktraining) GREEN LED */
1505#define HFI1_LED_LOG 2 /* Logical (link) YELLOW LED */
1506void hfi1_set_led_override(struct hfi1_pportdata *ppd, unsigned int val);
1507
1508#define HFI1_CREDIT_RETURN_RATE (100)
1509
1510/*
1511 * The number of words for the KDETH protocol field. If this is
1512 * larger then the actual field used, then part of the payload
1513 * will be in the header.
1514 *
1515 * Optimally, we want this sized so that a typical case will
1516 * use full cache lines. The typical local KDETH header would
1517 * be:
1518 *
1519 * Bytes Field
1520 * 8 LRH
1521 * 12 BHT
1522 * ?? KDETH
1523 * 8 RHF
1524 * ---
1525 * 28 + KDETH
1526 *
1527 * For a 64-byte cache line, KDETH would need to be 36 bytes or 9 DWORDS
1528 */
1529#define DEFAULT_RCVHDRSIZE 9
1530
1531/*
1532 * Maximal header byte count:
1533 *
1534 * Bytes Field
1535 * 8 LRH
1536 * 40 GRH (optional)
1537 * 12 BTH
1538 * ?? KDETH
1539 * 8 RHF
1540 * ---
1541 * 68 + KDETH
1542 *
1543 * We also want to maintain a cache line alignment to assist DMA'ing
1544 * of the header bytes. Round up to a good size.
1545 */
1546#define DEFAULT_RCVHDR_ENTSIZE 32
1547
1548int hfi1_get_user_pages(unsigned long, size_t, struct page **);
1549void hfi1_release_user_pages(struct page **, size_t);
1550
1551static inline void clear_rcvhdrtail(const struct hfi1_ctxtdata *rcd)
1552{
1553 *((u64 *) rcd->rcvhdrtail_kvaddr) = 0ULL;
1554}
1555
1556static inline u32 get_rcvhdrtail(const struct hfi1_ctxtdata *rcd)
1557{
1558 /*
1559 * volatile because it's a DMA target from the chip, routine is
1560 * inlined, and don't want register caching or reordering.
1561 */
1562 return (u32) le64_to_cpu(*rcd->rcvhdrtail_kvaddr);
1563}
1564
1565/*
1566 * sysfs interface.
1567 */
1568
1569extern const char ib_hfi1_version[];
1570
1571int hfi1_device_create(struct hfi1_devdata *);
1572void hfi1_device_remove(struct hfi1_devdata *);
1573
1574int hfi1_create_port_files(struct ib_device *ibdev, u8 port_num,
1575 struct kobject *kobj);
1576int hfi1_verbs_register_sysfs(struct hfi1_devdata *);
1577void hfi1_verbs_unregister_sysfs(struct hfi1_devdata *);
1578/* Hook for sysfs read of QSFP */
1579int qsfp_dump(struct hfi1_pportdata *ppd, char *buf, int len);
1580
1581int hfi1_pcie_init(struct pci_dev *, const struct pci_device_id *);
1582void hfi1_pcie_cleanup(struct pci_dev *);
1583int hfi1_pcie_ddinit(struct hfi1_devdata *, struct pci_dev *,
1584 const struct pci_device_id *);
1585void hfi1_pcie_ddcleanup(struct hfi1_devdata *);
1586void hfi1_pcie_flr(struct hfi1_devdata *);
1587int pcie_speeds(struct hfi1_devdata *);
1588void request_msix(struct hfi1_devdata *, u32 *, struct hfi1_msix_entry *);
1589void hfi1_enable_intx(struct pci_dev *);
77241056
MM
1590void restore_pci_variables(struct hfi1_devdata *dd);
1591int do_pcie_gen3_transition(struct hfi1_devdata *dd);
1592int parse_platform_config(struct hfi1_devdata *dd);
1593int get_platform_config_field(struct hfi1_devdata *dd,
1594 enum platform_config_table_type_encoding table_type,
1595 int table_index, int field_index, u32 *data, u32 len);
1596
1597dma_addr_t hfi1_map_page(struct pci_dev *, struct page *, unsigned long,
1598 size_t, int);
1599const char *get_unit_name(int unit);
1600
1601/*
1602 * Flush write combining store buffers (if present) and perform a write
1603 * barrier.
1604 */
1605static inline void flush_wc(void)
1606{
1607 asm volatile("sfence" : : : "memory");
1608}
1609
1610void handle_eflags(struct hfi1_packet *packet);
1611int process_receive_ib(struct hfi1_packet *packet);
1612int process_receive_bypass(struct hfi1_packet *packet);
1613int process_receive_error(struct hfi1_packet *packet);
1614int kdeth_process_expected(struct hfi1_packet *packet);
1615int kdeth_process_eager(struct hfi1_packet *packet);
1616int process_receive_invalid(struct hfi1_packet *packet);
1617
1618extern rhf_rcv_function_ptr snoop_rhf_rcv_functions[8];
1619
1620void update_sge(struct hfi1_sge_state *ss, u32 length);
1621
1622/* global module parameter variables */
1623extern unsigned int hfi1_max_mtu;
1624extern unsigned int hfi1_cu;
1625extern unsigned int user_credit_return_threshold;
1626extern uint num_rcv_contexts;
1627extern unsigned n_krcvqs;
1628extern u8 krcvqs[];
1629extern int krcvqsset;
1630extern uint kdeth_qp;
1631extern uint loopback;
1632extern uint quick_linkup;
1633extern uint rcv_intr_timeout;
1634extern uint rcv_intr_count;
1635extern uint rcv_intr_dynamic;
1636extern ushort link_crc_mask;
1637
1638extern struct mutex hfi1_mutex;
1639
1640/* Number of seconds before our card status check... */
1641#define STATUS_TIMEOUT 60
1642
1643#define DRIVER_NAME "hfi1"
1644#define HFI1_USER_MINOR_BASE 0
1645#define HFI1_TRACE_MINOR 127
1646#define HFI1_DIAGPKT_MINOR 128
1647#define HFI1_DIAG_MINOR_BASE 129
1648#define HFI1_SNOOP_CAPTURE_BASE 200
1649#define HFI1_NMINORS 255
1650
1651#define PCI_VENDOR_ID_INTEL 0x8086
1652#define PCI_DEVICE_ID_INTEL0 0x24f0
1653#define PCI_DEVICE_ID_INTEL1 0x24f1
1654
1655#define HFI1_PKT_USER_SC_INTEGRITY \
1656 (SEND_CTXT_CHECK_ENABLE_DISALLOW_NON_KDETH_PACKETS_SMASK \
1657 | SEND_CTXT_CHECK_ENABLE_DISALLOW_BYPASS_SMASK \
1658 | SEND_CTXT_CHECK_ENABLE_DISALLOW_GRH_SMASK)
1659
1660#define HFI1_PKT_KERNEL_SC_INTEGRITY \
1661 (SEND_CTXT_CHECK_ENABLE_DISALLOW_KDETH_PACKETS_SMASK)
1662
1663static inline u64 hfi1_pkt_default_send_ctxt_mask(struct hfi1_devdata *dd,
1664 u16 ctxt_type)
1665{
1666 u64 base_sc_integrity =
1667 SEND_CTXT_CHECK_ENABLE_DISALLOW_BYPASS_BAD_PKT_LEN_SMASK
1668 | SEND_CTXT_CHECK_ENABLE_DISALLOW_PBC_STATIC_RATE_CONTROL_SMASK
1669 | SEND_CTXT_CHECK_ENABLE_DISALLOW_TOO_LONG_BYPASS_PACKETS_SMASK
1670 | SEND_CTXT_CHECK_ENABLE_DISALLOW_TOO_LONG_IB_PACKETS_SMASK
1671 | SEND_CTXT_CHECK_ENABLE_DISALLOW_BAD_PKT_LEN_SMASK
1672 | SEND_CTXT_CHECK_ENABLE_DISALLOW_PBC_TEST_SMASK
1673 | SEND_CTXT_CHECK_ENABLE_DISALLOW_TOO_SMALL_BYPASS_PACKETS_SMASK
1674 | SEND_CTXT_CHECK_ENABLE_DISALLOW_TOO_SMALL_IB_PACKETS_SMASK
1675 | SEND_CTXT_CHECK_ENABLE_DISALLOW_RAW_IPV6_SMASK
1676 | SEND_CTXT_CHECK_ENABLE_DISALLOW_RAW_SMASK
1677 | SEND_CTXT_CHECK_ENABLE_CHECK_BYPASS_VL_MAPPING_SMASK
1678 | SEND_CTXT_CHECK_ENABLE_CHECK_VL_MAPPING_SMASK
1679 | SEND_CTXT_CHECK_ENABLE_CHECK_OPCODE_SMASK
1680 | SEND_CTXT_CHECK_ENABLE_CHECK_SLID_SMASK
1681 | SEND_CTXT_CHECK_ENABLE_CHECK_JOB_KEY_SMASK
1682 | SEND_CTXT_CHECK_ENABLE_CHECK_VL_SMASK
1683 | SEND_CTXT_CHECK_ENABLE_CHECK_ENABLE_SMASK;
1684
1685 if (ctxt_type == SC_USER)
1686 base_sc_integrity |= HFI1_PKT_USER_SC_INTEGRITY;
1687 else
1688 base_sc_integrity |= HFI1_PKT_KERNEL_SC_INTEGRITY;
1689
1690 if (is_a0(dd))
1691 /* turn off send-side job key checks - A0 erratum */
1692 return base_sc_integrity &
1693 ~SEND_CTXT_CHECK_ENABLE_CHECK_JOB_KEY_SMASK;
1694 return base_sc_integrity;
1695}
1696
1697static inline u64 hfi1_pkt_base_sdma_integrity(struct hfi1_devdata *dd)
1698{
1699 u64 base_sdma_integrity =
1700 SEND_DMA_CHECK_ENABLE_DISALLOW_BYPASS_BAD_PKT_LEN_SMASK
1701 | SEND_DMA_CHECK_ENABLE_DISALLOW_PBC_STATIC_RATE_CONTROL_SMASK
1702 | SEND_DMA_CHECK_ENABLE_DISALLOW_TOO_LONG_BYPASS_PACKETS_SMASK
1703 | SEND_DMA_CHECK_ENABLE_DISALLOW_TOO_LONG_IB_PACKETS_SMASK
1704 | SEND_DMA_CHECK_ENABLE_DISALLOW_BAD_PKT_LEN_SMASK
1705 | SEND_DMA_CHECK_ENABLE_DISALLOW_TOO_SMALL_BYPASS_PACKETS_SMASK
1706 | SEND_DMA_CHECK_ENABLE_DISALLOW_TOO_SMALL_IB_PACKETS_SMASK
1707 | SEND_DMA_CHECK_ENABLE_DISALLOW_RAW_IPV6_SMASK
1708 | SEND_DMA_CHECK_ENABLE_DISALLOW_RAW_SMASK
1709 | SEND_DMA_CHECK_ENABLE_CHECK_BYPASS_VL_MAPPING_SMASK
1710 | SEND_DMA_CHECK_ENABLE_CHECK_VL_MAPPING_SMASK
1711 | SEND_DMA_CHECK_ENABLE_CHECK_OPCODE_SMASK
1712 | SEND_DMA_CHECK_ENABLE_CHECK_SLID_SMASK
1713 | SEND_DMA_CHECK_ENABLE_CHECK_JOB_KEY_SMASK
1714 | SEND_DMA_CHECK_ENABLE_CHECK_VL_SMASK
1715 | SEND_DMA_CHECK_ENABLE_CHECK_ENABLE_SMASK;
1716
1717 if (is_a0(dd))
1718 /* turn off send-side job key checks - A0 erratum */
1719 return base_sdma_integrity &
1720 ~SEND_DMA_CHECK_ENABLE_CHECK_JOB_KEY_SMASK;
1721 return base_sdma_integrity;
1722}
1723
1724/*
1725 * hfi1_early_err is used (only!) to print early errors before devdata is
1726 * allocated, or when dd->pcidev may not be valid, and at the tail end of
1727 * cleanup when devdata may have been freed, etc. hfi1_dev_porterr is
1728 * the same as dd_dev_err, but is used when the message really needs
1729 * the IB port# to be definitive as to what's happening..
1730 */
1731#define hfi1_early_err(dev, fmt, ...) \
1732 dev_err(dev, fmt, ##__VA_ARGS__)
1733
1734#define hfi1_early_info(dev, fmt, ...) \
1735 dev_info(dev, fmt, ##__VA_ARGS__)
1736
1737#define dd_dev_emerg(dd, fmt, ...) \
1738 dev_emerg(&(dd)->pcidev->dev, "%s: " fmt, \
1739 get_unit_name((dd)->unit), ##__VA_ARGS__)
1740#define dd_dev_err(dd, fmt, ...) \
1741 dev_err(&(dd)->pcidev->dev, "%s: " fmt, \
1742 get_unit_name((dd)->unit), ##__VA_ARGS__)
1743#define dd_dev_warn(dd, fmt, ...) \
1744 dev_warn(&(dd)->pcidev->dev, "%s: " fmt, \
1745 get_unit_name((dd)->unit), ##__VA_ARGS__)
1746
1747#define dd_dev_warn_ratelimited(dd, fmt, ...) \
1748 dev_warn_ratelimited(&(dd)->pcidev->dev, "%s: " fmt, \
1749 get_unit_name((dd)->unit), ##__VA_ARGS__)
1750
1751#define dd_dev_info(dd, fmt, ...) \
1752 dev_info(&(dd)->pcidev->dev, "%s: " fmt, \
1753 get_unit_name((dd)->unit), ##__VA_ARGS__)
1754
1755#define hfi1_dev_porterr(dd, port, fmt, ...) \
1756 dev_err(&(dd)->pcidev->dev, "%s: IB%u:%u " fmt, \
1757 get_unit_name((dd)->unit), (dd)->unit, (port), \
1758 ##__VA_ARGS__)
1759
1760/*
1761 * this is used for formatting hw error messages...
1762 */
1763struct hfi1_hwerror_msgs {
1764 u64 mask;
1765 const char *msg;
1766 size_t sz;
1767};
1768
1769/* in intr.c... */
1770void hfi1_format_hwerrors(u64 hwerrs,
1771 const struct hfi1_hwerror_msgs *hwerrmsgs,
1772 size_t nhwerrmsgs, char *msg, size_t lmsg);
1773
1774#define USER_OPCODE_CHECK_VAL 0xC0
1775#define USER_OPCODE_CHECK_MASK 0xC0
1776#define OPCODE_CHECK_VAL_DISABLED 0x0
1777#define OPCODE_CHECK_MASK_DISABLED 0x0
1778
1779static inline void hfi1_reset_cpu_counters(struct hfi1_devdata *dd)
1780{
1781 struct hfi1_pportdata *ppd;
1782 int i;
1783
1784 dd->z_int_counter = get_all_cpu_total(dd->int_counter);
1785 dd->z_rcv_limit = get_all_cpu_total(dd->rcv_limit);
1786
1787 ppd = (struct hfi1_pportdata *)(dd + 1);
1788 for (i = 0; i < dd->num_pports; i++, ppd++) {
1789 ppd->ibport_data.z_rc_acks =
1790 get_all_cpu_total(ppd->ibport_data.rc_acks);
1791 ppd->ibport_data.z_rc_qacks =
1792 get_all_cpu_total(ppd->ibport_data.rc_qacks);
1793 }
1794}
1795
1796/* Control LED state */
1797static inline void setextled(struct hfi1_devdata *dd, u32 on)
1798{
1799 if (on)
1800 write_csr(dd, DCC_CFG_LED_CNTRL, 0x1F);
1801 else
1802 write_csr(dd, DCC_CFG_LED_CNTRL, 0x10);
1803}
1804
1805int hfi1_tempsense_rd(struct hfi1_devdata *dd, struct hfi1_temp *temp);
1806
1807#endif /* _HFI1_KERNEL_H */