hfi.h 72 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458
  1. #ifndef _HFI1_KERNEL_H
  2. #define _HFI1_KERNEL_H
  3. /*
  4. * Copyright(c) 2015-2018 Intel Corporation.
  5. *
  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. *
  11. * 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. *
  22. * 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. #include <linux/interrupt.h>
  50. #include <linux/pci.h>
  51. #include <linux/dma-mapping.h>
  52. #include <linux/mutex.h>
  53. #include <linux/list.h>
  54. #include <linux/scatterlist.h>
  55. #include <linux/slab.h>
  56. #include <linux/idr.h>
  57. #include <linux/io.h>
  58. #include <linux/fs.h>
  59. #include <linux/completion.h>
  60. #include <linux/kref.h>
  61. #include <linux/sched.h>
  62. #include <linux/cdev.h>
  63. #include <linux/delay.h>
  64. #include <linux/kthread.h>
  65. #include <linux/i2c.h>
  66. #include <linux/i2c-algo-bit.h>
  67. #include <rdma/ib_hdrs.h>
  68. #include <rdma/opa_addr.h>
  69. #include <linux/rhashtable.h>
  70. #include <linux/netdevice.h>
  71. #include <rdma/rdma_vt.h>
  72. #include "chip_registers.h"
  73. #include "common.h"
  74. #include "verbs.h"
  75. #include "pio.h"
  76. #include "chip.h"
  77. #include "mad.h"
  78. #include "qsfp.h"
  79. #include "platform.h"
  80. #include "affinity.h"
  81. #include "msix.h"
  82. /* bumped 1 from s/w major version of TrueScale */
  83. #define HFI1_CHIP_VERS_MAJ 3U
  84. /* don't care about this except printing */
  85. #define HFI1_CHIP_VERS_MIN 0U
  86. /* The Organization Unique Identifier (Mfg code), and its position in GUID */
  87. #define HFI1_OUI 0x001175
  88. #define HFI1_OUI_LSB 40
  89. #define DROP_PACKET_OFF 0
  90. #define DROP_PACKET_ON 1
  91. #define NEIGHBOR_TYPE_HFI 0
  92. #define NEIGHBOR_TYPE_SWITCH 1
  93. extern unsigned long hfi1_cap_mask;
  94. #define HFI1_CAP_KGET_MASK(mask, cap) ((mask) & HFI1_CAP_##cap)
  95. #define HFI1_CAP_UGET_MASK(mask, cap) \
  96. (((mask) >> HFI1_CAP_USER_SHIFT) & HFI1_CAP_##cap)
  97. #define HFI1_CAP_KGET(cap) (HFI1_CAP_KGET_MASK(hfi1_cap_mask, cap))
  98. #define HFI1_CAP_UGET(cap) (HFI1_CAP_UGET_MASK(hfi1_cap_mask, cap))
  99. #define HFI1_CAP_IS_KSET(cap) (!!HFI1_CAP_KGET(cap))
  100. #define HFI1_CAP_IS_USET(cap) (!!HFI1_CAP_UGET(cap))
  101. #define HFI1_MISC_GET() ((hfi1_cap_mask >> HFI1_CAP_MISC_SHIFT) & \
  102. HFI1_CAP_MISC_MASK)
  103. /* Offline Disabled Reason is 4-bits */
  104. #define HFI1_ODR_MASK(rsn) ((rsn) & OPA_PI_MASK_OFFLINE_REASON)
  105. /*
  106. * Control context is always 0 and handles the error packets.
  107. * It also handles the VL15 and multicast packets.
  108. */
  109. #define HFI1_CTRL_CTXT 0
  110. /*
  111. * Driver context will store software counters for each of the events
  112. * associated with these status registers
  113. */
  114. #define NUM_CCE_ERR_STATUS_COUNTERS 41
  115. #define NUM_RCV_ERR_STATUS_COUNTERS 64
  116. #define NUM_MISC_ERR_STATUS_COUNTERS 13
  117. #define NUM_SEND_PIO_ERR_STATUS_COUNTERS 36
  118. #define NUM_SEND_DMA_ERR_STATUS_COUNTERS 4
  119. #define NUM_SEND_EGRESS_ERR_STATUS_COUNTERS 64
  120. #define NUM_SEND_ERR_STATUS_COUNTERS 3
  121. #define NUM_SEND_CTXT_ERR_STATUS_COUNTERS 5
  122. #define NUM_SEND_DMA_ENG_ERR_STATUS_COUNTERS 24
  123. /*
  124. * per driver stats, either not device nor port-specific, or
  125. * summed over all of the devices and ports.
  126. * They are described by name via ipathfs filesystem, so layout
  127. * and number of elements can change without breaking compatibility.
  128. * If members are added or deleted hfi1_statnames[] in debugfs.c must
  129. * change to match.
  130. */
  131. struct hfi1_ib_stats {
  132. __u64 sps_ints; /* number of interrupts handled */
  133. __u64 sps_errints; /* number of error interrupts */
  134. __u64 sps_txerrs; /* tx-related packet errors */
  135. __u64 sps_rcverrs; /* non-crc rcv packet errors */
  136. __u64 sps_hwerrs; /* hardware errors reported (parity, etc.) */
  137. __u64 sps_nopiobufs; /* no pio bufs avail from kernel */
  138. __u64 sps_ctxts; /* number of contexts currently open */
  139. __u64 sps_lenerrs; /* number of kernel packets where RHF != LRH len */
  140. __u64 sps_buffull;
  141. __u64 sps_hdrfull;
  142. };
  143. extern struct hfi1_ib_stats hfi1_stats;
  144. extern const struct pci_error_handlers hfi1_pci_err_handler;
  145. extern int num_driver_cntrs;
  146. /*
  147. * First-cut criterion for "device is active" is
  148. * two thousand dwords combined Tx, Rx traffic per
  149. * 5-second interval. SMA packets are 64 dwords,
  150. * and occur "a few per second", presumably each way.
  151. */
  152. #define HFI1_TRAFFIC_ACTIVE_THRESHOLD (2000)
  153. /*
  154. * Below contains all data related to a single context (formerly called port).
  155. */
  156. struct hfi1_opcode_stats_perctx;
  157. struct ctxt_eager_bufs {
  158. struct eager_buffer {
  159. void *addr;
  160. dma_addr_t dma;
  161. ssize_t len;
  162. } *buffers;
  163. struct {
  164. void *addr;
  165. dma_addr_t dma;
  166. } *rcvtids;
  167. u32 size; /* total size of eager buffers */
  168. u32 rcvtid_size; /* size of each eager rcv tid */
  169. u16 count; /* size of buffers array */
  170. u16 numbufs; /* number of buffers allocated */
  171. u16 alloced; /* number of rcvarray entries used */
  172. u16 threshold; /* head update threshold */
  173. };
  174. struct exp_tid_set {
  175. struct list_head list;
  176. u32 count;
  177. };
  178. typedef int (*rhf_rcv_function_ptr)(struct hfi1_packet *packet);
  179. struct hfi1_ctxtdata {
  180. /* rcvhdrq base, needs mmap before useful */
  181. void *rcvhdrq;
  182. /* kernel virtual address where hdrqtail is updated */
  183. volatile __le64 *rcvhdrtail_kvaddr;
  184. /* so functions that need physical port can get it easily */
  185. struct hfi1_pportdata *ppd;
  186. /* so file ops can get at unit */
  187. struct hfi1_devdata *dd;
  188. /* this receive context's assigned PIO ACK send context */
  189. struct send_context *sc;
  190. /* per context recv functions */
  191. const rhf_rcv_function_ptr *rhf_rcv_function_map;
  192. /*
  193. * The interrupt handler for a particular receive context can vary
  194. * throughout it's lifetime. This is not a lock protected data member so
  195. * it must be updated atomically and the prev and new value must always
  196. * be valid. Worst case is we process an extra interrupt and up to 64
  197. * packets with the wrong interrupt handler.
  198. */
  199. int (*do_interrupt)(struct hfi1_ctxtdata *rcd, int threaded);
  200. /* verbs rx_stats per rcd */
  201. struct hfi1_opcode_stats_perctx *opstats;
  202. /* clear interrupt mask */
  203. u64 imask;
  204. /* ctxt rcvhdrq head offset */
  205. u32 head;
  206. /* number of rcvhdrq entries */
  207. u16 rcvhdrq_cnt;
  208. u8 ireg; /* clear interrupt register */
  209. /* receive packet sequence counter */
  210. u8 seq_cnt;
  211. /* size of each of the rcvhdrq entries */
  212. u8 rcvhdrqentsize;
  213. /* offset of RHF within receive header entry */
  214. u8 rhf_offset;
  215. /* dynamic receive available interrupt timeout */
  216. u8 rcvavail_timeout;
  217. /* Indicates that this is vnic context */
  218. bool is_vnic;
  219. /* vnic queue index this context is mapped to */
  220. u8 vnic_q_idx;
  221. /* Is ASPM interrupt supported for this context */
  222. bool aspm_intr_supported;
  223. /* ASPM state (enabled/disabled) for this context */
  224. bool aspm_enabled;
  225. /* Is ASPM processing enabled for this context (in intr context) */
  226. bool aspm_intr_enable;
  227. struct ctxt_eager_bufs egrbufs;
  228. /* QPs waiting for context processing */
  229. struct list_head qp_wait_list;
  230. /* tid allocation lists */
  231. struct exp_tid_set tid_group_list;
  232. struct exp_tid_set tid_used_list;
  233. struct exp_tid_set tid_full_list;
  234. /* Timer for re-enabling ASPM if interrupt activity quiets down */
  235. struct timer_list aspm_timer;
  236. /* per-context configuration flags */
  237. unsigned long flags;
  238. /* array of tid_groups */
  239. struct tid_group *groups;
  240. /* mmap of hdrq, must fit in 44 bits */
  241. dma_addr_t rcvhdrq_dma;
  242. dma_addr_t rcvhdrqtailaddr_dma;
  243. /* Last interrupt timestamp */
  244. ktime_t aspm_ts_last_intr;
  245. /* Last timestamp at which we scheduled a timer for this context */
  246. ktime_t aspm_ts_timer_sched;
  247. /* Lock to serialize between intr, timer intr and user threads */
  248. spinlock_t aspm_lock;
  249. /* Reference count the base context usage */
  250. struct kref kref;
  251. /* numa node of this context */
  252. int numa_id;
  253. /* associated msix interrupt. */
  254. s16 msix_intr;
  255. /* job key */
  256. u16 jkey;
  257. /* number of RcvArray groups for this context. */
  258. u16 rcv_array_groups;
  259. /* index of first eager TID entry. */
  260. u16 eager_base;
  261. /* number of expected TID entries */
  262. u16 expected_count;
  263. /* index of first expected TID entry. */
  264. u16 expected_base;
  265. /* Device context index */
  266. u8 ctxt;
  267. /* PSM Specific fields */
  268. /* lock protecting all Expected TID data */
  269. struct mutex exp_mutex;
  270. /* when waiting for rcv or pioavail */
  271. wait_queue_head_t wait;
  272. /* uuid from PSM */
  273. u8 uuid[16];
  274. /* same size as task_struct .comm[], command that opened context */
  275. char comm[TASK_COMM_LEN];
  276. /* Bitmask of in use context(s) */
  277. DECLARE_BITMAP(in_use_ctxts, HFI1_MAX_SHARED_CTXTS);
  278. /* per-context event flags for fileops/intr communication */
  279. unsigned long event_flags;
  280. /* A page of memory for rcvhdrhead, rcvegrhead, rcvegrtail * N */
  281. void *subctxt_uregbase;
  282. /* An array of pages for the eager receive buffers * N */
  283. void *subctxt_rcvegrbuf;
  284. /* An array of pages for the eager header queue entries * N */
  285. void *subctxt_rcvhdr_base;
  286. /* total number of polled urgent packets */
  287. u32 urgent;
  288. /* saved total number of polled urgent packets for poll edge trigger */
  289. u32 urgent_poll;
  290. /* Type of packets or conditions we want to poll for */
  291. u16 poll_type;
  292. /* non-zero if ctxt is being shared. */
  293. u16 subctxt_id;
  294. /* The version of the library which opened this ctxt */
  295. u32 userversion;
  296. /*
  297. * non-zero if ctxt can be shared, and defines the maximum number of
  298. * sub-contexts for this device context.
  299. */
  300. u8 subctxt_cnt;
  301. };
  302. /**
  303. * rcvhdrq_size - return total size in bytes for header queue
  304. * @rcd: the receive context
  305. *
  306. * rcvhdrqentsize is in DWs, so we have to convert to bytes
  307. *
  308. */
  309. static inline u32 rcvhdrq_size(struct hfi1_ctxtdata *rcd)
  310. {
  311. return PAGE_ALIGN(rcd->rcvhdrq_cnt *
  312. rcd->rcvhdrqentsize * sizeof(u32));
  313. }
  314. /*
  315. * Represents a single packet at a high level. Put commonly computed things in
  316. * here so we do not have to keep doing them over and over. The rule of thumb is
  317. * if something is used one time to derive some value, store that something in
  318. * here. If it is used multiple times, then store the result of that derivation
  319. * in here.
  320. */
  321. struct hfi1_packet {
  322. void *ebuf;
  323. void *hdr;
  324. void *payload;
  325. struct hfi1_ctxtdata *rcd;
  326. __le32 *rhf_addr;
  327. struct rvt_qp *qp;
  328. struct ib_other_headers *ohdr;
  329. struct ib_grh *grh;
  330. struct opa_16b_mgmt *mgmt;
  331. u64 rhf;
  332. u32 maxcnt;
  333. u32 rhqoff;
  334. u32 dlid;
  335. u32 slid;
  336. u16 tlen;
  337. s16 etail;
  338. u16 pkey;
  339. u8 hlen;
  340. u8 numpkt;
  341. u8 rsize;
  342. u8 updegr;
  343. u8 etype;
  344. u8 extra_byte;
  345. u8 pad;
  346. u8 sc;
  347. u8 sl;
  348. u8 opcode;
  349. bool migrated;
  350. };
  351. /* Packet types */
  352. #define HFI1_PKT_TYPE_9B 0
  353. #define HFI1_PKT_TYPE_16B 1
  354. /*
  355. * OPA 16B Header
  356. */
  357. #define OPA_16B_L4_MASK 0xFFull
  358. #define OPA_16B_SC_MASK 0x1F00000ull
  359. #define OPA_16B_SC_SHIFT 20
  360. #define OPA_16B_LID_MASK 0xFFFFFull
  361. #define OPA_16B_DLID_MASK 0xF000ull
  362. #define OPA_16B_DLID_SHIFT 20
  363. #define OPA_16B_DLID_HIGH_SHIFT 12
  364. #define OPA_16B_SLID_MASK 0xF00ull
  365. #define OPA_16B_SLID_SHIFT 20
  366. #define OPA_16B_SLID_HIGH_SHIFT 8
  367. #define OPA_16B_BECN_MASK 0x80000000ull
  368. #define OPA_16B_BECN_SHIFT 31
  369. #define OPA_16B_FECN_MASK 0x10000000ull
  370. #define OPA_16B_FECN_SHIFT 28
  371. #define OPA_16B_L2_MASK 0x60000000ull
  372. #define OPA_16B_L2_SHIFT 29
  373. #define OPA_16B_PKEY_MASK 0xFFFF0000ull
  374. #define OPA_16B_PKEY_SHIFT 16
  375. #define OPA_16B_LEN_MASK 0x7FF00000ull
  376. #define OPA_16B_LEN_SHIFT 20
  377. #define OPA_16B_RC_MASK 0xE000000ull
  378. #define OPA_16B_RC_SHIFT 25
  379. #define OPA_16B_AGE_MASK 0xFF0000ull
  380. #define OPA_16B_AGE_SHIFT 16
  381. #define OPA_16B_ENTROPY_MASK 0xFFFFull
  382. /*
  383. * OPA 16B L2/L4 Encodings
  384. */
  385. #define OPA_16B_L4_9B 0x00
  386. #define OPA_16B_L2_TYPE 0x02
  387. #define OPA_16B_L4_FM 0x08
  388. #define OPA_16B_L4_IB_LOCAL 0x09
  389. #define OPA_16B_L4_IB_GLOBAL 0x0A
  390. #define OPA_16B_L4_ETHR OPA_VNIC_L4_ETHR
  391. /*
  392. * OPA 16B Management
  393. */
  394. #define OPA_16B_L4_FM_PAD 3 /* fixed 3B pad */
  395. #define OPA_16B_L4_FM_HLEN 24 /* 16B(16) + L4_FM(8) */
  396. static inline u8 hfi1_16B_get_l4(struct hfi1_16b_header *hdr)
  397. {
  398. return (u8)(hdr->lrh[2] & OPA_16B_L4_MASK);
  399. }
  400. static inline u8 hfi1_16B_get_sc(struct hfi1_16b_header *hdr)
  401. {
  402. return (u8)((hdr->lrh[1] & OPA_16B_SC_MASK) >> OPA_16B_SC_SHIFT);
  403. }
  404. static inline u32 hfi1_16B_get_dlid(struct hfi1_16b_header *hdr)
  405. {
  406. return (u32)((hdr->lrh[1] & OPA_16B_LID_MASK) |
  407. (((hdr->lrh[2] & OPA_16B_DLID_MASK) >>
  408. OPA_16B_DLID_HIGH_SHIFT) << OPA_16B_DLID_SHIFT));
  409. }
  410. static inline u32 hfi1_16B_get_slid(struct hfi1_16b_header *hdr)
  411. {
  412. return (u32)((hdr->lrh[0] & OPA_16B_LID_MASK) |
  413. (((hdr->lrh[2] & OPA_16B_SLID_MASK) >>
  414. OPA_16B_SLID_HIGH_SHIFT) << OPA_16B_SLID_SHIFT));
  415. }
  416. static inline u8 hfi1_16B_get_becn(struct hfi1_16b_header *hdr)
  417. {
  418. return (u8)((hdr->lrh[0] & OPA_16B_BECN_MASK) >> OPA_16B_BECN_SHIFT);
  419. }
  420. static inline u8 hfi1_16B_get_fecn(struct hfi1_16b_header *hdr)
  421. {
  422. return (u8)((hdr->lrh[1] & OPA_16B_FECN_MASK) >> OPA_16B_FECN_SHIFT);
  423. }
  424. static inline u8 hfi1_16B_get_l2(struct hfi1_16b_header *hdr)
  425. {
  426. return (u8)((hdr->lrh[1] & OPA_16B_L2_MASK) >> OPA_16B_L2_SHIFT);
  427. }
  428. static inline u16 hfi1_16B_get_pkey(struct hfi1_16b_header *hdr)
  429. {
  430. return (u16)((hdr->lrh[2] & OPA_16B_PKEY_MASK) >> OPA_16B_PKEY_SHIFT);
  431. }
  432. static inline u8 hfi1_16B_get_rc(struct hfi1_16b_header *hdr)
  433. {
  434. return (u8)((hdr->lrh[1] & OPA_16B_RC_MASK) >> OPA_16B_RC_SHIFT);
  435. }
  436. static inline u8 hfi1_16B_get_age(struct hfi1_16b_header *hdr)
  437. {
  438. return (u8)((hdr->lrh[3] & OPA_16B_AGE_MASK) >> OPA_16B_AGE_SHIFT);
  439. }
  440. static inline u16 hfi1_16B_get_len(struct hfi1_16b_header *hdr)
  441. {
  442. return (u16)((hdr->lrh[0] & OPA_16B_LEN_MASK) >> OPA_16B_LEN_SHIFT);
  443. }
  444. static inline u16 hfi1_16B_get_entropy(struct hfi1_16b_header *hdr)
  445. {
  446. return (u16)(hdr->lrh[3] & OPA_16B_ENTROPY_MASK);
  447. }
  448. #define OPA_16B_MAKE_QW(low_dw, high_dw) (((u64)(high_dw) << 32) | (low_dw))
  449. /*
  450. * BTH
  451. */
  452. #define OPA_16B_BTH_PAD_MASK 7
  453. static inline u8 hfi1_16B_bth_get_pad(struct ib_other_headers *ohdr)
  454. {
  455. return (u8)((be32_to_cpu(ohdr->bth[0]) >> IB_BTH_PAD_SHIFT) &
  456. OPA_16B_BTH_PAD_MASK);
  457. }
  458. /*
  459. * 16B Management
  460. */
  461. #define OPA_16B_MGMT_QPN_MASK 0xFFFFFF
  462. static inline u32 hfi1_16B_get_dest_qpn(struct opa_16b_mgmt *mgmt)
  463. {
  464. return be32_to_cpu(mgmt->dest_qpn) & OPA_16B_MGMT_QPN_MASK;
  465. }
  466. static inline u32 hfi1_16B_get_src_qpn(struct opa_16b_mgmt *mgmt)
  467. {
  468. return be32_to_cpu(mgmt->src_qpn) & OPA_16B_MGMT_QPN_MASK;
  469. }
  470. static inline void hfi1_16B_set_qpn(struct opa_16b_mgmt *mgmt,
  471. u32 dest_qp, u32 src_qp)
  472. {
  473. mgmt->dest_qpn = cpu_to_be32(dest_qp & OPA_16B_MGMT_QPN_MASK);
  474. mgmt->src_qpn = cpu_to_be32(src_qp & OPA_16B_MGMT_QPN_MASK);
  475. }
  476. struct rvt_sge_state;
  477. /*
  478. * Get/Set IB link-level config parameters for f_get/set_ib_cfg()
  479. * Mostly for MADs that set or query link parameters, also ipath
  480. * config interfaces
  481. */
  482. #define HFI1_IB_CFG_LIDLMC 0 /* LID (LS16b) and Mask (MS16b) */
  483. #define HFI1_IB_CFG_LWID_DG_ENB 1 /* allowed Link-width downgrade */
  484. #define HFI1_IB_CFG_LWID_ENB 2 /* allowed Link-width */
  485. #define HFI1_IB_CFG_LWID 3 /* currently active Link-width */
  486. #define HFI1_IB_CFG_SPD_ENB 4 /* allowed Link speeds */
  487. #define HFI1_IB_CFG_SPD 5 /* current Link spd */
  488. #define HFI1_IB_CFG_RXPOL_ENB 6 /* Auto-RX-polarity enable */
  489. #define HFI1_IB_CFG_LREV_ENB 7 /* Auto-Lane-reversal enable */
  490. #define HFI1_IB_CFG_LINKLATENCY 8 /* Link Latency (IB1.2 only) */
  491. #define HFI1_IB_CFG_HRTBT 9 /* IB heartbeat off/enable/auto; DDR/QDR only */
  492. #define HFI1_IB_CFG_OP_VLS 10 /* operational VLs */
  493. #define HFI1_IB_CFG_VL_HIGH_CAP 11 /* num of VL high priority weights */
  494. #define HFI1_IB_CFG_VL_LOW_CAP 12 /* num of VL low priority weights */
  495. #define HFI1_IB_CFG_OVERRUN_THRESH 13 /* IB overrun threshold */
  496. #define HFI1_IB_CFG_PHYERR_THRESH 14 /* IB PHY error threshold */
  497. #define HFI1_IB_CFG_LINKDEFAULT 15 /* IB link default (sleep/poll) */
  498. #define HFI1_IB_CFG_PKEYS 16 /* update partition keys */
  499. #define HFI1_IB_CFG_MTU 17 /* update MTU in IBC */
  500. #define HFI1_IB_CFG_VL_HIGH_LIMIT 19
  501. #define HFI1_IB_CFG_PMA_TICKS 20 /* PMA sample tick resolution */
  502. #define HFI1_IB_CFG_PORT 21 /* switch port we are connected to */
  503. /*
  504. * HFI or Host Link States
  505. *
  506. * These describe the states the driver thinks the logical and physical
  507. * states are in. Used as an argument to set_link_state(). Implemented
  508. * as bits for easy multi-state checking. The actual state can only be
  509. * one.
  510. */
  511. #define __HLS_UP_INIT_BP 0
  512. #define __HLS_UP_ARMED_BP 1
  513. #define __HLS_UP_ACTIVE_BP 2
  514. #define __HLS_DN_DOWNDEF_BP 3 /* link down default */
  515. #define __HLS_DN_POLL_BP 4
  516. #define __HLS_DN_DISABLE_BP 5
  517. #define __HLS_DN_OFFLINE_BP 6
  518. #define __HLS_VERIFY_CAP_BP 7
  519. #define __HLS_GOING_UP_BP 8
  520. #define __HLS_GOING_OFFLINE_BP 9
  521. #define __HLS_LINK_COOLDOWN_BP 10
  522. #define HLS_UP_INIT BIT(__HLS_UP_INIT_BP)
  523. #define HLS_UP_ARMED BIT(__HLS_UP_ARMED_BP)
  524. #define HLS_UP_ACTIVE BIT(__HLS_UP_ACTIVE_BP)
  525. #define HLS_DN_DOWNDEF BIT(__HLS_DN_DOWNDEF_BP) /* link down default */
  526. #define HLS_DN_POLL BIT(__HLS_DN_POLL_BP)
  527. #define HLS_DN_DISABLE BIT(__HLS_DN_DISABLE_BP)
  528. #define HLS_DN_OFFLINE BIT(__HLS_DN_OFFLINE_BP)
  529. #define HLS_VERIFY_CAP BIT(__HLS_VERIFY_CAP_BP)
  530. #define HLS_GOING_UP BIT(__HLS_GOING_UP_BP)
  531. #define HLS_GOING_OFFLINE BIT(__HLS_GOING_OFFLINE_BP)
  532. #define HLS_LINK_COOLDOWN BIT(__HLS_LINK_COOLDOWN_BP)
  533. #define HLS_UP (HLS_UP_INIT | HLS_UP_ARMED | HLS_UP_ACTIVE)
  534. #define HLS_DOWN ~(HLS_UP)
  535. #define HLS_DEFAULT HLS_DN_POLL
  536. /* use this MTU size if none other is given */
  537. #define HFI1_DEFAULT_ACTIVE_MTU 10240
  538. /* use this MTU size as the default maximum */
  539. #define HFI1_DEFAULT_MAX_MTU 10240
  540. /* default partition key */
  541. #define DEFAULT_PKEY 0xffff
  542. /*
  543. * Possible fabric manager config parameters for fm_{get,set}_table()
  544. */
  545. #define FM_TBL_VL_HIGH_ARB 1 /* Get/set VL high prio weights */
  546. #define FM_TBL_VL_LOW_ARB 2 /* Get/set VL low prio weights */
  547. #define FM_TBL_BUFFER_CONTROL 3 /* Get/set Buffer Control */
  548. #define FM_TBL_SC2VLNT 4 /* Get/set SC->VLnt */
  549. #define FM_TBL_VL_PREEMPT_ELEMS 5 /* Get (no set) VL preempt elems */
  550. #define FM_TBL_VL_PREEMPT_MATRIX 6 /* Get (no set) VL preempt matrix */
  551. /*
  552. * Possible "operations" for f_rcvctrl(ppd, op, ctxt)
  553. * these are bits so they can be combined, e.g.
  554. * HFI1_RCVCTRL_INTRAVAIL_ENB | HFI1_RCVCTRL_CTXT_ENB
  555. */
  556. #define HFI1_RCVCTRL_TAILUPD_ENB 0x01
  557. #define HFI1_RCVCTRL_TAILUPD_DIS 0x02
  558. #define HFI1_RCVCTRL_CTXT_ENB 0x04
  559. #define HFI1_RCVCTRL_CTXT_DIS 0x08
  560. #define HFI1_RCVCTRL_INTRAVAIL_ENB 0x10
  561. #define HFI1_RCVCTRL_INTRAVAIL_DIS 0x20
  562. #define HFI1_RCVCTRL_PKEY_ENB 0x40 /* Note, default is enabled */
  563. #define HFI1_RCVCTRL_PKEY_DIS 0x80
  564. #define HFI1_RCVCTRL_TIDFLOW_ENB 0x0400
  565. #define HFI1_RCVCTRL_TIDFLOW_DIS 0x0800
  566. #define HFI1_RCVCTRL_ONE_PKT_EGR_ENB 0x1000
  567. #define HFI1_RCVCTRL_ONE_PKT_EGR_DIS 0x2000
  568. #define HFI1_RCVCTRL_NO_RHQ_DROP_ENB 0x4000
  569. #define HFI1_RCVCTRL_NO_RHQ_DROP_DIS 0x8000
  570. #define HFI1_RCVCTRL_NO_EGR_DROP_ENB 0x10000
  571. #define HFI1_RCVCTRL_NO_EGR_DROP_DIS 0x20000
  572. #define HFI1_RCVCTRL_URGENT_ENB 0x40000
  573. #define HFI1_RCVCTRL_URGENT_DIS 0x80000
  574. /* partition enforcement flags */
  575. #define HFI1_PART_ENFORCE_IN 0x1
  576. #define HFI1_PART_ENFORCE_OUT 0x2
  577. /* how often we check for synthetic counter wrap around */
  578. #define SYNTH_CNT_TIME 3
  579. /* Counter flags */
  580. #define CNTR_NORMAL 0x0 /* Normal counters, just read register */
  581. #define CNTR_SYNTH 0x1 /* Synthetic counters, saturate at all 1s */
  582. #define CNTR_DISABLED 0x2 /* Disable this counter */
  583. #define CNTR_32BIT 0x4 /* Simulate 64 bits for this counter */
  584. #define CNTR_VL 0x8 /* Per VL counter */
  585. #define CNTR_SDMA 0x10
  586. #define CNTR_INVALID_VL -1 /* Specifies invalid VL */
  587. #define CNTR_MODE_W 0x0
  588. #define CNTR_MODE_R 0x1
  589. /* VLs Supported/Operational */
  590. #define HFI1_MIN_VLS_SUPPORTED 1
  591. #define HFI1_MAX_VLS_SUPPORTED 8
  592. #define HFI1_GUIDS_PER_PORT 5
  593. #define HFI1_PORT_GUID_INDEX 0
  594. static inline void incr_cntr64(u64 *cntr)
  595. {
  596. if (*cntr < (u64)-1LL)
  597. (*cntr)++;
  598. }
  599. static inline void incr_cntr32(u32 *cntr)
  600. {
  601. if (*cntr < (u32)-1LL)
  602. (*cntr)++;
  603. }
  604. #define MAX_NAME_SIZE 64
  605. struct hfi1_msix_entry {
  606. enum irq_type type;
  607. int irq;
  608. void *arg;
  609. cpumask_t mask;
  610. struct irq_affinity_notify notify;
  611. };
  612. struct hfi1_msix_info {
  613. /* lock to synchronize in_use_msix access */
  614. spinlock_t msix_lock;
  615. DECLARE_BITMAP(in_use_msix, CCE_NUM_MSIX_VECTORS);
  616. struct hfi1_msix_entry *msix_entries;
  617. u16 max_requested;
  618. };
  619. /* per-SL CCA information */
  620. struct cca_timer {
  621. struct hrtimer hrtimer;
  622. struct hfi1_pportdata *ppd; /* read-only */
  623. int sl; /* read-only */
  624. u16 ccti; /* read/write - current value of CCTI */
  625. };
  626. struct link_down_reason {
  627. /*
  628. * SMA-facing value. Should be set from .latest when
  629. * HLS_UP_* -> HLS_DN_* transition actually occurs.
  630. */
  631. u8 sma;
  632. u8 latest;
  633. };
  634. enum {
  635. LO_PRIO_TABLE,
  636. HI_PRIO_TABLE,
  637. MAX_PRIO_TABLE
  638. };
  639. struct vl_arb_cache {
  640. /* protect vl arb cache */
  641. spinlock_t lock;
  642. struct ib_vl_weight_elem table[VL_ARB_TABLE_SIZE];
  643. };
  644. /*
  645. * The structure below encapsulates data relevant to a physical IB Port.
  646. * Current chips support only one such port, but the separation
  647. * clarifies things a bit. Note that to conform to IB conventions,
  648. * port-numbers are one-based. The first or only port is port1.
  649. */
  650. struct hfi1_pportdata {
  651. struct hfi1_ibport ibport_data;
  652. struct hfi1_devdata *dd;
  653. struct kobject pport_cc_kobj;
  654. struct kobject sc2vl_kobj;
  655. struct kobject sl2sc_kobj;
  656. struct kobject vl2mtu_kobj;
  657. /* PHY support */
  658. struct qsfp_data qsfp_info;
  659. /* Values for SI tuning of SerDes */
  660. u32 port_type;
  661. u32 tx_preset_eq;
  662. u32 tx_preset_noeq;
  663. u32 rx_preset;
  664. u8 local_atten;
  665. u8 remote_atten;
  666. u8 default_atten;
  667. u8 max_power_class;
  668. /* did we read platform config from scratch registers? */
  669. bool config_from_scratch;
  670. /* GUIDs for this interface, in host order, guids[0] is a port guid */
  671. u64 guids[HFI1_GUIDS_PER_PORT];
  672. /* GUID for peer interface, in host order */
  673. u64 neighbor_guid;
  674. /* up or down physical link state */
  675. u32 linkup;
  676. /*
  677. * this address is mapped read-only into user processes so they can
  678. * get status cheaply, whenever they want. One qword of status per port
  679. */
  680. u64 *statusp;
  681. /* SendDMA related entries */
  682. struct workqueue_struct *hfi1_wq;
  683. struct workqueue_struct *link_wq;
  684. /* move out of interrupt context */
  685. struct work_struct link_vc_work;
  686. struct work_struct link_up_work;
  687. struct work_struct link_down_work;
  688. struct work_struct sma_message_work;
  689. struct work_struct freeze_work;
  690. struct work_struct link_downgrade_work;
  691. struct work_struct link_bounce_work;
  692. struct delayed_work start_link_work;
  693. /* host link state variables */
  694. struct mutex hls_lock;
  695. u32 host_link_state;
  696. /* these are the "32 bit" regs */
  697. u32 ibmtu; /* The MTU programmed for this unit */
  698. /*
  699. * Current max size IB packet (in bytes) including IB headers, that
  700. * we can send. Changes when ibmtu changes.
  701. */
  702. u32 ibmaxlen;
  703. u32 current_egress_rate; /* units [10^6 bits/sec] */
  704. /* LID programmed for this instance */
  705. u32 lid;
  706. /* list of pkeys programmed; 0 if not set */
  707. u16 pkeys[MAX_PKEY_VALUES];
  708. u16 link_width_supported;
  709. u16 link_width_downgrade_supported;
  710. u16 link_speed_supported;
  711. u16 link_width_enabled;
  712. u16 link_width_downgrade_enabled;
  713. u16 link_speed_enabled;
  714. u16 link_width_active;
  715. u16 link_width_downgrade_tx_active;
  716. u16 link_width_downgrade_rx_active;
  717. u16 link_speed_active;
  718. u8 vls_supported;
  719. u8 vls_operational;
  720. u8 actual_vls_operational;
  721. /* LID mask control */
  722. u8 lmc;
  723. /* Rx Polarity inversion (compensate for ~tx on partner) */
  724. u8 rx_pol_inv;
  725. u8 hw_pidx; /* physical port index */
  726. u8 port; /* IB port number and index into dd->pports - 1 */
  727. /* type of neighbor node */
  728. u8 neighbor_type;
  729. u8 neighbor_normal;
  730. u8 neighbor_fm_security; /* 1 if firmware checking is disabled */
  731. u8 neighbor_port_number;
  732. u8 is_sm_config_started;
  733. u8 offline_disabled_reason;
  734. u8 is_active_optimize_enabled;
  735. u8 driver_link_ready; /* driver ready for active link */
  736. u8 link_enabled; /* link enabled? */
  737. u8 linkinit_reason;
  738. u8 local_tx_rate; /* rate given to 8051 firmware */
  739. u8 qsfp_retry_count;
  740. /* placeholders for IB MAD packet settings */
  741. u8 overrun_threshold;
  742. u8 phy_error_threshold;
  743. unsigned int is_link_down_queued;
  744. /* Used to override LED behavior for things like maintenance beaconing*/
  745. /*
  746. * Alternates per phase of blink
  747. * [0] holds LED off duration, [1] holds LED on duration
  748. */
  749. unsigned long led_override_vals[2];
  750. u8 led_override_phase; /* LSB picks from vals[] */
  751. atomic_t led_override_timer_active;
  752. /* Used to flash LEDs in override mode */
  753. struct timer_list led_override_timer;
  754. u32 sm_trap_qp;
  755. u32 sa_qp;
  756. /*
  757. * cca_timer_lock protects access to the per-SL cca_timer
  758. * structures (specifically the ccti member).
  759. */
  760. spinlock_t cca_timer_lock ____cacheline_aligned_in_smp;
  761. struct cca_timer cca_timer[OPA_MAX_SLS];
  762. /* List of congestion control table entries */
  763. struct ib_cc_table_entry_shadow ccti_entries[CC_TABLE_SHADOW_MAX];
  764. /* congestion entries, each entry corresponding to a SL */
  765. struct opa_congestion_setting_entry_shadow
  766. congestion_entries[OPA_MAX_SLS];
  767. /*
  768. * cc_state_lock protects (write) access to the per-port
  769. * struct cc_state.
  770. */
  771. spinlock_t cc_state_lock ____cacheline_aligned_in_smp;
  772. struct cc_state __rcu *cc_state;
  773. /* Total number of congestion control table entries */
  774. u16 total_cct_entry;
  775. /* Bit map identifying service level */
  776. u32 cc_sl_control_map;
  777. /* CA's max number of 64 entry units in the congestion control table */
  778. u8 cc_max_table_entries;
  779. /*
  780. * begin congestion log related entries
  781. * cc_log_lock protects all congestion log related data
  782. */
  783. spinlock_t cc_log_lock ____cacheline_aligned_in_smp;
  784. u8 threshold_cong_event_map[OPA_MAX_SLS / 8];
  785. u16 threshold_event_counter;
  786. struct opa_hfi1_cong_log_event_internal cc_events[OPA_CONG_LOG_ELEMS];
  787. int cc_log_idx; /* index for logging events */
  788. int cc_mad_idx; /* index for reporting events */
  789. /* end congestion log related entries */
  790. struct vl_arb_cache vl_arb_cache[MAX_PRIO_TABLE];
  791. /* port relative counter buffer */
  792. u64 *cntrs;
  793. /* port relative synthetic counter buffer */
  794. u64 *scntrs;
  795. /* port_xmit_discards are synthesized from different egress errors */
  796. u64 port_xmit_discards;
  797. u64 port_xmit_discards_vl[C_VL_COUNT];
  798. u64 port_xmit_constraint_errors;
  799. u64 port_rcv_constraint_errors;
  800. /* count of 'link_err' interrupts from DC */
  801. u64 link_downed;
  802. /* number of times link retrained successfully */
  803. u64 link_up;
  804. /* number of times a link unknown frame was reported */
  805. u64 unknown_frame_count;
  806. /* port_ltp_crc_mode is returned in 'portinfo' MADs */
  807. u16 port_ltp_crc_mode;
  808. /* port_crc_mode_enabled is the crc we support */
  809. u8 port_crc_mode_enabled;
  810. /* mgmt_allowed is also returned in 'portinfo' MADs */
  811. u8 mgmt_allowed;
  812. u8 part_enforce; /* partition enforcement flags */
  813. struct link_down_reason local_link_down_reason;
  814. struct link_down_reason neigh_link_down_reason;
  815. /* Value to be sent to link peer on LinkDown .*/
  816. u8 remote_link_down_reason;
  817. /* Error events that will cause a port bounce. */
  818. u32 port_error_action;
  819. struct work_struct linkstate_active_work;
  820. /* Does this port need to prescan for FECNs */
  821. bool cc_prescan;
  822. /*
  823. * Sample sendWaitCnt & sendWaitVlCnt during link transition
  824. * and counter request.
  825. */
  826. u64 port_vl_xmit_wait_last[C_VL_COUNT + 1];
  827. u16 prev_link_width;
  828. u64 vl_xmit_flit_cnt[C_VL_COUNT + 1];
  829. };
  830. typedef void (*opcode_handler)(struct hfi1_packet *packet);
  831. typedef void (*hfi1_make_req)(struct rvt_qp *qp,
  832. struct hfi1_pkt_state *ps,
  833. struct rvt_swqe *wqe);
  834. extern const rhf_rcv_function_ptr normal_rhf_rcv_functions[];
  835. /* return values for the RHF receive functions */
  836. #define RHF_RCV_CONTINUE 0 /* keep going */
  837. #define RHF_RCV_DONE 1 /* stop, this packet processed */
  838. #define RHF_RCV_REPROCESS 2 /* stop. retain this packet */
  839. struct rcv_array_data {
  840. u16 ngroups;
  841. u16 nctxt_extra;
  842. u8 group_size;
  843. };
  844. struct per_vl_data {
  845. u16 mtu;
  846. struct send_context *sc;
  847. };
  848. /* 16 to directly index */
  849. #define PER_VL_SEND_CONTEXTS 16
  850. struct err_info_rcvport {
  851. u8 status_and_code;
  852. u64 packet_flit1;
  853. u64 packet_flit2;
  854. };
  855. struct err_info_constraint {
  856. u8 status;
  857. u16 pkey;
  858. u32 slid;
  859. };
  860. struct hfi1_temp {
  861. unsigned int curr; /* current temperature */
  862. unsigned int lo_lim; /* low temperature limit */
  863. unsigned int hi_lim; /* high temperature limit */
  864. unsigned int crit_lim; /* critical temperature limit */
  865. u8 triggers; /* temperature triggers */
  866. };
  867. struct hfi1_i2c_bus {
  868. struct hfi1_devdata *controlling_dd; /* current controlling device */
  869. struct i2c_adapter adapter; /* bus details */
  870. struct i2c_algo_bit_data algo; /* bus algorithm details */
  871. int num; /* bus number, 0 or 1 */
  872. };
  873. /* common data between shared ASIC HFIs */
  874. struct hfi1_asic_data {
  875. struct hfi1_devdata *dds[2]; /* back pointers */
  876. struct mutex asic_resource_mutex;
  877. struct hfi1_i2c_bus *i2c_bus0;
  878. struct hfi1_i2c_bus *i2c_bus1;
  879. };
  880. /* sizes for both the QP and RSM map tables */
  881. #define NUM_MAP_ENTRIES 256
  882. #define NUM_MAP_REGS 32
  883. /*
  884. * Number of VNIC contexts used. Ensure it is less than or equal to
  885. * max queues supported by VNIC (HFI1_VNIC_MAX_QUEUE).
  886. */
  887. #define HFI1_NUM_VNIC_CTXT 8
  888. /* Number of VNIC RSM entries */
  889. #define NUM_VNIC_MAP_ENTRIES 8
  890. /* Virtual NIC information */
  891. struct hfi1_vnic_data {
  892. struct hfi1_ctxtdata *ctxt[HFI1_NUM_VNIC_CTXT];
  893. struct kmem_cache *txreq_cache;
  894. u8 num_vports;
  895. struct idr vesw_idr;
  896. u8 rmt_start;
  897. u8 num_ctxt;
  898. };
  899. struct hfi1_vnic_vport_info;
  900. /* device data struct now contains only "general per-device" info.
  901. * fields related to a physical IB port are in a hfi1_pportdata struct.
  902. */
  903. struct sdma_engine;
  904. struct sdma_vl_map;
  905. #define BOARD_VERS_MAX 96 /* how long the version string can be */
  906. #define SERIAL_MAX 16 /* length of the serial number */
  907. typedef int (*send_routine)(struct rvt_qp *, struct hfi1_pkt_state *, u64);
  908. struct hfi1_devdata {
  909. struct hfi1_ibdev verbs_dev; /* must be first */
  910. struct list_head list;
  911. /* pointers to related structs for this device */
  912. /* pci access data structure */
  913. struct pci_dev *pcidev;
  914. struct cdev user_cdev;
  915. struct cdev diag_cdev;
  916. struct cdev ui_cdev;
  917. struct device *user_device;
  918. struct device *diag_device;
  919. struct device *ui_device;
  920. /* first mapping up to RcvArray */
  921. u8 __iomem *kregbase1;
  922. resource_size_t physaddr;
  923. /* second uncached mapping from RcvArray to pio send buffers */
  924. u8 __iomem *kregbase2;
  925. /* for detecting offset above kregbase2 address */
  926. u32 base2_start;
  927. /* Per VL data. Enough for all VLs but not all elements are set/used. */
  928. struct per_vl_data vld[PER_VL_SEND_CONTEXTS];
  929. /* send context data */
  930. struct send_context_info *send_contexts;
  931. /* map hardware send contexts to software index */
  932. u8 *hw_to_sw;
  933. /* spinlock for allocating and releasing send context resources */
  934. spinlock_t sc_lock;
  935. /* lock for pio_map */
  936. spinlock_t pio_map_lock;
  937. /* Send Context initialization lock. */
  938. spinlock_t sc_init_lock;
  939. /* lock for sdma_map */
  940. spinlock_t sde_map_lock;
  941. /* array of kernel send contexts */
  942. struct send_context **kernel_send_context;
  943. /* array of vl maps */
  944. struct pio_vl_map __rcu *pio_map;
  945. /* default flags to last descriptor */
  946. u64 default_desc1;
  947. /* fields common to all SDMA engines */
  948. volatile __le64 *sdma_heads_dma; /* DMA'ed by chip */
  949. dma_addr_t sdma_heads_phys;
  950. void *sdma_pad_dma; /* DMA'ed by chip */
  951. dma_addr_t sdma_pad_phys;
  952. /* for deallocation */
  953. size_t sdma_heads_size;
  954. /* num used */
  955. u32 num_sdma;
  956. /* array of engines sized by num_sdma */
  957. struct sdma_engine *per_sdma;
  958. /* array of vl maps */
  959. struct sdma_vl_map __rcu *sdma_map;
  960. /* SPC freeze waitqueue and variable */
  961. wait_queue_head_t sdma_unfreeze_wq;
  962. atomic_t sdma_unfreeze_count;
  963. u32 lcb_access_count; /* count of LCB users */
  964. /* common data between shared ASIC HFIs in this OS */
  965. struct hfi1_asic_data *asic_data;
  966. /* mem-mapped pointer to base of PIO buffers */
  967. void __iomem *piobase;
  968. /*
  969. * write-combining mem-mapped pointer to base of RcvArray
  970. * memory.
  971. */
  972. void __iomem *rcvarray_wc;
  973. /*
  974. * credit return base - a per-NUMA range of DMA address that
  975. * the chip will use to update the per-context free counter
  976. */
  977. struct credit_return_base *cr_base;
  978. /* send context numbers and sizes for each type */
  979. struct sc_config_sizes sc_sizes[SC_MAX];
  980. char *boardname; /* human readable board info */
  981. /* reset value */
  982. u64 z_int_counter;
  983. u64 z_rcv_limit;
  984. u64 z_send_schedule;
  985. u64 __percpu *send_schedule;
  986. /* number of reserved contexts for VNIC usage */
  987. u16 num_vnic_contexts;
  988. /* number of receive contexts in use by the driver */
  989. u32 num_rcv_contexts;
  990. /* number of pio send contexts in use by the driver */
  991. u32 num_send_contexts;
  992. /*
  993. * number of ctxts available for PSM open
  994. */
  995. u32 freectxts;
  996. /* total number of available user/PSM contexts */
  997. u32 num_user_contexts;
  998. /* base receive interrupt timeout, in CSR units */
  999. u32 rcv_intr_timeout_csr;
  1000. spinlock_t sendctrl_lock; /* protect changes to SendCtrl */
  1001. spinlock_t rcvctrl_lock; /* protect changes to RcvCtrl */
  1002. spinlock_t uctxt_lock; /* protect rcd changes */
  1003. struct mutex dc8051_lock; /* exclusive access to 8051 */
  1004. struct workqueue_struct *update_cntr_wq;
  1005. struct work_struct update_cntr_work;
  1006. /* exclusive access to 8051 memory */
  1007. spinlock_t dc8051_memlock;
  1008. int dc8051_timed_out; /* remember if the 8051 timed out */
  1009. /*
  1010. * A page that will hold event notification bitmaps for all
  1011. * contexts. This page will be mapped into all processes.
  1012. */
  1013. unsigned long *events;
  1014. /*
  1015. * per unit status, see also portdata statusp
  1016. * mapped read-only into user processes so they can get unit and
  1017. * IB link status cheaply
  1018. */
  1019. struct hfi1_status *status;
  1020. /* revision register shadow */
  1021. u64 revision;
  1022. /* Base GUID for device (network order) */
  1023. u64 base_guid;
  1024. /* both sides of the PCIe link are gen3 capable */
  1025. u8 link_gen3_capable;
  1026. u8 dc_shutdown;
  1027. /* localbus width (1, 2,4,8,16,32) from config space */
  1028. u32 lbus_width;
  1029. /* localbus speed in MHz */
  1030. u32 lbus_speed;
  1031. int unit; /* unit # of this chip */
  1032. int node; /* home node of this chip */
  1033. /* save these PCI fields to restore after a reset */
  1034. u32 pcibar0;
  1035. u32 pcibar1;
  1036. u32 pci_rom;
  1037. u16 pci_command;
  1038. u16 pcie_devctl;
  1039. u16 pcie_lnkctl;
  1040. u16 pcie_devctl2;
  1041. u32 pci_msix0;
  1042. u32 pci_tph2;
  1043. /*
  1044. * ASCII serial number, from flash, large enough for original
  1045. * all digit strings, and longer serial number format
  1046. */
  1047. u8 serial[SERIAL_MAX];
  1048. /* human readable board version */
  1049. u8 boardversion[BOARD_VERS_MAX];
  1050. u8 lbus_info[32]; /* human readable localbus info */
  1051. /* chip major rev, from CceRevision */
  1052. u8 majrev;
  1053. /* chip minor rev, from CceRevision */
  1054. u8 minrev;
  1055. /* hardware ID */
  1056. u8 hfi1_id;
  1057. /* implementation code */
  1058. u8 icode;
  1059. /* vAU of this device */
  1060. u8 vau;
  1061. /* vCU of this device */
  1062. u8 vcu;
  1063. /* link credits of this device */
  1064. u16 link_credits;
  1065. /* initial vl15 credits to use */
  1066. u16 vl15_init;
  1067. /*
  1068. * Cached value for vl15buf, read during verify cap interrupt. VL15
  1069. * credits are to be kept at 0 and set when handling the link-up
  1070. * interrupt. This removes the possibility of receiving VL15 MAD
  1071. * packets before this HFI is ready.
  1072. */
  1073. u16 vl15buf_cached;
  1074. /* Misc small ints */
  1075. u8 n_krcv_queues;
  1076. u8 qos_shift;
  1077. u16 irev; /* implementation revision */
  1078. u32 dc8051_ver; /* 8051 firmware version */
  1079. spinlock_t hfi1_diag_trans_lock; /* protect diag observer ops */
  1080. struct platform_config platform_config;
  1081. struct platform_config_cache pcfg_cache;
  1082. struct diag_client *diag_client;
  1083. /* general interrupt: mask of handled interrupts */
  1084. u64 gi_mask[CCE_NUM_INT_CSRS];
  1085. struct rcv_array_data rcv_entries;
  1086. /* cycle length of PS* counters in HW (in picoseconds) */
  1087. u16 psxmitwait_check_rate;
  1088. /*
  1089. * 64 bit synthetic counters
  1090. */
  1091. struct timer_list synth_stats_timer;
  1092. /* MSI-X information */
  1093. struct hfi1_msix_info msix_info;
  1094. /*
  1095. * device counters
  1096. */
  1097. char *cntrnames;
  1098. size_t cntrnameslen;
  1099. size_t ndevcntrs;
  1100. u64 *cntrs;
  1101. u64 *scntrs;
  1102. /*
  1103. * remembered values for synthetic counters
  1104. */
  1105. u64 last_tx;
  1106. u64 last_rx;
  1107. /*
  1108. * per-port counters
  1109. */
  1110. size_t nportcntrs;
  1111. char *portcntrnames;
  1112. size_t portcntrnameslen;
  1113. struct err_info_rcvport err_info_rcvport;
  1114. struct err_info_constraint err_info_rcv_constraint;
  1115. struct err_info_constraint err_info_xmit_constraint;
  1116. atomic_t drop_packet;
  1117. u8 do_drop;
  1118. u8 err_info_uncorrectable;
  1119. u8 err_info_fmconfig;
  1120. /*
  1121. * Software counters for the status bits defined by the
  1122. * associated error status registers
  1123. */
  1124. u64 cce_err_status_cnt[NUM_CCE_ERR_STATUS_COUNTERS];
  1125. u64 rcv_err_status_cnt[NUM_RCV_ERR_STATUS_COUNTERS];
  1126. u64 misc_err_status_cnt[NUM_MISC_ERR_STATUS_COUNTERS];
  1127. u64 send_pio_err_status_cnt[NUM_SEND_PIO_ERR_STATUS_COUNTERS];
  1128. u64 send_dma_err_status_cnt[NUM_SEND_DMA_ERR_STATUS_COUNTERS];
  1129. u64 send_egress_err_status_cnt[NUM_SEND_EGRESS_ERR_STATUS_COUNTERS];
  1130. u64 send_err_status_cnt[NUM_SEND_ERR_STATUS_COUNTERS];
  1131. /* Software counter that spans all contexts */
  1132. u64 sw_ctxt_err_status_cnt[NUM_SEND_CTXT_ERR_STATUS_COUNTERS];
  1133. /* Software counter that spans all DMA engines */
  1134. u64 sw_send_dma_eng_err_status_cnt[
  1135. NUM_SEND_DMA_ENG_ERR_STATUS_COUNTERS];
  1136. /* Software counter that aggregates all cce_err_status errors */
  1137. u64 sw_cce_err_status_aggregate;
  1138. /* Software counter that aggregates all bypass packet rcv errors */
  1139. u64 sw_rcv_bypass_packet_errors;
  1140. /* Save the enabled LCB error bits */
  1141. u64 lcb_err_en;
  1142. struct cpu_mask_set *comp_vect;
  1143. int *comp_vect_mappings;
  1144. u32 comp_vect_possible_cpus;
  1145. /*
  1146. * Capability to have different send engines simply by changing a
  1147. * pointer value.
  1148. */
  1149. send_routine process_pio_send ____cacheline_aligned_in_smp;
  1150. send_routine process_dma_send;
  1151. void (*pio_inline_send)(struct hfi1_devdata *dd, struct pio_buf *pbuf,
  1152. u64 pbc, const void *from, size_t count);
  1153. int (*process_vnic_dma_send)(struct hfi1_devdata *dd, u8 q_idx,
  1154. struct hfi1_vnic_vport_info *vinfo,
  1155. struct sk_buff *skb, u64 pbc, u8 plen);
  1156. /* hfi1_pportdata, points to array of (physical) port-specific
  1157. * data structs, indexed by pidx (0..n-1)
  1158. */
  1159. struct hfi1_pportdata *pport;
  1160. /* receive context data */
  1161. struct hfi1_ctxtdata **rcd;
  1162. u64 __percpu *int_counter;
  1163. /* verbs tx opcode stats */
  1164. struct hfi1_opcode_stats_perctx __percpu *tx_opstats;
  1165. /* device (not port) flags, basically device capabilities */
  1166. u16 flags;
  1167. /* Number of physical ports available */
  1168. u8 num_pports;
  1169. /* Lowest context number which can be used by user processes or VNIC */
  1170. u8 first_dyn_alloc_ctxt;
  1171. /* adding a new field here would make it part of this cacheline */
  1172. /* seqlock for sc2vl */
  1173. seqlock_t sc2vl_lock ____cacheline_aligned_in_smp;
  1174. u64 sc2vl[4];
  1175. u64 __percpu *rcv_limit;
  1176. /* adding a new field here would make it part of this cacheline */
  1177. /* OUI comes from the HW. Used everywhere as 3 separate bytes. */
  1178. u8 oui1;
  1179. u8 oui2;
  1180. u8 oui3;
  1181. /* Timer and counter used to detect RcvBufOvflCnt changes */
  1182. struct timer_list rcverr_timer;
  1183. wait_queue_head_t event_queue;
  1184. /* receive context tail dummy address */
  1185. __le64 *rcvhdrtail_dummy_kvaddr;
  1186. dma_addr_t rcvhdrtail_dummy_dma;
  1187. u32 rcv_ovfl_cnt;
  1188. /* Serialize ASPM enable/disable between multiple verbs contexts */
  1189. spinlock_t aspm_lock;
  1190. /* Number of verbs contexts which have disabled ASPM */
  1191. atomic_t aspm_disabled_cnt;
  1192. /* Keeps track of user space clients */
  1193. atomic_t user_refcount;
  1194. /* Used to wait for outstanding user space clients before dev removal */
  1195. struct completion user_comp;
  1196. bool eprom_available; /* true if EPROM is available for this device */
  1197. bool aspm_supported; /* Does HW support ASPM */
  1198. bool aspm_enabled; /* ASPM state: enabled/disabled */
  1199. struct rhashtable *sdma_rht;
  1200. struct kobject kobj;
  1201. /* vnic data */
  1202. struct hfi1_vnic_data vnic;
  1203. /* Lock to protect IRQ SRC register access */
  1204. spinlock_t irq_src_lock;
  1205. };
  1206. static 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. /* 8051 firmware version helper */
  1211. #define dc8051_ver(a, b, c) ((a) << 16 | (b) << 8 | (c))
  1212. #define dc8051_ver_maj(a) (((a) & 0xff0000) >> 16)
  1213. #define dc8051_ver_min(a) (((a) & 0x00ff00) >> 8)
  1214. #define dc8051_ver_patch(a) ((a) & 0x0000ff)
  1215. /* f_put_tid types */
  1216. #define PT_EXPECTED 0
  1217. #define PT_EAGER 1
  1218. #define PT_INVALID_FLUSH 2
  1219. #define PT_INVALID 3
  1220. struct tid_rb_node;
  1221. struct mmu_rb_node;
  1222. struct mmu_rb_handler;
  1223. /* Private data for file operations */
  1224. struct hfi1_filedata {
  1225. struct hfi1_devdata *dd;
  1226. struct hfi1_ctxtdata *uctxt;
  1227. struct hfi1_user_sdma_comp_q *cq;
  1228. struct hfi1_user_sdma_pkt_q *pq;
  1229. u16 subctxt;
  1230. /* for cpu affinity; -1 if none */
  1231. int rec_cpu_num;
  1232. u32 tid_n_pinned;
  1233. struct mmu_rb_handler *handler;
  1234. struct tid_rb_node **entry_to_rb;
  1235. spinlock_t tid_lock; /* protect tid_[limit,used] counters */
  1236. u32 tid_limit;
  1237. u32 tid_used;
  1238. u32 *invalid_tids;
  1239. u32 invalid_tid_idx;
  1240. /* protect invalid_tids array and invalid_tid_idx */
  1241. spinlock_t invalid_lock;
  1242. struct mm_struct *mm;
  1243. };
  1244. extern struct list_head hfi1_dev_list;
  1245. extern spinlock_t hfi1_devs_lock;
  1246. struct hfi1_devdata *hfi1_lookup(int unit);
  1247. static inline unsigned long uctxt_offset(struct hfi1_ctxtdata *uctxt)
  1248. {
  1249. return (uctxt->ctxt - uctxt->dd->first_dyn_alloc_ctxt) *
  1250. HFI1_MAX_SHARED_CTXTS;
  1251. }
  1252. int hfi1_init(struct hfi1_devdata *dd, int reinit);
  1253. int hfi1_count_active_units(void);
  1254. int hfi1_diag_add(struct hfi1_devdata *dd);
  1255. void hfi1_diag_remove(struct hfi1_devdata *dd);
  1256. void handle_linkup_change(struct hfi1_devdata *dd, u32 linkup);
  1257. void handle_user_interrupt(struct hfi1_ctxtdata *rcd);
  1258. int hfi1_create_rcvhdrq(struct hfi1_devdata *dd, struct hfi1_ctxtdata *rcd);
  1259. int hfi1_setup_eagerbufs(struct hfi1_ctxtdata *rcd);
  1260. int hfi1_create_kctxts(struct hfi1_devdata *dd);
  1261. int hfi1_create_ctxtdata(struct hfi1_pportdata *ppd, int numa,
  1262. struct hfi1_ctxtdata **rcd);
  1263. void hfi1_free_ctxt(struct hfi1_ctxtdata *rcd);
  1264. void hfi1_init_pportdata(struct pci_dev *pdev, struct hfi1_pportdata *ppd,
  1265. struct hfi1_devdata *dd, u8 hw_pidx, u8 port);
  1266. void hfi1_free_ctxtdata(struct hfi1_devdata *dd, struct hfi1_ctxtdata *rcd);
  1267. int hfi1_rcd_put(struct hfi1_ctxtdata *rcd);
  1268. void hfi1_rcd_get(struct hfi1_ctxtdata *rcd);
  1269. struct hfi1_ctxtdata *hfi1_rcd_get_by_index_safe(struct hfi1_devdata *dd,
  1270. u16 ctxt);
  1271. struct hfi1_ctxtdata *hfi1_rcd_get_by_index(struct hfi1_devdata *dd, u16 ctxt);
  1272. int handle_receive_interrupt(struct hfi1_ctxtdata *rcd, int thread);
  1273. int handle_receive_interrupt_nodma_rtail(struct hfi1_ctxtdata *rcd, int thread);
  1274. int handle_receive_interrupt_dma_rtail(struct hfi1_ctxtdata *rcd, int thread);
  1275. void set_all_slowpath(struct hfi1_devdata *dd);
  1276. extern const struct pci_device_id hfi1_pci_tbl[];
  1277. void hfi1_make_ud_req_9B(struct rvt_qp *qp,
  1278. struct hfi1_pkt_state *ps,
  1279. struct rvt_swqe *wqe);
  1280. void hfi1_make_ud_req_16B(struct rvt_qp *qp,
  1281. struct hfi1_pkt_state *ps,
  1282. struct rvt_swqe *wqe);
  1283. /* receive packet handler dispositions */
  1284. #define RCV_PKT_OK 0x0 /* keep going */
  1285. #define RCV_PKT_LIMIT 0x1 /* stop, hit limit, start thread */
  1286. #define RCV_PKT_DONE 0x2 /* stop, no more packets detected */
  1287. /* calculate the current RHF address */
  1288. static inline __le32 *get_rhf_addr(struct hfi1_ctxtdata *rcd)
  1289. {
  1290. return (__le32 *)rcd->rcvhdrq + rcd->head + rcd->rhf_offset;
  1291. }
  1292. int hfi1_reset_device(int);
  1293. void receive_interrupt_work(struct work_struct *work);
  1294. /* extract service channel from header and rhf */
  1295. static inline int hfi1_9B_get_sc5(struct ib_header *hdr, u64 rhf)
  1296. {
  1297. return ib_get_sc(hdr) | ((!!(rhf_dc_info(rhf))) << 4);
  1298. }
  1299. #define HFI1_JKEY_WIDTH 16
  1300. #define HFI1_JKEY_MASK (BIT(16) - 1)
  1301. #define HFI1_ADMIN_JKEY_RANGE 32
  1302. /*
  1303. * J_KEYs are split and allocated in the following groups:
  1304. * 0 - 31 - users with administrator privileges
  1305. * 32 - 63 - kernel protocols using KDETH packets
  1306. * 64 - 65535 - all other users using KDETH packets
  1307. */
  1308. static inline u16 generate_jkey(kuid_t uid)
  1309. {
  1310. u16 jkey = from_kuid(current_user_ns(), uid) & HFI1_JKEY_MASK;
  1311. if (capable(CAP_SYS_ADMIN))
  1312. jkey &= HFI1_ADMIN_JKEY_RANGE - 1;
  1313. else if (jkey < 64)
  1314. jkey |= BIT(HFI1_JKEY_WIDTH - 1);
  1315. return jkey;
  1316. }
  1317. /*
  1318. * active_egress_rate
  1319. *
  1320. * returns the active egress rate in units of [10^6 bits/sec]
  1321. */
  1322. static inline u32 active_egress_rate(struct hfi1_pportdata *ppd)
  1323. {
  1324. u16 link_speed = ppd->link_speed_active;
  1325. u16 link_width = ppd->link_width_active;
  1326. u32 egress_rate;
  1327. if (link_speed == OPA_LINK_SPEED_25G)
  1328. egress_rate = 25000;
  1329. else /* assume OPA_LINK_SPEED_12_5G */
  1330. egress_rate = 12500;
  1331. switch (link_width) {
  1332. case OPA_LINK_WIDTH_4X:
  1333. egress_rate *= 4;
  1334. break;
  1335. case OPA_LINK_WIDTH_3X:
  1336. egress_rate *= 3;
  1337. break;
  1338. case OPA_LINK_WIDTH_2X:
  1339. egress_rate *= 2;
  1340. break;
  1341. default:
  1342. /* assume IB_WIDTH_1X */
  1343. break;
  1344. }
  1345. return egress_rate;
  1346. }
  1347. /*
  1348. * egress_cycles
  1349. *
  1350. * Returns the number of 'fabric clock cycles' to egress a packet
  1351. * of length 'len' bytes, at 'rate' Mbit/s. Since the fabric clock
  1352. * rate is (approximately) 805 MHz, the units of the returned value
  1353. * are (1/805 MHz).
  1354. */
  1355. static inline u32 egress_cycles(u32 len, u32 rate)
  1356. {
  1357. u32 cycles;
  1358. /*
  1359. * cycles is:
  1360. *
  1361. * (length) [bits] / (rate) [bits/sec]
  1362. * ---------------------------------------------------
  1363. * fabric_clock_period == 1 /(805 * 10^6) [cycles/sec]
  1364. */
  1365. cycles = len * 8; /* bits */
  1366. cycles *= 805;
  1367. cycles /= rate;
  1368. return cycles;
  1369. }
  1370. void set_link_ipg(struct hfi1_pportdata *ppd);
  1371. void process_becn(struct hfi1_pportdata *ppd, u8 sl, u32 rlid, u32 lqpn,
  1372. u32 rqpn, u8 svc_type);
  1373. void return_cnp(struct hfi1_ibport *ibp, struct rvt_qp *qp, u32 remote_qpn,
  1374. u16 pkey, u32 slid, u32 dlid, u8 sc5,
  1375. const struct ib_grh *old_grh);
  1376. void return_cnp_16B(struct hfi1_ibport *ibp, struct rvt_qp *qp,
  1377. u32 remote_qpn, u16 pkey, u32 slid, u32 dlid,
  1378. u8 sc5, const struct ib_grh *old_grh);
  1379. typedef void (*hfi1_handle_cnp)(struct hfi1_ibport *ibp, struct rvt_qp *qp,
  1380. u32 remote_qpn, u16 pkey, u32 slid, u32 dlid,
  1381. u8 sc5, const struct ib_grh *old_grh);
  1382. #define PKEY_CHECK_INVALID -1
  1383. int egress_pkey_check(struct hfi1_pportdata *ppd, u32 slid, u16 pkey,
  1384. u8 sc5, int8_t s_pkey_index);
  1385. #define PACKET_EGRESS_TIMEOUT 350
  1386. static inline void pause_for_credit_return(struct hfi1_devdata *dd)
  1387. {
  1388. /* Pause at least 1us, to ensure chip returns all credits */
  1389. u32 usec = cclock_to_ns(dd, PACKET_EGRESS_TIMEOUT) / 1000;
  1390. udelay(usec ? usec : 1);
  1391. }
  1392. /**
  1393. * sc_to_vlt() reverse lookup sc to vl
  1394. * @dd - devdata
  1395. * @sc5 - 5 bit sc
  1396. */
  1397. static inline u8 sc_to_vlt(struct hfi1_devdata *dd, u8 sc5)
  1398. {
  1399. unsigned seq;
  1400. u8 rval;
  1401. if (sc5 >= OPA_MAX_SCS)
  1402. return (u8)(0xff);
  1403. do {
  1404. seq = read_seqbegin(&dd->sc2vl_lock);
  1405. rval = *(((u8 *)dd->sc2vl) + sc5);
  1406. } while (read_seqretry(&dd->sc2vl_lock, seq));
  1407. return rval;
  1408. }
  1409. #define PKEY_MEMBER_MASK 0x8000
  1410. #define PKEY_LOW_15_MASK 0x7fff
  1411. /*
  1412. * ingress_pkey_matches_entry - return 1 if the pkey matches ent (ent
  1413. * being an entry from the ingress partition key table), return 0
  1414. * otherwise. Use the matching criteria for ingress partition keys
  1415. * specified in the OPAv1 spec., section 9.10.14.
  1416. */
  1417. static inline int ingress_pkey_matches_entry(u16 pkey, u16 ent)
  1418. {
  1419. u16 mkey = pkey & PKEY_LOW_15_MASK;
  1420. u16 ment = ent & PKEY_LOW_15_MASK;
  1421. if (mkey == ment) {
  1422. /*
  1423. * If pkey[15] is clear (limited partition member),
  1424. * is bit 15 in the corresponding table element
  1425. * clear (limited member)?
  1426. */
  1427. if (!(pkey & PKEY_MEMBER_MASK))
  1428. return !!(ent & PKEY_MEMBER_MASK);
  1429. return 1;
  1430. }
  1431. return 0;
  1432. }
  1433. /*
  1434. * ingress_pkey_table_search - search the entire pkey table for
  1435. * an entry which matches 'pkey'. return 0 if a match is found,
  1436. * and 1 otherwise.
  1437. */
  1438. static int ingress_pkey_table_search(struct hfi1_pportdata *ppd, u16 pkey)
  1439. {
  1440. int i;
  1441. for (i = 0; i < MAX_PKEY_VALUES; i++) {
  1442. if (ingress_pkey_matches_entry(pkey, ppd->pkeys[i]))
  1443. return 0;
  1444. }
  1445. return 1;
  1446. }
  1447. /*
  1448. * ingress_pkey_table_fail - record a failure of ingress pkey validation,
  1449. * i.e., increment port_rcv_constraint_errors for the port, and record
  1450. * the 'error info' for this failure.
  1451. */
  1452. static void ingress_pkey_table_fail(struct hfi1_pportdata *ppd, u16 pkey,
  1453. u32 slid)
  1454. {
  1455. struct hfi1_devdata *dd = ppd->dd;
  1456. incr_cntr64(&ppd->port_rcv_constraint_errors);
  1457. if (!(dd->err_info_rcv_constraint.status & OPA_EI_STATUS_SMASK)) {
  1458. dd->err_info_rcv_constraint.status |= OPA_EI_STATUS_SMASK;
  1459. dd->err_info_rcv_constraint.slid = slid;
  1460. dd->err_info_rcv_constraint.pkey = pkey;
  1461. }
  1462. }
  1463. /*
  1464. * ingress_pkey_check - Return 0 if the ingress pkey is valid, return 1
  1465. * otherwise. Use the criteria in the OPAv1 spec, section 9.10.14. idx
  1466. * is a hint as to the best place in the partition key table to begin
  1467. * searching. This function should not be called on the data path because
  1468. * of performance reasons. On datapath pkey check is expected to be done
  1469. * by HW and rcv_pkey_check function should be called instead.
  1470. */
  1471. static inline int ingress_pkey_check(struct hfi1_pportdata *ppd, u16 pkey,
  1472. u8 sc5, u8 idx, u32 slid, bool force)
  1473. {
  1474. if (!(force) && !(ppd->part_enforce & HFI1_PART_ENFORCE_IN))
  1475. return 0;
  1476. /* If SC15, pkey[0:14] must be 0x7fff */
  1477. if ((sc5 == 0xf) && ((pkey & PKEY_LOW_15_MASK) != PKEY_LOW_15_MASK))
  1478. goto bad;
  1479. /* Is the pkey = 0x0, or 0x8000? */
  1480. if ((pkey & PKEY_LOW_15_MASK) == 0)
  1481. goto bad;
  1482. /* The most likely matching pkey has index 'idx' */
  1483. if (ingress_pkey_matches_entry(pkey, ppd->pkeys[idx]))
  1484. return 0;
  1485. /* no match - try the whole table */
  1486. if (!ingress_pkey_table_search(ppd, pkey))
  1487. return 0;
  1488. bad:
  1489. ingress_pkey_table_fail(ppd, pkey, slid);
  1490. return 1;
  1491. }
  1492. /*
  1493. * rcv_pkey_check - Return 0 if the ingress pkey is valid, return 1
  1494. * otherwise. It only ensures pkey is vlid for QP0. This function
  1495. * should be called on the data path instead of ingress_pkey_check
  1496. * as on data path, pkey check is done by HW (except for QP0).
  1497. */
  1498. static inline int rcv_pkey_check(struct hfi1_pportdata *ppd, u16 pkey,
  1499. u8 sc5, u16 slid)
  1500. {
  1501. if (!(ppd->part_enforce & HFI1_PART_ENFORCE_IN))
  1502. return 0;
  1503. /* If SC15, pkey[0:14] must be 0x7fff */
  1504. if ((sc5 == 0xf) && ((pkey & PKEY_LOW_15_MASK) != PKEY_LOW_15_MASK))
  1505. goto bad;
  1506. return 0;
  1507. bad:
  1508. ingress_pkey_table_fail(ppd, pkey, slid);
  1509. return 1;
  1510. }
  1511. /* MTU handling */
  1512. /* MTU enumeration, 256-4k match IB */
  1513. #define OPA_MTU_0 0
  1514. #define OPA_MTU_256 1
  1515. #define OPA_MTU_512 2
  1516. #define OPA_MTU_1024 3
  1517. #define OPA_MTU_2048 4
  1518. #define OPA_MTU_4096 5
  1519. u32 lrh_max_header_bytes(struct hfi1_devdata *dd);
  1520. int mtu_to_enum(u32 mtu, int default_if_bad);
  1521. u16 enum_to_mtu(int mtu);
  1522. static inline int valid_ib_mtu(unsigned int mtu)
  1523. {
  1524. return mtu == 256 || mtu == 512 ||
  1525. mtu == 1024 || mtu == 2048 ||
  1526. mtu == 4096;
  1527. }
  1528. static inline int valid_opa_max_mtu(unsigned int mtu)
  1529. {
  1530. return mtu >= 2048 &&
  1531. (valid_ib_mtu(mtu) || mtu == 8192 || mtu == 10240);
  1532. }
  1533. int set_mtu(struct hfi1_pportdata *ppd);
  1534. int hfi1_set_lid(struct hfi1_pportdata *ppd, u32 lid, u8 lmc);
  1535. void hfi1_disable_after_error(struct hfi1_devdata *dd);
  1536. int hfi1_set_uevent_bits(struct hfi1_pportdata *ppd, const int evtbit);
  1537. int hfi1_rcvbuf_validate(u32 size, u8 type, u16 *encode);
  1538. int fm_get_table(struct hfi1_pportdata *ppd, int which, void *t);
  1539. int fm_set_table(struct hfi1_pportdata *ppd, int which, void *t);
  1540. void set_up_vau(struct hfi1_devdata *dd, u8 vau);
  1541. void set_up_vl15(struct hfi1_devdata *dd, u16 vl15buf);
  1542. void reset_link_credits(struct hfi1_devdata *dd);
  1543. void assign_remote_cm_au_table(struct hfi1_devdata *dd, u8 vcu);
  1544. int set_buffer_control(struct hfi1_pportdata *ppd, struct buffer_control *bc);
  1545. static inline struct hfi1_devdata *dd_from_ppd(struct hfi1_pportdata *ppd)
  1546. {
  1547. return ppd->dd;
  1548. }
  1549. static inline struct hfi1_devdata *dd_from_dev(struct hfi1_ibdev *dev)
  1550. {
  1551. return container_of(dev, struct hfi1_devdata, verbs_dev);
  1552. }
  1553. static inline struct hfi1_devdata *dd_from_ibdev(struct ib_device *ibdev)
  1554. {
  1555. return dd_from_dev(to_idev(ibdev));
  1556. }
  1557. static inline struct hfi1_pportdata *ppd_from_ibp(struct hfi1_ibport *ibp)
  1558. {
  1559. return container_of(ibp, struct hfi1_pportdata, ibport_data);
  1560. }
  1561. static inline struct hfi1_ibdev *dev_from_rdi(struct rvt_dev_info *rdi)
  1562. {
  1563. return container_of(rdi, struct hfi1_ibdev, rdi);
  1564. }
  1565. static inline struct hfi1_ibport *to_iport(struct ib_device *ibdev, u8 port)
  1566. {
  1567. struct hfi1_devdata *dd = dd_from_ibdev(ibdev);
  1568. unsigned pidx = port - 1; /* IB number port from 1, hdw from 0 */
  1569. WARN_ON(pidx >= dd->num_pports);
  1570. return &dd->pport[pidx].ibport_data;
  1571. }
  1572. static inline struct hfi1_ibport *rcd_to_iport(struct hfi1_ctxtdata *rcd)
  1573. {
  1574. return &rcd->ppd->ibport_data;
  1575. }
  1576. void hfi1_process_ecn_slowpath(struct rvt_qp *qp, struct hfi1_packet *pkt,
  1577. bool do_cnp);
  1578. static inline bool process_ecn(struct rvt_qp *qp, struct hfi1_packet *pkt,
  1579. bool do_cnp)
  1580. {
  1581. bool becn;
  1582. bool fecn;
  1583. if (pkt->etype == RHF_RCV_TYPE_BYPASS) {
  1584. fecn = hfi1_16B_get_fecn(pkt->hdr);
  1585. becn = hfi1_16B_get_becn(pkt->hdr);
  1586. } else {
  1587. fecn = ib_bth_get_fecn(pkt->ohdr);
  1588. becn = ib_bth_get_becn(pkt->ohdr);
  1589. }
  1590. if (unlikely(fecn || becn)) {
  1591. hfi1_process_ecn_slowpath(qp, pkt, do_cnp);
  1592. return fecn;
  1593. }
  1594. return false;
  1595. }
  1596. /*
  1597. * Return the indexed PKEY from the port PKEY table.
  1598. */
  1599. static inline u16 hfi1_get_pkey(struct hfi1_ibport *ibp, unsigned index)
  1600. {
  1601. struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
  1602. u16 ret;
  1603. if (index >= ARRAY_SIZE(ppd->pkeys))
  1604. ret = 0;
  1605. else
  1606. ret = ppd->pkeys[index];
  1607. return ret;
  1608. }
  1609. /*
  1610. * Return the indexed GUID from the port GUIDs table.
  1611. */
  1612. static inline __be64 get_sguid(struct hfi1_ibport *ibp, unsigned int index)
  1613. {
  1614. struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
  1615. WARN_ON(index >= HFI1_GUIDS_PER_PORT);
  1616. return cpu_to_be64(ppd->guids[index]);
  1617. }
  1618. /*
  1619. * Called by readers of cc_state only, must call under rcu_read_lock().
  1620. */
  1621. static inline struct cc_state *get_cc_state(struct hfi1_pportdata *ppd)
  1622. {
  1623. return rcu_dereference(ppd->cc_state);
  1624. }
  1625. /*
  1626. * Called by writers of cc_state only, must call under cc_state_lock.
  1627. */
  1628. static inline
  1629. struct cc_state *get_cc_state_protected(struct hfi1_pportdata *ppd)
  1630. {
  1631. return rcu_dereference_protected(ppd->cc_state,
  1632. lockdep_is_held(&ppd->cc_state_lock));
  1633. }
  1634. /*
  1635. * values for dd->flags (_device_ related flags)
  1636. */
  1637. #define HFI1_INITTED 0x1 /* chip and driver up and initted */
  1638. #define HFI1_PRESENT 0x2 /* chip accesses can be done */
  1639. #define HFI1_FROZEN 0x4 /* chip in SPC freeze */
  1640. #define HFI1_HAS_SDMA_TIMEOUT 0x8
  1641. #define HFI1_HAS_SEND_DMA 0x10 /* Supports Send DMA */
  1642. #define HFI1_FORCED_FREEZE 0x80 /* driver forced freeze mode */
  1643. #define HFI1_SHUTDOWN 0x100 /* device is shutting down */
  1644. /* IB dword length mask in PBC (lower 11 bits); same for all chips */
  1645. #define HFI1_PBC_LENGTH_MASK ((1 << 11) - 1)
  1646. /* ctxt_flag bit offsets */
  1647. /* base context has not finished initializing */
  1648. #define HFI1_CTXT_BASE_UNINIT 1
  1649. /* base context initaliation failed */
  1650. #define HFI1_CTXT_BASE_FAILED 2
  1651. /* waiting for a packet to arrive */
  1652. #define HFI1_CTXT_WAITING_RCV 3
  1653. /* waiting for an urgent packet to arrive */
  1654. #define HFI1_CTXT_WAITING_URG 4
  1655. /* free up any allocated data at closes */
  1656. int hfi1_init_dd(struct hfi1_devdata *dd);
  1657. void hfi1_free_devdata(struct hfi1_devdata *dd);
  1658. /* LED beaconing functions */
  1659. void hfi1_start_led_override(struct hfi1_pportdata *ppd, unsigned int timeon,
  1660. unsigned int timeoff);
  1661. void shutdown_led_override(struct hfi1_pportdata *ppd);
  1662. #define HFI1_CREDIT_RETURN_RATE (100)
  1663. /*
  1664. * The number of words for the KDETH protocol field. If this is
  1665. * larger then the actual field used, then part of the payload
  1666. * will be in the header.
  1667. *
  1668. * Optimally, we want this sized so that a typical case will
  1669. * use full cache lines. The typical local KDETH header would
  1670. * be:
  1671. *
  1672. * Bytes Field
  1673. * 8 LRH
  1674. * 12 BHT
  1675. * ?? KDETH
  1676. * 8 RHF
  1677. * ---
  1678. * 28 + KDETH
  1679. *
  1680. * For a 64-byte cache line, KDETH would need to be 36 bytes or 9 DWORDS
  1681. */
  1682. #define DEFAULT_RCVHDRSIZE 9
  1683. /*
  1684. * Maximal header byte count:
  1685. *
  1686. * Bytes Field
  1687. * 8 LRH
  1688. * 40 GRH (optional)
  1689. * 12 BTH
  1690. * ?? KDETH
  1691. * 8 RHF
  1692. * ---
  1693. * 68 + KDETH
  1694. *
  1695. * We also want to maintain a cache line alignment to assist DMA'ing
  1696. * of the header bytes. Round up to a good size.
  1697. */
  1698. #define DEFAULT_RCVHDR_ENTSIZE 32
  1699. bool hfi1_can_pin_pages(struct hfi1_devdata *dd, struct mm_struct *mm,
  1700. u32 nlocked, u32 npages);
  1701. int hfi1_acquire_user_pages(struct mm_struct *mm, unsigned long vaddr,
  1702. size_t npages, bool writable, struct page **pages);
  1703. void hfi1_release_user_pages(struct mm_struct *mm, struct page **p,
  1704. size_t npages, bool dirty);
  1705. static inline void clear_rcvhdrtail(const struct hfi1_ctxtdata *rcd)
  1706. {
  1707. *((u64 *)rcd->rcvhdrtail_kvaddr) = 0ULL;
  1708. }
  1709. static inline u32 get_rcvhdrtail(const struct hfi1_ctxtdata *rcd)
  1710. {
  1711. /*
  1712. * volatile because it's a DMA target from the chip, routine is
  1713. * inlined, and don't want register caching or reordering.
  1714. */
  1715. return (u32)le64_to_cpu(*rcd->rcvhdrtail_kvaddr);
  1716. }
  1717. /*
  1718. * sysfs interface.
  1719. */
  1720. extern const char ib_hfi1_version[];
  1721. extern const struct attribute_group ib_hfi1_attr_group;
  1722. int hfi1_device_create(struct hfi1_devdata *dd);
  1723. void hfi1_device_remove(struct hfi1_devdata *dd);
  1724. int hfi1_create_port_files(struct ib_device *ibdev, u8 port_num,
  1725. struct kobject *kobj);
  1726. int hfi1_verbs_register_sysfs(struct hfi1_devdata *dd);
  1727. void hfi1_verbs_unregister_sysfs(struct hfi1_devdata *dd);
  1728. /* Hook for sysfs read of QSFP */
  1729. int qsfp_dump(struct hfi1_pportdata *ppd, char *buf, int len);
  1730. int hfi1_pcie_init(struct hfi1_devdata *dd);
  1731. void hfi1_pcie_cleanup(struct pci_dev *pdev);
  1732. int hfi1_pcie_ddinit(struct hfi1_devdata *dd, struct pci_dev *pdev);
  1733. void hfi1_pcie_ddcleanup(struct hfi1_devdata *);
  1734. int pcie_speeds(struct hfi1_devdata *dd);
  1735. int restore_pci_variables(struct hfi1_devdata *dd);
  1736. int save_pci_variables(struct hfi1_devdata *dd);
  1737. int do_pcie_gen3_transition(struct hfi1_devdata *dd);
  1738. void tune_pcie_caps(struct hfi1_devdata *dd);
  1739. int parse_platform_config(struct hfi1_devdata *dd);
  1740. int get_platform_config_field(struct hfi1_devdata *dd,
  1741. enum platform_config_table_type_encoding
  1742. table_type, int table_index, int field_index,
  1743. u32 *data, u32 len);
  1744. struct pci_dev *get_pci_dev(struct rvt_dev_info *rdi);
  1745. /*
  1746. * Flush write combining store buffers (if present) and perform a write
  1747. * barrier.
  1748. */
  1749. static inline void flush_wc(void)
  1750. {
  1751. asm volatile("sfence" : : : "memory");
  1752. }
  1753. void handle_eflags(struct hfi1_packet *packet);
  1754. void seqfile_dump_rcd(struct seq_file *s, struct hfi1_ctxtdata *rcd);
  1755. /* global module parameter variables */
  1756. extern unsigned int hfi1_max_mtu;
  1757. extern unsigned int hfi1_cu;
  1758. extern unsigned int user_credit_return_threshold;
  1759. extern int num_user_contexts;
  1760. extern unsigned long n_krcvqs;
  1761. extern uint krcvqs[];
  1762. extern int krcvqsset;
  1763. extern uint kdeth_qp;
  1764. extern uint loopback;
  1765. extern uint quick_linkup;
  1766. extern uint rcv_intr_timeout;
  1767. extern uint rcv_intr_count;
  1768. extern uint rcv_intr_dynamic;
  1769. extern ushort link_crc_mask;
  1770. extern struct mutex hfi1_mutex;
  1771. /* Number of seconds before our card status check... */
  1772. #define STATUS_TIMEOUT 60
  1773. #define DRIVER_NAME "hfi1"
  1774. #define HFI1_USER_MINOR_BASE 0
  1775. #define HFI1_TRACE_MINOR 127
  1776. #define HFI1_NMINORS 255
  1777. #define PCI_VENDOR_ID_INTEL 0x8086
  1778. #define PCI_DEVICE_ID_INTEL0 0x24f0
  1779. #define PCI_DEVICE_ID_INTEL1 0x24f1
  1780. #define HFI1_PKT_USER_SC_INTEGRITY \
  1781. (SEND_CTXT_CHECK_ENABLE_DISALLOW_NON_KDETH_PACKETS_SMASK \
  1782. | SEND_CTXT_CHECK_ENABLE_DISALLOW_KDETH_PACKETS_SMASK \
  1783. | SEND_CTXT_CHECK_ENABLE_DISALLOW_BYPASS_SMASK \
  1784. | SEND_CTXT_CHECK_ENABLE_DISALLOW_GRH_SMASK)
  1785. #define HFI1_PKT_KERNEL_SC_INTEGRITY \
  1786. (SEND_CTXT_CHECK_ENABLE_DISALLOW_KDETH_PACKETS_SMASK)
  1787. static inline u64 hfi1_pkt_default_send_ctxt_mask(struct hfi1_devdata *dd,
  1788. u16 ctxt_type)
  1789. {
  1790. u64 base_sc_integrity;
  1791. /* No integrity checks if HFI1_CAP_NO_INTEGRITY is set */
  1792. if (HFI1_CAP_IS_KSET(NO_INTEGRITY))
  1793. return 0;
  1794. base_sc_integrity =
  1795. SEND_CTXT_CHECK_ENABLE_DISALLOW_BYPASS_BAD_PKT_LEN_SMASK
  1796. | SEND_CTXT_CHECK_ENABLE_DISALLOW_PBC_STATIC_RATE_CONTROL_SMASK
  1797. | SEND_CTXT_CHECK_ENABLE_DISALLOW_TOO_LONG_BYPASS_PACKETS_SMASK
  1798. | SEND_CTXT_CHECK_ENABLE_DISALLOW_TOO_LONG_IB_PACKETS_SMASK
  1799. | SEND_CTXT_CHECK_ENABLE_DISALLOW_BAD_PKT_LEN_SMASK
  1800. #ifndef CONFIG_FAULT_INJECTION
  1801. | SEND_CTXT_CHECK_ENABLE_DISALLOW_PBC_TEST_SMASK
  1802. #endif
  1803. | SEND_CTXT_CHECK_ENABLE_DISALLOW_TOO_SMALL_BYPASS_PACKETS_SMASK
  1804. | SEND_CTXT_CHECK_ENABLE_DISALLOW_TOO_SMALL_IB_PACKETS_SMASK
  1805. | SEND_CTXT_CHECK_ENABLE_DISALLOW_RAW_IPV6_SMASK
  1806. | SEND_CTXT_CHECK_ENABLE_DISALLOW_RAW_SMASK
  1807. | SEND_CTXT_CHECK_ENABLE_CHECK_BYPASS_VL_MAPPING_SMASK
  1808. | SEND_CTXT_CHECK_ENABLE_CHECK_VL_MAPPING_SMASK
  1809. | SEND_CTXT_CHECK_ENABLE_CHECK_OPCODE_SMASK
  1810. | SEND_CTXT_CHECK_ENABLE_CHECK_SLID_SMASK
  1811. | SEND_CTXT_CHECK_ENABLE_CHECK_VL_SMASK
  1812. | SEND_CTXT_CHECK_ENABLE_CHECK_ENABLE_SMASK;
  1813. if (ctxt_type == SC_USER)
  1814. base_sc_integrity |=
  1815. #ifndef CONFIG_FAULT_INJECTION
  1816. SEND_CTXT_CHECK_ENABLE_DISALLOW_PBC_TEST_SMASK |
  1817. #endif
  1818. HFI1_PKT_USER_SC_INTEGRITY;
  1819. else
  1820. base_sc_integrity |= HFI1_PKT_KERNEL_SC_INTEGRITY;
  1821. /* turn on send-side job key checks if !A0 */
  1822. if (!is_ax(dd))
  1823. base_sc_integrity |= SEND_CTXT_CHECK_ENABLE_CHECK_JOB_KEY_SMASK;
  1824. return base_sc_integrity;
  1825. }
  1826. static inline u64 hfi1_pkt_base_sdma_integrity(struct hfi1_devdata *dd)
  1827. {
  1828. u64 base_sdma_integrity;
  1829. /* No integrity checks if HFI1_CAP_NO_INTEGRITY is set */
  1830. if (HFI1_CAP_IS_KSET(NO_INTEGRITY))
  1831. return 0;
  1832. base_sdma_integrity =
  1833. SEND_DMA_CHECK_ENABLE_DISALLOW_BYPASS_BAD_PKT_LEN_SMASK
  1834. | SEND_DMA_CHECK_ENABLE_DISALLOW_TOO_LONG_BYPASS_PACKETS_SMASK
  1835. | SEND_DMA_CHECK_ENABLE_DISALLOW_TOO_LONG_IB_PACKETS_SMASK
  1836. | SEND_DMA_CHECK_ENABLE_DISALLOW_BAD_PKT_LEN_SMASK
  1837. | SEND_DMA_CHECK_ENABLE_DISALLOW_TOO_SMALL_BYPASS_PACKETS_SMASK
  1838. | SEND_DMA_CHECK_ENABLE_DISALLOW_TOO_SMALL_IB_PACKETS_SMASK
  1839. | SEND_DMA_CHECK_ENABLE_DISALLOW_RAW_IPV6_SMASK
  1840. | SEND_DMA_CHECK_ENABLE_DISALLOW_RAW_SMASK
  1841. | SEND_DMA_CHECK_ENABLE_CHECK_BYPASS_VL_MAPPING_SMASK
  1842. | SEND_DMA_CHECK_ENABLE_CHECK_VL_MAPPING_SMASK
  1843. | SEND_DMA_CHECK_ENABLE_CHECK_OPCODE_SMASK
  1844. | SEND_DMA_CHECK_ENABLE_CHECK_SLID_SMASK
  1845. | SEND_DMA_CHECK_ENABLE_CHECK_VL_SMASK
  1846. | SEND_DMA_CHECK_ENABLE_CHECK_ENABLE_SMASK;
  1847. if (!HFI1_CAP_IS_KSET(STATIC_RATE_CTRL))
  1848. base_sdma_integrity |=
  1849. SEND_DMA_CHECK_ENABLE_DISALLOW_PBC_STATIC_RATE_CONTROL_SMASK;
  1850. /* turn on send-side job key checks if !A0 */
  1851. if (!is_ax(dd))
  1852. base_sdma_integrity |=
  1853. SEND_DMA_CHECK_ENABLE_CHECK_JOB_KEY_SMASK;
  1854. return base_sdma_integrity;
  1855. }
  1856. #define dd_dev_emerg(dd, fmt, ...) \
  1857. dev_emerg(&(dd)->pcidev->dev, "%s: " fmt, \
  1858. rvt_get_ibdev_name(&(dd)->verbs_dev.rdi), ##__VA_ARGS__)
  1859. #define dd_dev_err(dd, fmt, ...) \
  1860. dev_err(&(dd)->pcidev->dev, "%s: " fmt, \
  1861. rvt_get_ibdev_name(&(dd)->verbs_dev.rdi), ##__VA_ARGS__)
  1862. #define dd_dev_err_ratelimited(dd, fmt, ...) \
  1863. dev_err_ratelimited(&(dd)->pcidev->dev, "%s: " fmt, \
  1864. rvt_get_ibdev_name(&(dd)->verbs_dev.rdi), \
  1865. ##__VA_ARGS__)
  1866. #define dd_dev_warn(dd, fmt, ...) \
  1867. dev_warn(&(dd)->pcidev->dev, "%s: " fmt, \
  1868. rvt_get_ibdev_name(&(dd)->verbs_dev.rdi), ##__VA_ARGS__)
  1869. #define dd_dev_warn_ratelimited(dd, fmt, ...) \
  1870. dev_warn_ratelimited(&(dd)->pcidev->dev, "%s: " fmt, \
  1871. rvt_get_ibdev_name(&(dd)->verbs_dev.rdi), \
  1872. ##__VA_ARGS__)
  1873. #define dd_dev_info(dd, fmt, ...) \
  1874. dev_info(&(dd)->pcidev->dev, "%s: " fmt, \
  1875. rvt_get_ibdev_name(&(dd)->verbs_dev.rdi), ##__VA_ARGS__)
  1876. #define dd_dev_info_ratelimited(dd, fmt, ...) \
  1877. dev_info_ratelimited(&(dd)->pcidev->dev, "%s: " fmt, \
  1878. rvt_get_ibdev_name(&(dd)->verbs_dev.rdi), \
  1879. ##__VA_ARGS__)
  1880. #define dd_dev_dbg(dd, fmt, ...) \
  1881. dev_dbg(&(dd)->pcidev->dev, "%s: " fmt, \
  1882. rvt_get_ibdev_name(&(dd)->verbs_dev.rdi), ##__VA_ARGS__)
  1883. #define hfi1_dev_porterr(dd, port, fmt, ...) \
  1884. dev_err(&(dd)->pcidev->dev, "%s: port %u: " fmt, \
  1885. rvt_get_ibdev_name(&(dd)->verbs_dev.rdi), (port), ##__VA_ARGS__)
  1886. /*
  1887. * this is used for formatting hw error messages...
  1888. */
  1889. struct hfi1_hwerror_msgs {
  1890. u64 mask;
  1891. const char *msg;
  1892. size_t sz;
  1893. };
  1894. /* in intr.c... */
  1895. void hfi1_format_hwerrors(u64 hwerrs,
  1896. const struct hfi1_hwerror_msgs *hwerrmsgs,
  1897. size_t nhwerrmsgs, char *msg, size_t lmsg);
  1898. #define USER_OPCODE_CHECK_VAL 0xC0
  1899. #define USER_OPCODE_CHECK_MASK 0xC0
  1900. #define OPCODE_CHECK_VAL_DISABLED 0x0
  1901. #define OPCODE_CHECK_MASK_DISABLED 0x0
  1902. static inline void hfi1_reset_cpu_counters(struct hfi1_devdata *dd)
  1903. {
  1904. struct hfi1_pportdata *ppd;
  1905. int i;
  1906. dd->z_int_counter = get_all_cpu_total(dd->int_counter);
  1907. dd->z_rcv_limit = get_all_cpu_total(dd->rcv_limit);
  1908. dd->z_send_schedule = get_all_cpu_total(dd->send_schedule);
  1909. ppd = (struct hfi1_pportdata *)(dd + 1);
  1910. for (i = 0; i < dd->num_pports; i++, ppd++) {
  1911. ppd->ibport_data.rvp.z_rc_acks =
  1912. get_all_cpu_total(ppd->ibport_data.rvp.rc_acks);
  1913. ppd->ibport_data.rvp.z_rc_qacks =
  1914. get_all_cpu_total(ppd->ibport_data.rvp.rc_qacks);
  1915. }
  1916. }
  1917. /* Control LED state */
  1918. static inline void setextled(struct hfi1_devdata *dd, u32 on)
  1919. {
  1920. if (on)
  1921. write_csr(dd, DCC_CFG_LED_CNTRL, 0x1F);
  1922. else
  1923. write_csr(dd, DCC_CFG_LED_CNTRL, 0x10);
  1924. }
  1925. /* return the i2c resource given the target */
  1926. static inline u32 i2c_target(u32 target)
  1927. {
  1928. return target ? CR_I2C2 : CR_I2C1;
  1929. }
  1930. /* return the i2c chain chip resource that this HFI uses for QSFP */
  1931. static inline u32 qsfp_resource(struct hfi1_devdata *dd)
  1932. {
  1933. return i2c_target(dd->hfi1_id);
  1934. }
  1935. /* Is this device integrated or discrete? */
  1936. static inline bool is_integrated(struct hfi1_devdata *dd)
  1937. {
  1938. return dd->pcidev->device == PCI_DEVICE_ID_INTEL1;
  1939. }
  1940. int hfi1_tempsense_rd(struct hfi1_devdata *dd, struct hfi1_temp *temp);
  1941. #define DD_DEV_ENTRY(dd) __string(dev, dev_name(&(dd)->pcidev->dev))
  1942. #define DD_DEV_ASSIGN(dd) __assign_str(dev, dev_name(&(dd)->pcidev->dev))
  1943. static inline void hfi1_update_ah_attr(struct ib_device *ibdev,
  1944. struct rdma_ah_attr *attr)
  1945. {
  1946. struct hfi1_pportdata *ppd;
  1947. struct hfi1_ibport *ibp;
  1948. u32 dlid = rdma_ah_get_dlid(attr);
  1949. /*
  1950. * Kernel clients may not have setup GRH information
  1951. * Set that here.
  1952. */
  1953. ibp = to_iport(ibdev, rdma_ah_get_port_num(attr));
  1954. ppd = ppd_from_ibp(ibp);
  1955. if ((((dlid >= be16_to_cpu(IB_MULTICAST_LID_BASE)) ||
  1956. (ppd->lid >= be16_to_cpu(IB_MULTICAST_LID_BASE))) &&
  1957. (dlid != be32_to_cpu(OPA_LID_PERMISSIVE)) &&
  1958. (dlid != be16_to_cpu(IB_LID_PERMISSIVE)) &&
  1959. (!(rdma_ah_get_ah_flags(attr) & IB_AH_GRH))) ||
  1960. (rdma_ah_get_make_grd(attr))) {
  1961. rdma_ah_set_ah_flags(attr, IB_AH_GRH);
  1962. rdma_ah_set_interface_id(attr, OPA_MAKE_ID(dlid));
  1963. rdma_ah_set_subnet_prefix(attr, ibp->rvp.gid_prefix);
  1964. }
  1965. }
  1966. /*
  1967. * hfi1_check_mcast- Check if the given lid is
  1968. * in the OPA multicast range.
  1969. *
  1970. * The LID might either reside in ah.dlid or might be
  1971. * in the GRH of the address handle as DGID if extended
  1972. * addresses are in use.
  1973. */
  1974. static inline bool hfi1_check_mcast(u32 lid)
  1975. {
  1976. return ((lid >= opa_get_mcast_base(OPA_MCAST_NR)) &&
  1977. (lid != be32_to_cpu(OPA_LID_PERMISSIVE)));
  1978. }
  1979. #define opa_get_lid(lid, format) \
  1980. __opa_get_lid(lid, OPA_PORT_PACKET_FORMAT_##format)
  1981. /* Convert a lid to a specific lid space */
  1982. static inline u32 __opa_get_lid(u32 lid, u8 format)
  1983. {
  1984. bool is_mcast = hfi1_check_mcast(lid);
  1985. switch (format) {
  1986. case OPA_PORT_PACKET_FORMAT_8B:
  1987. case OPA_PORT_PACKET_FORMAT_10B:
  1988. if (is_mcast)
  1989. return (lid - opa_get_mcast_base(OPA_MCAST_NR) +
  1990. 0xF0000);
  1991. return lid & 0xFFFFF;
  1992. case OPA_PORT_PACKET_FORMAT_16B:
  1993. if (is_mcast)
  1994. return (lid - opa_get_mcast_base(OPA_MCAST_NR) +
  1995. 0xF00000);
  1996. return lid & 0xFFFFFF;
  1997. case OPA_PORT_PACKET_FORMAT_9B:
  1998. if (is_mcast)
  1999. return (lid -
  2000. opa_get_mcast_base(OPA_MCAST_NR) +
  2001. be16_to_cpu(IB_MULTICAST_LID_BASE));
  2002. else
  2003. return lid & 0xFFFF;
  2004. default:
  2005. return lid;
  2006. }
  2007. }
  2008. /* Return true if the given lid is the OPA 16B multicast range */
  2009. static inline bool hfi1_is_16B_mcast(u32 lid)
  2010. {
  2011. return ((lid >=
  2012. opa_get_lid(opa_get_mcast_base(OPA_MCAST_NR), 16B)) &&
  2013. (lid != opa_get_lid(be32_to_cpu(OPA_LID_PERMISSIVE), 16B)));
  2014. }
  2015. static inline void hfi1_make_opa_lid(struct rdma_ah_attr *attr)
  2016. {
  2017. const struct ib_global_route *grh = rdma_ah_read_grh(attr);
  2018. u32 dlid = rdma_ah_get_dlid(attr);
  2019. /* Modify ah_attr.dlid to be in the 32 bit LID space.
  2020. * This is how the address will be laid out:
  2021. * Assuming MCAST_NR to be 4,
  2022. * 32 bit permissive LID = 0xFFFFFFFF
  2023. * Multicast LID range = 0xFFFFFFFE to 0xF0000000
  2024. * Unicast LID range = 0xEFFFFFFF to 1
  2025. * Invalid LID = 0
  2026. */
  2027. if (ib_is_opa_gid(&grh->dgid))
  2028. dlid = opa_get_lid_from_gid(&grh->dgid);
  2029. else if ((dlid >= be16_to_cpu(IB_MULTICAST_LID_BASE)) &&
  2030. (dlid != be16_to_cpu(IB_LID_PERMISSIVE)) &&
  2031. (dlid != be32_to_cpu(OPA_LID_PERMISSIVE)))
  2032. dlid = dlid - be16_to_cpu(IB_MULTICAST_LID_BASE) +
  2033. opa_get_mcast_base(OPA_MCAST_NR);
  2034. else if (dlid == be16_to_cpu(IB_LID_PERMISSIVE))
  2035. dlid = be32_to_cpu(OPA_LID_PERMISSIVE);
  2036. rdma_ah_set_dlid(attr, dlid);
  2037. }
  2038. static inline u8 hfi1_get_packet_type(u32 lid)
  2039. {
  2040. /* 9B if lid > 0xF0000000 */
  2041. if (lid >= opa_get_mcast_base(OPA_MCAST_NR))
  2042. return HFI1_PKT_TYPE_9B;
  2043. /* 16B if lid > 0xC000 */
  2044. if (lid >= opa_get_lid(opa_get_mcast_base(OPA_MCAST_NR), 9B))
  2045. return HFI1_PKT_TYPE_16B;
  2046. return HFI1_PKT_TYPE_9B;
  2047. }
  2048. static inline bool hfi1_get_hdr_type(u32 lid, struct rdma_ah_attr *attr)
  2049. {
  2050. /*
  2051. * If there was an incoming 16B packet with permissive
  2052. * LIDs, OPA GIDs would have been programmed when those
  2053. * packets were received. A 16B packet will have to
  2054. * be sent in response to that packet. Return a 16B
  2055. * header type if that's the case.
  2056. */
  2057. if (rdma_ah_get_dlid(attr) == be32_to_cpu(OPA_LID_PERMISSIVE))
  2058. return (ib_is_opa_gid(&rdma_ah_read_grh(attr)->dgid)) ?
  2059. HFI1_PKT_TYPE_16B : HFI1_PKT_TYPE_9B;
  2060. /*
  2061. * Return a 16B header type if either the the destination
  2062. * or source lid is extended.
  2063. */
  2064. if (hfi1_get_packet_type(rdma_ah_get_dlid(attr)) == HFI1_PKT_TYPE_16B)
  2065. return HFI1_PKT_TYPE_16B;
  2066. return hfi1_get_packet_type(lid);
  2067. }
  2068. static inline void hfi1_make_ext_grh(struct hfi1_packet *packet,
  2069. struct ib_grh *grh, u32 slid,
  2070. u32 dlid)
  2071. {
  2072. struct hfi1_ibport *ibp = &packet->rcd->ppd->ibport_data;
  2073. struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
  2074. if (!ibp)
  2075. return;
  2076. grh->hop_limit = 1;
  2077. grh->sgid.global.subnet_prefix = ibp->rvp.gid_prefix;
  2078. if (slid == opa_get_lid(be32_to_cpu(OPA_LID_PERMISSIVE), 16B))
  2079. grh->sgid.global.interface_id =
  2080. OPA_MAKE_ID(be32_to_cpu(OPA_LID_PERMISSIVE));
  2081. else
  2082. grh->sgid.global.interface_id = OPA_MAKE_ID(slid);
  2083. /*
  2084. * Upper layers (like mad) may compare the dgid in the
  2085. * wc that is obtained here with the sgid_index in
  2086. * the wr. Since sgid_index in wr is always 0 for
  2087. * extended lids, set the dgid here to the default
  2088. * IB gid.
  2089. */
  2090. grh->dgid.global.subnet_prefix = ibp->rvp.gid_prefix;
  2091. grh->dgid.global.interface_id =
  2092. cpu_to_be64(ppd->guids[HFI1_PORT_GUID_INDEX]);
  2093. }
  2094. static inline int hfi1_get_16b_padding(u32 hdr_size, u32 payload)
  2095. {
  2096. return -(hdr_size + payload + (SIZE_OF_CRC << 2) +
  2097. SIZE_OF_LT) & 0x7;
  2098. }
  2099. static inline void hfi1_make_ib_hdr(struct ib_header *hdr,
  2100. u16 lrh0, u16 len,
  2101. u16 dlid, u16 slid)
  2102. {
  2103. hdr->lrh[0] = cpu_to_be16(lrh0);
  2104. hdr->lrh[1] = cpu_to_be16(dlid);
  2105. hdr->lrh[2] = cpu_to_be16(len);
  2106. hdr->lrh[3] = cpu_to_be16(slid);
  2107. }
  2108. static inline void hfi1_make_16b_hdr(struct hfi1_16b_header *hdr,
  2109. u32 slid, u32 dlid,
  2110. u16 len, u16 pkey,
  2111. bool becn, bool fecn, u8 l4,
  2112. u8 sc)
  2113. {
  2114. u32 lrh0 = 0;
  2115. u32 lrh1 = 0x40000000;
  2116. u32 lrh2 = 0;
  2117. u32 lrh3 = 0;
  2118. lrh0 = (lrh0 & ~OPA_16B_BECN_MASK) | (becn << OPA_16B_BECN_SHIFT);
  2119. lrh0 = (lrh0 & ~OPA_16B_LEN_MASK) | (len << OPA_16B_LEN_SHIFT);
  2120. lrh0 = (lrh0 & ~OPA_16B_LID_MASK) | (slid & OPA_16B_LID_MASK);
  2121. lrh1 = (lrh1 & ~OPA_16B_FECN_MASK) | (fecn << OPA_16B_FECN_SHIFT);
  2122. lrh1 = (lrh1 & ~OPA_16B_SC_MASK) | (sc << OPA_16B_SC_SHIFT);
  2123. lrh1 = (lrh1 & ~OPA_16B_LID_MASK) | (dlid & OPA_16B_LID_MASK);
  2124. lrh2 = (lrh2 & ~OPA_16B_SLID_MASK) |
  2125. ((slid >> OPA_16B_SLID_SHIFT) << OPA_16B_SLID_HIGH_SHIFT);
  2126. lrh2 = (lrh2 & ~OPA_16B_DLID_MASK) |
  2127. ((dlid >> OPA_16B_DLID_SHIFT) << OPA_16B_DLID_HIGH_SHIFT);
  2128. lrh2 = (lrh2 & ~OPA_16B_PKEY_MASK) | ((u32)pkey << OPA_16B_PKEY_SHIFT);
  2129. lrh2 = (lrh2 & ~OPA_16B_L4_MASK) | l4;
  2130. hdr->lrh[0] = lrh0;
  2131. hdr->lrh[1] = lrh1;
  2132. hdr->lrh[2] = lrh2;
  2133. hdr->lrh[3] = lrh3;
  2134. }
  2135. #endif /* _HFI1_KERNEL_H */