ipath_kernel.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883
  1. #ifndef _IPATH_KERNEL_H
  2. #define _IPATH_KERNEL_H
  3. /*
  4. * Copyright (c) 2003, 2004, 2005, 2006 PathScale, Inc. All rights reserved.
  5. *
  6. * This software is available to you under a choice of one of two
  7. * licenses. You may choose to be licensed under the terms of the GNU
  8. * General Public License (GPL) Version 2, available from the file
  9. * COPYING in the main directory of this source tree, or the
  10. * OpenIB.org BSD license below:
  11. *
  12. * Redistribution and use in source and binary forms, with or
  13. * without modification, are permitted provided that the following
  14. * conditions are met:
  15. *
  16. * - Redistributions of source code must retain the above
  17. * copyright notice, this list of conditions and the following
  18. * disclaimer.
  19. *
  20. * - Redistributions in binary form must reproduce the above
  21. * copyright notice, this list of conditions and the following
  22. * disclaimer in the documentation and/or other materials
  23. * provided with the distribution.
  24. *
  25. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  26. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  27. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  28. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  29. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  30. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  31. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  32. * SOFTWARE.
  33. */
  34. /*
  35. * This header file is the base header file for infinipath kernel code
  36. * ipath_user.h serves a similar purpose for user code.
  37. */
  38. #include <linux/interrupt.h>
  39. #include <asm/io.h>
  40. #include "ipath_common.h"
  41. #include "ipath_debug.h"
  42. #include "ipath_registers.h"
  43. /* only s/w major version of InfiniPath we can handle */
  44. #define IPATH_CHIP_VERS_MAJ 2U
  45. /* don't care about this except printing */
  46. #define IPATH_CHIP_VERS_MIN 0U
  47. /* temporary, maybe always */
  48. extern struct infinipath_stats ipath_stats;
  49. #define IPATH_CHIP_SWVERSION IPATH_CHIP_VERS_MAJ
  50. struct ipath_portdata {
  51. void **port_rcvegrbuf;
  52. dma_addr_t *port_rcvegrbuf_phys;
  53. /* rcvhdrq base, needs mmap before useful */
  54. void *port_rcvhdrq;
  55. /* kernel virtual address where hdrqtail is updated */
  56. u64 *port_rcvhdrtail_kvaddr;
  57. /* page * used for uaddr */
  58. struct page *port_rcvhdrtail_pagep;
  59. /*
  60. * temp buffer for expected send setup, allocated at open, instead
  61. * of each setup call
  62. */
  63. void *port_tid_pg_list;
  64. /* when waiting for rcv or pioavail */
  65. wait_queue_head_t port_wait;
  66. /*
  67. * rcvegr bufs base, physical, must fit
  68. * in 44 bits so 32 bit programs mmap64 44 bit works)
  69. */
  70. dma_addr_t port_rcvegr_phys;
  71. /* mmap of hdrq, must fit in 44 bits */
  72. dma_addr_t port_rcvhdrq_phys;
  73. /*
  74. * the actual user address that we ipath_mlock'ed, so we can
  75. * ipath_munlock it at close
  76. */
  77. unsigned long port_rcvhdrtail_uaddr;
  78. /*
  79. * number of opens on this instance (0 or 1; ignoring forks, dup,
  80. * etc. for now)
  81. */
  82. int port_cnt;
  83. /*
  84. * how much space to leave at start of eager TID entries for
  85. * protocol use, on each TID
  86. */
  87. /* instead of calculating it */
  88. unsigned port_port;
  89. /* chip offset of PIO buffers for this port */
  90. u32 port_piobufs;
  91. /* how many alloc_pages() chunks in port_rcvegrbuf_pages */
  92. u32 port_rcvegrbuf_chunks;
  93. /* how many egrbufs per chunk */
  94. u32 port_rcvegrbufs_perchunk;
  95. /* order for port_rcvegrbuf_pages */
  96. size_t port_rcvegrbuf_size;
  97. /* rcvhdrq size (for freeing) */
  98. size_t port_rcvhdrq_size;
  99. /* next expected TID to check when looking for free */
  100. u32 port_tidcursor;
  101. /* next expected TID to check */
  102. unsigned long port_flag;
  103. /* WAIT_RCV that timed out, no interrupt */
  104. u32 port_rcvwait_to;
  105. /* WAIT_PIO that timed out, no interrupt */
  106. u32 port_piowait_to;
  107. /* WAIT_RCV already happened, no wait */
  108. u32 port_rcvnowait;
  109. /* WAIT_PIO already happened, no wait */
  110. u32 port_pionowait;
  111. /* total number of rcvhdrqfull errors */
  112. u32 port_hdrqfull;
  113. /* pid of process using this port */
  114. pid_t port_pid;
  115. /* same size as task_struct .comm[] */
  116. char port_comm[16];
  117. /* pkeys set by this use of this port */
  118. u16 port_pkeys[4];
  119. /* so file ops can get at unit */
  120. struct ipath_devdata *port_dd;
  121. };
  122. struct sk_buff;
  123. /*
  124. * control information for layered drivers
  125. */
  126. struct _ipath_layer {
  127. void *l_arg;
  128. };
  129. /* Verbs layer interface */
  130. struct _verbs_layer {
  131. void *l_arg;
  132. struct timer_list l_timer;
  133. };
  134. struct ipath_devdata {
  135. struct list_head ipath_list;
  136. struct ipath_kregs const *ipath_kregs;
  137. struct ipath_cregs const *ipath_cregs;
  138. /* mem-mapped pointer to base of chip regs */
  139. u64 __iomem *ipath_kregbase;
  140. /* end of mem-mapped chip space; range checking */
  141. u64 __iomem *ipath_kregend;
  142. /* physical address of chip for io_remap, etc. */
  143. unsigned long ipath_physaddr;
  144. /* base of memory alloced for ipath_kregbase, for free */
  145. u64 *ipath_kregalloc;
  146. /*
  147. * version of kregbase that doesn't have high bits set (for 32 bit
  148. * programs, so mmap64 44 bit works)
  149. */
  150. u64 __iomem *ipath_kregvirt;
  151. /*
  152. * virtual address where port0 rcvhdrqtail updated for this unit.
  153. * only written to by the chip, not the driver.
  154. */
  155. volatile __le64 *ipath_hdrqtailptr;
  156. dma_addr_t ipath_dma_addr;
  157. /* ipath_cfgports pointers */
  158. struct ipath_portdata **ipath_pd;
  159. /* sk_buffs used by port 0 eager receive queue */
  160. struct sk_buff **ipath_port0_skbs;
  161. /* kvirt address of 1st 2k pio buffer */
  162. void __iomem *ipath_pio2kbase;
  163. /* kvirt address of 1st 4k pio buffer */
  164. void __iomem *ipath_pio4kbase;
  165. /*
  166. * points to area where PIOavail registers will be DMA'ed.
  167. * Has to be on a page of it's own, because the page will be
  168. * mapped into user program space. This copy is *ONLY* ever
  169. * written by DMA, not by the driver! Need a copy per device
  170. * when we get to multiple devices
  171. */
  172. volatile __le64 *ipath_pioavailregs_dma;
  173. /* physical address where updates occur */
  174. dma_addr_t ipath_pioavailregs_phys;
  175. struct _ipath_layer ipath_layer;
  176. /* setup intr */
  177. int (*ipath_f_intrsetup)(struct ipath_devdata *);
  178. /* setup on-chip bus config */
  179. int (*ipath_f_bus)(struct ipath_devdata *, struct pci_dev *);
  180. /* hard reset chip */
  181. int (*ipath_f_reset)(struct ipath_devdata *);
  182. int (*ipath_f_get_boardname)(struct ipath_devdata *, char *,
  183. size_t);
  184. void (*ipath_f_init_hwerrors)(struct ipath_devdata *);
  185. void (*ipath_f_handle_hwerrors)(struct ipath_devdata *, char *,
  186. size_t);
  187. void (*ipath_f_quiet_serdes)(struct ipath_devdata *);
  188. int (*ipath_f_bringup_serdes)(struct ipath_devdata *);
  189. int (*ipath_f_early_init)(struct ipath_devdata *);
  190. void (*ipath_f_clear_tids)(struct ipath_devdata *, unsigned);
  191. void (*ipath_f_put_tid)(struct ipath_devdata *, u64 __iomem*,
  192. u32, unsigned long);
  193. void (*ipath_f_tidtemplate)(struct ipath_devdata *);
  194. void (*ipath_f_cleanup)(struct ipath_devdata *);
  195. void (*ipath_f_setextled)(struct ipath_devdata *, u64, u64);
  196. /* fill out chip-specific fields */
  197. int (*ipath_f_get_base_info)(struct ipath_portdata *, void *);
  198. struct _verbs_layer verbs_layer;
  199. /* total dwords sent (summed from counter) */
  200. u64 ipath_sword;
  201. /* total dwords rcvd (summed from counter) */
  202. u64 ipath_rword;
  203. /* total packets sent (summed from counter) */
  204. u64 ipath_spkts;
  205. /* total packets rcvd (summed from counter) */
  206. u64 ipath_rpkts;
  207. /* ipath_statusp initially points to this. */
  208. u64 _ipath_status;
  209. /* GUID for this interface, in network order */
  210. __be64 ipath_guid;
  211. /*
  212. * aggregrate of error bits reported since last cleared, for
  213. * limiting of error reporting
  214. */
  215. ipath_err_t ipath_lasterror;
  216. /*
  217. * aggregrate of error bits reported since last cleared, for
  218. * limiting of hwerror reporting
  219. */
  220. ipath_err_t ipath_lasthwerror;
  221. /*
  222. * errors masked because they occur too fast, also includes errors
  223. * that are always ignored (ipath_ignorederrs)
  224. */
  225. ipath_err_t ipath_maskederrs;
  226. /* time in jiffies at which to re-enable maskederrs */
  227. unsigned long ipath_unmasktime;
  228. /*
  229. * errors always ignored (masked), at least for a given
  230. * chip/device, because they are wrong or not useful
  231. */
  232. ipath_err_t ipath_ignorederrs;
  233. /* count of egrfull errors, combined for all ports */
  234. u64 ipath_last_tidfull;
  235. /* for ipath_qcheck() */
  236. u64 ipath_lastport0rcv_cnt;
  237. /* template for writing TIDs */
  238. u64 ipath_tidtemplate;
  239. /* value to write to free TIDs */
  240. u64 ipath_tidinvalid;
  241. /* PE-800 rcv interrupt setup */
  242. u64 ipath_rhdrhead_intr_off;
  243. /* size of memory at ipath_kregbase */
  244. u32 ipath_kregsize;
  245. /* number of registers used for pioavail */
  246. u32 ipath_pioavregs;
  247. /* IPATH_POLL, etc. */
  248. u32 ipath_flags;
  249. /* ipath_flags sma is waiting for */
  250. u32 ipath_sma_state_wanted;
  251. /* last buffer for user use, first buf for kernel use is this
  252. * index. */
  253. u32 ipath_lastport_piobuf;
  254. /* is a stats timer active */
  255. u32 ipath_stats_timer_active;
  256. /* dwords sent read from counter */
  257. u32 ipath_lastsword;
  258. /* dwords received read from counter */
  259. u32 ipath_lastrword;
  260. /* sent packets read from counter */
  261. u32 ipath_lastspkts;
  262. /* received packets read from counter */
  263. u32 ipath_lastrpkts;
  264. /* pio bufs allocated per port */
  265. u32 ipath_pbufsport;
  266. /*
  267. * number of ports configured as max; zero is set to number chip
  268. * supports, less gives more pio bufs/port, etc.
  269. */
  270. u32 ipath_cfgports;
  271. /* port0 rcvhdrq head offset */
  272. u32 ipath_port0head;
  273. /* count of port 0 hdrqfull errors */
  274. u32 ipath_p0_hdrqfull;
  275. /*
  276. * (*cfgports) used to suppress multiple instances of same
  277. * port staying stuck at same point
  278. */
  279. u32 *ipath_lastrcvhdrqtails;
  280. /*
  281. * (*cfgports) used to suppress multiple instances of same
  282. * port staying stuck at same point
  283. */
  284. u32 *ipath_lastegrheads;
  285. /*
  286. * index of last piobuffer we used. Speeds up searching, by
  287. * starting at this point. Doesn't matter if multiple cpu's use and
  288. * update, last updater is only write that matters. Whenever it
  289. * wraps, we update shadow copies. Need a copy per device when we
  290. * get to multiple devices
  291. */
  292. u32 ipath_lastpioindex;
  293. /* max length of freezemsg */
  294. u32 ipath_freezelen;
  295. /*
  296. * consecutive times we wanted a PIO buffer but were unable to
  297. * get one
  298. */
  299. u32 ipath_consec_nopiobuf;
  300. /*
  301. * hint that we should update ipath_pioavailshadow before
  302. * looking for a PIO buffer
  303. */
  304. u32 ipath_upd_pio_shadow;
  305. /* so we can rewrite it after a chip reset */
  306. u32 ipath_pcibar0;
  307. /* so we can rewrite it after a chip reset */
  308. u32 ipath_pcibar1;
  309. /* sequential tries for SMA send and no bufs */
  310. u32 ipath_nosma_bufs;
  311. /* duration (seconds) ipath_nosma_bufs set */
  312. u32 ipath_nosma_secs;
  313. /* HT/PCI Vendor ID (here for NodeInfo) */
  314. u16 ipath_vendorid;
  315. /* HT/PCI Device ID (here for NodeInfo) */
  316. u16 ipath_deviceid;
  317. /* offset in HT config space of slave/primary interface block */
  318. u8 ipath_ht_slave_off;
  319. /* for write combining settings */
  320. unsigned long ipath_wc_cookie;
  321. /* ref count for each pkey */
  322. atomic_t ipath_pkeyrefs[4];
  323. /* shadow copy of all exptids physaddr; used only by funcsim */
  324. u64 *ipath_tidsimshadow;
  325. /* shadow copy of struct page *'s for exp tid pages */
  326. struct page **ipath_pageshadow;
  327. /* lock to workaround chip bug 9437 */
  328. spinlock_t ipath_tid_lock;
  329. /*
  330. * IPATH_STATUS_*,
  331. * this address is mapped readonly into user processes so they can
  332. * get status cheaply, whenever they want.
  333. */
  334. u64 *ipath_statusp;
  335. /* freeze msg if hw error put chip in freeze */
  336. char *ipath_freezemsg;
  337. /* pci access data structure */
  338. struct pci_dev *pcidev;
  339. struct cdev *cdev;
  340. struct class_device *class_dev;
  341. /* timer used to prevent stats overflow, error throttling, etc. */
  342. struct timer_list ipath_stats_timer;
  343. /* check for stale messages in rcv queue */
  344. /* only allow one intr at a time. */
  345. unsigned long ipath_rcv_pending;
  346. /*
  347. * Shadow copies of registers; size indicates read access size.
  348. * Most of them are readonly, but some are write-only register,
  349. * where we manipulate the bits in the shadow copy, and then write
  350. * the shadow copy to infinipath.
  351. *
  352. * We deliberately make most of these 32 bits, since they have
  353. * restricted range. For any that we read, we won't to generate 32
  354. * bit accesses, since Opteron will generate 2 separate 32 bit HT
  355. * transactions for a 64 bit read, and we want to avoid unnecessary
  356. * HT transactions.
  357. */
  358. /* This is the 64 bit group */
  359. /*
  360. * shadow of pioavail, check to be sure it's large enough at
  361. * init time.
  362. */
  363. unsigned long ipath_pioavailshadow[8];
  364. /* shadow of kr_gpio_out, for rmw ops */
  365. u64 ipath_gpio_out;
  366. /* kr_revision shadow */
  367. u64 ipath_revision;
  368. /*
  369. * shadow of ibcctrl, for interrupt handling of link changes,
  370. * etc.
  371. */
  372. u64 ipath_ibcctrl;
  373. /*
  374. * last ibcstatus, to suppress "duplicate" status change messages,
  375. * mostly from 2 to 3
  376. */
  377. u64 ipath_lastibcstat;
  378. /* hwerrmask shadow */
  379. ipath_err_t ipath_hwerrmask;
  380. /* interrupt config reg shadow */
  381. u64 ipath_intconfig;
  382. /* kr_sendpiobufbase value */
  383. u64 ipath_piobufbase;
  384. /* these are the "32 bit" regs */
  385. /*
  386. * number of GUIDs in the flash for this interface; may need some
  387. * rethinking for setting on other ifaces
  388. */
  389. u32 ipath_nguid;
  390. /*
  391. * the following two are 32-bit bitmasks, but {test,clear,set}_bit
  392. * all expect bit fields to be "unsigned long"
  393. */
  394. /* shadow kr_rcvctrl */
  395. unsigned long ipath_rcvctrl;
  396. /* shadow kr_sendctrl */
  397. unsigned long ipath_sendctrl;
  398. /* value we put in kr_rcvhdrcnt */
  399. u32 ipath_rcvhdrcnt;
  400. /* value we put in kr_rcvhdrsize */
  401. u32 ipath_rcvhdrsize;
  402. /* value we put in kr_rcvhdrentsize */
  403. u32 ipath_rcvhdrentsize;
  404. /* offset of last entry in rcvhdrq */
  405. u32 ipath_hdrqlast;
  406. /* kr_portcnt value */
  407. u32 ipath_portcnt;
  408. /* kr_pagealign value */
  409. u32 ipath_palign;
  410. /* number of "2KB" PIO buffers */
  411. u32 ipath_piobcnt2k;
  412. /* size in bytes of "2KB" PIO buffers */
  413. u32 ipath_piosize2k;
  414. /* number of "4KB" PIO buffers */
  415. u32 ipath_piobcnt4k;
  416. /* size in bytes of "4KB" PIO buffers */
  417. u32 ipath_piosize4k;
  418. /* kr_rcvegrbase value */
  419. u32 ipath_rcvegrbase;
  420. /* kr_rcvegrcnt value */
  421. u32 ipath_rcvegrcnt;
  422. /* kr_rcvtidbase value */
  423. u32 ipath_rcvtidbase;
  424. /* kr_rcvtidcnt value */
  425. u32 ipath_rcvtidcnt;
  426. /* kr_sendregbase */
  427. u32 ipath_sregbase;
  428. /* kr_userregbase */
  429. u32 ipath_uregbase;
  430. /* kr_counterregbase */
  431. u32 ipath_cregbase;
  432. /* shadow the control register contents */
  433. u32 ipath_control;
  434. /* shadow the gpio output contents */
  435. u32 ipath_extctrl;
  436. /* PCI revision register (HTC rev on FPGA) */
  437. u32 ipath_pcirev;
  438. /* chip address space used by 4k pio buffers */
  439. u32 ipath_4kalign;
  440. /* The MTU programmed for this unit */
  441. u32 ipath_ibmtu;
  442. /*
  443. * The max size IB packet, included IB headers that we can send.
  444. * Starts same as ipath_piosize, but is affected when ibmtu is
  445. * changed, or by size of eager buffers
  446. */
  447. u32 ipath_ibmaxlen;
  448. /*
  449. * ibmaxlen at init time, limited by chip and by receive buffer
  450. * size. Not changed after init.
  451. */
  452. u32 ipath_init_ibmaxlen;
  453. /* size of each rcvegrbuffer */
  454. u32 ipath_rcvegrbufsize;
  455. /* width (2,4,8,16,32) from HT config reg */
  456. u32 ipath_htwidth;
  457. /* HT speed (200,400,800,1000) from HT config */
  458. u32 ipath_htspeed;
  459. /* ports waiting for PIOavail intr */
  460. unsigned long ipath_portpiowait;
  461. /*
  462. * number of sequential ibcstatus change for polling active/quiet
  463. * (i.e., link not coming up).
  464. */
  465. u32 ipath_ibpollcnt;
  466. /* low and high portions of MSI capability/vector */
  467. u32 ipath_msi_lo;
  468. /* saved after PCIe init for restore after reset */
  469. u32 ipath_msi_hi;
  470. /* MSI data (vector) saved for restore */
  471. u16 ipath_msi_data;
  472. /* MLID programmed for this instance */
  473. u16 ipath_mlid;
  474. /* LID programmed for this instance */
  475. u16 ipath_lid;
  476. /* list of pkeys programmed; 0 if not set */
  477. u16 ipath_pkeys[4];
  478. /* ASCII serial number, from flash */
  479. u8 ipath_serial[12];
  480. /* human readable board version */
  481. u8 ipath_boardversion[80];
  482. /* chip major rev, from ipath_revision */
  483. u8 ipath_majrev;
  484. /* chip minor rev, from ipath_revision */
  485. u8 ipath_minrev;
  486. /* board rev, from ipath_revision */
  487. u8 ipath_boardrev;
  488. /* unit # of this chip, if present */
  489. int ipath_unit;
  490. /* saved for restore after reset */
  491. u8 ipath_pci_cacheline;
  492. /* LID mask control */
  493. u8 ipath_lmc;
  494. };
  495. extern volatile __le64 *ipath_port0_rcvhdrtail;
  496. extern dma_addr_t ipath_port0_rcvhdrtail_dma;
  497. #define IPATH_PORT0_RCVHDRTAIL_SIZE PAGE_SIZE
  498. extern struct list_head ipath_dev_list;
  499. extern spinlock_t ipath_devs_lock;
  500. extern struct ipath_devdata *ipath_lookup(int unit);
  501. extern u16 ipath_layer_rcv_opcode;
  502. extern int __ipath_layer_intr(struct ipath_devdata *, u32);
  503. extern int ipath_layer_intr(struct ipath_devdata *, u32);
  504. extern int __ipath_layer_rcv(struct ipath_devdata *, void *,
  505. struct sk_buff *);
  506. extern int __ipath_layer_rcv_lid(struct ipath_devdata *, void *);
  507. extern int __ipath_verbs_piobufavail(struct ipath_devdata *);
  508. extern int __ipath_verbs_rcv(struct ipath_devdata *, void *, void *, u32);
  509. void ipath_layer_add(struct ipath_devdata *);
  510. void ipath_layer_del(struct ipath_devdata *);
  511. int ipath_init_chip(struct ipath_devdata *, int);
  512. int ipath_enable_wc(struct ipath_devdata *dd);
  513. void ipath_disable_wc(struct ipath_devdata *dd);
  514. int ipath_count_units(int *npresentp, int *nupp, u32 *maxportsp);
  515. void ipath_shutdown_device(struct ipath_devdata *);
  516. struct file_operations;
  517. int ipath_cdev_init(int minor, char *name, struct file_operations *fops,
  518. struct cdev **cdevp, struct class_device **class_devp);
  519. void ipath_cdev_cleanup(struct cdev **cdevp,
  520. struct class_device **class_devp);
  521. int ipath_diag_init(void);
  522. void ipath_diag_cleanup(void);
  523. void ipath_diag_bringup_link(struct ipath_devdata *);
  524. extern wait_queue_head_t ipath_sma_state_wait;
  525. int ipath_user_add(struct ipath_devdata *dd);
  526. void ipath_user_del(struct ipath_devdata *dd);
  527. struct sk_buff *ipath_alloc_skb(struct ipath_devdata *dd, gfp_t);
  528. extern int ipath_diag_inuse;
  529. irqreturn_t ipath_intr(int irq, void *devid, struct pt_regs *regs);
  530. void ipath_decode_err(char *buf, size_t blen, ipath_err_t err);
  531. #if __IPATH_INFO || __IPATH_DBG
  532. extern const char *ipath_ibcstatus_str[];
  533. #endif
  534. /* clean up any per-chip chip-specific stuff */
  535. void ipath_chip_cleanup(struct ipath_devdata *);
  536. /* clean up any chip type-specific stuff */
  537. void ipath_chip_done(void);
  538. /* check to see if we have to force ordering for write combining */
  539. int ipath_unordered_wc(void);
  540. void ipath_disarm_piobufs(struct ipath_devdata *, unsigned first,
  541. unsigned cnt);
  542. int ipath_create_rcvhdrq(struct ipath_devdata *, struct ipath_portdata *);
  543. void ipath_free_pddata(struct ipath_devdata *, u32, int);
  544. int ipath_parse_ushort(const char *str, unsigned short *valp);
  545. int ipath_wait_linkstate(struct ipath_devdata *, u32, int);
  546. void ipath_set_ib_lstate(struct ipath_devdata *, int);
  547. void ipath_kreceive(struct ipath_devdata *);
  548. int ipath_setrcvhdrsize(struct ipath_devdata *, unsigned);
  549. int ipath_reset_device(int);
  550. void ipath_get_faststats(unsigned long);
  551. /* for use in system calls, where we want to know device type, etc. */
  552. #define port_fp(fp) ((struct ipath_portdata *) (fp)->private_data)
  553. /*
  554. * values for ipath_flags
  555. */
  556. /* The chip is up and initted */
  557. #define IPATH_INITTED 0x2
  558. /* set if any user code has set kr_rcvhdrsize */
  559. #define IPATH_RCVHDRSZ_SET 0x4
  560. /* The chip is present and valid for accesses */
  561. #define IPATH_PRESENT 0x8
  562. /* HT link0 is only 8 bits wide, ignore upper byte crc
  563. * errors, etc. */
  564. #define IPATH_8BIT_IN_HT0 0x10
  565. /* HT link1 is only 8 bits wide, ignore upper byte crc
  566. * errors, etc. */
  567. #define IPATH_8BIT_IN_HT1 0x20
  568. /* The link is down */
  569. #define IPATH_LINKDOWN 0x40
  570. /* The link level is up (0x11) */
  571. #define IPATH_LINKINIT 0x80
  572. /* The link is in the armed (0x21) state */
  573. #define IPATH_LINKARMED 0x100
  574. /* The link is in the active (0x31) state */
  575. #define IPATH_LINKACTIVE 0x200
  576. /* link current state is unknown */
  577. #define IPATH_LINKUNK 0x400
  578. /* no IB cable, or no device on IB cable */
  579. #define IPATH_NOCABLE 0x4000
  580. /* Supports port zero per packet receive interrupts via
  581. * GPIO */
  582. #define IPATH_GPIO_INTR 0x8000
  583. /* uses the coded 4byte TID, not 8 byte */
  584. #define IPATH_4BYTE_TID 0x10000
  585. /* packet/word counters are 32 bit, else those 4 counters
  586. * are 64bit */
  587. #define IPATH_32BITCOUNTERS 0x20000
  588. /* can miss port0 rx interrupts */
  589. #define IPATH_POLL_RX_INTR 0x40000
  590. #define IPATH_DISABLED 0x80000 /* administratively disabled */
  591. /* portdata flag bit offsets */
  592. /* waiting for a packet to arrive */
  593. #define IPATH_PORT_WAITING_RCV 2
  594. /* waiting for a PIO buffer to be available */
  595. #define IPATH_PORT_WAITING_PIO 3
  596. /* free up any allocated data at closes */
  597. void ipath_free_data(struct ipath_portdata *dd);
  598. int ipath_waitfor_mdio_cmdready(struct ipath_devdata *);
  599. int ipath_waitfor_complete(struct ipath_devdata *, ipath_kreg, u64, u64 *);
  600. u32 __iomem *ipath_getpiobuf(struct ipath_devdata *, u32 *);
  601. /* init PE-800-specific func */
  602. void ipath_init_pe800_funcs(struct ipath_devdata *);
  603. /* init HT-400-specific func */
  604. void ipath_init_ht400_funcs(struct ipath_devdata *);
  605. void ipath_get_guid(struct ipath_devdata *);
  606. u64 ipath_snap_cntr(struct ipath_devdata *, ipath_creg);
  607. /*
  608. * number of words used for protocol header if not set by ipath_userinit();
  609. */
  610. #define IPATH_DFLT_RCVHDRSIZE 9
  611. #define IPATH_MDIO_CMD_WRITE 1
  612. #define IPATH_MDIO_CMD_READ 2
  613. #define IPATH_MDIO_CLD_DIV 25 /* to get 2.5 Mhz mdio clock */
  614. #define IPATH_MDIO_CMDVALID 0x40000000 /* bit 30 */
  615. #define IPATH_MDIO_DATAVALID 0x80000000 /* bit 31 */
  616. #define IPATH_MDIO_CTRL_STD 0x0
  617. static inline u64 ipath_mdio_req(int cmd, int dev, int reg, int data)
  618. {
  619. return (((u64) IPATH_MDIO_CLD_DIV) << 32) |
  620. (cmd << 26) |
  621. (dev << 21) |
  622. (reg << 16) |
  623. (data & 0xFFFF);
  624. }
  625. /* signal and fifo status, in bank 31 */
  626. #define IPATH_MDIO_CTRL_XGXS_REG_8 0x8
  627. /* controls loopback, redundancy */
  628. #define IPATH_MDIO_CTRL_8355_REG_1 0x10
  629. /* premph, encdec, etc. */
  630. #define IPATH_MDIO_CTRL_8355_REG_2 0x11
  631. /* Kchars, etc. */
  632. #define IPATH_MDIO_CTRL_8355_REG_6 0x15
  633. #define IPATH_MDIO_CTRL_8355_REG_9 0x18
  634. #define IPATH_MDIO_CTRL_8355_REG_10 0x1D
  635. int ipath_get_user_pages(unsigned long, size_t, struct page **);
  636. int ipath_get_user_pages_nocopy(unsigned long, struct page **);
  637. void ipath_release_user_pages(struct page **, size_t);
  638. void ipath_release_user_pages_on_close(struct page **, size_t);
  639. int ipath_eeprom_read(struct ipath_devdata *, u8, void *, int);
  640. int ipath_eeprom_write(struct ipath_devdata *, u8, const void *, int);
  641. /* these are used for the registers that vary with port */
  642. void ipath_write_kreg_port(const struct ipath_devdata *, ipath_kreg,
  643. unsigned, u64);
  644. u64 ipath_read_kreg64_port(const struct ipath_devdata *, ipath_kreg,
  645. unsigned);
  646. /*
  647. * We could have a single register get/put routine, that takes a group type,
  648. * but this is somewhat clearer and cleaner. It also gives us some error
  649. * checking. 64 bit register reads should always work, but are inefficient
  650. * on opteron (the northbridge always generates 2 separate HT 32 bit reads),
  651. * so we use kreg32 wherever possible. User register and counter register
  652. * reads are always 32 bit reads, so only one form of those routines.
  653. */
  654. /*
  655. * At the moment, none of the s-registers are writable, so no
  656. * ipath_write_sreg(), and none of the c-registers are writable, so no
  657. * ipath_write_creg().
  658. */
  659. /**
  660. * ipath_read_ureg32 - read 32-bit virtualized per-port register
  661. * @dd: device
  662. * @regno: register number
  663. * @port: port number
  664. *
  665. * Return the contents of a register that is virtualized to be per port.
  666. * Prints a debug message and returns -1 on errors (not distinguishable from
  667. * valid contents at runtime; we may add a separate error variable at some
  668. * point).
  669. *
  670. * This is normally not used by the kernel, but may be for debugging, and
  671. * has a different implementation than user mode, which is why it's not in
  672. * _common.h.
  673. */
  674. static inline u32 ipath_read_ureg32(const struct ipath_devdata *dd,
  675. ipath_ureg regno, int port)
  676. {
  677. if (!dd->ipath_kregbase)
  678. return 0;
  679. return readl(regno + (u64 __iomem *)
  680. (dd->ipath_uregbase +
  681. (char __iomem *)dd->ipath_kregbase +
  682. dd->ipath_palign * port));
  683. }
  684. /**
  685. * ipath_write_ureg - write 32-bit virtualized per-port register
  686. * @dd: device
  687. * @regno: register number
  688. * @value: value
  689. * @port: port
  690. *
  691. * Write the contents of a register that is virtualized to be per port.
  692. */
  693. static inline void ipath_write_ureg(const struct ipath_devdata *dd,
  694. ipath_ureg regno, u64 value, int port)
  695. {
  696. u64 __iomem *ubase = (u64 __iomem *)
  697. (dd->ipath_uregbase + (char __iomem *) dd->ipath_kregbase +
  698. dd->ipath_palign * port);
  699. if (dd->ipath_kregbase)
  700. writeq(value, &ubase[regno]);
  701. }
  702. static inline u32 ipath_read_kreg32(const struct ipath_devdata *dd,
  703. ipath_kreg regno)
  704. {
  705. if (!dd->ipath_kregbase)
  706. return -1;
  707. return readl((u32 __iomem *) & dd->ipath_kregbase[regno]);
  708. }
  709. static inline u64 ipath_read_kreg64(const struct ipath_devdata *dd,
  710. ipath_kreg regno)
  711. {
  712. if (!dd->ipath_kregbase)
  713. return -1;
  714. return readq(&dd->ipath_kregbase[regno]);
  715. }
  716. static inline void ipath_write_kreg(const struct ipath_devdata *dd,
  717. ipath_kreg regno, u64 value)
  718. {
  719. if (dd->ipath_kregbase)
  720. writeq(value, &dd->ipath_kregbase[regno]);
  721. }
  722. static inline u64 ipath_read_creg(const struct ipath_devdata *dd,
  723. ipath_sreg regno)
  724. {
  725. if (!dd->ipath_kregbase)
  726. return 0;
  727. return readq(regno + (u64 __iomem *)
  728. (dd->ipath_cregbase +
  729. (char __iomem *)dd->ipath_kregbase));
  730. }
  731. static inline u32 ipath_read_creg32(const struct ipath_devdata *dd,
  732. ipath_sreg regno)
  733. {
  734. if (!dd->ipath_kregbase)
  735. return 0;
  736. return readl(regno + (u64 __iomem *)
  737. (dd->ipath_cregbase +
  738. (char __iomem *)dd->ipath_kregbase));
  739. }
  740. /*
  741. * sysfs interface.
  742. */
  743. struct device_driver;
  744. extern const char ipath_core_version[];
  745. int ipath_driver_create_group(struct device_driver *);
  746. void ipath_driver_remove_group(struct device_driver *);
  747. int ipath_device_create_group(struct device *, struct ipath_devdata *);
  748. void ipath_device_remove_group(struct device *, struct ipath_devdata *);
  749. int ipath_expose_reset(struct device *);
  750. int ipath_init_ipathfs(void);
  751. void ipath_exit_ipathfs(void);
  752. int ipathfs_add_device(struct ipath_devdata *);
  753. int ipathfs_remove_device(struct ipath_devdata *);
  754. /*
  755. * Flush write combining store buffers (if present) and perform a write
  756. * barrier.
  757. */
  758. #if defined(CONFIG_X86_64)
  759. #define ipath_flush_wc() asm volatile("sfence" ::: "memory")
  760. #else
  761. #define ipath_flush_wc() wmb()
  762. #endif
  763. extern unsigned ipath_debug; /* debugging bit mask */
  764. const char *ipath_get_unit_name(int unit);
  765. extern struct mutex ipath_mutex;
  766. #define IPATH_DRV_NAME "ipath_core"
  767. #define IPATH_MAJOR 233
  768. #define IPATH_SMA_MINOR 128
  769. #define IPATH_DIAG_MINOR 129
  770. #define IPATH_NMINORS 130
  771. #define ipath_dev_err(dd,fmt,...) \
  772. do { \
  773. const struct ipath_devdata *__dd = (dd); \
  774. if (__dd->pcidev) \
  775. dev_err(&__dd->pcidev->dev, "%s: " fmt, \
  776. ipath_get_unit_name(__dd->ipath_unit), \
  777. ##__VA_ARGS__); \
  778. else \
  779. printk(KERN_ERR IPATH_DRV_NAME ": %s: " fmt, \
  780. ipath_get_unit_name(__dd->ipath_unit), \
  781. ##__VA_ARGS__); \
  782. } while (0)
  783. #if _IPATH_DEBUGGING
  784. # define __IPATH_DBG_WHICH(which,fmt,...) \
  785. do { \
  786. if(unlikely(ipath_debug&(which))) \
  787. printk(KERN_DEBUG IPATH_DRV_NAME ": %s: " fmt, \
  788. __func__,##__VA_ARGS__); \
  789. } while(0)
  790. # define ipath_dbg(fmt,...) \
  791. __IPATH_DBG_WHICH(__IPATH_DBG,fmt,##__VA_ARGS__)
  792. # define ipath_cdbg(which,fmt,...) \
  793. __IPATH_DBG_WHICH(__IPATH_##which##DBG,fmt,##__VA_ARGS__)
  794. #else /* ! _IPATH_DEBUGGING */
  795. # define ipath_dbg(fmt,...)
  796. # define ipath_cdbg(which,fmt,...)
  797. #endif /* _IPATH_DEBUGGING */
  798. #endif /* _IPATH_KERNEL_H */