ipath_kernel.h 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036
  1. #ifndef _IPATH_KERNEL_H
  2. #define _IPATH_KERNEL_H
  3. /*
  4. * Copyright (c) 2006, 2007 QLogic Corporation. 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 <linux/pci.h>
  41. #include <linux/dma-mapping.h>
  42. #include <asm/io.h>
  43. #include "ipath_common.h"
  44. #include "ipath_debug.h"
  45. #include "ipath_registers.h"
  46. /* only s/w major version of InfiniPath we can handle */
  47. #define IPATH_CHIP_VERS_MAJ 2U
  48. /* don't care about this except printing */
  49. #define IPATH_CHIP_VERS_MIN 0U
  50. /* temporary, maybe always */
  51. extern struct infinipath_stats ipath_stats;
  52. #define IPATH_CHIP_SWVERSION IPATH_CHIP_VERS_MAJ
  53. /*
  54. * First-cut critierion for "device is active" is
  55. * two thousand dwords combined Tx, Rx traffic per
  56. * 5-second interval. SMA packets are 64 dwords,
  57. * and occur "a few per second", presumably each way.
  58. */
  59. #define IPATH_TRAFFIC_ACTIVE_THRESHOLD (2000)
  60. /*
  61. * Struct used to indicate which errors are logged in each of the
  62. * error-counters that are logged to EEPROM. A counter is incremented
  63. * _once_ (saturating at 255) for each event with any bits set in
  64. * the error or hwerror register masks below.
  65. */
  66. #define IPATH_EEP_LOG_CNT (4)
  67. struct ipath_eep_log_mask {
  68. u64 errs_to_log;
  69. u64 hwerrs_to_log;
  70. };
  71. struct ipath_portdata {
  72. void **port_rcvegrbuf;
  73. dma_addr_t *port_rcvegrbuf_phys;
  74. /* rcvhdrq base, needs mmap before useful */
  75. void *port_rcvhdrq;
  76. /* kernel virtual address where hdrqtail is updated */
  77. void *port_rcvhdrtail_kvaddr;
  78. /*
  79. * temp buffer for expected send setup, allocated at open, instead
  80. * of each setup call
  81. */
  82. void *port_tid_pg_list;
  83. /* when waiting for rcv or pioavail */
  84. wait_queue_head_t port_wait;
  85. /*
  86. * rcvegr bufs base, physical, must fit
  87. * in 44 bits so 32 bit programs mmap64 44 bit works)
  88. */
  89. dma_addr_t port_rcvegr_phys;
  90. /* mmap of hdrq, must fit in 44 bits */
  91. dma_addr_t port_rcvhdrq_phys;
  92. dma_addr_t port_rcvhdrqtailaddr_phys;
  93. /*
  94. * number of opens (including slave subports) on this instance
  95. * (ignoring forks, dup, etc. for now)
  96. */
  97. int port_cnt;
  98. /*
  99. * how much space to leave at start of eager TID entries for
  100. * protocol use, on each TID
  101. */
  102. /* instead of calculating it */
  103. unsigned port_port;
  104. /* non-zero if port is being shared. */
  105. u16 port_subport_cnt;
  106. /* non-zero if port is being shared. */
  107. u16 port_subport_id;
  108. /* chip offset of PIO buffers for this port */
  109. u32 port_piobufs;
  110. /* how many alloc_pages() chunks in port_rcvegrbuf_pages */
  111. u32 port_rcvegrbuf_chunks;
  112. /* how many egrbufs per chunk */
  113. u32 port_rcvegrbufs_perchunk;
  114. /* order for port_rcvegrbuf_pages */
  115. size_t port_rcvegrbuf_size;
  116. /* rcvhdrq size (for freeing) */
  117. size_t port_rcvhdrq_size;
  118. /* next expected TID to check when looking for free */
  119. u32 port_tidcursor;
  120. /* next expected TID to check */
  121. unsigned long port_flag;
  122. /* what happened */
  123. unsigned long int_flag;
  124. /* WAIT_RCV that timed out, no interrupt */
  125. u32 port_rcvwait_to;
  126. /* WAIT_PIO that timed out, no interrupt */
  127. u32 port_piowait_to;
  128. /* WAIT_RCV already happened, no wait */
  129. u32 port_rcvnowait;
  130. /* WAIT_PIO already happened, no wait */
  131. u32 port_pionowait;
  132. /* total number of rcvhdrqfull errors */
  133. u32 port_hdrqfull;
  134. /* pid of process using this port */
  135. pid_t port_pid;
  136. /* same size as task_struct .comm[] */
  137. char port_comm[16];
  138. /* pkeys set by this use of this port */
  139. u16 port_pkeys[4];
  140. /* so file ops can get at unit */
  141. struct ipath_devdata *port_dd;
  142. /* A page of memory for rcvhdrhead, rcvegrhead, rcvegrtail * N */
  143. void *subport_uregbase;
  144. /* An array of pages for the eager receive buffers * N */
  145. void *subport_rcvegrbuf;
  146. /* An array of pages for the eager header queue entries * N */
  147. void *subport_rcvhdr_base;
  148. /* The version of the library which opened this port */
  149. u32 userversion;
  150. /* Bitmask of active slaves */
  151. u32 active_slaves;
  152. /* Type of packets or conditions we want to poll for */
  153. u16 poll_type;
  154. };
  155. struct sk_buff;
  156. /*
  157. * control information for layered drivers
  158. */
  159. struct _ipath_layer {
  160. void *l_arg;
  161. };
  162. struct ipath_skbinfo {
  163. struct sk_buff *skb;
  164. dma_addr_t phys;
  165. };
  166. struct ipath_devdata {
  167. struct list_head ipath_list;
  168. struct ipath_kregs const *ipath_kregs;
  169. struct ipath_cregs const *ipath_cregs;
  170. /* mem-mapped pointer to base of chip regs */
  171. u64 __iomem *ipath_kregbase;
  172. /* end of mem-mapped chip space; range checking */
  173. u64 __iomem *ipath_kregend;
  174. /* physical address of chip for io_remap, etc. */
  175. unsigned long ipath_physaddr;
  176. /* base of memory alloced for ipath_kregbase, for free */
  177. u64 *ipath_kregalloc;
  178. /*
  179. * virtual address where port0 rcvhdrqtail updated for this unit.
  180. * only written to by the chip, not the driver.
  181. */
  182. volatile __le64 *ipath_hdrqtailptr;
  183. /* ipath_cfgports pointers */
  184. struct ipath_portdata **ipath_pd;
  185. /* sk_buffs used by port 0 eager receive queue */
  186. struct ipath_skbinfo *ipath_port0_skbinfo;
  187. /* kvirt address of 1st 2k pio buffer */
  188. void __iomem *ipath_pio2kbase;
  189. /* kvirt address of 1st 4k pio buffer */
  190. void __iomem *ipath_pio4kbase;
  191. /*
  192. * points to area where PIOavail registers will be DMA'ed.
  193. * Has to be on a page of it's own, because the page will be
  194. * mapped into user program space. This copy is *ONLY* ever
  195. * written by DMA, not by the driver! Need a copy per device
  196. * when we get to multiple devices
  197. */
  198. volatile __le64 *ipath_pioavailregs_dma;
  199. /* physical address where updates occur */
  200. dma_addr_t ipath_pioavailregs_phys;
  201. struct _ipath_layer ipath_layer;
  202. /* setup intr */
  203. int (*ipath_f_intrsetup)(struct ipath_devdata *);
  204. /* setup on-chip bus config */
  205. int (*ipath_f_bus)(struct ipath_devdata *, struct pci_dev *);
  206. /* hard reset chip */
  207. int (*ipath_f_reset)(struct ipath_devdata *);
  208. int (*ipath_f_get_boardname)(struct ipath_devdata *, char *,
  209. size_t);
  210. void (*ipath_f_init_hwerrors)(struct ipath_devdata *);
  211. void (*ipath_f_handle_hwerrors)(struct ipath_devdata *, char *,
  212. size_t);
  213. void (*ipath_f_quiet_serdes)(struct ipath_devdata *);
  214. int (*ipath_f_bringup_serdes)(struct ipath_devdata *);
  215. int (*ipath_f_early_init)(struct ipath_devdata *);
  216. void (*ipath_f_clear_tids)(struct ipath_devdata *, unsigned);
  217. void (*ipath_f_put_tid)(struct ipath_devdata *, u64 __iomem*,
  218. u32, unsigned long);
  219. void (*ipath_f_tidtemplate)(struct ipath_devdata *);
  220. void (*ipath_f_cleanup)(struct ipath_devdata *);
  221. void (*ipath_f_setextled)(struct ipath_devdata *, u64, u64);
  222. /* fill out chip-specific fields */
  223. int (*ipath_f_get_base_info)(struct ipath_portdata *, void *);
  224. /* free irq */
  225. void (*ipath_f_free_irq)(struct ipath_devdata *);
  226. struct ipath_ibdev *verbs_dev;
  227. struct timer_list verbs_timer;
  228. /* total dwords sent (summed from counter) */
  229. u64 ipath_sword;
  230. /* total dwords rcvd (summed from counter) */
  231. u64 ipath_rword;
  232. /* total packets sent (summed from counter) */
  233. u64 ipath_spkts;
  234. /* total packets rcvd (summed from counter) */
  235. u64 ipath_rpkts;
  236. /* ipath_statusp initially points to this. */
  237. u64 _ipath_status;
  238. /* GUID for this interface, in network order */
  239. __be64 ipath_guid;
  240. /*
  241. * aggregrate of error bits reported since last cleared, for
  242. * limiting of error reporting
  243. */
  244. ipath_err_t ipath_lasterror;
  245. /*
  246. * aggregrate of error bits reported since last cleared, for
  247. * limiting of hwerror reporting
  248. */
  249. ipath_err_t ipath_lasthwerror;
  250. /*
  251. * errors masked because they occur too fast, also includes errors
  252. * that are always ignored (ipath_ignorederrs)
  253. */
  254. ipath_err_t ipath_maskederrs;
  255. /* time in jiffies at which to re-enable maskederrs */
  256. unsigned long ipath_unmasktime;
  257. /*
  258. * errors always ignored (masked), at least for a given
  259. * chip/device, because they are wrong or not useful
  260. */
  261. ipath_err_t ipath_ignorederrs;
  262. /* count of egrfull errors, combined for all ports */
  263. u64 ipath_last_tidfull;
  264. /* for ipath_qcheck() */
  265. u64 ipath_lastport0rcv_cnt;
  266. /* template for writing TIDs */
  267. u64 ipath_tidtemplate;
  268. /* value to write to free TIDs */
  269. u64 ipath_tidinvalid;
  270. /* IBA6120 rcv interrupt setup */
  271. u64 ipath_rhdrhead_intr_off;
  272. /* size of memory at ipath_kregbase */
  273. u32 ipath_kregsize;
  274. /* number of registers used for pioavail */
  275. u32 ipath_pioavregs;
  276. /* IPATH_POLL, etc. */
  277. u32 ipath_flags;
  278. /* ipath_flags driver is waiting for */
  279. u32 ipath_state_wanted;
  280. /* last buffer for user use, first buf for kernel use is this
  281. * index. */
  282. u32 ipath_lastport_piobuf;
  283. /* is a stats timer active */
  284. u32 ipath_stats_timer_active;
  285. /* number of interrupts for this device -- saturates... */
  286. u32 ipath_int_counter;
  287. /* dwords sent read from counter */
  288. u32 ipath_lastsword;
  289. /* dwords received read from counter */
  290. u32 ipath_lastrword;
  291. /* sent packets read from counter */
  292. u32 ipath_lastspkts;
  293. /* received packets read from counter */
  294. u32 ipath_lastrpkts;
  295. /* pio bufs allocated per port */
  296. u32 ipath_pbufsport;
  297. /*
  298. * number of ports configured as max; zero is set to number chip
  299. * supports, less gives more pio bufs/port, etc.
  300. */
  301. u32 ipath_cfgports;
  302. /* port0 rcvhdrq head offset */
  303. u32 ipath_port0head;
  304. /* count of port 0 hdrqfull errors */
  305. u32 ipath_p0_hdrqfull;
  306. /*
  307. * (*cfgports) used to suppress multiple instances of same
  308. * port staying stuck at same point
  309. */
  310. u32 *ipath_lastrcvhdrqtails;
  311. /*
  312. * (*cfgports) used to suppress multiple instances of same
  313. * port staying stuck at same point
  314. */
  315. u32 *ipath_lastegrheads;
  316. /*
  317. * index of last piobuffer we used. Speeds up searching, by
  318. * starting at this point. Doesn't matter if multiple cpu's use and
  319. * update, last updater is only write that matters. Whenever it
  320. * wraps, we update shadow copies. Need a copy per device when we
  321. * get to multiple devices
  322. */
  323. u32 ipath_lastpioindex;
  324. /* max length of freezemsg */
  325. u32 ipath_freezelen;
  326. /*
  327. * consecutive times we wanted a PIO buffer but were unable to
  328. * get one
  329. */
  330. u32 ipath_consec_nopiobuf;
  331. /*
  332. * hint that we should update ipath_pioavailshadow before
  333. * looking for a PIO buffer
  334. */
  335. u32 ipath_upd_pio_shadow;
  336. /* so we can rewrite it after a chip reset */
  337. u32 ipath_pcibar0;
  338. /* so we can rewrite it after a chip reset */
  339. u32 ipath_pcibar1;
  340. /* interrupt number */
  341. int ipath_irq;
  342. /* HT/PCI Vendor ID (here for NodeInfo) */
  343. u16 ipath_vendorid;
  344. /* HT/PCI Device ID (here for NodeInfo) */
  345. u16 ipath_deviceid;
  346. /* offset in HT config space of slave/primary interface block */
  347. u8 ipath_ht_slave_off;
  348. /* for write combining settings */
  349. unsigned long ipath_wc_cookie;
  350. unsigned long ipath_wc_base;
  351. unsigned long ipath_wc_len;
  352. /* ref count for each pkey */
  353. atomic_t ipath_pkeyrefs[4];
  354. /* shadow copy of all exptids physaddr; used only by funcsim */
  355. u64 *ipath_tidsimshadow;
  356. /* shadow copy of struct page *'s for exp tid pages */
  357. struct page **ipath_pageshadow;
  358. /* shadow copy of dma handles for exp tid pages */
  359. dma_addr_t *ipath_physshadow;
  360. /* lock to workaround chip bug 9437 */
  361. spinlock_t ipath_tid_lock;
  362. /*
  363. * IPATH_STATUS_*,
  364. * this address is mapped readonly into user processes so they can
  365. * get status cheaply, whenever they want.
  366. */
  367. u64 *ipath_statusp;
  368. /* freeze msg if hw error put chip in freeze */
  369. char *ipath_freezemsg;
  370. /* pci access data structure */
  371. struct pci_dev *pcidev;
  372. struct cdev *user_cdev;
  373. struct cdev *diag_cdev;
  374. struct class_device *user_class_dev;
  375. struct class_device *diag_class_dev;
  376. /* timer used to prevent stats overflow, error throttling, etc. */
  377. struct timer_list ipath_stats_timer;
  378. void *ipath_dummy_hdrq; /* used after port close */
  379. dma_addr_t ipath_dummy_hdrq_phys;
  380. /*
  381. * Shadow copies of registers; size indicates read access size.
  382. * Most of them are readonly, but some are write-only register,
  383. * where we manipulate the bits in the shadow copy, and then write
  384. * the shadow copy to infinipath.
  385. *
  386. * We deliberately make most of these 32 bits, since they have
  387. * restricted range. For any that we read, we won't to generate 32
  388. * bit accesses, since Opteron will generate 2 separate 32 bit HT
  389. * transactions for a 64 bit read, and we want to avoid unnecessary
  390. * HT transactions.
  391. */
  392. /* This is the 64 bit group */
  393. /*
  394. * shadow of pioavail, check to be sure it's large enough at
  395. * init time.
  396. */
  397. unsigned long ipath_pioavailshadow[8];
  398. /* shadow of kr_gpio_out, for rmw ops */
  399. u64 ipath_gpio_out;
  400. /* shadow the gpio mask register */
  401. u64 ipath_gpio_mask;
  402. /* shadow the gpio output enable, etc... */
  403. u64 ipath_extctrl;
  404. /* kr_revision shadow */
  405. u64 ipath_revision;
  406. /*
  407. * shadow of ibcctrl, for interrupt handling of link changes,
  408. * etc.
  409. */
  410. u64 ipath_ibcctrl;
  411. /*
  412. * last ibcstatus, to suppress "duplicate" status change messages,
  413. * mostly from 2 to 3
  414. */
  415. u64 ipath_lastibcstat;
  416. /* hwerrmask shadow */
  417. ipath_err_t ipath_hwerrmask;
  418. /* interrupt config reg shadow */
  419. u64 ipath_intconfig;
  420. /* kr_sendpiobufbase value */
  421. u64 ipath_piobufbase;
  422. /* these are the "32 bit" regs */
  423. /*
  424. * number of GUIDs in the flash for this interface; may need some
  425. * rethinking for setting on other ifaces
  426. */
  427. u32 ipath_nguid;
  428. /*
  429. * the following two are 32-bit bitmasks, but {test,clear,set}_bit
  430. * all expect bit fields to be "unsigned long"
  431. */
  432. /* shadow kr_rcvctrl */
  433. unsigned long ipath_rcvctrl;
  434. /* shadow kr_sendctrl */
  435. unsigned long ipath_sendctrl;
  436. /* ports waiting for PIOavail intr */
  437. unsigned long ipath_portpiowait;
  438. unsigned long ipath_lastcancel; /* to not count armlaunch after cancel */
  439. /* value we put in kr_rcvhdrcnt */
  440. u32 ipath_rcvhdrcnt;
  441. /* value we put in kr_rcvhdrsize */
  442. u32 ipath_rcvhdrsize;
  443. /* value we put in kr_rcvhdrentsize */
  444. u32 ipath_rcvhdrentsize;
  445. /* offset of last entry in rcvhdrq */
  446. u32 ipath_hdrqlast;
  447. /* kr_portcnt value */
  448. u32 ipath_portcnt;
  449. /* kr_pagealign value */
  450. u32 ipath_palign;
  451. /* number of "2KB" PIO buffers */
  452. u32 ipath_piobcnt2k;
  453. /* size in bytes of "2KB" PIO buffers */
  454. u32 ipath_piosize2k;
  455. /* number of "4KB" PIO buffers */
  456. u32 ipath_piobcnt4k;
  457. /* size in bytes of "4KB" PIO buffers */
  458. u32 ipath_piosize4k;
  459. /* kr_rcvegrbase value */
  460. u32 ipath_rcvegrbase;
  461. /* kr_rcvegrcnt value */
  462. u32 ipath_rcvegrcnt;
  463. /* kr_rcvtidbase value */
  464. u32 ipath_rcvtidbase;
  465. /* kr_rcvtidcnt value */
  466. u32 ipath_rcvtidcnt;
  467. /* kr_sendregbase */
  468. u32 ipath_sregbase;
  469. /* kr_userregbase */
  470. u32 ipath_uregbase;
  471. /* kr_counterregbase */
  472. u32 ipath_cregbase;
  473. /* shadow the control register contents */
  474. u32 ipath_control;
  475. /* PCI revision register (HTC rev on FPGA) */
  476. u32 ipath_pcirev;
  477. /* chip address space used by 4k pio buffers */
  478. u32 ipath_4kalign;
  479. /* The MTU programmed for this unit */
  480. u32 ipath_ibmtu;
  481. /*
  482. * The max size IB packet, included IB headers that we can send.
  483. * Starts same as ipath_piosize, but is affected when ibmtu is
  484. * changed, or by size of eager buffers
  485. */
  486. u32 ipath_ibmaxlen;
  487. /*
  488. * ibmaxlen at init time, limited by chip and by receive buffer
  489. * size. Not changed after init.
  490. */
  491. u32 ipath_init_ibmaxlen;
  492. /* size of each rcvegrbuffer */
  493. u32 ipath_rcvegrbufsize;
  494. /* width (2,4,8,16,32) from HT config reg */
  495. u32 ipath_htwidth;
  496. /* HT speed (200,400,800,1000) from HT config */
  497. u32 ipath_htspeed;
  498. /*
  499. * number of sequential ibcstatus change for polling active/quiet
  500. * (i.e., link not coming up).
  501. */
  502. u32 ipath_ibpollcnt;
  503. /* low and high portions of MSI capability/vector */
  504. u32 ipath_msi_lo;
  505. /* saved after PCIe init for restore after reset */
  506. u32 ipath_msi_hi;
  507. /* MSI data (vector) saved for restore */
  508. u16 ipath_msi_data;
  509. /* MLID programmed for this instance */
  510. u16 ipath_mlid;
  511. /* LID programmed for this instance */
  512. u16 ipath_lid;
  513. /* list of pkeys programmed; 0 if not set */
  514. u16 ipath_pkeys[4];
  515. /*
  516. * ASCII serial number, from flash, large enough for original
  517. * all digit strings, and longer QLogic serial number format
  518. */
  519. u8 ipath_serial[16];
  520. /* human readable board version */
  521. u8 ipath_boardversion[80];
  522. /* chip major rev, from ipath_revision */
  523. u8 ipath_majrev;
  524. /* chip minor rev, from ipath_revision */
  525. u8 ipath_minrev;
  526. /* board rev, from ipath_revision */
  527. u8 ipath_boardrev;
  528. /* unit # of this chip, if present */
  529. int ipath_unit;
  530. /* saved for restore after reset */
  531. u8 ipath_pci_cacheline;
  532. /* LID mask control */
  533. u8 ipath_lmc;
  534. /* Rx Polarity inversion (compensate for ~tx on partner) */
  535. u8 ipath_rx_pol_inv;
  536. /* local link integrity counter */
  537. u32 ipath_lli_counter;
  538. /* local link integrity errors */
  539. u32 ipath_lli_errors;
  540. /*
  541. * Above counts only cases where _successive_ LocalLinkIntegrity
  542. * errors were seen in the receive headers of kern-packets.
  543. * Below are the three (monotonically increasing) counters
  544. * maintained via GPIO interrupts on iba6120-rev2.
  545. */
  546. u32 ipath_rxfc_unsupvl_errs;
  547. u32 ipath_overrun_thresh_errs;
  548. u32 ipath_lli_errs;
  549. /* status check work */
  550. struct delayed_work status_work;
  551. /*
  552. * Not all devices managed by a driver instance are the same
  553. * type, so these fields must be per-device.
  554. */
  555. u64 ipath_i_bitsextant;
  556. ipath_err_t ipath_e_bitsextant;
  557. ipath_err_t ipath_hwe_bitsextant;
  558. /*
  559. * Below should be computable from number of ports,
  560. * since they are never modified.
  561. */
  562. u32 ipath_i_rcvavail_mask;
  563. u32 ipath_i_rcvurg_mask;
  564. /*
  565. * Register bits for selecting i2c direction and values, used for
  566. * I2C serial flash.
  567. */
  568. u16 ipath_gpio_sda_num;
  569. u16 ipath_gpio_scl_num;
  570. u64 ipath_gpio_sda;
  571. u64 ipath_gpio_scl;
  572. /* lock for doing RMW of shadows/regs for ExtCtrl and GPIO */
  573. spinlock_t ipath_gpio_lock;
  574. /* used to override LED behavior */
  575. u8 ipath_led_override; /* Substituted for normal value, if non-zero */
  576. u16 ipath_led_override_timeoff; /* delta to next timer event */
  577. u8 ipath_led_override_vals[2]; /* Alternates per blink-frame */
  578. u8 ipath_led_override_phase; /* Just counts, LSB picks from vals[] */
  579. atomic_t ipath_led_override_timer_active;
  580. /* Used to flash LEDs in override mode */
  581. struct timer_list ipath_led_override_timer;
  582. /* Support (including locks) for EEPROM logging of errors and time */
  583. /* control access to actual counters, timer */
  584. spinlock_t ipath_eep_st_lock;
  585. /* control high-level access to EEPROM */
  586. struct semaphore ipath_eep_sem;
  587. /* Below inc'd by ipath_snap_cntrs(), locked by ipath_eep_st_lock */
  588. uint64_t ipath_traffic_wds;
  589. /* active time is kept in seconds, but logged in hours */
  590. atomic_t ipath_active_time;
  591. /* Below are nominal shadow of EEPROM, new since last EEPROM update */
  592. uint8_t ipath_eep_st_errs[IPATH_EEP_LOG_CNT];
  593. uint8_t ipath_eep_st_new_errs[IPATH_EEP_LOG_CNT];
  594. uint16_t ipath_eep_hrs;
  595. /*
  596. * masks for which bits of errs, hwerrs that cause
  597. * each of the counters to increment.
  598. */
  599. struct ipath_eep_log_mask ipath_eep_st_masks[IPATH_EEP_LOG_CNT];
  600. };
  601. /* Private data for file operations */
  602. struct ipath_filedata {
  603. struct ipath_portdata *pd;
  604. unsigned subport;
  605. unsigned tidcursor;
  606. };
  607. extern struct list_head ipath_dev_list;
  608. extern spinlock_t ipath_devs_lock;
  609. extern struct ipath_devdata *ipath_lookup(int unit);
  610. int ipath_init_chip(struct ipath_devdata *, int);
  611. int ipath_enable_wc(struct ipath_devdata *dd);
  612. void ipath_disable_wc(struct ipath_devdata *dd);
  613. int ipath_count_units(int *npresentp, int *nupp, u32 *maxportsp);
  614. void ipath_shutdown_device(struct ipath_devdata *);
  615. void ipath_clear_freeze(struct ipath_devdata *);
  616. struct file_operations;
  617. int ipath_cdev_init(int minor, char *name, const struct file_operations *fops,
  618. struct cdev **cdevp, struct class_device **class_devp);
  619. void ipath_cdev_cleanup(struct cdev **cdevp,
  620. struct class_device **class_devp);
  621. int ipath_diag_add(struct ipath_devdata *);
  622. void ipath_diag_remove(struct ipath_devdata *);
  623. extern wait_queue_head_t ipath_state_wait;
  624. int ipath_user_add(struct ipath_devdata *dd);
  625. void ipath_user_remove(struct ipath_devdata *dd);
  626. struct sk_buff *ipath_alloc_skb(struct ipath_devdata *dd, gfp_t);
  627. extern int ipath_diag_inuse;
  628. irqreturn_t ipath_intr(int irq, void *devid);
  629. int ipath_decode_err(char *buf, size_t blen, ipath_err_t err);
  630. #if __IPATH_INFO || __IPATH_DBG
  631. extern const char *ipath_ibcstatus_str[];
  632. #endif
  633. /* clean up any per-chip chip-specific stuff */
  634. void ipath_chip_cleanup(struct ipath_devdata *);
  635. /* clean up any chip type-specific stuff */
  636. void ipath_chip_done(void);
  637. /* check to see if we have to force ordering for write combining */
  638. int ipath_unordered_wc(void);
  639. void ipath_disarm_piobufs(struct ipath_devdata *, unsigned first,
  640. unsigned cnt);
  641. void ipath_cancel_sends(struct ipath_devdata *);
  642. int ipath_create_rcvhdrq(struct ipath_devdata *, struct ipath_portdata *);
  643. void ipath_free_pddata(struct ipath_devdata *, struct ipath_portdata *);
  644. int ipath_parse_ushort(const char *str, unsigned short *valp);
  645. void ipath_kreceive(struct ipath_devdata *);
  646. int ipath_setrcvhdrsize(struct ipath_devdata *, unsigned);
  647. int ipath_reset_device(int);
  648. void ipath_get_faststats(unsigned long);
  649. int ipath_set_linkstate(struct ipath_devdata *, u8);
  650. int ipath_set_mtu(struct ipath_devdata *, u16);
  651. int ipath_set_lid(struct ipath_devdata *, u32, u8);
  652. int ipath_set_rx_pol_inv(struct ipath_devdata *dd, u8 new_pol_inv);
  653. /* for use in system calls, where we want to know device type, etc. */
  654. #define port_fp(fp) ((struct ipath_filedata *)(fp)->private_data)->pd
  655. #define subport_fp(fp) \
  656. ((struct ipath_filedata *)(fp)->private_data)->subport
  657. #define tidcursor_fp(fp) \
  658. ((struct ipath_filedata *)(fp)->private_data)->tidcursor
  659. /*
  660. * values for ipath_flags
  661. */
  662. /* The chip is up and initted */
  663. #define IPATH_INITTED 0x2
  664. /* set if any user code has set kr_rcvhdrsize */
  665. #define IPATH_RCVHDRSZ_SET 0x4
  666. /* The chip is present and valid for accesses */
  667. #define IPATH_PRESENT 0x8
  668. /* HT link0 is only 8 bits wide, ignore upper byte crc
  669. * errors, etc. */
  670. #define IPATH_8BIT_IN_HT0 0x10
  671. /* HT link1 is only 8 bits wide, ignore upper byte crc
  672. * errors, etc. */
  673. #define IPATH_8BIT_IN_HT1 0x20
  674. /* The link is down */
  675. #define IPATH_LINKDOWN 0x40
  676. /* The link level is up (0x11) */
  677. #define IPATH_LINKINIT 0x80
  678. /* The link is in the armed (0x21) state */
  679. #define IPATH_LINKARMED 0x100
  680. /* The link is in the active (0x31) state */
  681. #define IPATH_LINKACTIVE 0x200
  682. /* link current state is unknown */
  683. #define IPATH_LINKUNK 0x400
  684. /* no IB cable, or no device on IB cable */
  685. #define IPATH_NOCABLE 0x4000
  686. /* Supports port zero per packet receive interrupts via
  687. * GPIO */
  688. #define IPATH_GPIO_INTR 0x8000
  689. /* uses the coded 4byte TID, not 8 byte */
  690. #define IPATH_4BYTE_TID 0x10000
  691. /* packet/word counters are 32 bit, else those 4 counters
  692. * are 64bit */
  693. #define IPATH_32BITCOUNTERS 0x20000
  694. /* can miss port0 rx interrupts */
  695. #define IPATH_DISABLED 0x80000 /* administratively disabled */
  696. /* Use GPIO interrupts for new counters */
  697. #define IPATH_GPIO_ERRINTRS 0x100000
  698. /* Bits in GPIO for the added interrupts */
  699. #define IPATH_GPIO_PORT0_BIT 2
  700. #define IPATH_GPIO_RXUVL_BIT 3
  701. #define IPATH_GPIO_OVRUN_BIT 4
  702. #define IPATH_GPIO_LLI_BIT 5
  703. #define IPATH_GPIO_ERRINTR_MASK 0x38
  704. /* portdata flag bit offsets */
  705. /* waiting for a packet to arrive */
  706. #define IPATH_PORT_WAITING_RCV 2
  707. /* waiting for a PIO buffer to be available */
  708. #define IPATH_PORT_WAITING_PIO 3
  709. /* master has not finished initializing */
  710. #define IPATH_PORT_MASTER_UNINIT 4
  711. /* waiting for an urgent packet to arrive */
  712. #define IPATH_PORT_WAITING_URG 5
  713. /* waiting for a header overflow */
  714. #define IPATH_PORT_WAITING_OVERFLOW 6
  715. /* free up any allocated data at closes */
  716. void ipath_free_data(struct ipath_portdata *dd);
  717. int ipath_waitfor_mdio_cmdready(struct ipath_devdata *);
  718. int ipath_waitfor_complete(struct ipath_devdata *, ipath_kreg, u64, u64 *);
  719. u32 __iomem *ipath_getpiobuf(struct ipath_devdata *, u32 *);
  720. void ipath_init_iba6120_funcs(struct ipath_devdata *);
  721. void ipath_init_iba6110_funcs(struct ipath_devdata *);
  722. void ipath_get_eeprom_info(struct ipath_devdata *);
  723. int ipath_update_eeprom_log(struct ipath_devdata *dd);
  724. void ipath_inc_eeprom_err(struct ipath_devdata *dd, u32 eidx, u32 incr);
  725. u64 ipath_snap_cntr(struct ipath_devdata *, ipath_creg);
  726. void ipath_disarm_senderrbufs(struct ipath_devdata *, int);
  727. /*
  728. * Set LED override, only the two LSBs have "public" meaning, but
  729. * any non-zero value substitutes them for the Link and LinkTrain
  730. * LED states.
  731. */
  732. #define IPATH_LED_PHYS 1 /* Physical (linktraining) GREEN LED */
  733. #define IPATH_LED_LOG 2 /* Logical (link) YELLOW LED */
  734. void ipath_set_led_override(struct ipath_devdata *dd, unsigned int val);
  735. /*
  736. * number of words used for protocol header if not set by ipath_userinit();
  737. */
  738. #define IPATH_DFLT_RCVHDRSIZE 9
  739. #define IPATH_MDIO_CMD_WRITE 1
  740. #define IPATH_MDIO_CMD_READ 2
  741. #define IPATH_MDIO_CLD_DIV 25 /* to get 2.5 Mhz mdio clock */
  742. #define IPATH_MDIO_CMDVALID 0x40000000 /* bit 30 */
  743. #define IPATH_MDIO_DATAVALID 0x80000000 /* bit 31 */
  744. #define IPATH_MDIO_CTRL_STD 0x0
  745. static inline u64 ipath_mdio_req(int cmd, int dev, int reg, int data)
  746. {
  747. return (((u64) IPATH_MDIO_CLD_DIV) << 32) |
  748. (cmd << 26) |
  749. (dev << 21) |
  750. (reg << 16) |
  751. (data & 0xFFFF);
  752. }
  753. /* signal and fifo status, in bank 31 */
  754. #define IPATH_MDIO_CTRL_XGXS_REG_8 0x8
  755. /* controls loopback, redundancy */
  756. #define IPATH_MDIO_CTRL_8355_REG_1 0x10
  757. /* premph, encdec, etc. */
  758. #define IPATH_MDIO_CTRL_8355_REG_2 0x11
  759. /* Kchars, etc. */
  760. #define IPATH_MDIO_CTRL_8355_REG_6 0x15
  761. #define IPATH_MDIO_CTRL_8355_REG_9 0x18
  762. #define IPATH_MDIO_CTRL_8355_REG_10 0x1D
  763. int ipath_get_user_pages(unsigned long, size_t, struct page **);
  764. int ipath_get_user_pages_nocopy(unsigned long, struct page **);
  765. void ipath_release_user_pages(struct page **, size_t);
  766. void ipath_release_user_pages_on_close(struct page **, size_t);
  767. int ipath_eeprom_read(struct ipath_devdata *, u8, void *, int);
  768. int ipath_eeprom_write(struct ipath_devdata *, u8, const void *, int);
  769. /* these are used for the registers that vary with port */
  770. void ipath_write_kreg_port(const struct ipath_devdata *, ipath_kreg,
  771. unsigned, u64);
  772. /*
  773. * We could have a single register get/put routine, that takes a group type,
  774. * but this is somewhat clearer and cleaner. It also gives us some error
  775. * checking. 64 bit register reads should always work, but are inefficient
  776. * on opteron (the northbridge always generates 2 separate HT 32 bit reads),
  777. * so we use kreg32 wherever possible. User register and counter register
  778. * reads are always 32 bit reads, so only one form of those routines.
  779. */
  780. /*
  781. * At the moment, none of the s-registers are writable, so no
  782. * ipath_write_sreg(), and none of the c-registers are writable, so no
  783. * ipath_write_creg().
  784. */
  785. /**
  786. * ipath_read_ureg32 - read 32-bit virtualized per-port register
  787. * @dd: device
  788. * @regno: register number
  789. * @port: port number
  790. *
  791. * Return the contents of a register that is virtualized to be per port.
  792. * Returns -1 on errors (not distinguishable from valid contents at
  793. * runtime; we may add a separate error variable at some point).
  794. */
  795. static inline u32 ipath_read_ureg32(const struct ipath_devdata *dd,
  796. ipath_ureg regno, int port)
  797. {
  798. if (!dd->ipath_kregbase || !(dd->ipath_flags & IPATH_PRESENT))
  799. return 0;
  800. return readl(regno + (u64 __iomem *)
  801. (dd->ipath_uregbase +
  802. (char __iomem *)dd->ipath_kregbase +
  803. dd->ipath_palign * port));
  804. }
  805. /**
  806. * ipath_write_ureg - write 32-bit virtualized per-port register
  807. * @dd: device
  808. * @regno: register number
  809. * @value: value
  810. * @port: port
  811. *
  812. * Write the contents of a register that is virtualized to be per port.
  813. */
  814. static inline void ipath_write_ureg(const struct ipath_devdata *dd,
  815. ipath_ureg regno, u64 value, int port)
  816. {
  817. u64 __iomem *ubase = (u64 __iomem *)
  818. (dd->ipath_uregbase + (char __iomem *) dd->ipath_kregbase +
  819. dd->ipath_palign * port);
  820. if (dd->ipath_kregbase)
  821. writeq(value, &ubase[regno]);
  822. }
  823. static inline u32 ipath_read_kreg32(const struct ipath_devdata *dd,
  824. ipath_kreg regno)
  825. {
  826. if (!dd->ipath_kregbase || !(dd->ipath_flags & IPATH_PRESENT))
  827. return -1;
  828. return readl((u32 __iomem *) & dd->ipath_kregbase[regno]);
  829. }
  830. static inline u64 ipath_read_kreg64(const struct ipath_devdata *dd,
  831. ipath_kreg regno)
  832. {
  833. if (!dd->ipath_kregbase || !(dd->ipath_flags & IPATH_PRESENT))
  834. return -1;
  835. return readq(&dd->ipath_kregbase[regno]);
  836. }
  837. static inline void ipath_write_kreg(const struct ipath_devdata *dd,
  838. ipath_kreg regno, u64 value)
  839. {
  840. if (dd->ipath_kregbase)
  841. writeq(value, &dd->ipath_kregbase[regno]);
  842. }
  843. static inline u64 ipath_read_creg(const struct ipath_devdata *dd,
  844. ipath_sreg regno)
  845. {
  846. if (!dd->ipath_kregbase || !(dd->ipath_flags & IPATH_PRESENT))
  847. return 0;
  848. return readq(regno + (u64 __iomem *)
  849. (dd->ipath_cregbase +
  850. (char __iomem *)dd->ipath_kregbase));
  851. }
  852. static inline u32 ipath_read_creg32(const struct ipath_devdata *dd,
  853. ipath_sreg regno)
  854. {
  855. if (!dd->ipath_kregbase || !(dd->ipath_flags & IPATH_PRESENT))
  856. return 0;
  857. return readl(regno + (u64 __iomem *)
  858. (dd->ipath_cregbase +
  859. (char __iomem *)dd->ipath_kregbase));
  860. }
  861. /*
  862. * sysfs interface.
  863. */
  864. struct device_driver;
  865. extern const char ib_ipath_version[];
  866. int ipath_driver_create_group(struct device_driver *);
  867. void ipath_driver_remove_group(struct device_driver *);
  868. int ipath_device_create_group(struct device *, struct ipath_devdata *);
  869. void ipath_device_remove_group(struct device *, struct ipath_devdata *);
  870. int ipath_expose_reset(struct device *);
  871. int ipath_init_ipathfs(void);
  872. void ipath_exit_ipathfs(void);
  873. int ipathfs_add_device(struct ipath_devdata *);
  874. int ipathfs_remove_device(struct ipath_devdata *);
  875. /*
  876. * dma_addr wrappers - all 0's invalid for hw
  877. */
  878. dma_addr_t ipath_map_page(struct pci_dev *, struct page *, unsigned long,
  879. size_t, int);
  880. dma_addr_t ipath_map_single(struct pci_dev *, void *, size_t, int);
  881. /*
  882. * Flush write combining store buffers (if present) and perform a write
  883. * barrier.
  884. */
  885. #if defined(CONFIG_X86_64)
  886. #define ipath_flush_wc() asm volatile("sfence" ::: "memory")
  887. #else
  888. #define ipath_flush_wc() wmb()
  889. #endif
  890. extern unsigned ipath_debug; /* debugging bit mask */
  891. #define IPATH_MAX_PARITY_ATTEMPTS 10000 /* max times to try recovery */
  892. const char *ipath_get_unit_name(int unit);
  893. extern struct mutex ipath_mutex;
  894. #define IPATH_DRV_NAME "ib_ipath"
  895. #define IPATH_MAJOR 233
  896. #define IPATH_USER_MINOR_BASE 0
  897. #define IPATH_DIAGPKT_MINOR 127
  898. #define IPATH_DIAG_MINOR_BASE 129
  899. #define IPATH_NMINORS 255
  900. #define ipath_dev_err(dd,fmt,...) \
  901. do { \
  902. const struct ipath_devdata *__dd = (dd); \
  903. if (__dd->pcidev) \
  904. dev_err(&__dd->pcidev->dev, "%s: " fmt, \
  905. ipath_get_unit_name(__dd->ipath_unit), \
  906. ##__VA_ARGS__); \
  907. else \
  908. printk(KERN_ERR IPATH_DRV_NAME ": %s: " fmt, \
  909. ipath_get_unit_name(__dd->ipath_unit), \
  910. ##__VA_ARGS__); \
  911. } while (0)
  912. #if _IPATH_DEBUGGING
  913. # define __IPATH_DBG_WHICH(which,fmt,...) \
  914. do { \
  915. if(unlikely(ipath_debug&(which))) \
  916. printk(KERN_DEBUG IPATH_DRV_NAME ": %s: " fmt, \
  917. __func__,##__VA_ARGS__); \
  918. } while(0)
  919. # define ipath_dbg(fmt,...) \
  920. __IPATH_DBG_WHICH(__IPATH_DBG,fmt,##__VA_ARGS__)
  921. # define ipath_cdbg(which,fmt,...) \
  922. __IPATH_DBG_WHICH(__IPATH_##which##DBG,fmt,##__VA_ARGS__)
  923. #else /* ! _IPATH_DEBUGGING */
  924. # define ipath_dbg(fmt,...)
  925. # define ipath_cdbg(which,fmt,...)
  926. #endif /* _IPATH_DEBUGGING */
  927. /*
  928. * this is used for formatting hw error messages...
  929. */
  930. struct ipath_hwerror_msgs {
  931. u64 mask;
  932. const char *msg;
  933. };
  934. #define INFINIPATH_HWE_MSG(a, b) { .mask = INFINIPATH_HWE_##a, .msg = b }
  935. /* in ipath_intr.c... */
  936. void ipath_format_hwerrors(u64 hwerrs,
  937. const struct ipath_hwerror_msgs *hwerrmsgs,
  938. size_t nhwerrmsgs,
  939. char *msg, size_t lmsg);
  940. #endif /* _IPATH_KERNEL_H */