csio_hw.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665
  1. /*
  2. * This file is part of the Chelsio FCoE driver for Linux.
  3. *
  4. * Copyright (c) 2008-2012 Chelsio Communications, Inc. All rights reserved.
  5. *
  6. * This software is available to you under a choice of one of two
  7. * licenses. You may choose to be licensed under the terms of the GNU
  8. * General Public License (GPL) Version 2, available from the file
  9. * COPYING in the main directory of this source tree, or the
  10. * OpenIB.org BSD license below:
  11. *
  12. * Redistribution and use in source and binary forms, with or
  13. * without modification, are permitted provided that the following
  14. * conditions are met:
  15. *
  16. * - Redistributions of source code must retain the above
  17. * copyright notice, this list of conditions and the following
  18. * disclaimer.
  19. *
  20. * - Redistributions in binary form must reproduce the above
  21. * copyright notice, this list of conditions and the following
  22. * disclaimer in the documentation and/or other materials
  23. * provided with the distribution.
  24. *
  25. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  26. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  27. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  28. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  29. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  30. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  31. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  32. * SOFTWARE.
  33. */
  34. #ifndef __CSIO_HW_H__
  35. #define __CSIO_HW_H__
  36. #include <linux/kernel.h>
  37. #include <linux/pci.h>
  38. #include <linux/device.h>
  39. #include <linux/workqueue.h>
  40. #include <linux/compiler.h>
  41. #include <linux/cdev.h>
  42. #include <linux/list.h>
  43. #include <linux/mempool.h>
  44. #include <linux/io.h>
  45. #include <linux/spinlock_types.h>
  46. #include <scsi/scsi_device.h>
  47. #include <scsi/scsi_transport_fc.h>
  48. #include "csio_wr.h"
  49. #include "csio_mb.h"
  50. #include "csio_scsi.h"
  51. #include "csio_defs.h"
  52. #include "t4_regs.h"
  53. #include "t4_msg.h"
  54. /*
  55. * An error value used by host. Should not clash with FW defined return values.
  56. */
  57. #define FW_HOSTERROR 255
  58. #define CSIO_FW_FNAME "cxgb4/t4fw.bin"
  59. #define CSIO_CF_FNAME "cxgb4/t4-config.txt"
  60. #define FW_VERSION_MAJOR 1
  61. #define FW_VERSION_MINOR 2
  62. #define FW_VERSION_MICRO 8
  63. #define CSIO_HW_NAME "Chelsio FCoE Adapter"
  64. #define CSIO_MAX_PFN 8
  65. #define CSIO_MAX_PPORTS 4
  66. #define CSIO_MAX_LUN 0xFFFF
  67. #define CSIO_MAX_QUEUE 2048
  68. #define CSIO_MAX_CMD_PER_LUN 32
  69. #define CSIO_MAX_DDP_BUF_SIZE (1024 * 1024)
  70. #define CSIO_MAX_SECTOR_SIZE 128
  71. /* Interrupts */
  72. #define CSIO_EXTRA_MSI_IQS 2 /* Extra iqs for INTX/MSI mode
  73. * (Forward intr iq + fw iq) */
  74. #define CSIO_EXTRA_VECS 2 /* non-data + FW evt */
  75. #define CSIO_MAX_SCSI_CPU 128
  76. #define CSIO_MAX_SCSI_QSETS (CSIO_MAX_SCSI_CPU * CSIO_MAX_PPORTS)
  77. #define CSIO_MAX_MSIX_VECS (CSIO_MAX_SCSI_QSETS + CSIO_EXTRA_VECS)
  78. /* Queues */
  79. enum {
  80. CSIO_INTR_WRSIZE = 128,
  81. CSIO_INTR_IQSIZE = ((CSIO_MAX_MSIX_VECS + 1) * CSIO_INTR_WRSIZE),
  82. CSIO_FWEVT_WRSIZE = 128,
  83. CSIO_FWEVT_IQLEN = 128,
  84. CSIO_FWEVT_FLBUFS = 64,
  85. CSIO_FWEVT_IQSIZE = (CSIO_FWEVT_WRSIZE * CSIO_FWEVT_IQLEN),
  86. CSIO_HW_NIQ = 1,
  87. CSIO_HW_NFLQ = 1,
  88. CSIO_HW_NEQ = 1,
  89. CSIO_HW_NINTXQ = 1,
  90. };
  91. struct csio_msix_entries {
  92. unsigned short vector; /* Vector assigned by pci_enable_msix */
  93. void *dev_id; /* Priv object associated w/ this msix*/
  94. char desc[24]; /* Description of this vector */
  95. };
  96. struct csio_scsi_qset {
  97. int iq_idx; /* Ingress index */
  98. int eq_idx; /* Egress index */
  99. uint32_t intr_idx; /* MSIX Vector index */
  100. };
  101. struct csio_scsi_cpu_info {
  102. int16_t max_cpus;
  103. };
  104. extern int csio_dbg_level;
  105. extern int csio_force_master;
  106. extern unsigned int csio_port_mask;
  107. extern int csio_msi;
  108. #define CSIO_VENDOR_ID 0x1425
  109. #define CSIO_ASIC_DEVID_PROTO_MASK 0xFF00
  110. #define CSIO_ASIC_DEVID_TYPE_MASK 0x00FF
  111. #define CSIO_FPGA 0xA000
  112. #define CSIO_T4_FCOE_ASIC 0x4600
  113. #define CSIO_GLBL_INTR_MASK (CIM | MPS | PL | PCIE | MC | EDC0 | \
  114. EDC1 | LE | TP | MA | PM_TX | PM_RX | \
  115. ULP_RX | CPL_SWITCH | SGE | \
  116. ULP_TX | SF)
  117. /*
  118. * Hard parameters used to initialize the card in the absence of a
  119. * configuration file.
  120. */
  121. enum {
  122. /* General */
  123. CSIO_SGE_DBFIFO_INT_THRESH = 10,
  124. CSIO_SGE_RX_DMA_OFFSET = 2,
  125. CSIO_SGE_FLBUF_SIZE1 = 65536,
  126. CSIO_SGE_FLBUF_SIZE2 = 1536,
  127. CSIO_SGE_FLBUF_SIZE3 = 9024,
  128. CSIO_SGE_FLBUF_SIZE4 = 9216,
  129. CSIO_SGE_FLBUF_SIZE5 = 2048,
  130. CSIO_SGE_FLBUF_SIZE6 = 128,
  131. CSIO_SGE_FLBUF_SIZE7 = 8192,
  132. CSIO_SGE_FLBUF_SIZE8 = 16384,
  133. CSIO_SGE_TIMER_VAL_0 = 5,
  134. CSIO_SGE_TIMER_VAL_1 = 10,
  135. CSIO_SGE_TIMER_VAL_2 = 20,
  136. CSIO_SGE_TIMER_VAL_3 = 50,
  137. CSIO_SGE_TIMER_VAL_4 = 100,
  138. CSIO_SGE_TIMER_VAL_5 = 200,
  139. CSIO_SGE_INT_CNT_VAL_0 = 1,
  140. CSIO_SGE_INT_CNT_VAL_1 = 4,
  141. CSIO_SGE_INT_CNT_VAL_2 = 8,
  142. CSIO_SGE_INT_CNT_VAL_3 = 16,
  143. /* Storage specific - used by FW_PFVF_CMD */
  144. CSIO_WX_CAPS = FW_CMD_CAP_PF, /* w/x all */
  145. CSIO_R_CAPS = FW_CMD_CAP_PF, /* r all */
  146. CSIO_NVI = 4,
  147. CSIO_NIQ_FLINT = 34,
  148. CSIO_NETH_CTRL = 32,
  149. CSIO_NEQ = 66,
  150. CSIO_NEXACTF = 32,
  151. CSIO_CMASK = FW_PFVF_CMD_CMASK_MASK,
  152. CSIO_PMASK = FW_PFVF_CMD_PMASK_MASK,
  153. };
  154. /* Slowpath events */
  155. enum csio_evt {
  156. CSIO_EVT_FW = 0, /* FW event */
  157. CSIO_EVT_MBX, /* MBX event */
  158. CSIO_EVT_SCN, /* State change notification */
  159. CSIO_EVT_DEV_LOSS, /* Device loss event */
  160. CSIO_EVT_MAX, /* Max supported event */
  161. };
  162. #define CSIO_EVT_MSG_SIZE 512
  163. #define CSIO_EVTQ_SIZE 512
  164. /* Event msg */
  165. struct csio_evt_msg {
  166. struct list_head list; /* evt queue*/
  167. enum csio_evt type;
  168. uint8_t data[CSIO_EVT_MSG_SIZE];
  169. };
  170. enum {
  171. EEPROMVSIZE = 32768, /* Serial EEPROM virtual address space size */
  172. SERNUM_LEN = 16, /* Serial # length */
  173. EC_LEN = 16, /* E/C length */
  174. ID_LEN = 16, /* ID length */
  175. TRACE_LEN = 112, /* length of trace data and mask */
  176. };
  177. enum {
  178. SF_PAGE_SIZE = 256, /* serial flash page size */
  179. SF_SEC_SIZE = 64 * 1024, /* serial flash sector size */
  180. SF_SIZE = SF_SEC_SIZE * 16, /* serial flash size */
  181. };
  182. enum { MEM_EDC0, MEM_EDC1, MEM_MC };
  183. enum {
  184. MEMWIN0_APERTURE = 2048,
  185. MEMWIN0_BASE = 0x1b800,
  186. MEMWIN1_APERTURE = 32768,
  187. MEMWIN1_BASE = 0x28000,
  188. MEMWIN2_APERTURE = 65536,
  189. MEMWIN2_BASE = 0x30000,
  190. };
  191. /* serial flash and firmware constants */
  192. enum {
  193. SF_ATTEMPTS = 10, /* max retries for SF operations */
  194. /* flash command opcodes */
  195. SF_PROG_PAGE = 2, /* program page */
  196. SF_WR_DISABLE = 4, /* disable writes */
  197. SF_RD_STATUS = 5, /* read status register */
  198. SF_WR_ENABLE = 6, /* enable writes */
  199. SF_RD_DATA_FAST = 0xb, /* read flash */
  200. SF_RD_ID = 0x9f, /* read ID */
  201. SF_ERASE_SECTOR = 0xd8, /* erase sector */
  202. FW_START_SEC = 8, /* first flash sector for FW */
  203. FW_END_SEC = 15, /* last flash sector for FW */
  204. FW_IMG_START = FW_START_SEC * SF_SEC_SIZE,
  205. FW_MAX_SIZE = (FW_END_SEC - FW_START_SEC + 1) * SF_SEC_SIZE,
  206. FLASH_CFG_MAX_SIZE = 0x10000 , /* max size of the flash config file*/
  207. FLASH_CFG_OFFSET = 0x1f0000,
  208. FLASH_CFG_START_SEC = FLASH_CFG_OFFSET / SF_SEC_SIZE,
  209. FPGA_FLASH_CFG_OFFSET = 0xf0000 , /* if FPGA mode, then cfg file is
  210. * at 1MB - 64KB */
  211. FPGA_FLASH_CFG_START_SEC = FPGA_FLASH_CFG_OFFSET / SF_SEC_SIZE,
  212. };
  213. /*
  214. * Flash layout.
  215. */
  216. #define FLASH_START(start) ((start) * SF_SEC_SIZE)
  217. #define FLASH_MAX_SIZE(nsecs) ((nsecs) * SF_SEC_SIZE)
  218. enum {
  219. /*
  220. * Location of firmware image in FLASH.
  221. */
  222. FLASH_FW_START_SEC = 8,
  223. FLASH_FW_NSECS = 8,
  224. FLASH_FW_START = FLASH_START(FLASH_FW_START_SEC),
  225. FLASH_FW_MAX_SIZE = FLASH_MAX_SIZE(FLASH_FW_NSECS),
  226. };
  227. #undef FLASH_START
  228. #undef FLASH_MAX_SIZE
  229. /* Management module */
  230. enum {
  231. CSIO_MGMT_EQ_WRSIZE = 512,
  232. CSIO_MGMT_IQ_WRSIZE = 128,
  233. CSIO_MGMT_EQLEN = 64,
  234. CSIO_MGMT_IQLEN = 64,
  235. };
  236. #define CSIO_MGMT_EQSIZE (CSIO_MGMT_EQLEN * CSIO_MGMT_EQ_WRSIZE)
  237. #define CSIO_MGMT_IQSIZE (CSIO_MGMT_IQLEN * CSIO_MGMT_IQ_WRSIZE)
  238. /* mgmt module stats */
  239. struct csio_mgmtm_stats {
  240. uint32_t n_abort_req; /* Total abort request */
  241. uint32_t n_abort_rsp; /* Total abort response */
  242. uint32_t n_close_req; /* Total close request */
  243. uint32_t n_close_rsp; /* Total close response */
  244. uint32_t n_err; /* Total Errors */
  245. uint32_t n_drop; /* Total request dropped */
  246. uint32_t n_active; /* Count of active_q */
  247. uint32_t n_cbfn; /* Count of cbfn_q */
  248. };
  249. /* MGMT module */
  250. struct csio_mgmtm {
  251. struct csio_hw *hw; /* Pointer to HW moduel */
  252. int eq_idx; /* Egress queue index */
  253. int iq_idx; /* Ingress queue index */
  254. int msi_vec; /* MSI vector */
  255. struct list_head active_q; /* Outstanding ELS/CT */
  256. struct list_head abort_q; /* Outstanding abort req */
  257. struct list_head cbfn_q; /* Completion queue */
  258. struct list_head mgmt_req_freelist; /* Free poll of reqs */
  259. /* ELSCT request freelist*/
  260. struct timer_list mgmt_timer; /* MGMT timer */
  261. struct csio_mgmtm_stats stats; /* ELS/CT stats */
  262. };
  263. struct csio_adap_desc {
  264. char model_no[16];
  265. char description[32];
  266. };
  267. struct pci_params {
  268. uint16_t vendor_id;
  269. uint16_t device_id;
  270. uint32_t vpd_cap_addr;
  271. uint16_t speed;
  272. uint8_t width;
  273. };
  274. /* User configurable hw parameters */
  275. struct csio_hw_params {
  276. uint32_t sf_size; /* serial flash
  277. * size in bytes
  278. */
  279. uint32_t sf_nsec; /* # of flash sectors */
  280. struct pci_params pci;
  281. uint32_t log_level; /* Module-level for
  282. * debug log.
  283. */
  284. };
  285. struct csio_vpd {
  286. uint32_t cclk;
  287. uint8_t ec[EC_LEN + 1];
  288. uint8_t sn[SERNUM_LEN + 1];
  289. uint8_t id[ID_LEN + 1];
  290. };
  291. struct csio_pport {
  292. uint16_t pcap;
  293. uint8_t portid;
  294. uint8_t link_status;
  295. uint16_t link_speed;
  296. uint8_t mac[6];
  297. uint8_t mod_type;
  298. uint8_t rsvd1;
  299. uint8_t rsvd2;
  300. uint8_t rsvd3;
  301. };
  302. /* fcoe resource information */
  303. struct csio_fcoe_res_info {
  304. uint16_t e_d_tov;
  305. uint16_t r_a_tov_seq;
  306. uint16_t r_a_tov_els;
  307. uint16_t r_r_tov;
  308. uint32_t max_xchgs;
  309. uint32_t max_ssns;
  310. uint32_t used_xchgs;
  311. uint32_t used_ssns;
  312. uint32_t max_fcfs;
  313. uint32_t max_vnps;
  314. uint32_t used_fcfs;
  315. uint32_t used_vnps;
  316. };
  317. /* HW State machine Events */
  318. enum csio_hw_ev {
  319. CSIO_HWE_CFG = (uint32_t)1, /* Starts off the State machine */
  320. CSIO_HWE_INIT, /* Config done, start Init */
  321. CSIO_HWE_INIT_DONE, /* Init Mailboxes sent, HW ready */
  322. CSIO_HWE_FATAL, /* Fatal error during initialization */
  323. CSIO_HWE_PCIERR_DETECTED,/* PCI error recovery detetced */
  324. CSIO_HWE_PCIERR_SLOT_RESET, /* Slot reset after PCI recoviery */
  325. CSIO_HWE_PCIERR_RESUME, /* Resume after PCI error recovery */
  326. CSIO_HWE_QUIESCED, /* HBA quiesced */
  327. CSIO_HWE_HBA_RESET, /* HBA reset requested */
  328. CSIO_HWE_HBA_RESET_DONE, /* HBA reset completed */
  329. CSIO_HWE_FW_DLOAD, /* FW download requested */
  330. CSIO_HWE_PCI_REMOVE, /* PCI de-instantiation */
  331. CSIO_HWE_SUSPEND, /* HW suspend for Online(hot) replacement */
  332. CSIO_HWE_RESUME, /* HW resume for Online(hot) replacement */
  333. CSIO_HWE_MAX, /* Max HW event */
  334. };
  335. /* hw stats */
  336. struct csio_hw_stats {
  337. uint32_t n_evt_activeq; /* Number of event in active Q */
  338. uint32_t n_evt_freeq; /* Number of event in free Q */
  339. uint32_t n_evt_drop; /* Number of event droped */
  340. uint32_t n_evt_unexp; /* Number of unexpected events */
  341. uint32_t n_pcich_offline;/* Number of pci channel offline */
  342. uint32_t n_lnlkup_miss; /* Number of lnode lookup miss */
  343. uint32_t n_cpl_fw6_msg; /* Number of cpl fw6 message*/
  344. uint32_t n_cpl_fw6_pld; /* Number of cpl fw6 payload*/
  345. uint32_t n_cpl_unexp; /* Number of unexpected cpl */
  346. uint32_t n_mbint_unexp; /* Number of unexpected mbox */
  347. /* interrupt */
  348. uint32_t n_plint_unexp; /* Number of unexpected PL */
  349. /* interrupt */
  350. uint32_t n_plint_cnt; /* Number of PL interrupt */
  351. uint32_t n_int_stray; /* Number of stray interrupt */
  352. uint32_t n_err; /* Number of hw errors */
  353. uint32_t n_err_fatal; /* Number of fatal errors */
  354. uint32_t n_err_nomem; /* Number of memory alloc failure */
  355. uint32_t n_err_io; /* Number of IO failure */
  356. enum csio_hw_ev n_evt_sm[CSIO_HWE_MAX]; /* Number of sm events */
  357. uint64_t n_reset_start; /* Start time after the reset */
  358. uint32_t rsvd1;
  359. };
  360. /* Defines for hw->flags */
  361. #define CSIO_HWF_MASTER 0x00000001 /* This is the Master
  362. * function for the
  363. * card.
  364. */
  365. #define CSIO_HWF_HW_INTR_ENABLED 0x00000002 /* Are HW Interrupt
  366. * enable bit set?
  367. */
  368. #define CSIO_HWF_FWEVT_PENDING 0x00000004 /* FW events pending */
  369. #define CSIO_HWF_Q_MEM_ALLOCED 0x00000008 /* Queues have been
  370. * allocated memory.
  371. */
  372. #define CSIO_HWF_Q_FW_ALLOCED 0x00000010 /* Queues have been
  373. * allocated in FW.
  374. */
  375. #define CSIO_HWF_VPD_VALID 0x00000020 /* Valid VPD copied */
  376. #define CSIO_HWF_DEVID_CACHED 0X00000040 /* PCI vendor & device
  377. * id cached */
  378. #define CSIO_HWF_FWEVT_STOP 0x00000080 /* Stop processing
  379. * FW events
  380. */
  381. #define CSIO_HWF_USING_SOFT_PARAMS 0x00000100 /* Using FW config
  382. * params
  383. */
  384. #define CSIO_HWF_HOST_INTR_ENABLED 0x00000200 /* Are host interrupts
  385. * enabled?
  386. */
  387. #define csio_is_hw_intr_enabled(__hw) \
  388. ((__hw)->flags & CSIO_HWF_HW_INTR_ENABLED)
  389. #define csio_is_host_intr_enabled(__hw) \
  390. ((__hw)->flags & CSIO_HWF_HOST_INTR_ENABLED)
  391. #define csio_is_hw_master(__hw) ((__hw)->flags & CSIO_HWF_MASTER)
  392. #define csio_is_valid_vpd(__hw) ((__hw)->flags & CSIO_HWF_VPD_VALID)
  393. #define csio_is_dev_id_cached(__hw) ((__hw)->flags & CSIO_HWF_DEVID_CACHED)
  394. #define csio_valid_vpd_copied(__hw) ((__hw)->flags |= CSIO_HWF_VPD_VALID)
  395. #define csio_dev_id_cached(__hw) ((__hw)->flags |= CSIO_HWF_DEVID_CACHED)
  396. /* Defines for intr_mode */
  397. enum csio_intr_mode {
  398. CSIO_IM_NONE = 0,
  399. CSIO_IM_INTX = 1,
  400. CSIO_IM_MSI = 2,
  401. CSIO_IM_MSIX = 3,
  402. };
  403. /* Master HW structure: One per function */
  404. struct csio_hw {
  405. struct csio_sm sm; /* State machine: should
  406. * be the 1st member.
  407. */
  408. spinlock_t lock; /* Lock for hw */
  409. struct csio_scsim scsim; /* SCSI module*/
  410. struct csio_wrm wrm; /* Work request module*/
  411. struct pci_dev *pdev; /* PCI device */
  412. void __iomem *regstart; /* Virtual address of
  413. * register map
  414. */
  415. /* SCSI queue sets */
  416. uint32_t num_sqsets; /* Number of SCSI
  417. * queue sets */
  418. uint32_t num_scsi_msix_cpus; /* Number of CPUs that
  419. * will be used
  420. * for ingress
  421. * processing.
  422. */
  423. struct csio_scsi_qset sqset[CSIO_MAX_PPORTS][CSIO_MAX_SCSI_CPU];
  424. struct csio_scsi_cpu_info scsi_cpu_info[CSIO_MAX_PPORTS];
  425. uint32_t evtflag; /* Event flag */
  426. uint32_t flags; /* HW flags */
  427. struct csio_mgmtm mgmtm; /* management module */
  428. struct csio_mbm mbm; /* Mailbox module */
  429. /* Lnodes */
  430. uint32_t num_lns; /* Number of lnodes */
  431. struct csio_lnode *rln; /* Root lnode */
  432. struct list_head sln_head; /* Sibling node list
  433. * list
  434. */
  435. int intr_iq_idx; /* Forward interrupt
  436. * queue.
  437. */
  438. int fwevt_iq_idx; /* FW evt queue */
  439. struct work_struct evtq_work; /* Worker thread for
  440. * HW events.
  441. */
  442. struct list_head evt_free_q; /* freelist of evt
  443. * elements
  444. */
  445. struct list_head evt_active_q; /* active evt queue*/
  446. /* board related info */
  447. char name[32];
  448. char hw_ver[16];
  449. char model_desc[32];
  450. char drv_version[32];
  451. char fwrev_str[32];
  452. uint32_t optrom_ver;
  453. uint32_t fwrev;
  454. uint32_t tp_vers;
  455. char chip_ver;
  456. uint32_t cfg_finiver;
  457. uint32_t cfg_finicsum;
  458. uint32_t cfg_cfcsum;
  459. uint8_t cfg_csum_status;
  460. uint8_t cfg_store;
  461. enum csio_dev_state fw_state;
  462. struct csio_vpd vpd;
  463. uint8_t pfn; /* Physical Function
  464. * number
  465. */
  466. uint32_t port_vec; /* Port vector */
  467. uint8_t num_pports; /* Number of physical
  468. * ports.
  469. */
  470. uint8_t rst_retries; /* Reset retries */
  471. uint8_t cur_evt; /* current s/m evt */
  472. uint8_t prev_evt; /* Previous s/m evt */
  473. uint32_t dev_num; /* device number */
  474. struct csio_pport pport[CSIO_MAX_PPORTS]; /* Ports (XGMACs) */
  475. struct csio_hw_params params; /* Hw parameters */
  476. struct pci_pool *scsi_pci_pool; /* PCI pool for SCSI */
  477. mempool_t *mb_mempool; /* Mailbox memory pool*/
  478. mempool_t *rnode_mempool; /* rnode memory pool */
  479. /* Interrupt */
  480. enum csio_intr_mode intr_mode; /* INTx, MSI, MSIX */
  481. uint32_t fwevt_intr_idx; /* FW evt MSIX/interrupt
  482. * index
  483. */
  484. uint32_t nondata_intr_idx; /* nondata MSIX/intr
  485. * idx
  486. */
  487. uint8_t cfg_neq; /* FW configured no of
  488. * egress queues
  489. */
  490. uint8_t cfg_niq; /* FW configured no of
  491. * iq queues.
  492. */
  493. struct csio_fcoe_res_info fres_info; /* Fcoe resource info */
  494. /* MSIX vectors */
  495. struct csio_msix_entries msix_entries[CSIO_MAX_MSIX_VECS];
  496. struct dentry *debugfs_root; /* Debug FS */
  497. struct csio_hw_stats stats; /* Hw statistics */
  498. };
  499. /* Register access macros */
  500. #define csio_reg(_b, _r) ((_b) + (_r))
  501. #define csio_rd_reg8(_h, _r) readb(csio_reg((_h)->regstart, (_r)))
  502. #define csio_rd_reg16(_h, _r) readw(csio_reg((_h)->regstart, (_r)))
  503. #define csio_rd_reg32(_h, _r) readl(csio_reg((_h)->regstart, (_r)))
  504. #define csio_rd_reg64(_h, _r) readq(csio_reg((_h)->regstart, (_r)))
  505. #define csio_wr_reg8(_h, _v, _r) writeb((_v), \
  506. csio_reg((_h)->regstart, (_r)))
  507. #define csio_wr_reg16(_h, _v, _r) writew((_v), \
  508. csio_reg((_h)->regstart, (_r)))
  509. #define csio_wr_reg32(_h, _v, _r) writel((_v), \
  510. csio_reg((_h)->regstart, (_r)))
  511. #define csio_wr_reg64(_h, _v, _r) writeq((_v), \
  512. csio_reg((_h)->regstart, (_r)))
  513. void csio_set_reg_field(struct csio_hw *, uint32_t, uint32_t, uint32_t);
  514. /* Core clocks <==> uSecs */
  515. static inline uint32_t
  516. csio_core_ticks_to_us(struct csio_hw *hw, uint32_t ticks)
  517. {
  518. /* add Core Clock / 2 to round ticks to nearest uS */
  519. return (ticks * 1000 + hw->vpd.cclk/2) / hw->vpd.cclk;
  520. }
  521. static inline uint32_t
  522. csio_us_to_core_ticks(struct csio_hw *hw, uint32_t us)
  523. {
  524. return (us * hw->vpd.cclk) / 1000;
  525. }
  526. /* Easy access macros */
  527. #define csio_hw_to_wrm(hw) ((struct csio_wrm *)(&(hw)->wrm))
  528. #define csio_hw_to_mbm(hw) ((struct csio_mbm *)(&(hw)->mbm))
  529. #define csio_hw_to_scsim(hw) ((struct csio_scsim *)(&(hw)->scsim))
  530. #define csio_hw_to_mgmtm(hw) ((struct csio_mgmtm *)(&(hw)->mgmtm))
  531. #define CSIO_PCI_BUS(hw) ((hw)->pdev->bus->number)
  532. #define CSIO_PCI_DEV(hw) (PCI_SLOT((hw)->pdev->devfn))
  533. #define CSIO_PCI_FUNC(hw) (PCI_FUNC((hw)->pdev->devfn))
  534. #define csio_set_fwevt_intr_idx(_h, _i) ((_h)->fwevt_intr_idx = (_i))
  535. #define csio_get_fwevt_intr_idx(_h) ((_h)->fwevt_intr_idx)
  536. #define csio_set_nondata_intr_idx(_h, _i) ((_h)->nondata_intr_idx = (_i))
  537. #define csio_get_nondata_intr_idx(_h) ((_h)->nondata_intr_idx)
  538. /* Printing/logging */
  539. #define CSIO_DEVID(__dev) ((__dev)->dev_num)
  540. #define CSIO_DEVID_LO(__dev) (CSIO_DEVID((__dev)) & 0xFFFF)
  541. #define CSIO_DEVID_HI(__dev) ((CSIO_DEVID((__dev)) >> 16) & 0xFFFF)
  542. #define csio_info(__hw, __fmt, ...) \
  543. dev_info(&(__hw)->pdev->dev, __fmt, ##__VA_ARGS__)
  544. #define csio_fatal(__hw, __fmt, ...) \
  545. dev_crit(&(__hw)->pdev->dev, __fmt, ##__VA_ARGS__)
  546. #define csio_err(__hw, __fmt, ...) \
  547. dev_err(&(__hw)->pdev->dev, __fmt, ##__VA_ARGS__)
  548. #define csio_warn(__hw, __fmt, ...) \
  549. dev_warn(&(__hw)->pdev->dev, __fmt, ##__VA_ARGS__)
  550. #ifdef __CSIO_DEBUG__
  551. #define csio_dbg(__hw, __fmt, ...) \
  552. csio_info((__hw), __fmt, ##__VA_ARGS__);
  553. #else
  554. #define csio_dbg(__hw, __fmt, ...)
  555. #endif
  556. int csio_mgmt_req_lookup(struct csio_mgmtm *, struct csio_ioreq *);
  557. void csio_hw_intr_disable(struct csio_hw *);
  558. int csio_hw_slow_intr_handler(struct csio_hw *hw);
  559. int csio_hw_start(struct csio_hw *);
  560. int csio_hw_stop(struct csio_hw *);
  561. int csio_hw_reset(struct csio_hw *);
  562. int csio_is_hw_ready(struct csio_hw *);
  563. int csio_is_hw_removing(struct csio_hw *);
  564. int csio_fwevtq_handler(struct csio_hw *);
  565. void csio_evtq_worker(struct work_struct *);
  566. int csio_enqueue_evt(struct csio_hw *hw, enum csio_evt type,
  567. void *evt_msg, uint16_t len);
  568. void csio_evtq_flush(struct csio_hw *hw);
  569. int csio_request_irqs(struct csio_hw *);
  570. void csio_intr_enable(struct csio_hw *);
  571. void csio_intr_disable(struct csio_hw *, bool);
  572. struct csio_lnode *csio_lnode_alloc(struct csio_hw *);
  573. int csio_config_queues(struct csio_hw *);
  574. int csio_hw_mc_read(struct csio_hw *, uint32_t, __be32 *, uint64_t *);
  575. int csio_hw_edc_read(struct csio_hw *, int, uint32_t, __be32 *, uint64_t *);
  576. int csio_hw_init(struct csio_hw *);
  577. void csio_hw_exit(struct csio_hw *);
  578. #endif /* ifndef __CSIO_HW_H__ */