ipath_kernel.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875
  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. void *ipath_dummy_hdrq; /* used after port close */
  338. dma_addr_t ipath_dummy_hdrq_phys;
  339. /*
  340. * Shadow copies of registers; size indicates read access size.
  341. * Most of them are readonly, but some are write-only register,
  342. * where we manipulate the bits in the shadow copy, and then write
  343. * the shadow copy to infinipath.
  344. *
  345. * We deliberately make most of these 32 bits, since they have
  346. * restricted range. For any that we read, we won't to generate 32
  347. * bit accesses, since Opteron will generate 2 separate 32 bit HT
  348. * transactions for a 64 bit read, and we want to avoid unnecessary
  349. * HT transactions.
  350. */
  351. /* This is the 64 bit group */
  352. /*
  353. * shadow of pioavail, check to be sure it's large enough at
  354. * init time.
  355. */
  356. unsigned long ipath_pioavailshadow[8];
  357. /* shadow of kr_gpio_out, for rmw ops */
  358. u64 ipath_gpio_out;
  359. /* kr_revision shadow */
  360. u64 ipath_revision;
  361. /*
  362. * shadow of ibcctrl, for interrupt handling of link changes,
  363. * etc.
  364. */
  365. u64 ipath_ibcctrl;
  366. /*
  367. * last ibcstatus, to suppress "duplicate" status change messages,
  368. * mostly from 2 to 3
  369. */
  370. u64 ipath_lastibcstat;
  371. /* hwerrmask shadow */
  372. ipath_err_t ipath_hwerrmask;
  373. /* interrupt config reg shadow */
  374. u64 ipath_intconfig;
  375. /* kr_sendpiobufbase value */
  376. u64 ipath_piobufbase;
  377. /* these are the "32 bit" regs */
  378. /*
  379. * number of GUIDs in the flash for this interface; may need some
  380. * rethinking for setting on other ifaces
  381. */
  382. u32 ipath_nguid;
  383. /*
  384. * the following two are 32-bit bitmasks, but {test,clear,set}_bit
  385. * all expect bit fields to be "unsigned long"
  386. */
  387. /* shadow kr_rcvctrl */
  388. unsigned long ipath_rcvctrl;
  389. /* shadow kr_sendctrl */
  390. unsigned long ipath_sendctrl;
  391. /* value we put in kr_rcvhdrcnt */
  392. u32 ipath_rcvhdrcnt;
  393. /* value we put in kr_rcvhdrsize */
  394. u32 ipath_rcvhdrsize;
  395. /* value we put in kr_rcvhdrentsize */
  396. u32 ipath_rcvhdrentsize;
  397. /* offset of last entry in rcvhdrq */
  398. u32 ipath_hdrqlast;
  399. /* kr_portcnt value */
  400. u32 ipath_portcnt;
  401. /* kr_pagealign value */
  402. u32 ipath_palign;
  403. /* number of "2KB" PIO buffers */
  404. u32 ipath_piobcnt2k;
  405. /* size in bytes of "2KB" PIO buffers */
  406. u32 ipath_piosize2k;
  407. /* number of "4KB" PIO buffers */
  408. u32 ipath_piobcnt4k;
  409. /* size in bytes of "4KB" PIO buffers */
  410. u32 ipath_piosize4k;
  411. /* kr_rcvegrbase value */
  412. u32 ipath_rcvegrbase;
  413. /* kr_rcvegrcnt value */
  414. u32 ipath_rcvegrcnt;
  415. /* kr_rcvtidbase value */
  416. u32 ipath_rcvtidbase;
  417. /* kr_rcvtidcnt value */
  418. u32 ipath_rcvtidcnt;
  419. /* kr_sendregbase */
  420. u32 ipath_sregbase;
  421. /* kr_userregbase */
  422. u32 ipath_uregbase;
  423. /* kr_counterregbase */
  424. u32 ipath_cregbase;
  425. /* shadow the control register contents */
  426. u32 ipath_control;
  427. /* shadow the gpio output contents */
  428. u32 ipath_extctrl;
  429. /* PCI revision register (HTC rev on FPGA) */
  430. u32 ipath_pcirev;
  431. /* chip address space used by 4k pio buffers */
  432. u32 ipath_4kalign;
  433. /* The MTU programmed for this unit */
  434. u32 ipath_ibmtu;
  435. /*
  436. * The max size IB packet, included IB headers that we can send.
  437. * Starts same as ipath_piosize, but is affected when ibmtu is
  438. * changed, or by size of eager buffers
  439. */
  440. u32 ipath_ibmaxlen;
  441. /*
  442. * ibmaxlen at init time, limited by chip and by receive buffer
  443. * size. Not changed after init.
  444. */
  445. u32 ipath_init_ibmaxlen;
  446. /* size of each rcvegrbuffer */
  447. u32 ipath_rcvegrbufsize;
  448. /* width (2,4,8,16,32) from HT config reg */
  449. u32 ipath_htwidth;
  450. /* HT speed (200,400,800,1000) from HT config */
  451. u32 ipath_htspeed;
  452. /* ports waiting for PIOavail intr */
  453. unsigned long ipath_portpiowait;
  454. /*
  455. * number of sequential ibcstatus change for polling active/quiet
  456. * (i.e., link not coming up).
  457. */
  458. u32 ipath_ibpollcnt;
  459. /* low and high portions of MSI capability/vector */
  460. u32 ipath_msi_lo;
  461. /* saved after PCIe init for restore after reset */
  462. u32 ipath_msi_hi;
  463. /* MSI data (vector) saved for restore */
  464. u16 ipath_msi_data;
  465. /* MLID programmed for this instance */
  466. u16 ipath_mlid;
  467. /* LID programmed for this instance */
  468. u16 ipath_lid;
  469. /* list of pkeys programmed; 0 if not set */
  470. u16 ipath_pkeys[4];
  471. /*
  472. * ASCII serial number, from flash, large enough for original
  473. * all digit strings, and longer QLogic serial number format
  474. */
  475. u8 ipath_serial[16];
  476. /* human readable board version */
  477. u8 ipath_boardversion[80];
  478. /* chip major rev, from ipath_revision */
  479. u8 ipath_majrev;
  480. /* chip minor rev, from ipath_revision */
  481. u8 ipath_minrev;
  482. /* board rev, from ipath_revision */
  483. u8 ipath_boardrev;
  484. /* unit # of this chip, if present */
  485. int ipath_unit;
  486. /* saved for restore after reset */
  487. u8 ipath_pci_cacheline;
  488. /* LID mask control */
  489. u8 ipath_lmc;
  490. /* local link integrity counter */
  491. u32 ipath_lli_counter;
  492. /* local link integrity errors */
  493. u32 ipath_lli_errors;
  494. };
  495. extern struct list_head ipath_dev_list;
  496. extern spinlock_t ipath_devs_lock;
  497. extern struct ipath_devdata *ipath_lookup(int unit);
  498. extern u16 ipath_layer_rcv_opcode;
  499. extern int __ipath_layer_intr(struct ipath_devdata *, u32);
  500. extern int ipath_layer_intr(struct ipath_devdata *, u32);
  501. extern int __ipath_layer_rcv(struct ipath_devdata *, void *,
  502. struct sk_buff *);
  503. extern int __ipath_layer_rcv_lid(struct ipath_devdata *, void *);
  504. extern int __ipath_verbs_piobufavail(struct ipath_devdata *);
  505. extern int __ipath_verbs_rcv(struct ipath_devdata *, void *, void *, u32);
  506. void ipath_layer_add(struct ipath_devdata *);
  507. void ipath_layer_remove(struct ipath_devdata *);
  508. int ipath_init_chip(struct ipath_devdata *, int);
  509. int ipath_enable_wc(struct ipath_devdata *dd);
  510. void ipath_disable_wc(struct ipath_devdata *dd);
  511. int ipath_count_units(int *npresentp, int *nupp, u32 *maxportsp);
  512. void ipath_shutdown_device(struct ipath_devdata *);
  513. struct file_operations;
  514. int ipath_cdev_init(int minor, char *name, struct file_operations *fops,
  515. struct cdev **cdevp, struct class_device **class_devp);
  516. void ipath_cdev_cleanup(struct cdev **cdevp,
  517. struct class_device **class_devp);
  518. int ipath_diag_add(struct ipath_devdata *);
  519. void ipath_diag_remove(struct ipath_devdata *);
  520. void ipath_diag_bringup_link(struct ipath_devdata *);
  521. extern wait_queue_head_t ipath_sma_state_wait;
  522. int ipath_user_add(struct ipath_devdata *dd);
  523. void ipath_user_remove(struct ipath_devdata *dd);
  524. struct sk_buff *ipath_alloc_skb(struct ipath_devdata *dd, gfp_t);
  525. extern int ipath_diag_inuse;
  526. irqreturn_t ipath_intr(int irq, void *devid, struct pt_regs *regs);
  527. void ipath_decode_err(char *buf, size_t blen, ipath_err_t err);
  528. #if __IPATH_INFO || __IPATH_DBG
  529. extern const char *ipath_ibcstatus_str[];
  530. #endif
  531. /* clean up any per-chip chip-specific stuff */
  532. void ipath_chip_cleanup(struct ipath_devdata *);
  533. /* clean up any chip type-specific stuff */
  534. void ipath_chip_done(void);
  535. /* check to see if we have to force ordering for write combining */
  536. int ipath_unordered_wc(void);
  537. void ipath_disarm_piobufs(struct ipath_devdata *, unsigned first,
  538. unsigned cnt);
  539. int ipath_create_rcvhdrq(struct ipath_devdata *, struct ipath_portdata *);
  540. void ipath_free_pddata(struct ipath_devdata *, struct ipath_portdata *);
  541. int ipath_parse_ushort(const char *str, unsigned short *valp);
  542. int ipath_wait_linkstate(struct ipath_devdata *, u32, int);
  543. void ipath_set_ib_lstate(struct ipath_devdata *, int);
  544. void ipath_kreceive(struct ipath_devdata *);
  545. int ipath_setrcvhdrsize(struct ipath_devdata *, unsigned);
  546. int ipath_reset_device(int);
  547. void ipath_get_faststats(unsigned long);
  548. /* for use in system calls, where we want to know device type, etc. */
  549. #define port_fp(fp) ((struct ipath_portdata *) (fp)->private_data)
  550. /*
  551. * values for ipath_flags
  552. */
  553. /* The chip is up and initted */
  554. #define IPATH_INITTED 0x2
  555. /* set if any user code has set kr_rcvhdrsize */
  556. #define IPATH_RCVHDRSZ_SET 0x4
  557. /* The chip is present and valid for accesses */
  558. #define IPATH_PRESENT 0x8
  559. /* HT link0 is only 8 bits wide, ignore upper byte crc
  560. * errors, etc. */
  561. #define IPATH_8BIT_IN_HT0 0x10
  562. /* HT link1 is only 8 bits wide, ignore upper byte crc
  563. * errors, etc. */
  564. #define IPATH_8BIT_IN_HT1 0x20
  565. /* The link is down */
  566. #define IPATH_LINKDOWN 0x40
  567. /* The link level is up (0x11) */
  568. #define IPATH_LINKINIT 0x80
  569. /* The link is in the armed (0x21) state */
  570. #define IPATH_LINKARMED 0x100
  571. /* The link is in the active (0x31) state */
  572. #define IPATH_LINKACTIVE 0x200
  573. /* link current state is unknown */
  574. #define IPATH_LINKUNK 0x400
  575. /* no IB cable, or no device on IB cable */
  576. #define IPATH_NOCABLE 0x4000
  577. /* Supports port zero per packet receive interrupts via
  578. * GPIO */
  579. #define IPATH_GPIO_INTR 0x8000
  580. /* uses the coded 4byte TID, not 8 byte */
  581. #define IPATH_4BYTE_TID 0x10000
  582. /* packet/word counters are 32 bit, else those 4 counters
  583. * are 64bit */
  584. #define IPATH_32BITCOUNTERS 0x20000
  585. /* can miss port0 rx interrupts */
  586. #define IPATH_POLL_RX_INTR 0x40000
  587. #define IPATH_DISABLED 0x80000 /* administratively disabled */
  588. /* portdata flag bit offsets */
  589. /* waiting for a packet to arrive */
  590. #define IPATH_PORT_WAITING_RCV 2
  591. /* waiting for a PIO buffer to be available */
  592. #define IPATH_PORT_WAITING_PIO 3
  593. /* free up any allocated data at closes */
  594. void ipath_free_data(struct ipath_portdata *dd);
  595. int ipath_waitfor_mdio_cmdready(struct ipath_devdata *);
  596. int ipath_waitfor_complete(struct ipath_devdata *, ipath_kreg, u64, u64 *);
  597. u32 __iomem *ipath_getpiobuf(struct ipath_devdata *, u32 *);
  598. /* init PE-800-specific func */
  599. void ipath_init_pe800_funcs(struct ipath_devdata *);
  600. /* init HT-400-specific func */
  601. void ipath_init_ht400_funcs(struct ipath_devdata *);
  602. void ipath_get_eeprom_info(struct ipath_devdata *);
  603. u64 ipath_snap_cntr(struct ipath_devdata *, ipath_creg);
  604. /*
  605. * number of words used for protocol header if not set by ipath_userinit();
  606. */
  607. #define IPATH_DFLT_RCVHDRSIZE 9
  608. #define IPATH_MDIO_CMD_WRITE 1
  609. #define IPATH_MDIO_CMD_READ 2
  610. #define IPATH_MDIO_CLD_DIV 25 /* to get 2.5 Mhz mdio clock */
  611. #define IPATH_MDIO_CMDVALID 0x40000000 /* bit 30 */
  612. #define IPATH_MDIO_DATAVALID 0x80000000 /* bit 31 */
  613. #define IPATH_MDIO_CTRL_STD 0x0
  614. static inline u64 ipath_mdio_req(int cmd, int dev, int reg, int data)
  615. {
  616. return (((u64) IPATH_MDIO_CLD_DIV) << 32) |
  617. (cmd << 26) |
  618. (dev << 21) |
  619. (reg << 16) |
  620. (data & 0xFFFF);
  621. }
  622. /* signal and fifo status, in bank 31 */
  623. #define IPATH_MDIO_CTRL_XGXS_REG_8 0x8
  624. /* controls loopback, redundancy */
  625. #define IPATH_MDIO_CTRL_8355_REG_1 0x10
  626. /* premph, encdec, etc. */
  627. #define IPATH_MDIO_CTRL_8355_REG_2 0x11
  628. /* Kchars, etc. */
  629. #define IPATH_MDIO_CTRL_8355_REG_6 0x15
  630. #define IPATH_MDIO_CTRL_8355_REG_9 0x18
  631. #define IPATH_MDIO_CTRL_8355_REG_10 0x1D
  632. int ipath_get_user_pages(unsigned long, size_t, struct page **);
  633. int ipath_get_user_pages_nocopy(unsigned long, struct page **);
  634. void ipath_release_user_pages(struct page **, size_t);
  635. void ipath_release_user_pages_on_close(struct page **, size_t);
  636. int ipath_eeprom_read(struct ipath_devdata *, u8, void *, int);
  637. int ipath_eeprom_write(struct ipath_devdata *, u8, const void *, int);
  638. /* these are used for the registers that vary with port */
  639. void ipath_write_kreg_port(const struct ipath_devdata *, ipath_kreg,
  640. unsigned, u64);
  641. u64 ipath_read_kreg64_port(const struct ipath_devdata *, ipath_kreg,
  642. unsigned);
  643. /*
  644. * We could have a single register get/put routine, that takes a group type,
  645. * but this is somewhat clearer and cleaner. It also gives us some error
  646. * checking. 64 bit register reads should always work, but are inefficient
  647. * on opteron (the northbridge always generates 2 separate HT 32 bit reads),
  648. * so we use kreg32 wherever possible. User register and counter register
  649. * reads are always 32 bit reads, so only one form of those routines.
  650. */
  651. /*
  652. * At the moment, none of the s-registers are writable, so no
  653. * ipath_write_sreg(), and none of the c-registers are writable, so no
  654. * ipath_write_creg().
  655. */
  656. /**
  657. * ipath_read_ureg32 - read 32-bit virtualized per-port register
  658. * @dd: device
  659. * @regno: register number
  660. * @port: port number
  661. *
  662. * Return the contents of a register that is virtualized to be per port.
  663. * Returns -1 on errors (not distinguishable from valid contents at
  664. * runtime; we may add a separate error variable at some point).
  665. */
  666. static inline u32 ipath_read_ureg32(const struct ipath_devdata *dd,
  667. ipath_ureg regno, int port)
  668. {
  669. if (!dd->ipath_kregbase || !(dd->ipath_flags & IPATH_PRESENT))
  670. return 0;
  671. return readl(regno + (u64 __iomem *)
  672. (dd->ipath_uregbase +
  673. (char __iomem *)dd->ipath_kregbase +
  674. dd->ipath_palign * port));
  675. }
  676. /**
  677. * ipath_write_ureg - write 32-bit virtualized per-port register
  678. * @dd: device
  679. * @regno: register number
  680. * @value: value
  681. * @port: port
  682. *
  683. * Write the contents of a register that is virtualized to be per port.
  684. */
  685. static inline void ipath_write_ureg(const struct ipath_devdata *dd,
  686. ipath_ureg regno, u64 value, int port)
  687. {
  688. u64 __iomem *ubase = (u64 __iomem *)
  689. (dd->ipath_uregbase + (char __iomem *) dd->ipath_kregbase +
  690. dd->ipath_palign * port);
  691. if (dd->ipath_kregbase)
  692. writeq(value, &ubase[regno]);
  693. }
  694. static inline u32 ipath_read_kreg32(const struct ipath_devdata *dd,
  695. ipath_kreg regno)
  696. {
  697. if (!dd->ipath_kregbase || !(dd->ipath_flags & IPATH_PRESENT))
  698. return -1;
  699. return readl((u32 __iomem *) & dd->ipath_kregbase[regno]);
  700. }
  701. static inline u64 ipath_read_kreg64(const struct ipath_devdata *dd,
  702. ipath_kreg regno)
  703. {
  704. if (!dd->ipath_kregbase || !(dd->ipath_flags & IPATH_PRESENT))
  705. return -1;
  706. return readq(&dd->ipath_kregbase[regno]);
  707. }
  708. static inline void ipath_write_kreg(const struct ipath_devdata *dd,
  709. ipath_kreg regno, u64 value)
  710. {
  711. if (dd->ipath_kregbase)
  712. writeq(value, &dd->ipath_kregbase[regno]);
  713. }
  714. static inline u64 ipath_read_creg(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 readq(regno + (u64 __iomem *)
  720. (dd->ipath_cregbase +
  721. (char __iomem *)dd->ipath_kregbase));
  722. }
  723. static inline u32 ipath_read_creg32(const struct ipath_devdata *dd,
  724. ipath_sreg regno)
  725. {
  726. if (!dd->ipath_kregbase || !(dd->ipath_flags & IPATH_PRESENT))
  727. return 0;
  728. return readl(regno + (u64 __iomem *)
  729. (dd->ipath_cregbase +
  730. (char __iomem *)dd->ipath_kregbase));
  731. }
  732. /*
  733. * sysfs interface.
  734. */
  735. struct device_driver;
  736. extern const char ipath_core_version[];
  737. int ipath_driver_create_group(struct device_driver *);
  738. void ipath_driver_remove_group(struct device_driver *);
  739. int ipath_device_create_group(struct device *, struct ipath_devdata *);
  740. void ipath_device_remove_group(struct device *, struct ipath_devdata *);
  741. int ipath_expose_reset(struct device *);
  742. int ipath_init_ipathfs(void);
  743. void ipath_exit_ipathfs(void);
  744. int ipathfs_add_device(struct ipath_devdata *);
  745. int ipathfs_remove_device(struct ipath_devdata *);
  746. /*
  747. * Flush write combining store buffers (if present) and perform a write
  748. * barrier.
  749. */
  750. #if defined(CONFIG_X86_64)
  751. #define ipath_flush_wc() asm volatile("sfence" ::: "memory")
  752. #else
  753. #define ipath_flush_wc() wmb()
  754. #endif
  755. extern unsigned ipath_debug; /* debugging bit mask */
  756. const char *ipath_get_unit_name(int unit);
  757. extern struct mutex ipath_mutex;
  758. #define IPATH_DRV_NAME "ipath_core"
  759. #define IPATH_MAJOR 233
  760. #define IPATH_USER_MINOR_BASE 0
  761. #define IPATH_SMA_MINOR 128
  762. #define IPATH_DIAG_MINOR_BASE 129
  763. #define IPATH_NMINORS 255
  764. #define ipath_dev_err(dd,fmt,...) \
  765. do { \
  766. const struct ipath_devdata *__dd = (dd); \
  767. if (__dd->pcidev) \
  768. dev_err(&__dd->pcidev->dev, "%s: " fmt, \
  769. ipath_get_unit_name(__dd->ipath_unit), \
  770. ##__VA_ARGS__); \
  771. else \
  772. printk(KERN_ERR IPATH_DRV_NAME ": %s: " fmt, \
  773. ipath_get_unit_name(__dd->ipath_unit), \
  774. ##__VA_ARGS__); \
  775. } while (0)
  776. #if _IPATH_DEBUGGING
  777. # define __IPATH_DBG_WHICH(which,fmt,...) \
  778. do { \
  779. if(unlikely(ipath_debug&(which))) \
  780. printk(KERN_DEBUG IPATH_DRV_NAME ": %s: " fmt, \
  781. __func__,##__VA_ARGS__); \
  782. } while(0)
  783. # define ipath_dbg(fmt,...) \
  784. __IPATH_DBG_WHICH(__IPATH_DBG,fmt,##__VA_ARGS__)
  785. # define ipath_cdbg(which,fmt,...) \
  786. __IPATH_DBG_WHICH(__IPATH_##which##DBG,fmt,##__VA_ARGS__)
  787. #else /* ! _IPATH_DEBUGGING */
  788. # define ipath_dbg(fmt,...)
  789. # define ipath_cdbg(which,fmt,...)
  790. #endif /* _IPATH_DEBUGGING */
  791. #endif /* _IPATH_KERNEL_H */