ipath_kernel.h 27 KB

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