ipath_kernel.h 33 KB

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