hfi.h 73 KB

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