ipath_kernel.h 27 KB

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