blob: 728ed457e447e98a8ea81711f51d43d69a16d414 [file] [log] [blame]
Mike Marciniszyn77241052015-07-30 15:17:43 -04001#ifndef _HFI1_KERNEL_H
2#define _HFI1_KERNEL_H
3/*
Vishwanathapura, Niranjanad4829ea2017-04-12 20:29:28 -07004 * Copyright(c) 2015-2017 Intel Corporation.
Mike Marciniszyn77241052015-07-30 15:17:43 -04005 *
6 * This file is provided under a dual BSD/GPLv2 license. When using or
7 * redistributing this file, you may do so under either license.
8 *
9 * GPL LICENSE SUMMARY
10 *
Mike Marciniszyn77241052015-07-30 15:17:43 -040011 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of version 2 of the GNU General Public License as
13 * published by the Free Software Foundation.
14 *
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
19 *
20 * BSD LICENSE
21 *
Mike Marciniszyn77241052015-07-30 15:17:43 -040022 * Redistribution and use in source and binary forms, with or without
23 * modification, are permitted provided that the following conditions
24 * are met:
25 *
26 * - Redistributions of source code must retain the above copyright
27 * notice, this list of conditions and the following disclaimer.
28 * - Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in
30 * the documentation and/or other materials provided with the
31 * distribution.
32 * - Neither the name of Intel Corporation nor the names of its
33 * contributors may be used to endorse or promote products derived
34 * from this software without specific prior written permission.
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
37 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
38 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
39 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
40 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
43 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
44 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
45 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
46 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
47 *
48 */
49
50#include <linux/interrupt.h>
51#include <linux/pci.h>
52#include <linux/dma-mapping.h>
53#include <linux/mutex.h>
54#include <linux/list.h>
55#include <linux/scatterlist.h>
56#include <linux/slab.h>
Vishwanathapura, Niranjana22807402017-04-12 20:29:29 -070057#include <linux/idr.h>
Mike Marciniszyn77241052015-07-30 15:17:43 -040058#include <linux/io.h>
59#include <linux/fs.h>
60#include <linux/completion.h>
61#include <linux/kref.h>
62#include <linux/sched.h>
63#include <linux/cdev.h>
64#include <linux/delay.h>
65#include <linux/kthread.h>
Dean Luickdba715f2016-07-06 17:28:52 -040066#include <linux/i2c.h>
67#include <linux/i2c-algo-bit.h>
Mike Marciniszyn261a4352016-09-06 04:35:05 -070068#include <rdma/ib_hdrs.h>
Tadeusz Struk0cb2aa62016-09-25 07:44:23 -070069#include <linux/rhashtable.h>
Vishwanathapura, Niranjana22807402017-04-12 20:29:29 -070070#include <linux/netdevice.h>
Dennis Dalessandroec3f2c12016-01-19 14:41:33 -080071#include <rdma/rdma_vt.h>
Mike Marciniszyn77241052015-07-30 15:17:43 -040072
73#include "chip_registers.h"
74#include "common.h"
75#include "verbs.h"
76#include "pio.h"
77#include "chip.h"
78#include "mad.h"
79#include "qsfp.h"
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -080080#include "platform.h"
Mitko Haralanov957558c2016-02-03 14:33:40 -080081#include "affinity.h"
Mike Marciniszyn77241052015-07-30 15:17:43 -040082
83/* bumped 1 from s/w major version of TrueScale */
84#define HFI1_CHIP_VERS_MAJ 3U
85
86/* don't care about this except printing */
87#define HFI1_CHIP_VERS_MIN 0U
88
89/* The Organization Unique Identifier (Mfg code), and its position in GUID */
90#define HFI1_OUI 0x001175
91#define HFI1_OUI_LSB 40
92
93#define DROP_PACKET_OFF 0
94#define DROP_PACKET_ON 1
95
96extern unsigned long hfi1_cap_mask;
97#define HFI1_CAP_KGET_MASK(mask, cap) ((mask) & HFI1_CAP_##cap)
98#define HFI1_CAP_UGET_MASK(mask, cap) \
99 (((mask) >> HFI1_CAP_USER_SHIFT) & HFI1_CAP_##cap)
100#define HFI1_CAP_KGET(cap) (HFI1_CAP_KGET_MASK(hfi1_cap_mask, cap))
101#define HFI1_CAP_UGET(cap) (HFI1_CAP_UGET_MASK(hfi1_cap_mask, cap))
102#define HFI1_CAP_IS_KSET(cap) (!!HFI1_CAP_KGET(cap))
103#define HFI1_CAP_IS_USET(cap) (!!HFI1_CAP_UGET(cap))
104#define HFI1_MISC_GET() ((hfi1_cap_mask >> HFI1_CAP_MISC_SHIFT) & \
105 HFI1_CAP_MISC_MASK)
Bryan Morgana9c05e32016-02-03 14:30:49 -0800106/* Offline Disabled Reason is 4-bits */
107#define HFI1_ODR_MASK(rsn) ((rsn) & OPA_PI_MASK_OFFLINE_REASON)
Mike Marciniszyn77241052015-07-30 15:17:43 -0400108
109/*
Niranjana Vishwanathapura82c26112015-11-11 00:35:19 -0500110 * Control context is always 0 and handles the error packets.
111 * It also handles the VL15 and multicast packets.
112 */
113#define HFI1_CTRL_CTXT 0
114
115/*
Joel Rosenzweig2c5b5212015-12-01 15:38:19 -0500116 * Driver context will store software counters for each of the events
117 * associated with these status registers
118 */
119#define NUM_CCE_ERR_STATUS_COUNTERS 41
120#define NUM_RCV_ERR_STATUS_COUNTERS 64
121#define NUM_MISC_ERR_STATUS_COUNTERS 13
122#define NUM_SEND_PIO_ERR_STATUS_COUNTERS 36
123#define NUM_SEND_DMA_ERR_STATUS_COUNTERS 4
124#define NUM_SEND_EGRESS_ERR_STATUS_COUNTERS 64
125#define NUM_SEND_ERR_STATUS_COUNTERS 3
126#define NUM_SEND_CTXT_ERR_STATUS_COUNTERS 5
127#define NUM_SEND_DMA_ENG_ERR_STATUS_COUNTERS 24
128
129/*
Mike Marciniszyn77241052015-07-30 15:17:43 -0400130 * per driver stats, either not device nor port-specific, or
131 * summed over all of the devices and ports.
132 * They are described by name via ipathfs filesystem, so layout
133 * and number of elements can change without breaking compatibility.
134 * If members are added or deleted hfi1_statnames[] in debugfs.c must
135 * change to match.
136 */
137struct hfi1_ib_stats {
138 __u64 sps_ints; /* number of interrupts handled */
139 __u64 sps_errints; /* number of error interrupts */
140 __u64 sps_txerrs; /* tx-related packet errors */
141 __u64 sps_rcverrs; /* non-crc rcv packet errors */
142 __u64 sps_hwerrs; /* hardware errors reported (parity, etc.) */
143 __u64 sps_nopiobufs; /* no pio bufs avail from kernel */
144 __u64 sps_ctxts; /* number of contexts currently open */
145 __u64 sps_lenerrs; /* number of kernel packets where RHF != LRH len */
146 __u64 sps_buffull;
147 __u64 sps_hdrfull;
148};
149
150extern struct hfi1_ib_stats hfi1_stats;
151extern const struct pci_error_handlers hfi1_pci_err_handler;
152
153/*
154 * First-cut criterion for "device is active" is
155 * two thousand dwords combined Tx, Rx traffic per
156 * 5-second interval. SMA packets are 64 dwords,
157 * and occur "a few per second", presumably each way.
158 */
159#define HFI1_TRAFFIC_ACTIVE_THRESHOLD (2000)
160
161/*
162 * Below contains all data related to a single context (formerly called port).
163 */
164
165#ifdef CONFIG_DEBUG_FS
166struct hfi1_opcode_stats_perctx;
167#endif
168
Mike Marciniszyn77241052015-07-30 15:17:43 -0400169struct ctxt_eager_bufs {
170 ssize_t size; /* total size of eager buffers */
171 u32 count; /* size of buffers array */
172 u32 numbufs; /* number of buffers allocated */
173 u32 alloced; /* number of rcvarray entries used */
174 u32 rcvtid_size; /* size of each eager rcv tid */
175 u32 threshold; /* head update threshold */
176 struct eager_buffer {
177 void *addr;
Tymoteusz Kielan60368182016-09-06 04:35:54 -0700178 dma_addr_t dma;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400179 ssize_t len;
180 } *buffers;
181 struct {
182 void *addr;
Tymoteusz Kielan60368182016-09-06 04:35:54 -0700183 dma_addr_t dma;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400184 } *rcvtids;
185};
186
Mitko Haralanova86cd352016-02-05 11:57:49 -0500187struct exp_tid_set {
188 struct list_head list;
189 u32 count;
190};
191
Mike Marciniszyn77241052015-07-30 15:17:43 -0400192struct hfi1_ctxtdata {
193 /* shadow the ctxt's RcvCtrl register */
194 u64 rcvctrl;
195 /* rcvhdrq base, needs mmap before useful */
196 void *rcvhdrq;
197 /* kernel virtual address where hdrqtail is updated */
198 volatile __le64 *rcvhdrtail_kvaddr;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400199 /* when waiting for rcv or pioavail */
200 wait_queue_head_t wait;
201 /* rcvhdrq size (for freeing) */
202 size_t rcvhdrq_size;
203 /* number of rcvhdrq entries */
204 u16 rcvhdrq_cnt;
205 /* size of each of the rcvhdrq entries */
206 u16 rcvhdrqentsize;
207 /* mmap of hdrq, must fit in 44 bits */
Tymoteusz Kielan60368182016-09-06 04:35:54 -0700208 dma_addr_t rcvhdrq_dma;
209 dma_addr_t rcvhdrqtailaddr_dma;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400210 struct ctxt_eager_bufs egrbufs;
211 /* this receive context's assigned PIO ACK send context */
212 struct send_context *sc;
213
214 /* dynamic receive available interrupt timeout */
215 u32 rcvavail_timeout;
Michael J. Ruhlf683c802017-06-09 16:00:19 -0700216 /* Reference count the base context usage */
217 struct kref kref;
218
Michael J. Ruhl9b60d2c2017-05-04 05:15:09 -0700219 /* Device context index */
Michael J. Ruhle6f76222017-07-24 07:45:55 -0700220 u16 ctxt;
Michael J. Ruhl9b60d2c2017-05-04 05:15:09 -0700221 /*
222 * non-zero if ctxt can be shared, and defines the maximum number of
Michael J. Ruhl8737ce92017-05-04 05:15:15 -0700223 * sub-contexts for this device context.
Michael J. Ruhl9b60d2c2017-05-04 05:15:09 -0700224 */
Mike Marciniszyn77241052015-07-30 15:17:43 -0400225 u16 subctxt_cnt;
226 /* non-zero if ctxt is being shared. */
227 u16 subctxt_id;
228 u8 uuid[16];
229 /* job key */
230 u16 jkey;
231 /* number of RcvArray groups for this context. */
232 u32 rcv_array_groups;
233 /* index of first eager TID entry. */
234 u32 eager_base;
235 /* number of expected TID entries */
236 u32 expected_count;
237 /* index of first expected TID entry. */
238 u32 expected_base;
Mitko Haralanova86cd352016-02-05 11:57:49 -0500239
240 struct exp_tid_set tid_group_list;
241 struct exp_tid_set tid_used_list;
242 struct exp_tid_set tid_full_list;
243
Mike Marciniszyn77241052015-07-30 15:17:43 -0400244 /* lock protecting all Expected TID data */
Mitko Haralanov463e6eb2016-02-05 11:57:53 -0500245 struct mutex exp_lock;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400246 /* per-context configuration flags */
Dean Luickbdf77522016-07-28 15:21:13 -0400247 unsigned long flags;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400248 /* per-context event flags for fileops/intr communication */
249 unsigned long event_flags;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400250 /* total number of polled urgent packets */
251 u32 urgent;
252 /* saved total number of polled urgent packets for poll edge trigger */
253 u32 urgent_poll;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400254 /* same size as task_struct .comm[], command that opened context */
Geliang Tangc3af8a22015-10-08 22:04:26 -0700255 char comm[TASK_COMM_LEN];
Mike Marciniszyn77241052015-07-30 15:17:43 -0400256 /* so file ops can get at unit */
257 struct hfi1_devdata *dd;
258 /* so functions that need physical port can get it easily */
259 struct hfi1_pportdata *ppd;
Vishwanathapura, Niranjana22807402017-04-12 20:29:29 -0700260 /* associated msix interrupt */
261 u32 msix_intr;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400262 /* A page of memory for rcvhdrhead, rcvegrhead, rcvegrtail * N */
263 void *subctxt_uregbase;
264 /* An array of pages for the eager receive buffers * N */
265 void *subctxt_rcvegrbuf;
266 /* An array of pages for the eager header queue entries * N */
267 void *subctxt_rcvhdr_base;
Michael J. Ruhl8737ce92017-05-04 05:15:15 -0700268 /* Bitmask of in use context(s) */
269 DECLARE_BITMAP(in_use_ctxts, HFI1_MAX_SHARED_CTXTS);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400270 /* The version of the library which opened this ctxt */
271 u32 userversion;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400272 /* Type of packets or conditions we want to poll for */
273 u16 poll_type;
274 /* receive packet sequence counter */
275 u8 seq_cnt;
276 u8 redirect_seq_cnt;
277 /* ctxt rcvhdrq head offset */
278 u32 head;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400279 /* 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;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400287
Ashutosh Dixitaffa48d2016-02-03 14:33:06 -0800288 /* Is ASPM interrupt supported for this context */
289 bool aspm_intr_supported;
290 /* ASPM state (enabled/disabled) for this context */
291 bool aspm_enabled;
292 /* Timer for re-enabling ASPM if interrupt activity quietens down */
293 struct timer_list aspm_timer;
294 /* Lock to serialize between intr, timer intr and user threads */
295 spinlock_t aspm_lock;
296 /* Is ASPM processing enabled for this context (in intr context) */
297 bool aspm_intr_enable;
298 /* Last interrupt timestamp */
299 ktime_t aspm_ts_last_intr;
300 /* Last timestamp at which we scheduled a timer for this context */
301 ktime_t aspm_ts_timer_sched;
302
Mike Marciniszyn77241052015-07-30 15:17:43 -0400303 /*
304 * The interrupt handler for a particular receive context can vary
305 * throughout it's lifetime. This is not a lock protected data member so
306 * it must be updated atomically and the prev and new value must always
307 * be valid. Worst case is we process an extra interrupt and up to 64
308 * packets with the wrong interrupt handler.
309 */
Dean Luickf4f30031c2015-10-26 10:28:44 -0400310 int (*do_interrupt)(struct hfi1_ctxtdata *rcd, int threaded);
Vishwanathapura, Niranjanad4829ea2017-04-12 20:29:28 -0700311
312 /* Indicates that this is vnic context */
313 bool is_vnic;
314
315 /* vnic queue index this context is mapped to */
316 u8 vnic_q_idx;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400317};
318
319/*
320 * Represents a single packet at a high level. Put commonly computed things in
321 * here so we do not have to keep doing them over and over. The rule of thumb is
322 * if something is used one time to derive some value, store that something in
323 * here. If it is used multiple times, then store the result of that derivation
324 * in here.
325 */
326struct hfi1_packet {
327 void *ebuf;
328 void *hdr;
329 struct hfi1_ctxtdata *rcd;
330 __le32 *rhf_addr;
Dennis Dalessandro895420d2016-01-19 14:42:28 -0800331 struct rvt_qp *qp;
Mike Marciniszyn261a4352016-09-06 04:35:05 -0700332 struct ib_other_headers *ohdr;
Don Hiatt90397462017-05-12 09:20:20 -0700333 struct ib_grh *grh;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400334 u64 rhf;
335 u32 maxcnt;
336 u32 rhqoff;
Don Hiatt90397462017-05-12 09:20:20 -0700337 u32 dlid;
338 u32 slid;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400339 u16 tlen;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400340 s16 etail;
Sebastian Sanchez76327622017-02-08 05:26:49 -0800341 u8 hlen;
342 u8 numpkt;
343 u8 rsize;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400344 u8 updegr;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400345 u8 etype;
Don Hiatt90397462017-05-12 09:20:20 -0700346 u8 extra_byte;
347 u8 pad;
348 u8 sc;
349 u8 sl;
350 u8 opcode;
351 bool becn;
352 bool fecn;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400353};
354
Dennis Dalessandro895420d2016-01-19 14:42:28 -0800355struct rvt_sge_state;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400356
357/*
358 * Get/Set IB link-level config parameters for f_get/set_ib_cfg()
359 * Mostly for MADs that set or query link parameters, also ipath
360 * config interfaces
361 */
362#define HFI1_IB_CFG_LIDLMC 0 /* LID (LS16b) and Mask (MS16b) */
363#define HFI1_IB_CFG_LWID_DG_ENB 1 /* allowed Link-width downgrade */
364#define HFI1_IB_CFG_LWID_ENB 2 /* allowed Link-width */
365#define HFI1_IB_CFG_LWID 3 /* currently active Link-width */
366#define HFI1_IB_CFG_SPD_ENB 4 /* allowed Link speeds */
367#define HFI1_IB_CFG_SPD 5 /* current Link spd */
368#define HFI1_IB_CFG_RXPOL_ENB 6 /* Auto-RX-polarity enable */
369#define HFI1_IB_CFG_LREV_ENB 7 /* Auto-Lane-reversal enable */
370#define HFI1_IB_CFG_LINKLATENCY 8 /* Link Latency (IB1.2 only) */
371#define HFI1_IB_CFG_HRTBT 9 /* IB heartbeat off/enable/auto; DDR/QDR only */
372#define HFI1_IB_CFG_OP_VLS 10 /* operational VLs */
373#define HFI1_IB_CFG_VL_HIGH_CAP 11 /* num of VL high priority weights */
374#define HFI1_IB_CFG_VL_LOW_CAP 12 /* num of VL low priority weights */
375#define HFI1_IB_CFG_OVERRUN_THRESH 13 /* IB overrun threshold */
376#define HFI1_IB_CFG_PHYERR_THRESH 14 /* IB PHY error threshold */
377#define HFI1_IB_CFG_LINKDEFAULT 15 /* IB link default (sleep/poll) */
378#define HFI1_IB_CFG_PKEYS 16 /* update partition keys */
379#define HFI1_IB_CFG_MTU 17 /* update MTU in IBC */
380#define HFI1_IB_CFG_VL_HIGH_LIMIT 19
381#define HFI1_IB_CFG_PMA_TICKS 20 /* PMA sample tick resolution */
382#define HFI1_IB_CFG_PORT 21 /* switch port we are connected to */
383
384/*
385 * HFI or Host Link States
386 *
387 * These describe the states the driver thinks the logical and physical
388 * states are in. Used as an argument to set_link_state(). Implemented
389 * as bits for easy multi-state checking. The actual state can only be
390 * one.
391 */
392#define __HLS_UP_INIT_BP 0
393#define __HLS_UP_ARMED_BP 1
394#define __HLS_UP_ACTIVE_BP 2
395#define __HLS_DN_DOWNDEF_BP 3 /* link down default */
396#define __HLS_DN_POLL_BP 4
397#define __HLS_DN_DISABLE_BP 5
398#define __HLS_DN_OFFLINE_BP 6
399#define __HLS_VERIFY_CAP_BP 7
400#define __HLS_GOING_UP_BP 8
401#define __HLS_GOING_OFFLINE_BP 9
402#define __HLS_LINK_COOLDOWN_BP 10
403
jubin.john@intel.com349ac712016-01-11 18:30:52 -0500404#define HLS_UP_INIT BIT(__HLS_UP_INIT_BP)
405#define HLS_UP_ARMED BIT(__HLS_UP_ARMED_BP)
406#define HLS_UP_ACTIVE BIT(__HLS_UP_ACTIVE_BP)
407#define HLS_DN_DOWNDEF BIT(__HLS_DN_DOWNDEF_BP) /* link down default */
408#define HLS_DN_POLL BIT(__HLS_DN_POLL_BP)
409#define HLS_DN_DISABLE BIT(__HLS_DN_DISABLE_BP)
410#define HLS_DN_OFFLINE BIT(__HLS_DN_OFFLINE_BP)
411#define HLS_VERIFY_CAP BIT(__HLS_VERIFY_CAP_BP)
412#define HLS_GOING_UP BIT(__HLS_GOING_UP_BP)
413#define HLS_GOING_OFFLINE BIT(__HLS_GOING_OFFLINE_BP)
414#define HLS_LINK_COOLDOWN BIT(__HLS_LINK_COOLDOWN_BP)
Mike Marciniszyn77241052015-07-30 15:17:43 -0400415
416#define HLS_UP (HLS_UP_INIT | HLS_UP_ARMED | HLS_UP_ACTIVE)
Easwar Hariharan0c7f77a2016-05-12 10:22:33 -0700417#define HLS_DOWN ~(HLS_UP)
Mike Marciniszyn77241052015-07-30 15:17:43 -0400418
419/* use this MTU size if none other is given */
Sebastian Sanchezef699e82016-04-12 11:17:09 -0700420#define HFI1_DEFAULT_ACTIVE_MTU 10240
Mike Marciniszyn77241052015-07-30 15:17:43 -0400421/* use this MTU size as the default maximum */
Sebastian Sanchezef699e82016-04-12 11:17:09 -0700422#define HFI1_DEFAULT_MAX_MTU 10240
Mike Marciniszyn77241052015-07-30 15:17:43 -0400423/* default partition key */
424#define DEFAULT_PKEY 0xffff
425
426/*
427 * Possible fabric manager config parameters for fm_{get,set}_table()
428 */
429#define FM_TBL_VL_HIGH_ARB 1 /* Get/set VL high prio weights */
430#define FM_TBL_VL_LOW_ARB 2 /* Get/set VL low prio weights */
431#define FM_TBL_BUFFER_CONTROL 3 /* Get/set Buffer Control */
432#define FM_TBL_SC2VLNT 4 /* Get/set SC->VLnt */
433#define FM_TBL_VL_PREEMPT_ELEMS 5 /* Get (no set) VL preempt elems */
434#define FM_TBL_VL_PREEMPT_MATRIX 6 /* Get (no set) VL preempt matrix */
435
436/*
437 * Possible "operations" for f_rcvctrl(ppd, op, ctxt)
438 * these are bits so they can be combined, e.g.
439 * HFI1_RCVCTRL_INTRAVAIL_ENB | HFI1_RCVCTRL_CTXT_ENB
440 */
441#define HFI1_RCVCTRL_TAILUPD_ENB 0x01
442#define HFI1_RCVCTRL_TAILUPD_DIS 0x02
443#define HFI1_RCVCTRL_CTXT_ENB 0x04
444#define HFI1_RCVCTRL_CTXT_DIS 0x08
445#define HFI1_RCVCTRL_INTRAVAIL_ENB 0x10
446#define HFI1_RCVCTRL_INTRAVAIL_DIS 0x20
447#define HFI1_RCVCTRL_PKEY_ENB 0x40 /* Note, default is enabled */
448#define HFI1_RCVCTRL_PKEY_DIS 0x80
449#define HFI1_RCVCTRL_TIDFLOW_ENB 0x0400
450#define HFI1_RCVCTRL_TIDFLOW_DIS 0x0800
451#define HFI1_RCVCTRL_ONE_PKT_EGR_ENB 0x1000
452#define HFI1_RCVCTRL_ONE_PKT_EGR_DIS 0x2000
453#define HFI1_RCVCTRL_NO_RHQ_DROP_ENB 0x4000
454#define HFI1_RCVCTRL_NO_RHQ_DROP_DIS 0x8000
455#define HFI1_RCVCTRL_NO_EGR_DROP_ENB 0x10000
456#define HFI1_RCVCTRL_NO_EGR_DROP_DIS 0x20000
457
458/* partition enforcement flags */
459#define HFI1_PART_ENFORCE_IN 0x1
460#define HFI1_PART_ENFORCE_OUT 0x2
461
462/* how often we check for synthetic counter wrap around */
Tadeusz Struk22546b72017-04-28 10:40:02 -0700463#define SYNTH_CNT_TIME 3
Mike Marciniszyn77241052015-07-30 15:17:43 -0400464
465/* Counter flags */
466#define CNTR_NORMAL 0x0 /* Normal counters, just read register */
467#define CNTR_SYNTH 0x1 /* Synthetic counters, saturate at all 1s */
468#define CNTR_DISABLED 0x2 /* Disable this counter */
469#define CNTR_32BIT 0x4 /* Simulate 64 bits for this counter */
470#define CNTR_VL 0x8 /* Per VL counter */
Vennila Megavannana699c6c2016-01-11 18:30:56 -0500471#define CNTR_SDMA 0x10
Mike Marciniszyn77241052015-07-30 15:17:43 -0400472#define CNTR_INVALID_VL -1 /* Specifies invalid VL */
473#define CNTR_MODE_W 0x0
474#define CNTR_MODE_R 0x1
475
476/* VLs Supported/Operational */
477#define HFI1_MIN_VLS_SUPPORTED 1
478#define HFI1_MAX_VLS_SUPPORTED 8
479
Jakub Pawlaka6cd5f02016-10-17 04:19:30 -0700480#define HFI1_GUIDS_PER_PORT 5
481#define HFI1_PORT_GUID_INDEX 0
482
Mike Marciniszyn77241052015-07-30 15:17:43 -0400483static inline void incr_cntr64(u64 *cntr)
484{
485 if (*cntr < (u64)-1LL)
486 (*cntr)++;
487}
488
489static inline void incr_cntr32(u32 *cntr)
490{
491 if (*cntr < (u32)-1LL)
492 (*cntr)++;
493}
494
495#define MAX_NAME_SIZE 64
496struct hfi1_msix_entry {
Mitko Haralanov957558c2016-02-03 14:33:40 -0800497 enum irq_type type;
Michael J. Ruhlbb7dde82017-05-26 05:35:31 -0700498 int irq;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400499 void *arg;
500 char name[MAX_NAME_SIZE];
Mitko Haralanov957558c2016-02-03 14:33:40 -0800501 cpumask_t mask;
Tadeusz Struk2d01c372016-09-25 07:44:37 -0700502 struct irq_affinity_notify notify;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400503};
504
505/* per-SL CCA information */
506struct cca_timer {
507 struct hrtimer hrtimer;
508 struct hfi1_pportdata *ppd; /* read-only */
509 int sl; /* read-only */
510 u16 ccti; /* read/write - current value of CCTI */
511};
512
513struct link_down_reason {
514 /*
515 * SMA-facing value. Should be set from .latest when
516 * HLS_UP_* -> HLS_DN_* transition actually occurs.
517 */
518 u8 sma;
519 u8 latest;
520};
521
522enum {
523 LO_PRIO_TABLE,
524 HI_PRIO_TABLE,
525 MAX_PRIO_TABLE
526};
527
528struct vl_arb_cache {
Jubin John6a14c5e2016-02-14 20:21:34 -0800529 /* protect vl arb cache */
Mike Marciniszyn77241052015-07-30 15:17:43 -0400530 spinlock_t lock;
531 struct ib_vl_weight_elem table[VL_ARB_TABLE_SIZE];
532};
533
534/*
535 * The structure below encapsulates data relevant to a physical IB Port.
536 * Current chips support only one such port, but the separation
537 * clarifies things a bit. Note that to conform to IB conventions,
538 * port-numbers are one-based. The first or only port is port1.
539 */
540struct hfi1_pportdata {
541 struct hfi1_ibport ibport_data;
542
543 struct hfi1_devdata *dd;
544 struct kobject pport_cc_kobj;
545 struct kobject sc2vl_kobj;
546 struct kobject sl2sc_kobj;
547 struct kobject vl2mtu_kobj;
548
Easwar Hariharan8ebd4cf2016-02-03 14:31:14 -0800549 /* PHY support */
Mike Marciniszyn77241052015-07-30 15:17:43 -0400550 struct qsfp_data qsfp_info;
Easwar Hariharanfe4d9242016-10-17 04:19:47 -0700551 /* Values for SI tuning of SerDes */
552 u32 port_type;
553 u32 tx_preset_eq;
554 u32 tx_preset_noeq;
555 u32 rx_preset;
556 u8 local_atten;
557 u8 remote_atten;
558 u8 default_atten;
559 u8 max_power_class;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400560
Jakub Pawlaka6cd5f02016-10-17 04:19:30 -0700561 /* GUIDs for this interface, in host order, guids[0] is a port guid */
562 u64 guids[HFI1_GUIDS_PER_PORT];
563
Mike Marciniszyn77241052015-07-30 15:17:43 -0400564 /* GUID for peer interface, in host order */
565 u64 neighbor_guid;
566
567 /* up or down physical link state */
568 u32 linkup;
569
570 /*
571 * this address is mapped read-only into user processes so they can
572 * get status cheaply, whenever they want. One qword of status per port
573 */
574 u64 *statusp;
575
576 /* SendDMA related entries */
577
578 struct workqueue_struct *hfi1_wq;
Sebastian Sanchez71d47002017-07-29 08:43:49 -0700579 struct workqueue_struct *link_wq;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400580
581 /* move out of interrupt context */
582 struct work_struct link_vc_work;
583 struct work_struct link_up_work;
584 struct work_struct link_down_work;
585 struct work_struct sma_message_work;
586 struct work_struct freeze_work;
587 struct work_struct link_downgrade_work;
588 struct work_struct link_bounce_work;
Dean Luick673b9752016-08-31 07:24:33 -0700589 struct delayed_work start_link_work;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400590 /* host link state variables */
591 struct mutex hls_lock;
592 u32 host_link_state;
593
Mike Marciniszyn77241052015-07-30 15:17:43 -0400594 /* these are the "32 bit" regs */
595
596 u32 ibmtu; /* The MTU programmed for this unit */
597 /*
598 * Current max size IB packet (in bytes) including IB headers, that
599 * we can send. Changes when ibmtu changes.
600 */
601 u32 ibmaxlen;
602 u32 current_egress_rate; /* units [10^6 bits/sec] */
603 /* LID programmed for this instance */
604 u16 lid;
605 /* list of pkeys programmed; 0 if not set */
606 u16 pkeys[MAX_PKEY_VALUES];
607 u16 link_width_supported;
608 u16 link_width_downgrade_supported;
609 u16 link_speed_supported;
610 u16 link_width_enabled;
611 u16 link_width_downgrade_enabled;
612 u16 link_speed_enabled;
613 u16 link_width_active;
614 u16 link_width_downgrade_tx_active;
615 u16 link_width_downgrade_rx_active;
616 u16 link_speed_active;
617 u8 vls_supported;
618 u8 vls_operational;
Mike Marciniszyn8a4d3442016-02-14 12:46:01 -0800619 u8 actual_vls_operational;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400620 /* LID mask control */
621 u8 lmc;
622 /* Rx Polarity inversion (compensate for ~tx on partner) */
623 u8 rx_pol_inv;
624
625 u8 hw_pidx; /* physical port index */
626 u8 port; /* IB port number and index into dd->pports - 1 */
627 /* type of neighbor node */
628 u8 neighbor_type;
629 u8 neighbor_normal;
630 u8 neighbor_fm_security; /* 1 if firmware checking is disabled */
631 u8 neighbor_port_number;
632 u8 is_sm_config_started;
633 u8 offline_disabled_reason;
634 u8 is_active_optimize_enabled;
635 u8 driver_link_ready; /* driver ready for active link */
636 u8 link_enabled; /* link enabled? */
637 u8 linkinit_reason;
638 u8 local_tx_rate; /* rate given to 8051 firmware */
Byczkowski, Jakubbec7c792017-05-29 17:21:32 -0700639 u8 pstate; /* info only */
Dean Luick673b9752016-08-31 07:24:33 -0700640 u8 qsfp_retry_count;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400641
642 /* placeholders for IB MAD packet settings */
643 u8 overrun_threshold;
644 u8 phy_error_threshold;
Sebastian Sanchez626c0772017-07-29 08:43:55 -0700645 unsigned int is_link_down_queued;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400646
Easwar Hariharan91ab4ed2016-02-03 14:35:57 -0800647 /* Used to override LED behavior for things like maintenance beaconing*/
648 /*
649 * Alternates per phase of blink
650 * [0] holds LED off duration, [1] holds LED on duration
651 */
652 unsigned long led_override_vals[2];
653 u8 led_override_phase; /* LSB picks from vals[] */
Mike Marciniszyn77241052015-07-30 15:17:43 -0400654 atomic_t led_override_timer_active;
655 /* Used to flash LEDs in override mode */
656 struct timer_list led_override_timer;
Easwar Hariharan91ab4ed2016-02-03 14:35:57 -0800657
Mike Marciniszyn77241052015-07-30 15:17:43 -0400658 u32 sm_trap_qp;
659 u32 sa_qp;
660
661 /*
662 * cca_timer_lock protects access to the per-SL cca_timer
663 * structures (specifically the ccti member).
664 */
665 spinlock_t cca_timer_lock ____cacheline_aligned_in_smp;
666 struct cca_timer cca_timer[OPA_MAX_SLS];
667
668 /* List of congestion control table entries */
669 struct ib_cc_table_entry_shadow ccti_entries[CC_TABLE_SHADOW_MAX];
670
671 /* congestion entries, each entry corresponding to a SL */
672 struct opa_congestion_setting_entry_shadow
673 congestion_entries[OPA_MAX_SLS];
674
675 /*
676 * cc_state_lock protects (write) access to the per-port
677 * struct cc_state.
678 */
679 spinlock_t cc_state_lock ____cacheline_aligned_in_smp;
680
681 struct cc_state __rcu *cc_state;
682
683 /* Total number of congestion control table entries */
684 u16 total_cct_entry;
685
686 /* Bit map identifying service level */
687 u32 cc_sl_control_map;
688
689 /* CA's max number of 64 entry units in the congestion control table */
690 u8 cc_max_table_entries;
691
Jubin John4d114fd2016-02-14 20:21:43 -0800692 /*
693 * begin congestion log related entries
694 * cc_log_lock protects all congestion log related data
695 */
Mike Marciniszyn77241052015-07-30 15:17:43 -0400696 spinlock_t cc_log_lock ____cacheline_aligned_in_smp;
Jubin John8638b772016-02-14 20:19:24 -0800697 u8 threshold_cong_event_map[OPA_MAX_SLS / 8];
Mike Marciniszyn77241052015-07-30 15:17:43 -0400698 u16 threshold_event_counter;
699 struct opa_hfi1_cong_log_event_internal cc_events[OPA_CONG_LOG_ELEMS];
700 int cc_log_idx; /* index for logging events */
701 int cc_mad_idx; /* index for reporting events */
702 /* end congestion log related entries */
703
704 struct vl_arb_cache vl_arb_cache[MAX_PRIO_TABLE];
705
706 /* port relative counter buffer */
707 u64 *cntrs;
708 /* port relative synthetic counter buffer */
709 u64 *scntrs;
Mike Marciniszyn69a00b82016-02-03 14:31:49 -0800710 /* port_xmit_discards are synthesized from different egress errors */
Mike Marciniszyn77241052015-07-30 15:17:43 -0400711 u64 port_xmit_discards;
Mike Marciniszyn69a00b82016-02-03 14:31:49 -0800712 u64 port_xmit_discards_vl[C_VL_COUNT];
Mike Marciniszyn77241052015-07-30 15:17:43 -0400713 u64 port_xmit_constraint_errors;
714 u64 port_rcv_constraint_errors;
715 /* count of 'link_err' interrupts from DC */
716 u64 link_downed;
717 /* number of times link retrained successfully */
718 u64 link_up;
Dean Luick6d014532015-12-01 15:38:23 -0500719 /* number of times a link unknown frame was reported */
720 u64 unknown_frame_count;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400721 /* port_ltp_crc_mode is returned in 'portinfo' MADs */
722 u16 port_ltp_crc_mode;
723 /* port_crc_mode_enabled is the crc we support */
724 u8 port_crc_mode_enabled;
725 /* mgmt_allowed is also returned in 'portinfo' MADs */
726 u8 mgmt_allowed;
727 u8 part_enforce; /* partition enforcement flags */
728 struct link_down_reason local_link_down_reason;
729 struct link_down_reason neigh_link_down_reason;
730 /* Value to be sent to link peer on LinkDown .*/
731 u8 remote_link_down_reason;
732 /* Error events that will cause a port bounce. */
733 u32 port_error_action;
Jim Snowfb9036d2016-01-11 18:32:21 -0500734 struct work_struct linkstate_active_work;
Vennila Megavannan6c9e50f2016-02-03 14:32:57 -0800735 /* Does this port need to prescan for FECNs */
736 bool cc_prescan;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400737};
738
739typedef int (*rhf_rcv_function_ptr)(struct hfi1_packet *packet);
740
741typedef void (*opcode_handler)(struct hfi1_packet *packet);
742
743/* return values for the RHF receive functions */
744#define RHF_RCV_CONTINUE 0 /* keep going */
745#define RHF_RCV_DONE 1 /* stop, this packet processed */
746#define RHF_RCV_REPROCESS 2 /* stop. retain this packet */
747
748struct rcv_array_data {
749 u8 group_size;
750 u16 ngroups;
751 u16 nctxt_extra;
752};
753
754struct per_vl_data {
755 u16 mtu;
756 struct send_context *sc;
757};
758
759/* 16 to directly index */
760#define PER_VL_SEND_CONTEXTS 16
761
762struct err_info_rcvport {
763 u8 status_and_code;
764 u64 packet_flit1;
765 u64 packet_flit2;
766};
767
768struct err_info_constraint {
769 u8 status;
770 u16 pkey;
771 u32 slid;
772};
773
774struct hfi1_temp {
775 unsigned int curr; /* current temperature */
776 unsigned int lo_lim; /* low temperature limit */
777 unsigned int hi_lim; /* high temperature limit */
778 unsigned int crit_lim; /* critical temperature limit */
779 u8 triggers; /* temperature triggers */
780};
781
Dean Luickdba715f2016-07-06 17:28:52 -0400782struct hfi1_i2c_bus {
783 struct hfi1_devdata *controlling_dd; /* current controlling device */
784 struct i2c_adapter adapter; /* bus details */
785 struct i2c_algo_bit_data algo; /* bus algorithm details */
786 int num; /* bus number, 0 or 1 */
787};
788
Dean Luick78eb1292016-03-05 08:49:45 -0800789/* common data between shared ASIC HFIs */
790struct hfi1_asic_data {
791 struct hfi1_devdata *dds[2]; /* back pointers */
792 struct mutex asic_resource_mutex;
Dean Luickdba715f2016-07-06 17:28:52 -0400793 struct hfi1_i2c_bus *i2c_bus0;
794 struct hfi1_i2c_bus *i2c_bus1;
Dean Luick78eb1292016-03-05 08:49:45 -0800795};
796
Vishwanathapura, Niranjana22807402017-04-12 20:29:29 -0700797/* sizes for both the QP and RSM map tables */
798#define NUM_MAP_ENTRIES 256
799#define NUM_MAP_REGS 32
800
Vishwanathapura, Niranjanad4829ea2017-04-12 20:29:28 -0700801/*
802 * Number of VNIC contexts used. Ensure it is less than or equal to
803 * max queues supported by VNIC (HFI1_VNIC_MAX_QUEUE).
804 */
805#define HFI1_NUM_VNIC_CTXT 8
806
Vishwanathapura, Niranjana22807402017-04-12 20:29:29 -0700807/* Number of VNIC RSM entries */
808#define NUM_VNIC_MAP_ENTRIES 8
809
Vishwanathapura, Niranjanad4829ea2017-04-12 20:29:28 -0700810/* Virtual NIC information */
811struct hfi1_vnic_data {
Vishwanathapura, Niranjana22807402017-04-12 20:29:29 -0700812 struct hfi1_ctxtdata *ctxt[HFI1_NUM_VNIC_CTXT];
Vishwanathapura, Niranjana64551ed2017-04-12 20:29:30 -0700813 struct kmem_cache *txreq_cache;
Vishwanathapura, Niranjana22807402017-04-12 20:29:29 -0700814 u8 num_vports;
Vishwanathapura, Niranjanad4829ea2017-04-12 20:29:28 -0700815 struct idr vesw_idr;
Vishwanathapura, Niranjana22807402017-04-12 20:29:29 -0700816 u8 rmt_start;
817 u8 num_ctxt;
818 u32 msix_idx;
Vishwanathapura, Niranjanad4829ea2017-04-12 20:29:28 -0700819};
820
821struct hfi1_vnic_vport_info;
822
Mike Marciniszyn77241052015-07-30 15:17:43 -0400823/* device data struct now contains only "general per-device" info.
824 * fields related to a physical IB port are in a hfi1_pportdata struct.
825 */
826struct sdma_engine;
827struct sdma_vl_map;
828
829#define BOARD_VERS_MAX 96 /* how long the version string can be */
830#define SERIAL_MAX 16 /* length of the serial number */
831
Mike Marciniszyn14553ca2016-02-14 12:45:36 -0800832typedef int (*send_routine)(struct rvt_qp *, struct hfi1_pkt_state *, u64);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400833struct hfi1_devdata {
834 struct hfi1_ibdev verbs_dev; /* must be first */
835 struct list_head list;
836 /* pointers to related structs for this device */
837 /* pci access data structure */
838 struct pci_dev *pcidev;
839 struct cdev user_cdev;
840 struct cdev diag_cdev;
841 struct cdev ui_cdev;
842 struct device *user_device;
843 struct device *diag_device;
844 struct device *ui_device;
845
Mike Marciniszyncb51c5d2017-07-24 07:45:31 -0700846 /* first mapping up to RcvArray */
847 u8 __iomem *kregbase1;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400848 resource_size_t physaddr;
Mike Marciniszyncb51c5d2017-07-24 07:45:31 -0700849
850 /* second uncached mapping from RcvArray to pio send buffers */
851 u8 __iomem *kregbase2;
852 /* for detecting offset above kregbase2 address */
853 u32 base2_start;
854
Sebastian Sanchez6e768f02016-10-17 04:19:35 -0700855 /* Per VL data. Enough for all VLs but not all elements are set/used. */
856 struct per_vl_data vld[PER_VL_SEND_CONTEXTS];
Mike Marciniszyn77241052015-07-30 15:17:43 -0400857 /* send context data */
858 struct send_context_info *send_contexts;
859 /* map hardware send contexts to software index */
860 u8 *hw_to_sw;
861 /* spinlock for allocating and releasing send context resources */
862 spinlock_t sc_lock;
Jubin John35f6bef2016-02-14 12:46:10 -0800863 /* lock for pio_map */
864 spinlock_t pio_map_lock;
Sebastian Sanchez6e768f02016-10-17 04:19:35 -0700865 /* Send Context initialization lock. */
866 spinlock_t sc_init_lock;
867 /* lock for sdma_map */
868 spinlock_t sde_map_lock;
Jubin John35f6bef2016-02-14 12:46:10 -0800869 /* array of kernel send contexts */
870 struct send_context **kernel_send_context;
871 /* array of vl maps */
872 struct pio_vl_map __rcu *pio_map;
Sebastian Sanchez6e768f02016-10-17 04:19:35 -0700873 /* default flags to last descriptor */
874 u64 default_desc1;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400875
876 /* fields common to all SDMA engines */
877
Mike Marciniszyn77241052015-07-30 15:17:43 -0400878 volatile __le64 *sdma_heads_dma; /* DMA'ed by chip */
879 dma_addr_t sdma_heads_phys;
880 void *sdma_pad_dma; /* DMA'ed by chip */
881 dma_addr_t sdma_pad_phys;
882 /* for deallocation */
883 size_t sdma_heads_size;
884 /* number from the chip */
885 u32 chip_sdma_engines;
886 /* num used */
887 u32 num_sdma;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400888 /* array of engines sized by num_sdma */
889 struct sdma_engine *per_sdma;
890 /* array of vl maps */
891 struct sdma_vl_map __rcu *sdma_map;
892 /* SPC freeze waitqueue and variable */
893 wait_queue_head_t sdma_unfreeze_wq;
894 atomic_t sdma_unfreeze_count;
895
Sebastian Sanchez6e768f02016-10-17 04:19:35 -0700896 u32 lcb_access_count; /* count of LCB users */
897
Dean Luick78eb1292016-03-05 08:49:45 -0800898 /* common data between shared ASIC HFIs in this OS */
899 struct hfi1_asic_data *asic_data;
900
Mike Marciniszyn77241052015-07-30 15:17:43 -0400901 /* mem-mapped pointer to base of PIO buffers */
902 void __iomem *piobase;
903 /*
904 * write-combining mem-mapped pointer to base of RcvArray
905 * memory.
906 */
907 void __iomem *rcvarray_wc;
908 /*
909 * credit return base - a per-NUMA range of DMA address that
910 * the chip will use to update the per-context free counter
911 */
912 struct credit_return_base *cr_base;
913
914 /* send context numbers and sizes for each type */
915 struct sc_config_sizes sc_sizes[SC_MAX];
916
Mike Marciniszyn77241052015-07-30 15:17:43 -0400917 char *boardname; /* human readable board info */
918
Mike Marciniszyn77241052015-07-30 15:17:43 -0400919 /* reset value */
920 u64 z_int_counter;
921 u64 z_rcv_limit;
Vennila Megavannan89abfc82016-02-03 14:34:07 -0800922 u64 z_send_schedule;
Sebastian Sanchez6e768f02016-10-17 04:19:35 -0700923
Vennila Megavannan89abfc82016-02-03 14:34:07 -0800924 u64 __percpu *send_schedule;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400925 /* number of receive contexts in use by the driver */
926 u32 num_rcv_contexts;
927 /* number of pio send contexts in use by the driver */
928 u32 num_send_contexts;
929 /*
930 * number of ctxts available for PSM open
931 */
932 u32 freectxts;
Ashutosh Dixitaffa48d2016-02-03 14:33:06 -0800933 /* total number of available user/PSM contexts */
934 u32 num_user_contexts;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400935 /* base receive interrupt timeout, in CSR units */
936 u32 rcv_intr_timeout_csr;
937
Sebastian Sanchez6e768f02016-10-17 04:19:35 -0700938 u32 freezelen; /* max length of freezemsg */
Mike Marciniszyn77241052015-07-30 15:17:43 -0400939 u64 __iomem *egrtidbase;
940 spinlock_t sendctrl_lock; /* protect changes to SendCtrl */
941 spinlock_t rcvctrl_lock; /* protect changes to RcvCtrl */
942 /* around rcd and (user ctxts) ctxt_cnt use (intr vs free) */
943 spinlock_t uctxt_lock; /* rcd and user context changes */
Tadeusz Struk22546b72017-04-28 10:40:02 -0700944 struct mutex dc8051_lock; /* exclusive access to 8051 */
945 struct workqueue_struct *update_cntr_wq;
946 struct work_struct update_cntr_work;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400947 /* exclusive access to 8051 memory */
948 spinlock_t dc8051_memlock;
949 int dc8051_timed_out; /* remember if the 8051 timed out */
950 /*
951 * A page that will hold event notification bitmaps for all
952 * contexts. This page will be mapped into all processes.
953 */
954 unsigned long *events;
955 /*
956 * per unit status, see also portdata statusp
957 * mapped read-only into user processes so they can get unit and
958 * IB link status cheaply
959 */
960 struct hfi1_status *status;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400961
962 /* revision register shadow */
963 u64 revision;
964 /* Base GUID for device (network order) */
965 u64 base_guid;
966
967 /* these are the "32 bit" regs */
968
969 /* value we put in kr_rcvhdrsize */
970 u32 rcvhdrsize;
971 /* number of receive contexts the chip supports */
972 u32 chip_rcv_contexts;
973 /* number of receive array entries */
974 u32 chip_rcv_array_count;
975 /* number of PIO send contexts the chip supports */
976 u32 chip_send_contexts;
977 /* number of bytes in the PIO memory buffer */
978 u32 chip_pio_mem_size;
979 /* number of bytes in the SDMA memory buffer */
980 u32 chip_sdma_mem_size;
981
982 /* size of each rcvegrbuffer */
983 u32 rcvegrbufsize;
984 /* log2 of above */
985 u16 rcvegrbufsize_shift;
986 /* both sides of the PCIe link are gen3 capable */
987 u8 link_gen3_capable;
Sebastian Sanchez6e768f02016-10-17 04:19:35 -0700988 /* default link down value (poll/sleep) */
989 u8 link_default;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400990 /* localbus width (1, 2,4,8,16,32) from config space */
991 u32 lbus_width;
992 /* localbus speed in MHz */
993 u32 lbus_speed;
994 int unit; /* unit # of this chip */
995 int node; /* home node of this chip */
996
997 /* save these PCI fields to restore after a reset */
998 u32 pcibar0;
999 u32 pcibar1;
1000 u32 pci_rom;
1001 u16 pci_command;
1002 u16 pcie_devctl;
1003 u16 pcie_lnkctl;
1004 u16 pcie_devctl2;
1005 u32 pci_msix0;
1006 u32 pci_lnkctl3;
1007 u32 pci_tph2;
1008
1009 /*
1010 * ASCII serial number, from flash, large enough for original
1011 * all digit strings, and longer serial number format
1012 */
1013 u8 serial[SERIAL_MAX];
1014 /* human readable board version */
1015 u8 boardversion[BOARD_VERS_MAX];
1016 u8 lbus_info[32]; /* human readable localbus info */
1017 /* chip major rev, from CceRevision */
1018 u8 majrev;
1019 /* chip minor rev, from CceRevision */
1020 u8 minrev;
1021 /* hardware ID */
1022 u8 hfi1_id;
1023 /* implementation code */
1024 u8 icode;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001025 /* vAU of this device */
1026 u8 vau;
1027 /* vCU of this device */
1028 u8 vcu;
1029 /* link credits of this device */
1030 u16 link_credits;
1031 /* initial vl15 credits to use */
1032 u16 vl15_init;
1033
Byczkowski, Jakubb3e6b4b2017-05-12 09:01:37 -07001034 /*
1035 * Cached value for vl15buf, read during verify cap interrupt. VL15
1036 * credits are to be kept at 0 and set when handling the link-up
1037 * interrupt. This removes the possibility of receiving VL15 MAD
1038 * packets before this HFI is ready.
1039 */
1040 u16 vl15buf_cached;
1041
Mike Marciniszyn77241052015-07-30 15:17:43 -04001042 /* Misc small ints */
Mike Marciniszyn77241052015-07-30 15:17:43 -04001043 u8 n_krcv_queues;
1044 u8 qos_shift;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001045
Mike Marciniszyn77241052015-07-30 15:17:43 -04001046 u16 irev; /* implementation revision */
Michael J. Ruhl5e6e94242017-03-20 17:25:48 -07001047 u32 dc8051_ver; /* 8051 firmware version */
Mike Marciniszyn77241052015-07-30 15:17:43 -04001048
Sebastian Sanchez6e768f02016-10-17 04:19:35 -07001049 spinlock_t hfi1_diag_trans_lock; /* protect diag observer ops */
Easwar Hariharanc3838b32016-02-09 14:29:13 -08001050 struct platform_config platform_config;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001051 struct platform_config_cache pcfg_cache;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001052
1053 struct diag_client *diag_client;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001054
1055 /* MSI-X information */
1056 struct hfi1_msix_entry *msix_entries;
1057 u32 num_msix_entries;
Vishwanathapura, Niranjana22807402017-04-12 20:29:29 -07001058 u32 first_dyn_msix_idx;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001059
1060 /* INTx information */
1061 u32 requested_intx_irq; /* did we request one? */
1062 char intx_name[MAX_NAME_SIZE]; /* INTx name */
1063
1064 /* general interrupt: mask of handled interrupts */
1065 u64 gi_mask[CCE_NUM_INT_CSRS];
1066
1067 struct rcv_array_data rcv_entries;
1068
Sebastian Sanchez6e768f02016-10-17 04:19:35 -07001069 /* cycle length of PS* counters in HW (in picoseconds) */
1070 u16 psxmitwait_check_rate;
1071
Mike Marciniszyn77241052015-07-30 15:17:43 -04001072 /*
1073 * 64 bit synthetic counters
1074 */
1075 struct timer_list synth_stats_timer;
1076
1077 /*
1078 * device counters
1079 */
1080 char *cntrnames;
1081 size_t cntrnameslen;
1082 size_t ndevcntrs;
1083 u64 *cntrs;
1084 u64 *scntrs;
1085
1086 /*
1087 * remembered values for synthetic counters
1088 */
1089 u64 last_tx;
1090 u64 last_rx;
1091
1092 /*
1093 * per-port counters
1094 */
1095 size_t nportcntrs;
1096 char *portcntrnames;
1097 size_t portcntrnameslen;
1098
Mike Marciniszyn77241052015-07-30 15:17:43 -04001099 struct err_info_rcvport err_info_rcvport;
1100 struct err_info_constraint err_info_rcv_constraint;
1101 struct err_info_constraint err_info_xmit_constraint;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001102
1103 atomic_t drop_packet;
1104 u8 do_drop;
Sebastian Sanchez6e768f02016-10-17 04:19:35 -07001105 u8 err_info_uncorrectable;
1106 u8 err_info_fmconfig;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001107
Joel Rosenzweig2c5b5212015-12-01 15:38:19 -05001108 /*
1109 * Software counters for the status bits defined by the
1110 * associated error status registers
1111 */
1112 u64 cce_err_status_cnt[NUM_CCE_ERR_STATUS_COUNTERS];
1113 u64 rcv_err_status_cnt[NUM_RCV_ERR_STATUS_COUNTERS];
1114 u64 misc_err_status_cnt[NUM_MISC_ERR_STATUS_COUNTERS];
1115 u64 send_pio_err_status_cnt[NUM_SEND_PIO_ERR_STATUS_COUNTERS];
1116 u64 send_dma_err_status_cnt[NUM_SEND_DMA_ERR_STATUS_COUNTERS];
1117 u64 send_egress_err_status_cnt[NUM_SEND_EGRESS_ERR_STATUS_COUNTERS];
1118 u64 send_err_status_cnt[NUM_SEND_ERR_STATUS_COUNTERS];
1119
1120 /* Software counter that spans all contexts */
1121 u64 sw_ctxt_err_status_cnt[NUM_SEND_CTXT_ERR_STATUS_COUNTERS];
1122 /* Software counter that spans all DMA engines */
1123 u64 sw_send_dma_eng_err_status_cnt[
1124 NUM_SEND_DMA_ENG_ERR_STATUS_COUNTERS];
1125 /* Software counter that aggregates all cce_err_status errors */
1126 u64 sw_cce_err_status_aggregate;
Jakub Pawlak2b719042016-07-01 16:01:22 -07001127 /* Software counter that aggregates all bypass packet rcv errors */
1128 u64 sw_rcv_bypass_packet_errors;
Sebastian Sanchez6e768f02016-10-17 04:19:35 -07001129 /* receive interrupt function */
Mike Marciniszyn77241052015-07-30 15:17:43 -04001130 rhf_rcv_function_ptr normal_rhf_rcv_functions[8];
1131
Sebastian Sanchez6e768f02016-10-17 04:19:35 -07001132 /* Save the enabled LCB error bits */
1133 u64 lcb_err_en;
1134
Mike Marciniszyn77241052015-07-30 15:17:43 -04001135 /*
Dennis Dalessandroeacc8302016-10-17 04:19:52 -07001136 * Capability to have different send engines simply by changing a
1137 * pointer value.
Mike Marciniszyn77241052015-07-30 15:17:43 -04001138 */
Sebastian Sanchez6e768f02016-10-17 04:19:35 -07001139 send_routine process_pio_send ____cacheline_aligned_in_smp;
Mike Marciniszyn14553ca2016-02-14 12:45:36 -08001140 send_routine process_dma_send;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001141 void (*pio_inline_send)(struct hfi1_devdata *dd, struct pio_buf *pbuf,
1142 u64 pbc, const void *from, size_t count);
Vishwanathapura, Niranjanad4829ea2017-04-12 20:29:28 -07001143 int (*process_vnic_dma_send)(struct hfi1_devdata *dd, u8 q_idx,
1144 struct hfi1_vnic_vport_info *vinfo,
1145 struct sk_buff *skb, u64 pbc, u8 plen);
Sebastian Sanchez6e768f02016-10-17 04:19:35 -07001146 /* hfi1_pportdata, points to array of (physical) port-specific
1147 * data structs, indexed by pidx (0..n-1)
1148 */
1149 struct hfi1_pportdata *pport;
1150 /* receive context data */
1151 struct hfi1_ctxtdata **rcd;
1152 u64 __percpu *int_counter;
1153 /* device (not port) flags, basically device capabilities */
1154 u16 flags;
1155 /* Number of physical ports available */
1156 u8 num_pports;
Vishwanathapura, Niranjana22807402017-04-12 20:29:29 -07001157 /* Lowest context number which can be used by user processes or VNIC */
1158 u8 first_dyn_alloc_ctxt;
Sebastian Sanchez6e768f02016-10-17 04:19:35 -07001159 /* adding a new field here would make it part of this cacheline */
1160
1161 /* seqlock for sc2vl */
1162 seqlock_t sc2vl_lock ____cacheline_aligned_in_smp;
1163 u64 sc2vl[4];
1164 /* receive interrupt functions */
1165 rhf_rcv_function_ptr *rhf_rcv_function_map;
1166 u64 __percpu *rcv_limit;
1167 u16 rhf_offset; /* offset of RHF within receive header entry */
1168 /* adding a new field here would make it part of this cacheline */
Mike Marciniszyn77241052015-07-30 15:17:43 -04001169
1170 /* OUI comes from the HW. Used everywhere as 3 separate bytes. */
1171 u8 oui1;
1172 u8 oui2;
1173 u8 oui3;
Sebastian Sanchez6e768f02016-10-17 04:19:35 -07001174 u8 dc_shutdown;
1175
Mike Marciniszyn77241052015-07-30 15:17:43 -04001176 /* Timer and counter used to detect RcvBufOvflCnt changes */
1177 struct timer_list rcverr_timer;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001178
Mike Marciniszyn77241052015-07-30 15:17:43 -04001179 wait_queue_head_t event_queue;
1180
Mark F. Brown46b010d2015-11-09 19:18:20 -05001181 /* receive context tail dummy address */
1182 __le64 *rcvhdrtail_dummy_kvaddr;
Tymoteusz Kielan60368182016-09-06 04:35:54 -07001183 dma_addr_t rcvhdrtail_dummy_dma;
Ashutosh Dixitaffa48d2016-02-03 14:33:06 -08001184
Sebastian Sanchez6e768f02016-10-17 04:19:35 -07001185 u32 rcv_ovfl_cnt;
Ashutosh Dixitaffa48d2016-02-03 14:33:06 -08001186 /* Serialize ASPM enable/disable between multiple verbs contexts */
1187 spinlock_t aspm_lock;
1188 /* Number of verbs contexts which have disabled ASPM */
1189 atomic_t aspm_disabled_cnt;
Tadeusz Strukacd7c8f2016-10-25 08:57:55 -07001190 /* Keeps track of user space clients */
1191 atomic_t user_refcount;
1192 /* Used to wait for outstanding user space clients before dev removal */
1193 struct completion user_comp;
Mitko Haralanov957558c2016-02-03 14:33:40 -08001194
Sebastian Sanchez6e768f02016-10-17 04:19:35 -07001195 bool eprom_available; /* true if EPROM is available for this device */
1196 bool aspm_supported; /* Does HW support ASPM */
1197 bool aspm_enabled; /* ASPM state: enabled/disabled */
Sebastian Sanchez5a52a7a2017-03-20 17:24:58 -07001198 struct rhashtable *sdma_rht;
Sebastian Sanchez6e768f02016-10-17 04:19:35 -07001199
Dennis Dalessandroe11ffbd2016-05-19 05:26:44 -07001200 struct kobject kobj;
Vishwanathapura, Niranjanad4829ea2017-04-12 20:29:28 -07001201
1202 /* vnic data */
1203 struct hfi1_vnic_data vnic;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001204};
1205
Vishwanathapura, Niranjana22807402017-04-12 20:29:29 -07001206static inline bool hfi1_vnic_is_rsm_full(struct hfi1_devdata *dd, int spare)
1207{
1208 return (dd->vnic.rmt_start + spare) > NUM_MAP_ENTRIES;
1209}
1210
Mike Marciniszyn77241052015-07-30 15:17:43 -04001211/* 8051 firmware version helper */
Michael J. Ruhl5e6e94242017-03-20 17:25:48 -07001212#define dc8051_ver(a, b, c) ((a) << 16 | (b) << 8 | (c))
1213#define dc8051_ver_maj(a) (((a) & 0xff0000) >> 16)
1214#define dc8051_ver_min(a) (((a) & 0x00ff00) >> 8)
1215#define dc8051_ver_patch(a) ((a) & 0x0000ff)
Mike Marciniszyn77241052015-07-30 15:17:43 -04001216
1217/* f_put_tid types */
Mike Marciniszyncb51c5d2017-07-24 07:45:31 -07001218#define PT_EXPECTED 0
1219#define PT_EAGER 1
1220#define PT_INVALID_FLUSH 2
1221#define PT_INVALID 3
Mike Marciniszyn77241052015-07-30 15:17:43 -04001222
Mitko Haralanov06e0ffa2016-03-08 11:14:20 -08001223struct tid_rb_node;
Mitko Haralanovf727a0c2016-02-05 11:57:46 -05001224struct mmu_rb_node;
Dean Luicke0b09ac2016-07-28 15:21:20 -04001225struct mmu_rb_handler;
Mitko Haralanovf727a0c2016-02-05 11:57:46 -05001226
Mike Marciniszyn77241052015-07-30 15:17:43 -04001227/* Private data for file operations */
1228struct hfi1_filedata {
Michael J. Ruhl5fbded42017-05-04 05:14:57 -07001229 struct hfi1_devdata *dd;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001230 struct hfi1_ctxtdata *uctxt;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001231 struct hfi1_user_sdma_comp_q *cq;
1232 struct hfi1_user_sdma_pkt_q *pq;
Michael J. Ruhl8737ce92017-05-04 05:15:15 -07001233 u16 subctxt;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001234 /* for cpu affinity; -1 if none */
1235 int rec_cpu_num;
Mitko Haralanova7922f72016-03-08 11:15:39 -08001236 u32 tid_n_pinned;
Dean Luicke0b09ac2016-07-28 15:21:20 -04001237 struct mmu_rb_handler *handler;
Mitko Haralanov06e0ffa2016-03-08 11:14:20 -08001238 struct tid_rb_node **entry_to_rb;
Mitko Haralanova86cd352016-02-05 11:57:49 -05001239 spinlock_t tid_lock; /* protect tid_[limit,used] counters */
1240 u32 tid_limit;
1241 u32 tid_used;
Mitko Haralanova86cd352016-02-05 11:57:49 -05001242 u32 *invalid_tids;
1243 u32 invalid_tid_idx;
Mitko Haralanov06e0ffa2016-03-08 11:14:20 -08001244 /* protect invalid_tids array and invalid_tid_idx */
1245 spinlock_t invalid_lock;
Ira Weiny3faa3d92016-07-28 15:21:19 -04001246 struct mm_struct *mm;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001247};
1248
1249extern struct list_head hfi1_dev_list;
1250extern spinlock_t hfi1_devs_lock;
1251struct hfi1_devdata *hfi1_lookup(int unit);
1252extern u32 hfi1_cpulist_count;
1253extern unsigned long *hfi1_cpulist;
1254
Michael J. Ruhlf4cd8762017-05-04 05:14:39 -07001255int hfi1_init(struct hfi1_devdata *dd, int reinit);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001256int hfi1_count_active_units(void);
1257
Michael J. Ruhlf4cd8762017-05-04 05:14:39 -07001258int hfi1_diag_add(struct hfi1_devdata *dd);
1259void hfi1_diag_remove(struct hfi1_devdata *dd);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001260void handle_linkup_change(struct hfi1_devdata *dd, u32 linkup);
1261
1262void handle_user_interrupt(struct hfi1_ctxtdata *rcd);
1263
Michael J. Ruhlf4cd8762017-05-04 05:14:39 -07001264int hfi1_create_rcvhdrq(struct hfi1_devdata *dd, struct hfi1_ctxtdata *rcd);
1265int hfi1_setup_eagerbufs(struct hfi1_ctxtdata *rcd);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001266int hfi1_create_ctxts(struct hfi1_devdata *dd);
Michael J. Ruhle6f76222017-07-24 07:45:55 -07001267struct hfi1_ctxtdata *hfi1_create_ctxtdata(struct hfi1_pportdata *ppd, u16 ctxt,
Michael J. Ruhlf4cd8762017-05-04 05:14:39 -07001268 int numa);
1269void hfi1_init_pportdata(struct pci_dev *pdev, struct hfi1_pportdata *ppd,
1270 struct hfi1_devdata *dd, u8 hw_pidx, u8 port);
1271void hfi1_free_ctxtdata(struct hfi1_devdata *dd, struct hfi1_ctxtdata *rcd);
Michael J. Ruhlf683c802017-06-09 16:00:19 -07001272int hfi1_rcd_put(struct hfi1_ctxtdata *rcd);
1273void hfi1_rcd_get(struct hfi1_ctxtdata *rcd);
Michael J. Ruhlf4cd8762017-05-04 05:14:39 -07001274int handle_receive_interrupt(struct hfi1_ctxtdata *rcd, int thread);
1275int handle_receive_interrupt_nodma_rtail(struct hfi1_ctxtdata *rcd, int thread);
1276int handle_receive_interrupt_dma_rtail(struct hfi1_ctxtdata *rcd, int thread);
Jim Snowfb9036d2016-01-11 18:32:21 -05001277void set_all_slowpath(struct hfi1_devdata *dd);
Vishwanathapura, Niranjana22807402017-04-12 20:29:29 -07001278void hfi1_vnic_synchronize_irq(struct hfi1_devdata *dd);
1279void hfi1_set_vnic_msix_info(struct hfi1_ctxtdata *rcd);
1280void hfi1_reset_vnic_msix_info(struct hfi1_ctxtdata *rcd);
Dean Luickf4f30031c2015-10-26 10:28:44 -04001281
Sebastian Sanchezd6373012016-07-25 07:54:48 -07001282extern const struct pci_device_id hfi1_pci_tbl[];
1283
Dean Luickf4f30031c2015-10-26 10:28:44 -04001284/* receive packet handler dispositions */
1285#define RCV_PKT_OK 0x0 /* keep going */
1286#define RCV_PKT_LIMIT 0x1 /* stop, hit limit, start thread */
1287#define RCV_PKT_DONE 0x2 /* stop, no more packets detected */
1288
1289/* calculate the current RHF address */
1290static inline __le32 *get_rhf_addr(struct hfi1_ctxtdata *rcd)
1291{
1292 return (__le32 *)rcd->rcvhdrq + rcd->head + rcd->dd->rhf_offset;
1293}
1294
Mike Marciniszyn77241052015-07-30 15:17:43 -04001295int hfi1_reset_device(int);
1296
Byczkowski, Jakubbec7c792017-05-29 17:21:32 -07001297/* return the driver's idea of the physical OPA port state */
1298static inline u32 driver_pstate(struct hfi1_pportdata *ppd)
1299{
1300 /*
Bartlomiej Dudek64a296f2017-08-04 13:52:32 -07001301 * When DC is shut down and state is changed, its CSRs are not
1302 * impacted, therefore host_link_state should be used to get
1303 * current physical state.
1304 */
1305 if (ppd->dd->dc_shutdown)
1306 return driver_physical_state(ppd);
1307 /*
Byczkowski, Jakubbec7c792017-05-29 17:21:32 -07001308 * The driver does some processing from the time the physical
1309 * link state is at LINKUP to the time the SM can be notified
1310 * as such. Return IB_PORTPHYSSTATE_TRAINING until the software
1311 * state is ready.
1312 */
1313 if (ppd->pstate == PLS_LINKUP &&
1314 !(ppd->host_link_state & HLS_UP))
1315 return IB_PORTPHYSSTATE_TRAINING;
1316 else
1317 return chip_to_opa_pstate(ppd->dd, ppd->pstate);
1318}
1319
Jim Snowfb9036d2016-01-11 18:32:21 -05001320void receive_interrupt_work(struct work_struct *work);
1321
1322/* extract service channel from header and rhf */
Dasaratharaman Chandramouliaad559c2017-04-09 10:16:15 -07001323static inline int hfi1_9B_get_sc5(struct ib_header *hdr, u64 rhf)
Jim Snowfb9036d2016-01-11 18:32:21 -05001324{
Don Hiattcb4270572017-04-09 10:16:22 -07001325 return ib_get_sc(hdr) | ((!!(rhf_dc_info(rhf))) << 4);
Jim Snowfb9036d2016-01-11 18:32:21 -05001326}
1327
Mitko Haralanov08fe16f2016-08-16 13:26:12 -07001328#define HFI1_JKEY_WIDTH 16
1329#define HFI1_JKEY_MASK (BIT(16) - 1)
1330#define HFI1_ADMIN_JKEY_RANGE 32
1331
1332/*
1333 * J_KEYs are split and allocated in the following groups:
1334 * 0 - 31 - users with administrator privileges
1335 * 32 - 63 - kernel protocols using KDETH packets
1336 * 64 - 65535 - all other users using KDETH packets
1337 */
Mike Marciniszyn77241052015-07-30 15:17:43 -04001338static inline u16 generate_jkey(kuid_t uid)
1339{
Mitko Haralanov08fe16f2016-08-16 13:26:12 -07001340 u16 jkey = from_kuid(current_user_ns(), uid) & HFI1_JKEY_MASK;
1341
1342 if (capable(CAP_SYS_ADMIN))
1343 jkey &= HFI1_ADMIN_JKEY_RANGE - 1;
1344 else if (jkey < 64)
1345 jkey |= BIT(HFI1_JKEY_WIDTH - 1);
1346
1347 return jkey;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001348}
1349
1350/*
1351 * active_egress_rate
1352 *
1353 * returns the active egress rate in units of [10^6 bits/sec]
1354 */
1355static inline u32 active_egress_rate(struct hfi1_pportdata *ppd)
1356{
1357 u16 link_speed = ppd->link_speed_active;
1358 u16 link_width = ppd->link_width_active;
1359 u32 egress_rate;
1360
1361 if (link_speed == OPA_LINK_SPEED_25G)
1362 egress_rate = 25000;
1363 else /* assume OPA_LINK_SPEED_12_5G */
1364 egress_rate = 12500;
1365
1366 switch (link_width) {
1367 case OPA_LINK_WIDTH_4X:
1368 egress_rate *= 4;
1369 break;
1370 case OPA_LINK_WIDTH_3X:
1371 egress_rate *= 3;
1372 break;
1373 case OPA_LINK_WIDTH_2X:
1374 egress_rate *= 2;
1375 break;
1376 default:
1377 /* assume IB_WIDTH_1X */
1378 break;
1379 }
1380
1381 return egress_rate;
1382}
1383
1384/*
1385 * egress_cycles
1386 *
1387 * Returns the number of 'fabric clock cycles' to egress a packet
1388 * of length 'len' bytes, at 'rate' Mbit/s. Since the fabric clock
1389 * rate is (approximately) 805 MHz, the units of the returned value
1390 * are (1/805 MHz).
1391 */
1392static inline u32 egress_cycles(u32 len, u32 rate)
1393{
1394 u32 cycles;
1395
1396 /*
1397 * cycles is:
1398 *
1399 * (length) [bits] / (rate) [bits/sec]
1400 * ---------------------------------------------------
1401 * fabric_clock_period == 1 /(805 * 10^6) [cycles/sec]
1402 */
1403
1404 cycles = len * 8; /* bits */
1405 cycles *= 805;
1406 cycles /= rate;
1407
1408 return cycles;
1409}
1410
1411void set_link_ipg(struct hfi1_pportdata *ppd);
1412void process_becn(struct hfi1_pportdata *ppd, u8 sl, u16 rlid, u32 lqpn,
1413 u32 rqpn, u8 svc_type);
Dennis Dalessandro895420d2016-01-19 14:42:28 -08001414void return_cnp(struct hfi1_ibport *ibp, struct rvt_qp *qp, u32 remote_qpn,
Mike Marciniszyn77241052015-07-30 15:17:43 -04001415 u32 pkey, u32 slid, u32 dlid, u8 sc5,
1416 const struct ib_grh *old_grh);
Sebastian Sancheze38d1e42016-04-12 11:22:21 -07001417#define PKEY_CHECK_INVALID -1
1418int egress_pkey_check(struct hfi1_pportdata *ppd, __be16 *lrh, __be32 *bth,
1419 u8 sc5, int8_t s_pkey_index);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001420
1421#define PACKET_EGRESS_TIMEOUT 350
1422static inline void pause_for_credit_return(struct hfi1_devdata *dd)
1423{
1424 /* Pause at least 1us, to ensure chip returns all credits */
1425 u32 usec = cclock_to_ns(dd, PACKET_EGRESS_TIMEOUT) / 1000;
1426
1427 udelay(usec ? usec : 1);
1428}
1429
1430/**
1431 * sc_to_vlt() reverse lookup sc to vl
1432 * @dd - devdata
1433 * @sc5 - 5 bit sc
1434 */
1435static inline u8 sc_to_vlt(struct hfi1_devdata *dd, u8 sc5)
1436{
1437 unsigned seq;
1438 u8 rval;
1439
1440 if (sc5 >= OPA_MAX_SCS)
1441 return (u8)(0xff);
1442
1443 do {
1444 seq = read_seqbegin(&dd->sc2vl_lock);
1445 rval = *(((u8 *)dd->sc2vl) + sc5);
1446 } while (read_seqretry(&dd->sc2vl_lock, seq));
1447
1448 return rval;
1449}
1450
1451#define PKEY_MEMBER_MASK 0x8000
1452#define PKEY_LOW_15_MASK 0x7fff
1453
1454/*
1455 * ingress_pkey_matches_entry - return 1 if the pkey matches ent (ent
1456 * being an entry from the ingress partition key table), return 0
1457 * otherwise. Use the matching criteria for ingress partition keys
1458 * specified in the OPAv1 spec., section 9.10.14.
1459 */
1460static inline int ingress_pkey_matches_entry(u16 pkey, u16 ent)
1461{
1462 u16 mkey = pkey & PKEY_LOW_15_MASK;
1463 u16 ment = ent & PKEY_LOW_15_MASK;
1464
1465 if (mkey == ment) {
1466 /*
1467 * If pkey[15] is clear (limited partition member),
1468 * is bit 15 in the corresponding table element
1469 * clear (limited member)?
1470 */
1471 if (!(pkey & PKEY_MEMBER_MASK))
1472 return !!(ent & PKEY_MEMBER_MASK);
1473 return 1;
1474 }
1475 return 0;
1476}
1477
1478/*
1479 * ingress_pkey_table_search - search the entire pkey table for
1480 * an entry which matches 'pkey'. return 0 if a match is found,
1481 * and 1 otherwise.
1482 */
1483static int ingress_pkey_table_search(struct hfi1_pportdata *ppd, u16 pkey)
1484{
1485 int i;
1486
1487 for (i = 0; i < MAX_PKEY_VALUES; i++) {
1488 if (ingress_pkey_matches_entry(pkey, ppd->pkeys[i]))
1489 return 0;
1490 }
1491 return 1;
1492}
1493
1494/*
1495 * ingress_pkey_table_fail - record a failure of ingress pkey validation,
1496 * i.e., increment port_rcv_constraint_errors for the port, and record
1497 * the 'error info' for this failure.
1498 */
1499static void ingress_pkey_table_fail(struct hfi1_pportdata *ppd, u16 pkey,
1500 u16 slid)
1501{
1502 struct hfi1_devdata *dd = ppd->dd;
1503
1504 incr_cntr64(&ppd->port_rcv_constraint_errors);
1505 if (!(dd->err_info_rcv_constraint.status & OPA_EI_STATUS_SMASK)) {
1506 dd->err_info_rcv_constraint.status |= OPA_EI_STATUS_SMASK;
1507 dd->err_info_rcv_constraint.slid = slid;
1508 dd->err_info_rcv_constraint.pkey = pkey;
1509 }
1510}
1511
1512/*
1513 * ingress_pkey_check - Return 0 if the ingress pkey is valid, return 1
1514 * otherwise. Use the criteria in the OPAv1 spec, section 9.10.14. idx
1515 * is a hint as to the best place in the partition key table to begin
1516 * searching. This function should not be called on the data path because
1517 * of performance reasons. On datapath pkey check is expected to be done
1518 * by HW and rcv_pkey_check function should be called instead.
1519 */
1520static inline int ingress_pkey_check(struct hfi1_pportdata *ppd, u16 pkey,
1521 u8 sc5, u8 idx, u16 slid)
1522{
1523 if (!(ppd->part_enforce & HFI1_PART_ENFORCE_IN))
1524 return 0;
1525
1526 /* If SC15, pkey[0:14] must be 0x7fff */
1527 if ((sc5 == 0xf) && ((pkey & PKEY_LOW_15_MASK) != PKEY_LOW_15_MASK))
1528 goto bad;
1529
1530 /* Is the pkey = 0x0, or 0x8000? */
1531 if ((pkey & PKEY_LOW_15_MASK) == 0)
1532 goto bad;
1533
1534 /* The most likely matching pkey has index 'idx' */
1535 if (ingress_pkey_matches_entry(pkey, ppd->pkeys[idx]))
1536 return 0;
1537
1538 /* no match - try the whole table */
1539 if (!ingress_pkey_table_search(ppd, pkey))
1540 return 0;
1541
1542bad:
1543 ingress_pkey_table_fail(ppd, pkey, slid);
1544 return 1;
1545}
1546
1547/*
1548 * rcv_pkey_check - Return 0 if the ingress pkey is valid, return 1
1549 * otherwise. It only ensures pkey is vlid for QP0. This function
1550 * should be called on the data path instead of ingress_pkey_check
1551 * as on data path, pkey check is done by HW (except for QP0).
1552 */
1553static inline int rcv_pkey_check(struct hfi1_pportdata *ppd, u16 pkey,
1554 u8 sc5, u16 slid)
1555{
1556 if (!(ppd->part_enforce & HFI1_PART_ENFORCE_IN))
1557 return 0;
1558
1559 /* If SC15, pkey[0:14] must be 0x7fff */
1560 if ((sc5 == 0xf) && ((pkey & PKEY_LOW_15_MASK) != PKEY_LOW_15_MASK))
1561 goto bad;
1562
1563 return 0;
1564bad:
1565 ingress_pkey_table_fail(ppd, pkey, slid);
1566 return 1;
1567}
1568
1569/* MTU handling */
1570
1571/* MTU enumeration, 256-4k match IB */
1572#define OPA_MTU_0 0
1573#define OPA_MTU_256 1
1574#define OPA_MTU_512 2
1575#define OPA_MTU_1024 3
1576#define OPA_MTU_2048 4
1577#define OPA_MTU_4096 5
1578
1579u32 lrh_max_header_bytes(struct hfi1_devdata *dd);
1580int mtu_to_enum(u32 mtu, int default_if_bad);
Michael J. Ruhlf4cd8762017-05-04 05:14:39 -07001581u16 enum_to_mtu(int mtu);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001582static inline int valid_ib_mtu(unsigned int mtu)
1583{
1584 return mtu == 256 || mtu == 512 ||
1585 mtu == 1024 || mtu == 2048 ||
1586 mtu == 4096;
1587}
Jubin Johnf4d507c2016-02-14 20:20:25 -08001588
Mike Marciniszyn77241052015-07-30 15:17:43 -04001589static inline int valid_opa_max_mtu(unsigned int mtu)
1590{
1591 return mtu >= 2048 &&
1592 (valid_ib_mtu(mtu) || mtu == 8192 || mtu == 10240);
1593}
1594
Michael J. Ruhlf4cd8762017-05-04 05:14:39 -07001595int set_mtu(struct hfi1_pportdata *ppd);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001596
Michael J. Ruhlf4cd8762017-05-04 05:14:39 -07001597int hfi1_set_lid(struct hfi1_pportdata *ppd, u32 lid, u8 lmc);
1598void hfi1_disable_after_error(struct hfi1_devdata *dd);
1599int hfi1_set_uevent_bits(struct hfi1_pportdata *ppd, const int evtbit);
1600int hfi1_rcvbuf_validate(u32 size, u8 type, u16 *encode);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001601
Michael J. Ruhlf4cd8762017-05-04 05:14:39 -07001602int fm_get_table(struct hfi1_pportdata *ppd, int which, void *t);
1603int fm_set_table(struct hfi1_pportdata *ppd, int which, void *t);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001604
Byczkowski, Jakubb3e6b4b2017-05-12 09:01:37 -07001605void set_up_vau(struct hfi1_devdata *dd, u8 vau);
1606void set_up_vl15(struct hfi1_devdata *dd, u16 vl15buf);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001607void reset_link_credits(struct hfi1_devdata *dd);
1608void assign_remote_cm_au_table(struct hfi1_devdata *dd, u8 vcu);
1609
Mike Marciniszyn8a4d3442016-02-14 12:46:01 -08001610int set_buffer_control(struct hfi1_pportdata *ppd, struct buffer_control *bc);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001611
Mike Marciniszyn77241052015-07-30 15:17:43 -04001612static inline struct hfi1_devdata *dd_from_ppd(struct hfi1_pportdata *ppd)
1613{
1614 return ppd->dd;
1615}
1616
1617static inline struct hfi1_devdata *dd_from_dev(struct hfi1_ibdev *dev)
1618{
1619 return container_of(dev, struct hfi1_devdata, verbs_dev);
1620}
1621
1622static inline struct hfi1_devdata *dd_from_ibdev(struct ib_device *ibdev)
1623{
1624 return dd_from_dev(to_idev(ibdev));
1625}
1626
1627static inline struct hfi1_pportdata *ppd_from_ibp(struct hfi1_ibport *ibp)
1628{
1629 return container_of(ibp, struct hfi1_pportdata, ibport_data);
1630}
1631
Harish Chegondi45b59ee2016-02-03 14:36:49 -08001632static inline struct hfi1_ibdev *dev_from_rdi(struct rvt_dev_info *rdi)
1633{
1634 return container_of(rdi, struct hfi1_ibdev, rdi);
1635}
1636
Mike Marciniszyn77241052015-07-30 15:17:43 -04001637static inline struct hfi1_ibport *to_iport(struct ib_device *ibdev, u8 port)
1638{
1639 struct hfi1_devdata *dd = dd_from_ibdev(ibdev);
1640 unsigned pidx = port - 1; /* IB number port from 1, hdw from 0 */
1641
1642 WARN_ON(pidx >= dd->num_pports);
1643 return &dd->pport[pidx].ibport_data;
1644}
1645
Sebastian Sanchezf3e862c2017-02-08 05:26:25 -08001646static inline struct hfi1_ibport *rcd_to_iport(struct hfi1_ctxtdata *rcd)
1647{
1648 return &rcd->ppd->ibport_data;
1649}
1650
Mitko Haralanov5fd2b562016-07-25 13:38:07 -07001651void hfi1_process_ecn_slowpath(struct rvt_qp *qp, struct hfi1_packet *pkt,
1652 bool do_cnp);
1653static inline bool process_ecn(struct rvt_qp *qp, struct hfi1_packet *pkt,
1654 bool do_cnp)
1655{
Mike Marciniszyn261a4352016-09-06 04:35:05 -07001656 struct ib_other_headers *ohdr = pkt->ohdr;
Mitko Haralanov5fd2b562016-07-25 13:38:07 -07001657 u32 bth1;
1658
1659 bth1 = be32_to_cpu(ohdr->bth[1]);
Don Hiatt3d591092017-04-09 10:16:28 -07001660 if (unlikely(bth1 & (IB_BECN_SMASK | IB_FECN_SMASK))) {
Mitko Haralanov5fd2b562016-07-25 13:38:07 -07001661 hfi1_process_ecn_slowpath(qp, pkt, do_cnp);
Dennis Dalessandro4608e4c2017-04-09 10:17:30 -07001662 return !!(bth1 & IB_FECN_SMASK);
Mitko Haralanov5fd2b562016-07-25 13:38:07 -07001663 }
1664 return false;
1665}
1666
Mike Marciniszyn77241052015-07-30 15:17:43 -04001667/*
1668 * Return the indexed PKEY from the port PKEY table.
1669 */
1670static inline u16 hfi1_get_pkey(struct hfi1_ibport *ibp, unsigned index)
1671{
1672 struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
1673 u16 ret;
1674
1675 if (index >= ARRAY_SIZE(ppd->pkeys))
1676 ret = 0;
1677 else
1678 ret = ppd->pkeys[index];
1679
1680 return ret;
1681}
1682
1683/*
Jakub Pawlaka6cd5f02016-10-17 04:19:30 -07001684 * Return the indexed GUID from the port GUIDs table.
1685 */
1686static inline __be64 get_sguid(struct hfi1_ibport *ibp, unsigned int index)
1687{
1688 struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
1689
1690 WARN_ON(index >= HFI1_GUIDS_PER_PORT);
1691 return cpu_to_be64(ppd->guids[index]);
1692}
1693
1694/*
Jianxin Xiong8adf71f2016-07-25 13:39:14 -07001695 * Called by readers of cc_state only, must call under rcu_read_lock().
Mike Marciniszyn77241052015-07-30 15:17:43 -04001696 */
1697static inline struct cc_state *get_cc_state(struct hfi1_pportdata *ppd)
1698{
1699 return rcu_dereference(ppd->cc_state);
1700}
1701
1702/*
Jianxin Xiong8adf71f2016-07-25 13:39:14 -07001703 * Called by writers of cc_state only, must call under cc_state_lock.
1704 */
1705static inline
1706struct cc_state *get_cc_state_protected(struct hfi1_pportdata *ppd)
1707{
1708 return rcu_dereference_protected(ppd->cc_state,
1709 lockdep_is_held(&ppd->cc_state_lock));
1710}
1711
1712/*
Mike Marciniszyn77241052015-07-30 15:17:43 -04001713 * values for dd->flags (_device_ related flags)
1714 */
1715#define HFI1_INITTED 0x1 /* chip and driver up and initted */
1716#define HFI1_PRESENT 0x2 /* chip accesses can be done */
1717#define HFI1_FROZEN 0x4 /* chip in SPC freeze */
1718#define HFI1_HAS_SDMA_TIMEOUT 0x8
1719#define HFI1_HAS_SEND_DMA 0x10 /* Supports Send DMA */
1720#define HFI1_FORCED_FREEZE 0x80 /* driver forced freeze mode */
Mike Marciniszyn77241052015-07-30 15:17:43 -04001721
1722/* IB dword length mask in PBC (lower 11 bits); same for all chips */
1723#define HFI1_PBC_LENGTH_MASK ((1 << 11) - 1)
1724
Mike Marciniszyn77241052015-07-30 15:17:43 -04001725/* ctxt_flag bit offsets */
Michael J. Ruhl62239fc2017-05-04 05:15:21 -07001726 /* base context has not finished initializing */
1727#define HFI1_CTXT_BASE_UNINIT 1
1728 /* base context initaliation failed */
1729#define HFI1_CTXT_BASE_FAILED 2
Mike Marciniszyn77241052015-07-30 15:17:43 -04001730 /* waiting for a packet to arrive */
Michael J. Ruhl62239fc2017-05-04 05:15:21 -07001731#define HFI1_CTXT_WAITING_RCV 3
Mike Marciniszyn77241052015-07-30 15:17:43 -04001732 /* waiting for an urgent packet to arrive */
Michael J. Ruhl62239fc2017-05-04 05:15:21 -07001733#define HFI1_CTXT_WAITING_URG 4
Mike Marciniszyn77241052015-07-30 15:17:43 -04001734
1735/* free up any allocated data at closes */
Michael J. Ruhlf4cd8762017-05-04 05:14:39 -07001736struct hfi1_devdata *hfi1_init_dd(struct pci_dev *pdev,
1737 const struct pci_device_id *ent);
1738void hfi1_free_devdata(struct hfi1_devdata *dd);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001739struct hfi1_devdata *hfi1_alloc_devdata(struct pci_dev *pdev, size_t extra);
1740
Easwar Hariharan22434722016-03-07 11:35:03 -08001741/* LED beaconing functions */
1742void hfi1_start_led_override(struct hfi1_pportdata *ppd, unsigned int timeon,
1743 unsigned int timeoff);
Easwar Hariharan91ab4ed2016-02-03 14:35:57 -08001744void shutdown_led_override(struct hfi1_pportdata *ppd);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001745
1746#define HFI1_CREDIT_RETURN_RATE (100)
1747
1748/*
1749 * The number of words for the KDETH protocol field. If this is
1750 * larger then the actual field used, then part of the payload
1751 * will be in the header.
1752 *
1753 * Optimally, we want this sized so that a typical case will
1754 * use full cache lines. The typical local KDETH header would
1755 * be:
1756 *
1757 * Bytes Field
1758 * 8 LRH
1759 * 12 BHT
1760 * ?? KDETH
1761 * 8 RHF
1762 * ---
1763 * 28 + KDETH
1764 *
1765 * For a 64-byte cache line, KDETH would need to be 36 bytes or 9 DWORDS
1766 */
1767#define DEFAULT_RCVHDRSIZE 9
1768
1769/*
1770 * Maximal header byte count:
1771 *
1772 * Bytes Field
1773 * 8 LRH
1774 * 40 GRH (optional)
1775 * 12 BTH
1776 * ?? KDETH
1777 * 8 RHF
1778 * ---
1779 * 68 + KDETH
1780 *
1781 * We also want to maintain a cache line alignment to assist DMA'ing
1782 * of the header bytes. Round up to a good size.
1783 */
1784#define DEFAULT_RCVHDR_ENTSIZE 32
1785
Ira Weiny3faa3d92016-07-28 15:21:19 -04001786bool hfi1_can_pin_pages(struct hfi1_devdata *dd, struct mm_struct *mm,
1787 u32 nlocked, u32 npages);
1788int hfi1_acquire_user_pages(struct mm_struct *mm, unsigned long vaddr,
1789 size_t npages, bool writable, struct page **pages);
Ira Weinyac335e72016-07-28 12:27:28 -04001790void hfi1_release_user_pages(struct mm_struct *mm, struct page **p,
1791 size_t npages, bool dirty);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001792
1793static inline void clear_rcvhdrtail(const struct hfi1_ctxtdata *rcd)
1794{
Jubin John50e5dcb2016-02-14 20:19:41 -08001795 *((u64 *)rcd->rcvhdrtail_kvaddr) = 0ULL;
Mike Marciniszyn77241052015-07-30 15:17:43 -04001796}
1797
1798static inline u32 get_rcvhdrtail(const struct hfi1_ctxtdata *rcd)
1799{
1800 /*
1801 * volatile because it's a DMA target from the chip, routine is
1802 * inlined, and don't want register caching or reordering.
1803 */
Jubin John50e5dcb2016-02-14 20:19:41 -08001804 return (u32)le64_to_cpu(*rcd->rcvhdrtail_kvaddr);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001805}
1806
1807/*
1808 * sysfs interface.
1809 */
1810
1811extern const char ib_hfi1_version[];
1812
Michael J. Ruhlf4cd8762017-05-04 05:14:39 -07001813int hfi1_device_create(struct hfi1_devdata *dd);
1814void hfi1_device_remove(struct hfi1_devdata *dd);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001815
1816int hfi1_create_port_files(struct ib_device *ibdev, u8 port_num,
1817 struct kobject *kobj);
Michael J. Ruhlf4cd8762017-05-04 05:14:39 -07001818int hfi1_verbs_register_sysfs(struct hfi1_devdata *dd);
1819void hfi1_verbs_unregister_sysfs(struct hfi1_devdata *dd);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001820/* Hook for sysfs read of QSFP */
1821int qsfp_dump(struct hfi1_pportdata *ppd, char *buf, int len);
1822
Michael J. Ruhlf4cd8762017-05-04 05:14:39 -07001823int hfi1_pcie_init(struct pci_dev *pdev, const struct pci_device_id *ent);
1824void hfi1_pcie_cleanup(struct pci_dev *pdev);
1825int hfi1_pcie_ddinit(struct hfi1_devdata *dd, struct pci_dev *pdev);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001826void hfi1_pcie_ddcleanup(struct hfi1_devdata *);
Michael J. Ruhlf4cd8762017-05-04 05:14:39 -07001827int pcie_speeds(struct hfi1_devdata *dd);
Michael J. Ruhlbb7dde82017-05-26 05:35:31 -07001828int request_msix(struct hfi1_devdata *dd, u32 msireq);
Bartlomiej Dudekc53df622017-06-30 13:14:40 -07001829int restore_pci_variables(struct hfi1_devdata *dd);
Bartlomiej Dudeka618b7e2017-07-24 07:46:30 -07001830int save_pci_variables(struct hfi1_devdata *dd);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001831int do_pcie_gen3_transition(struct hfi1_devdata *dd);
1832int parse_platform_config(struct hfi1_devdata *dd);
1833int get_platform_config_field(struct hfi1_devdata *dd,
Jubin John17fb4f22016-02-14 20:21:52 -08001834 enum platform_config_table_type_encoding
1835 table_type, int table_index, int field_index,
1836 u32 *data, u32 len);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001837
Mike Marciniszyn77241052015-07-30 15:17:43 -04001838const char *get_unit_name(int unit);
Dennis Dalessandro49dbb6c2016-01-19 14:42:06 -08001839const char *get_card_name(struct rvt_dev_info *rdi);
1840struct pci_dev *get_pci_dev(struct rvt_dev_info *rdi);
Mike Marciniszyn77241052015-07-30 15:17:43 -04001841
1842/*
1843 * Flush write combining store buffers (if present) and perform a write
1844 * barrier.
1845 */
1846static inline void flush_wc(void)
1847{
1848 asm volatile("sfence" : : : "memory");
1849}
1850
1851void handle_eflags(struct hfi1_packet *packet);
1852int process_receive_ib(struct hfi1_packet *packet);
1853int process_receive_bypass(struct hfi1_packet *packet);
1854int process_receive_error(struct hfi1_packet *packet);
1855int kdeth_process_expected(struct hfi1_packet *packet);
1856int kdeth_process_eager(struct hfi1_packet *packet);
1857int process_receive_invalid(struct hfi1_packet *packet);
1858
Mike Marciniszyn77241052015-07-30 15:17:43 -04001859/* global module parameter variables */
1860extern unsigned int hfi1_max_mtu;
1861extern unsigned int hfi1_cu;
1862extern unsigned int user_credit_return_threshold;
Sebastian Sanchez2ce6bf22015-12-11 08:44:48 -05001863extern int num_user_contexts;
Harish Chegondi429b6a72016-08-31 07:24:40 -07001864extern unsigned long n_krcvqs;
Mark F. Brown5b55ea32016-01-11 18:30:54 -05001865extern uint krcvqs[];
Mike Marciniszyn77241052015-07-30 15:17:43 -04001866extern int krcvqsset;
1867extern uint kdeth_qp;
1868extern uint loopback;
1869extern uint quick_linkup;
1870extern uint rcv_intr_timeout;
1871extern uint rcv_intr_count;
1872extern uint rcv_intr_dynamic;
1873extern ushort link_crc_mask;
1874
1875extern struct mutex hfi1_mutex;
1876
1877/* Number of seconds before our card status check... */
1878#define STATUS_TIMEOUT 60
1879
1880#define DRIVER_NAME "hfi1"
1881#define HFI1_USER_MINOR_BASE 0
1882#define HFI1_TRACE_MINOR 127
Mike Marciniszyn77241052015-07-30 15:17:43 -04001883#define HFI1_NMINORS 255
1884
1885#define PCI_VENDOR_ID_INTEL 0x8086
1886#define PCI_DEVICE_ID_INTEL0 0x24f0
1887#define PCI_DEVICE_ID_INTEL1 0x24f1
1888
1889#define HFI1_PKT_USER_SC_INTEGRITY \
1890 (SEND_CTXT_CHECK_ENABLE_DISALLOW_NON_KDETH_PACKETS_SMASK \
Sebastian Sancheze38d1e42016-04-12 11:22:21 -07001891 | SEND_CTXT_CHECK_ENABLE_DISALLOW_KDETH_PACKETS_SMASK \
Mike Marciniszyn77241052015-07-30 15:17:43 -04001892 | SEND_CTXT_CHECK_ENABLE_DISALLOW_BYPASS_SMASK \
1893 | SEND_CTXT_CHECK_ENABLE_DISALLOW_GRH_SMASK)
1894
1895#define HFI1_PKT_KERNEL_SC_INTEGRITY \
1896 (SEND_CTXT_CHECK_ENABLE_DISALLOW_KDETH_PACKETS_SMASK)
1897
1898static inline u64 hfi1_pkt_default_send_ctxt_mask(struct hfi1_devdata *dd,
1899 u16 ctxt_type)
1900{
Jakub Pawlakd9ac4552016-10-10 06:14:56 -07001901 u64 base_sc_integrity;
1902
1903 /* No integrity checks if HFI1_CAP_NO_INTEGRITY is set */
1904 if (HFI1_CAP_IS_KSET(NO_INTEGRITY))
1905 return 0;
1906
1907 base_sc_integrity =
Mike Marciniszyn77241052015-07-30 15:17:43 -04001908 SEND_CTXT_CHECK_ENABLE_DISALLOW_BYPASS_BAD_PKT_LEN_SMASK
1909 | SEND_CTXT_CHECK_ENABLE_DISALLOW_PBC_STATIC_RATE_CONTROL_SMASK
1910 | SEND_CTXT_CHECK_ENABLE_DISALLOW_TOO_LONG_BYPASS_PACKETS_SMASK
1911 | SEND_CTXT_CHECK_ENABLE_DISALLOW_TOO_LONG_IB_PACKETS_SMASK
1912 | SEND_CTXT_CHECK_ENABLE_DISALLOW_BAD_PKT_LEN_SMASK
1913 | SEND_CTXT_CHECK_ENABLE_DISALLOW_PBC_TEST_SMASK
1914 | SEND_CTXT_CHECK_ENABLE_DISALLOW_TOO_SMALL_BYPASS_PACKETS_SMASK
1915 | SEND_CTXT_CHECK_ENABLE_DISALLOW_TOO_SMALL_IB_PACKETS_SMASK
1916 | SEND_CTXT_CHECK_ENABLE_DISALLOW_RAW_IPV6_SMASK
1917 | SEND_CTXT_CHECK_ENABLE_DISALLOW_RAW_SMASK
1918 | SEND_CTXT_CHECK_ENABLE_CHECK_BYPASS_VL_MAPPING_SMASK
1919 | SEND_CTXT_CHECK_ENABLE_CHECK_VL_MAPPING_SMASK
1920 | SEND_CTXT_CHECK_ENABLE_CHECK_OPCODE_SMASK
1921 | SEND_CTXT_CHECK_ENABLE_CHECK_SLID_SMASK
Mike Marciniszyn77241052015-07-30 15:17:43 -04001922 | SEND_CTXT_CHECK_ENABLE_CHECK_VL_SMASK
1923 | SEND_CTXT_CHECK_ENABLE_CHECK_ENABLE_SMASK;
1924
1925 if (ctxt_type == SC_USER)
1926 base_sc_integrity |= HFI1_PKT_USER_SC_INTEGRITY;
1927 else
1928 base_sc_integrity |= HFI1_PKT_KERNEL_SC_INTEGRITY;
1929
Jakub Pawlakd9ac4552016-10-10 06:14:56 -07001930 /* turn on send-side job key checks if !A0 */
1931 if (!is_ax(dd))
1932 base_sc_integrity |= SEND_CTXT_CHECK_ENABLE_CHECK_JOB_KEY_SMASK;
1933
Mike Marciniszyn77241052015-07-30 15:17:43 -04001934 return base_sc_integrity;
1935}
1936
1937static inline u64 hfi1_pkt_base_sdma_integrity(struct hfi1_devdata *dd)
1938{
Jakub Pawlakd9ac4552016-10-10 06:14:56 -07001939 u64 base_sdma_integrity;
1940
1941 /* No integrity checks if HFI1_CAP_NO_INTEGRITY is set */
1942 if (HFI1_CAP_IS_KSET(NO_INTEGRITY))
1943 return 0;
1944
1945 base_sdma_integrity =
Mike Marciniszyn77241052015-07-30 15:17:43 -04001946 SEND_DMA_CHECK_ENABLE_DISALLOW_BYPASS_BAD_PKT_LEN_SMASK
Mike Marciniszyn77241052015-07-30 15:17:43 -04001947 | SEND_DMA_CHECK_ENABLE_DISALLOW_TOO_LONG_BYPASS_PACKETS_SMASK
1948 | SEND_DMA_CHECK_ENABLE_DISALLOW_TOO_LONG_IB_PACKETS_SMASK
1949 | SEND_DMA_CHECK_ENABLE_DISALLOW_BAD_PKT_LEN_SMASK
1950 | SEND_DMA_CHECK_ENABLE_DISALLOW_TOO_SMALL_BYPASS_PACKETS_SMASK
1951 | SEND_DMA_CHECK_ENABLE_DISALLOW_TOO_SMALL_IB_PACKETS_SMASK
1952 | SEND_DMA_CHECK_ENABLE_DISALLOW_RAW_IPV6_SMASK
1953 | SEND_DMA_CHECK_ENABLE_DISALLOW_RAW_SMASK
1954 | SEND_DMA_CHECK_ENABLE_CHECK_BYPASS_VL_MAPPING_SMASK
1955 | SEND_DMA_CHECK_ENABLE_CHECK_VL_MAPPING_SMASK
1956 | SEND_DMA_CHECK_ENABLE_CHECK_OPCODE_SMASK
1957 | SEND_DMA_CHECK_ENABLE_CHECK_SLID_SMASK
Mike Marciniszyn77241052015-07-30 15:17:43 -04001958 | SEND_DMA_CHECK_ENABLE_CHECK_VL_SMASK
1959 | SEND_DMA_CHECK_ENABLE_CHECK_ENABLE_SMASK;
1960
Jakub Pawlakd9ac4552016-10-10 06:14:56 -07001961 if (!HFI1_CAP_IS_KSET(STATIC_RATE_CTRL))
1962 base_sdma_integrity |=
1963 SEND_DMA_CHECK_ENABLE_DISALLOW_PBC_STATIC_RATE_CONTROL_SMASK;
1964
1965 /* turn on send-side job key checks if !A0 */
1966 if (!is_ax(dd))
1967 base_sdma_integrity |=
1968 SEND_DMA_CHECK_ENABLE_CHECK_JOB_KEY_SMASK;
1969
Mike Marciniszyn77241052015-07-30 15:17:43 -04001970 return base_sdma_integrity;
1971}
1972
1973/*
1974 * hfi1_early_err is used (only!) to print early errors before devdata is
1975 * allocated, or when dd->pcidev may not be valid, and at the tail end of
1976 * cleanup when devdata may have been freed, etc. hfi1_dev_porterr is
1977 * the same as dd_dev_err, but is used when the message really needs
1978 * the IB port# to be definitive as to what's happening..
1979 */
1980#define hfi1_early_err(dev, fmt, ...) \
1981 dev_err(dev, fmt, ##__VA_ARGS__)
1982
1983#define hfi1_early_info(dev, fmt, ...) \
1984 dev_info(dev, fmt, ##__VA_ARGS__)
1985
1986#define dd_dev_emerg(dd, fmt, ...) \
1987 dev_emerg(&(dd)->pcidev->dev, "%s: " fmt, \
1988 get_unit_name((dd)->unit), ##__VA_ARGS__)
1989#define dd_dev_err(dd, fmt, ...) \
1990 dev_err(&(dd)->pcidev->dev, "%s: " fmt, \
1991 get_unit_name((dd)->unit), ##__VA_ARGS__)
1992#define dd_dev_warn(dd, fmt, ...) \
1993 dev_warn(&(dd)->pcidev->dev, "%s: " fmt, \
1994 get_unit_name((dd)->unit), ##__VA_ARGS__)
1995
1996#define dd_dev_warn_ratelimited(dd, fmt, ...) \
1997 dev_warn_ratelimited(&(dd)->pcidev->dev, "%s: " fmt, \
1998 get_unit_name((dd)->unit), ##__VA_ARGS__)
1999
2000#define dd_dev_info(dd, fmt, ...) \
2001 dev_info(&(dd)->pcidev->dev, "%s: " fmt, \
2002 get_unit_name((dd)->unit), ##__VA_ARGS__)
2003
Jakub Byczkowskic27aad02017-02-08 05:27:55 -08002004#define dd_dev_info_ratelimited(dd, fmt, ...) \
2005 dev_info_ratelimited(&(dd)->pcidev->dev, "%s: " fmt, \
2006 get_unit_name((dd)->unit), ##__VA_ARGS__)
2007
Ira Weinya1edc182016-01-11 13:04:32 -05002008#define dd_dev_dbg(dd, fmt, ...) \
2009 dev_dbg(&(dd)->pcidev->dev, "%s: " fmt, \
2010 get_unit_name((dd)->unit), ##__VA_ARGS__)
2011
Mike Marciniszyn77241052015-07-30 15:17:43 -04002012#define hfi1_dev_porterr(dd, port, fmt, ...) \
Jakub Pawlakcde10af2016-05-12 10:23:35 -07002013 dev_err(&(dd)->pcidev->dev, "%s: port %u: " fmt, \
2014 get_unit_name((dd)->unit), (port), ##__VA_ARGS__)
Mike Marciniszyn77241052015-07-30 15:17:43 -04002015
2016/*
2017 * this is used for formatting hw error messages...
2018 */
2019struct hfi1_hwerror_msgs {
2020 u64 mask;
2021 const char *msg;
2022 size_t sz;
2023};
2024
2025/* in intr.c... */
2026void hfi1_format_hwerrors(u64 hwerrs,
2027 const struct hfi1_hwerror_msgs *hwerrmsgs,
2028 size_t nhwerrmsgs, char *msg, size_t lmsg);
2029
2030#define USER_OPCODE_CHECK_VAL 0xC0
2031#define USER_OPCODE_CHECK_MASK 0xC0
2032#define OPCODE_CHECK_VAL_DISABLED 0x0
2033#define OPCODE_CHECK_MASK_DISABLED 0x0
2034
2035static inline void hfi1_reset_cpu_counters(struct hfi1_devdata *dd)
2036{
2037 struct hfi1_pportdata *ppd;
2038 int i;
2039
2040 dd->z_int_counter = get_all_cpu_total(dd->int_counter);
2041 dd->z_rcv_limit = get_all_cpu_total(dd->rcv_limit);
Vennila Megavannan89abfc82016-02-03 14:34:07 -08002042 dd->z_send_schedule = get_all_cpu_total(dd->send_schedule);
Mike Marciniszyn77241052015-07-30 15:17:43 -04002043
2044 ppd = (struct hfi1_pportdata *)(dd + 1);
2045 for (i = 0; i < dd->num_pports; i++, ppd++) {
Dennis Dalessandro4eb06882016-01-19 14:42:39 -08002046 ppd->ibport_data.rvp.z_rc_acks =
2047 get_all_cpu_total(ppd->ibport_data.rvp.rc_acks);
2048 ppd->ibport_data.rvp.z_rc_qacks =
2049 get_all_cpu_total(ppd->ibport_data.rvp.rc_qacks);
Mike Marciniszyn77241052015-07-30 15:17:43 -04002050 }
2051}
2052
2053/* Control LED state */
2054static inline void setextled(struct hfi1_devdata *dd, u32 on)
2055{
2056 if (on)
2057 write_csr(dd, DCC_CFG_LED_CNTRL, 0x1F);
2058 else
2059 write_csr(dd, DCC_CFG_LED_CNTRL, 0x10);
2060}
2061
Dean Luick765a6fa2016-03-05 08:50:06 -08002062/* return the i2c resource given the target */
2063static inline u32 i2c_target(u32 target)
2064{
2065 return target ? CR_I2C2 : CR_I2C1;
2066}
2067
2068/* return the i2c chain chip resource that this HFI uses for QSFP */
2069static inline u32 qsfp_resource(struct hfi1_devdata *dd)
2070{
2071 return i2c_target(dd->hfi1_id);
2072}
2073
Easwar Hariharanfe4d9242016-10-17 04:19:47 -07002074/* Is this device integrated or discrete? */
2075static inline bool is_integrated(struct hfi1_devdata *dd)
2076{
2077 return dd->pcidev->device == PCI_DEVICE_ID_INTEL1;
2078}
2079
Mike Marciniszyn77241052015-07-30 15:17:43 -04002080int hfi1_tempsense_rd(struct hfi1_devdata *dd, struct hfi1_temp *temp);
2081
Sebastian Sanchez462b6b22016-07-01 16:01:06 -07002082#define DD_DEV_ENTRY(dd) __string(dev, dev_name(&(dd)->pcidev->dev))
2083#define DD_DEV_ASSIGN(dd) __assign_str(dev, dev_name(&(dd)->pcidev->dev))
Don Hiatt90397462017-05-12 09:20:20 -07002084
2085/*
2086 * hfi1_check_mcast- Check if the given lid is
2087 * in the IB multicast range.
2088 */
2089static inline bool hfi1_check_mcast(u16 lid)
2090{
2091 return ((lid >= be16_to_cpu(IB_MULTICAST_LID_BASE)) &&
2092 (lid != be16_to_cpu(IB_LID_PERMISSIVE)));
2093}
Mike Marciniszyn77241052015-07-30 15:17:43 -04002094#endif /* _HFI1_KERNEL_H */