hfi.h 73 KB

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