cxgb4.h 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257
  1. /*
  2. * This file is part of the Chelsio T4 Ethernet driver for Linux.
  3. *
  4. * Copyright (c) 2003-2014 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 __CXGB4_H__
  35. #define __CXGB4_H__
  36. #include "t4_hw.h"
  37. #include <linux/bitops.h>
  38. #include <linux/cache.h>
  39. #include <linux/interrupt.h>
  40. #include <linux/list.h>
  41. #include <linux/netdevice.h>
  42. #include <linux/pci.h>
  43. #include <linux/spinlock.h>
  44. #include <linux/timer.h>
  45. #include <linux/vmalloc.h>
  46. #include <asm/io.h>
  47. #include "cxgb4_uld.h"
  48. #define CH_WARN(adap, fmt, ...) dev_warn(adap->pdev_dev, fmt, ## __VA_ARGS__)
  49. enum {
  50. MAX_NPORTS = 4, /* max # of ports */
  51. SERNUM_LEN = 24, /* Serial # length */
  52. EC_LEN = 16, /* E/C length */
  53. ID_LEN = 16, /* ID length */
  54. PN_LEN = 16, /* Part Number length */
  55. };
  56. enum {
  57. MEM_EDC0,
  58. MEM_EDC1,
  59. MEM_MC,
  60. MEM_MC0 = MEM_MC,
  61. MEM_MC1
  62. };
  63. enum {
  64. MEMWIN0_APERTURE = 2048,
  65. MEMWIN0_BASE = 0x1b800,
  66. MEMWIN1_APERTURE = 32768,
  67. MEMWIN1_BASE = 0x28000,
  68. MEMWIN1_BASE_T5 = 0x52000,
  69. MEMWIN2_APERTURE = 65536,
  70. MEMWIN2_BASE = 0x30000,
  71. MEMWIN2_APERTURE_T5 = 131072,
  72. MEMWIN2_BASE_T5 = 0x60000,
  73. };
  74. enum dev_master {
  75. MASTER_CANT,
  76. MASTER_MAY,
  77. MASTER_MUST
  78. };
  79. enum dev_state {
  80. DEV_STATE_UNINIT,
  81. DEV_STATE_INIT,
  82. DEV_STATE_ERR
  83. };
  84. enum {
  85. PAUSE_RX = 1 << 0,
  86. PAUSE_TX = 1 << 1,
  87. PAUSE_AUTONEG = 1 << 2
  88. };
  89. struct port_stats {
  90. u64 tx_octets; /* total # of octets in good frames */
  91. u64 tx_frames; /* all good frames */
  92. u64 tx_bcast_frames; /* all broadcast frames */
  93. u64 tx_mcast_frames; /* all multicast frames */
  94. u64 tx_ucast_frames; /* all unicast frames */
  95. u64 tx_error_frames; /* all error frames */
  96. u64 tx_frames_64; /* # of Tx frames in a particular range */
  97. u64 tx_frames_65_127;
  98. u64 tx_frames_128_255;
  99. u64 tx_frames_256_511;
  100. u64 tx_frames_512_1023;
  101. u64 tx_frames_1024_1518;
  102. u64 tx_frames_1519_max;
  103. u64 tx_drop; /* # of dropped Tx frames */
  104. u64 tx_pause; /* # of transmitted pause frames */
  105. u64 tx_ppp0; /* # of transmitted PPP prio 0 frames */
  106. u64 tx_ppp1; /* # of transmitted PPP prio 1 frames */
  107. u64 tx_ppp2; /* # of transmitted PPP prio 2 frames */
  108. u64 tx_ppp3; /* # of transmitted PPP prio 3 frames */
  109. u64 tx_ppp4; /* # of transmitted PPP prio 4 frames */
  110. u64 tx_ppp5; /* # of transmitted PPP prio 5 frames */
  111. u64 tx_ppp6; /* # of transmitted PPP prio 6 frames */
  112. u64 tx_ppp7; /* # of transmitted PPP prio 7 frames */
  113. u64 rx_octets; /* total # of octets in good frames */
  114. u64 rx_frames; /* all good frames */
  115. u64 rx_bcast_frames; /* all broadcast frames */
  116. u64 rx_mcast_frames; /* all multicast frames */
  117. u64 rx_ucast_frames; /* all unicast frames */
  118. u64 rx_too_long; /* # of frames exceeding MTU */
  119. u64 rx_jabber; /* # of jabber frames */
  120. u64 rx_fcs_err; /* # of received frames with bad FCS */
  121. u64 rx_len_err; /* # of received frames with length error */
  122. u64 rx_symbol_err; /* symbol errors */
  123. u64 rx_runt; /* # of short frames */
  124. u64 rx_frames_64; /* # of Rx frames in a particular range */
  125. u64 rx_frames_65_127;
  126. u64 rx_frames_128_255;
  127. u64 rx_frames_256_511;
  128. u64 rx_frames_512_1023;
  129. u64 rx_frames_1024_1518;
  130. u64 rx_frames_1519_max;
  131. u64 rx_pause; /* # of received pause frames */
  132. u64 rx_ppp0; /* # of received PPP prio 0 frames */
  133. u64 rx_ppp1; /* # of received PPP prio 1 frames */
  134. u64 rx_ppp2; /* # of received PPP prio 2 frames */
  135. u64 rx_ppp3; /* # of received PPP prio 3 frames */
  136. u64 rx_ppp4; /* # of received PPP prio 4 frames */
  137. u64 rx_ppp5; /* # of received PPP prio 5 frames */
  138. u64 rx_ppp6; /* # of received PPP prio 6 frames */
  139. u64 rx_ppp7; /* # of received PPP prio 7 frames */
  140. u64 rx_ovflow0; /* drops due to buffer-group 0 overflows */
  141. u64 rx_ovflow1; /* drops due to buffer-group 1 overflows */
  142. u64 rx_ovflow2; /* drops due to buffer-group 2 overflows */
  143. u64 rx_ovflow3; /* drops due to buffer-group 3 overflows */
  144. u64 rx_trunc0; /* buffer-group 0 truncated packets */
  145. u64 rx_trunc1; /* buffer-group 1 truncated packets */
  146. u64 rx_trunc2; /* buffer-group 2 truncated packets */
  147. u64 rx_trunc3; /* buffer-group 3 truncated packets */
  148. };
  149. struct lb_port_stats {
  150. u64 octets;
  151. u64 frames;
  152. u64 bcast_frames;
  153. u64 mcast_frames;
  154. u64 ucast_frames;
  155. u64 error_frames;
  156. u64 frames_64;
  157. u64 frames_65_127;
  158. u64 frames_128_255;
  159. u64 frames_256_511;
  160. u64 frames_512_1023;
  161. u64 frames_1024_1518;
  162. u64 frames_1519_max;
  163. u64 drop;
  164. u64 ovflow0;
  165. u64 ovflow1;
  166. u64 ovflow2;
  167. u64 ovflow3;
  168. u64 trunc0;
  169. u64 trunc1;
  170. u64 trunc2;
  171. u64 trunc3;
  172. };
  173. struct tp_tcp_stats {
  174. u32 tcpOutRsts;
  175. u64 tcpInSegs;
  176. u64 tcpOutSegs;
  177. u64 tcpRetransSegs;
  178. };
  179. struct tp_err_stats {
  180. u32 macInErrs[4];
  181. u32 hdrInErrs[4];
  182. u32 tcpInErrs[4];
  183. u32 tnlCongDrops[4];
  184. u32 ofldChanDrops[4];
  185. u32 tnlTxDrops[4];
  186. u32 ofldVlanDrops[4];
  187. u32 tcp6InErrs[4];
  188. u32 ofldNoNeigh;
  189. u32 ofldCongDefer;
  190. };
  191. struct sge_params {
  192. u32 hps; /* host page size for our PF/VF */
  193. u32 eq_qpp; /* egress queues/page for our PF/VF */
  194. u32 iq_qpp; /* egress queues/page for our PF/VF */
  195. };
  196. struct tp_params {
  197. unsigned int ntxchan; /* # of Tx channels */
  198. unsigned int tre; /* log2 of core clocks per TP tick */
  199. unsigned int la_mask; /* what events are recorded by TP LA */
  200. unsigned short tx_modq_map; /* TX modulation scheduler queue to */
  201. /* channel map */
  202. uint32_t dack_re; /* DACK timer resolution */
  203. unsigned short tx_modq[NCHAN]; /* channel to modulation queue map */
  204. u32 vlan_pri_map; /* cached TP_VLAN_PRI_MAP */
  205. u32 ingress_config; /* cached TP_INGRESS_CONFIG */
  206. /* TP_VLAN_PRI_MAP Compressed Filter Tuple field offsets. This is a
  207. * subset of the set of fields which may be present in the Compressed
  208. * Filter Tuple portion of filters and TCP TCB connections. The
  209. * fields which are present are controlled by the TP_VLAN_PRI_MAP.
  210. * Since a variable number of fields may or may not be present, their
  211. * shifted field positions within the Compressed Filter Tuple may
  212. * vary, or not even be present if the field isn't selected in
  213. * TP_VLAN_PRI_MAP. Since some of these fields are needed in various
  214. * places we store their offsets here, or a -1 if the field isn't
  215. * present.
  216. */
  217. int vlan_shift;
  218. int vnic_shift;
  219. int port_shift;
  220. int protocol_shift;
  221. };
  222. struct vpd_params {
  223. unsigned int cclk;
  224. u8 ec[EC_LEN + 1];
  225. u8 sn[SERNUM_LEN + 1];
  226. u8 id[ID_LEN + 1];
  227. u8 pn[PN_LEN + 1];
  228. };
  229. struct pci_params {
  230. unsigned char speed;
  231. unsigned char width;
  232. };
  233. #define CHELSIO_CHIP_CODE(version, revision) (((version) << 4) | (revision))
  234. #define CHELSIO_CHIP_FPGA 0x100
  235. #define CHELSIO_CHIP_VERSION(code) (((code) >> 4) & 0xf)
  236. #define CHELSIO_CHIP_RELEASE(code) ((code) & 0xf)
  237. #define CHELSIO_T4 0x4
  238. #define CHELSIO_T5 0x5
  239. enum chip_type {
  240. T4_A1 = CHELSIO_CHIP_CODE(CHELSIO_T4, 1),
  241. T4_A2 = CHELSIO_CHIP_CODE(CHELSIO_T4, 2),
  242. T4_FIRST_REV = T4_A1,
  243. T4_LAST_REV = T4_A2,
  244. T5_A0 = CHELSIO_CHIP_CODE(CHELSIO_T5, 0),
  245. T5_A1 = CHELSIO_CHIP_CODE(CHELSIO_T5, 1),
  246. T5_FIRST_REV = T5_A0,
  247. T5_LAST_REV = T5_A1,
  248. };
  249. struct devlog_params {
  250. u32 memtype; /* which memory (EDC0, EDC1, MC) */
  251. u32 start; /* start of log in firmware memory */
  252. u32 size; /* size of log */
  253. };
  254. struct adapter_params {
  255. struct sge_params sge;
  256. struct tp_params tp;
  257. struct vpd_params vpd;
  258. struct pci_params pci;
  259. struct devlog_params devlog;
  260. enum pcie_memwin drv_memwin;
  261. unsigned int cim_la_size;
  262. unsigned int sf_size; /* serial flash size in bytes */
  263. unsigned int sf_nsec; /* # of flash sectors */
  264. unsigned int sf_fw_start; /* start of FW image in flash */
  265. unsigned int fw_vers;
  266. unsigned int tp_vers;
  267. u8 api_vers[7];
  268. unsigned short mtus[NMTUS];
  269. unsigned short a_wnd[NCCTRL_WIN];
  270. unsigned short b_wnd[NCCTRL_WIN];
  271. unsigned char nports; /* # of ethernet ports */
  272. unsigned char portvec;
  273. enum chip_type chip; /* chip code */
  274. unsigned char offload;
  275. unsigned char bypass;
  276. unsigned int ofldq_wr_cred;
  277. bool ulptx_memwrite_dsgl; /* use of T5 DSGL allowed */
  278. unsigned int max_ordird_qp; /* Max read depth per RDMA QP */
  279. unsigned int max_ird_adapter; /* Max read depth per adapter */
  280. };
  281. #include "t4fw_api.h"
  282. #define FW_VERSION(chip) ( \
  283. FW_HDR_FW_VER_MAJOR_G(chip##FW_VERSION_MAJOR) | \
  284. FW_HDR_FW_VER_MINOR_G(chip##FW_VERSION_MINOR) | \
  285. FW_HDR_FW_VER_MICRO_G(chip##FW_VERSION_MICRO) | \
  286. FW_HDR_FW_VER_BUILD_G(chip##FW_VERSION_BUILD))
  287. #define FW_INTFVER(chip, intf) (FW_HDR_INTFVER_##intf)
  288. struct fw_info {
  289. u8 chip;
  290. char *fs_name;
  291. char *fw_mod_name;
  292. struct fw_hdr fw_hdr;
  293. };
  294. struct trace_params {
  295. u32 data[TRACE_LEN / 4];
  296. u32 mask[TRACE_LEN / 4];
  297. unsigned short snap_len;
  298. unsigned short min_len;
  299. unsigned char skip_ofst;
  300. unsigned char skip_len;
  301. unsigned char invert;
  302. unsigned char port;
  303. };
  304. struct link_config {
  305. unsigned short supported; /* link capabilities */
  306. unsigned short advertising; /* advertised capabilities */
  307. unsigned short requested_speed; /* speed user has requested */
  308. unsigned short speed; /* actual link speed */
  309. unsigned char requested_fc; /* flow control user has requested */
  310. unsigned char fc; /* actual link flow control */
  311. unsigned char autoneg; /* autonegotiating? */
  312. unsigned char link_ok; /* link up? */
  313. };
  314. #define FW_LEN16(fw_struct) FW_CMD_LEN16_V(sizeof(fw_struct) / 16)
  315. enum {
  316. MAX_ETH_QSETS = 32, /* # of Ethernet Tx/Rx queue sets */
  317. MAX_OFLD_QSETS = 16, /* # of offload Tx/Rx queue sets */
  318. MAX_CTRL_QUEUES = NCHAN, /* # of control Tx queues */
  319. MAX_RDMA_QUEUES = NCHAN, /* # of streaming RDMA Rx queues */
  320. MAX_RDMA_CIQS = 32, /* # of RDMA concentrator IQs */
  321. MAX_ISCSI_QUEUES = NCHAN, /* # of streaming iSCSI Rx queues */
  322. };
  323. enum {
  324. INGQ_EXTRAS = 2, /* firmware event queue and */
  325. /* forwarded interrupts */
  326. MAX_EGRQ = MAX_ETH_QSETS*2 + MAX_OFLD_QSETS*2
  327. + MAX_CTRL_QUEUES + MAX_RDMA_QUEUES + MAX_ISCSI_QUEUES,
  328. MAX_INGQ = MAX_ETH_QSETS + MAX_OFLD_QSETS + MAX_RDMA_QUEUES
  329. + MAX_RDMA_CIQS + MAX_ISCSI_QUEUES + INGQ_EXTRAS,
  330. };
  331. struct adapter;
  332. struct sge_rspq;
  333. #include "cxgb4_dcb.h"
  334. struct port_info {
  335. struct adapter *adapter;
  336. u16 viid;
  337. s16 xact_addr_filt; /* index of exact MAC address filter */
  338. u16 rss_size; /* size of VI's RSS table slice */
  339. s8 mdio_addr;
  340. enum fw_port_type port_type;
  341. u8 mod_type;
  342. u8 port_id;
  343. u8 tx_chan;
  344. u8 lport; /* associated offload logical port */
  345. u8 nqsets; /* # of qsets */
  346. u8 first_qset; /* index of first qset */
  347. u8 rss_mode;
  348. struct link_config link_cfg;
  349. u16 *rss;
  350. #ifdef CONFIG_CHELSIO_T4_DCB
  351. struct port_dcb_info dcb; /* Data Center Bridging support */
  352. #endif
  353. };
  354. struct dentry;
  355. struct work_struct;
  356. enum { /* adapter flags */
  357. FULL_INIT_DONE = (1 << 0),
  358. DEV_ENABLED = (1 << 1),
  359. USING_MSI = (1 << 2),
  360. USING_MSIX = (1 << 3),
  361. FW_OK = (1 << 4),
  362. RSS_TNLALLLOOKUP = (1 << 5),
  363. USING_SOFT_PARAMS = (1 << 6),
  364. MASTER_PF = (1 << 7),
  365. FW_OFLD_CONN = (1 << 9),
  366. };
  367. struct rx_sw_desc;
  368. struct sge_fl { /* SGE free-buffer queue state */
  369. unsigned int avail; /* # of available Rx buffers */
  370. unsigned int pend_cred; /* new buffers since last FL DB ring */
  371. unsigned int cidx; /* consumer index */
  372. unsigned int pidx; /* producer index */
  373. unsigned long alloc_failed; /* # of times buffer allocation failed */
  374. unsigned long large_alloc_failed;
  375. unsigned long starving;
  376. /* RO fields */
  377. unsigned int cntxt_id; /* SGE context id for the free list */
  378. unsigned int size; /* capacity of free list */
  379. struct rx_sw_desc *sdesc; /* address of SW Rx descriptor ring */
  380. __be64 *desc; /* address of HW Rx descriptor ring */
  381. dma_addr_t addr; /* bus address of HW ring start */
  382. void __iomem *bar2_addr; /* address of BAR2 Queue registers */
  383. unsigned int bar2_qid; /* Queue ID for BAR2 Queue registers */
  384. };
  385. /* A packet gather list */
  386. struct pkt_gl {
  387. struct page_frag frags[MAX_SKB_FRAGS];
  388. void *va; /* virtual address of first byte */
  389. unsigned int nfrags; /* # of fragments */
  390. unsigned int tot_len; /* total length of fragments */
  391. };
  392. typedef int (*rspq_handler_t)(struct sge_rspq *q, const __be64 *rsp,
  393. const struct pkt_gl *gl);
  394. struct sge_rspq { /* state for an SGE response queue */
  395. struct napi_struct napi;
  396. const __be64 *cur_desc; /* current descriptor in queue */
  397. unsigned int cidx; /* consumer index */
  398. u8 gen; /* current generation bit */
  399. u8 intr_params; /* interrupt holdoff parameters */
  400. u8 next_intr_params; /* holdoff params for next interrupt */
  401. u8 adaptive_rx;
  402. u8 pktcnt_idx; /* interrupt packet threshold */
  403. u8 uld; /* ULD handling this queue */
  404. u8 idx; /* queue index within its group */
  405. int offset; /* offset into current Rx buffer */
  406. u16 cntxt_id; /* SGE context id for the response q */
  407. u16 abs_id; /* absolute SGE id for the response q */
  408. __be64 *desc; /* address of HW response ring */
  409. dma_addr_t phys_addr; /* physical address of the ring */
  410. void __iomem *bar2_addr; /* address of BAR2 Queue registers */
  411. unsigned int bar2_qid; /* Queue ID for BAR2 Queue registers */
  412. unsigned int iqe_len; /* entry size */
  413. unsigned int size; /* capacity of response queue */
  414. struct adapter *adap;
  415. struct net_device *netdev; /* associated net device */
  416. rspq_handler_t handler;
  417. #ifdef CONFIG_NET_RX_BUSY_POLL
  418. #define CXGB_POLL_STATE_IDLE 0
  419. #define CXGB_POLL_STATE_NAPI BIT(0) /* NAPI owns this poll */
  420. #define CXGB_POLL_STATE_POLL BIT(1) /* poll owns this poll */
  421. #define CXGB_POLL_STATE_NAPI_YIELD BIT(2) /* NAPI yielded this poll */
  422. #define CXGB_POLL_STATE_POLL_YIELD BIT(3) /* poll yielded this poll */
  423. #define CXGB_POLL_YIELD (CXGB_POLL_STATE_NAPI_YIELD | \
  424. CXGB_POLL_STATE_POLL_YIELD)
  425. #define CXGB_POLL_LOCKED (CXGB_POLL_STATE_NAPI | \
  426. CXGB_POLL_STATE_POLL)
  427. #define CXGB_POLL_USER_PEND (CXGB_POLL_STATE_POLL | \
  428. CXGB_POLL_STATE_POLL_YIELD)
  429. unsigned int bpoll_state;
  430. spinlock_t bpoll_lock; /* lock for busy poll */
  431. #endif /* CONFIG_NET_RX_BUSY_POLL */
  432. };
  433. struct sge_eth_stats { /* Ethernet queue statistics */
  434. unsigned long pkts; /* # of ethernet packets */
  435. unsigned long lro_pkts; /* # of LRO super packets */
  436. unsigned long lro_merged; /* # of wire packets merged by LRO */
  437. unsigned long rx_cso; /* # of Rx checksum offloads */
  438. unsigned long vlan_ex; /* # of Rx VLAN extractions */
  439. unsigned long rx_drops; /* # of packets dropped due to no mem */
  440. };
  441. struct sge_eth_rxq { /* SW Ethernet Rx queue */
  442. struct sge_rspq rspq;
  443. struct sge_fl fl;
  444. struct sge_eth_stats stats;
  445. } ____cacheline_aligned_in_smp;
  446. struct sge_ofld_stats { /* offload queue statistics */
  447. unsigned long pkts; /* # of packets */
  448. unsigned long imm; /* # of immediate-data packets */
  449. unsigned long an; /* # of asynchronous notifications */
  450. unsigned long nomem; /* # of responses deferred due to no mem */
  451. };
  452. struct sge_ofld_rxq { /* SW offload Rx queue */
  453. struct sge_rspq rspq;
  454. struct sge_fl fl;
  455. struct sge_ofld_stats stats;
  456. } ____cacheline_aligned_in_smp;
  457. struct tx_desc {
  458. __be64 flit[8];
  459. };
  460. struct tx_sw_desc;
  461. struct sge_txq {
  462. unsigned int in_use; /* # of in-use Tx descriptors */
  463. unsigned int size; /* # of descriptors */
  464. unsigned int cidx; /* SW consumer index */
  465. unsigned int pidx; /* producer index */
  466. unsigned long stops; /* # of times q has been stopped */
  467. unsigned long restarts; /* # of queue restarts */
  468. unsigned int cntxt_id; /* SGE context id for the Tx q */
  469. struct tx_desc *desc; /* address of HW Tx descriptor ring */
  470. struct tx_sw_desc *sdesc; /* address of SW Tx descriptor ring */
  471. struct sge_qstat *stat; /* queue status entry */
  472. dma_addr_t phys_addr; /* physical address of the ring */
  473. spinlock_t db_lock;
  474. int db_disabled;
  475. unsigned short db_pidx;
  476. unsigned short db_pidx_inc;
  477. void __iomem *bar2_addr; /* address of BAR2 Queue registers */
  478. unsigned int bar2_qid; /* Queue ID for BAR2 Queue registers */
  479. };
  480. struct sge_eth_txq { /* state for an SGE Ethernet Tx queue */
  481. struct sge_txq q;
  482. struct netdev_queue *txq; /* associated netdev TX queue */
  483. #ifdef CONFIG_CHELSIO_T4_DCB
  484. u8 dcb_prio; /* DCB Priority bound to queue */
  485. #endif
  486. unsigned long tso; /* # of TSO requests */
  487. unsigned long tx_cso; /* # of Tx checksum offloads */
  488. unsigned long vlan_ins; /* # of Tx VLAN insertions */
  489. unsigned long mapping_err; /* # of I/O MMU packet mapping errors */
  490. } ____cacheline_aligned_in_smp;
  491. struct sge_ofld_txq { /* state for an SGE offload Tx queue */
  492. struct sge_txq q;
  493. struct adapter *adap;
  494. struct sk_buff_head sendq; /* list of backpressured packets */
  495. struct tasklet_struct qresume_tsk; /* restarts the queue */
  496. u8 full; /* the Tx ring is full */
  497. unsigned long mapping_err; /* # of I/O MMU packet mapping errors */
  498. } ____cacheline_aligned_in_smp;
  499. struct sge_ctrl_txq { /* state for an SGE control Tx queue */
  500. struct sge_txq q;
  501. struct adapter *adap;
  502. struct sk_buff_head sendq; /* list of backpressured packets */
  503. struct tasklet_struct qresume_tsk; /* restarts the queue */
  504. u8 full; /* the Tx ring is full */
  505. } ____cacheline_aligned_in_smp;
  506. struct sge {
  507. struct sge_eth_txq ethtxq[MAX_ETH_QSETS];
  508. struct sge_ofld_txq ofldtxq[MAX_OFLD_QSETS];
  509. struct sge_ctrl_txq ctrlq[MAX_CTRL_QUEUES];
  510. struct sge_eth_rxq ethrxq[MAX_ETH_QSETS];
  511. struct sge_ofld_rxq ofldrxq[MAX_OFLD_QSETS];
  512. struct sge_ofld_rxq rdmarxq[MAX_RDMA_QUEUES];
  513. struct sge_ofld_rxq rdmaciq[MAX_RDMA_CIQS];
  514. struct sge_rspq fw_evtq ____cacheline_aligned_in_smp;
  515. struct sge_rspq intrq ____cacheline_aligned_in_smp;
  516. spinlock_t intrq_lock;
  517. u16 max_ethqsets; /* # of available Ethernet queue sets */
  518. u16 ethqsets; /* # of active Ethernet queue sets */
  519. u16 ethtxq_rover; /* Tx queue to clean up next */
  520. u16 ofldqsets; /* # of active offload queue sets */
  521. u16 rdmaqs; /* # of available RDMA Rx queues */
  522. u16 rdmaciqs; /* # of available RDMA concentrator IQs */
  523. u16 ofld_rxq[MAX_OFLD_QSETS];
  524. u16 rdma_rxq[MAX_RDMA_QUEUES];
  525. u16 rdma_ciq[MAX_RDMA_CIQS];
  526. u16 timer_val[SGE_NTIMERS];
  527. u8 counter_val[SGE_NCOUNTERS];
  528. u32 fl_pg_order; /* large page allocation size */
  529. u32 stat_len; /* length of status page at ring end */
  530. u32 pktshift; /* padding between CPL & packet data */
  531. u32 fl_align; /* response queue message alignment */
  532. u32 fl_starve_thres; /* Free List starvation threshold */
  533. /* State variables for detecting an SGE Ingress DMA hang */
  534. unsigned int idma_1s_thresh;/* SGE same State Counter 1s threshold */
  535. unsigned int idma_stalled[2];/* SGE synthesized stalled timers in HZ */
  536. unsigned int idma_state[2]; /* SGE IDMA Hang detect state */
  537. unsigned int idma_qid[2]; /* SGE IDMA Hung Ingress Queue ID */
  538. unsigned int egr_start;
  539. unsigned int ingr_start;
  540. void *egr_map[MAX_EGRQ]; /* qid->queue egress queue map */
  541. struct sge_rspq *ingr_map[MAX_INGQ]; /* qid->queue ingress queue map */
  542. DECLARE_BITMAP(starving_fl, MAX_EGRQ);
  543. DECLARE_BITMAP(txq_maperr, MAX_EGRQ);
  544. struct timer_list rx_timer; /* refills starving FLs */
  545. struct timer_list tx_timer; /* checks Tx queues */
  546. };
  547. #define for_each_ethrxq(sge, i) for (i = 0; i < (sge)->ethqsets; i++)
  548. #define for_each_ofldrxq(sge, i) for (i = 0; i < (sge)->ofldqsets; i++)
  549. #define for_each_rdmarxq(sge, i) for (i = 0; i < (sge)->rdmaqs; i++)
  550. #define for_each_rdmaciq(sge, i) for (i = 0; i < (sge)->rdmaciqs; i++)
  551. struct l2t_data;
  552. #ifdef CONFIG_PCI_IOV
  553. /* T4 supports SRIOV on PF0-3 and T5 on PF0-7. However, the Serial
  554. * Configuration initialization for T5 only has SR-IOV functionality enabled
  555. * on PF0-3 in order to simplify everything.
  556. */
  557. #define NUM_OF_PF_WITH_SRIOV 4
  558. #endif
  559. struct adapter {
  560. void __iomem *regs;
  561. void __iomem *bar2;
  562. u32 t4_bar0;
  563. struct pci_dev *pdev;
  564. struct device *pdev_dev;
  565. unsigned int mbox;
  566. unsigned int fn;
  567. unsigned int flags;
  568. enum chip_type chip;
  569. int msg_enable;
  570. struct adapter_params params;
  571. struct cxgb4_virt_res vres;
  572. unsigned int swintr;
  573. unsigned int wol;
  574. struct {
  575. unsigned short vec;
  576. char desc[IFNAMSIZ + 10];
  577. } msix_info[MAX_INGQ + 1];
  578. struct sge sge;
  579. struct net_device *port[MAX_NPORTS];
  580. u8 chan_map[NCHAN]; /* channel -> port map */
  581. u32 filter_mode;
  582. unsigned int l2t_start;
  583. unsigned int l2t_end;
  584. struct l2t_data *l2t;
  585. unsigned int clipt_start;
  586. unsigned int clipt_end;
  587. struct clip_tbl *clipt;
  588. void *uld_handle[CXGB4_ULD_MAX];
  589. struct list_head list_node;
  590. struct list_head rcu_node;
  591. struct tid_info tids;
  592. void **tid_release_head;
  593. spinlock_t tid_release_lock;
  594. struct workqueue_struct *workq;
  595. struct work_struct tid_release_task;
  596. struct work_struct db_full_task;
  597. struct work_struct db_drop_task;
  598. bool tid_release_task_busy;
  599. struct dentry *debugfs_root;
  600. spinlock_t stats_lock;
  601. spinlock_t win0_lock ____cacheline_aligned_in_smp;
  602. };
  603. /* Defined bit width of user definable filter tuples
  604. */
  605. #define ETHTYPE_BITWIDTH 16
  606. #define FRAG_BITWIDTH 1
  607. #define MACIDX_BITWIDTH 9
  608. #define FCOE_BITWIDTH 1
  609. #define IPORT_BITWIDTH 3
  610. #define MATCHTYPE_BITWIDTH 3
  611. #define PROTO_BITWIDTH 8
  612. #define TOS_BITWIDTH 8
  613. #define PF_BITWIDTH 8
  614. #define VF_BITWIDTH 8
  615. #define IVLAN_BITWIDTH 16
  616. #define OVLAN_BITWIDTH 16
  617. /* Filter matching rules. These consist of a set of ingress packet field
  618. * (value, mask) tuples. The associated ingress packet field matches the
  619. * tuple when ((field & mask) == value). (Thus a wildcard "don't care" field
  620. * rule can be constructed by specifying a tuple of (0, 0).) A filter rule
  621. * matches an ingress packet when all of the individual individual field
  622. * matching rules are true.
  623. *
  624. * Partial field masks are always valid, however, while it may be easy to
  625. * understand their meanings for some fields (e.g. IP address to match a
  626. * subnet), for others making sensible partial masks is less intuitive (e.g.
  627. * MPS match type) ...
  628. *
  629. * Most of the following data structures are modeled on T4 capabilities.
  630. * Drivers for earlier chips use the subsets which make sense for those chips.
  631. * We really need to come up with a hardware-independent mechanism to
  632. * represent hardware filter capabilities ...
  633. */
  634. struct ch_filter_tuple {
  635. /* Compressed header matching field rules. The TP_VLAN_PRI_MAP
  636. * register selects which of these fields will participate in the
  637. * filter match rules -- up to a maximum of 36 bits. Because
  638. * TP_VLAN_PRI_MAP is a global register, all filters must use the same
  639. * set of fields.
  640. */
  641. uint32_t ethtype:ETHTYPE_BITWIDTH; /* Ethernet type */
  642. uint32_t frag:FRAG_BITWIDTH; /* IP fragmentation header */
  643. uint32_t ivlan_vld:1; /* inner VLAN valid */
  644. uint32_t ovlan_vld:1; /* outer VLAN valid */
  645. uint32_t pfvf_vld:1; /* PF/VF valid */
  646. uint32_t macidx:MACIDX_BITWIDTH; /* exact match MAC index */
  647. uint32_t fcoe:FCOE_BITWIDTH; /* FCoE packet */
  648. uint32_t iport:IPORT_BITWIDTH; /* ingress port */
  649. uint32_t matchtype:MATCHTYPE_BITWIDTH; /* MPS match type */
  650. uint32_t proto:PROTO_BITWIDTH; /* protocol type */
  651. uint32_t tos:TOS_BITWIDTH; /* TOS/Traffic Type */
  652. uint32_t pf:PF_BITWIDTH; /* PCI-E PF ID */
  653. uint32_t vf:VF_BITWIDTH; /* PCI-E VF ID */
  654. uint32_t ivlan:IVLAN_BITWIDTH; /* inner VLAN */
  655. uint32_t ovlan:OVLAN_BITWIDTH; /* outer VLAN */
  656. /* Uncompressed header matching field rules. These are always
  657. * available for field rules.
  658. */
  659. uint8_t lip[16]; /* local IP address (IPv4 in [3:0]) */
  660. uint8_t fip[16]; /* foreign IP address (IPv4 in [3:0]) */
  661. uint16_t lport; /* local port */
  662. uint16_t fport; /* foreign port */
  663. };
  664. /* A filter ioctl command.
  665. */
  666. struct ch_filter_specification {
  667. /* Administrative fields for filter.
  668. */
  669. uint32_t hitcnts:1; /* count filter hits in TCB */
  670. uint32_t prio:1; /* filter has priority over active/server */
  671. /* Fundamental filter typing. This is the one element of filter
  672. * matching that doesn't exist as a (value, mask) tuple.
  673. */
  674. uint32_t type:1; /* 0 => IPv4, 1 => IPv6 */
  675. /* Packet dispatch information. Ingress packets which match the
  676. * filter rules will be dropped, passed to the host or switched back
  677. * out as egress packets.
  678. */
  679. uint32_t action:2; /* drop, pass, switch */
  680. uint32_t rpttid:1; /* report TID in RSS hash field */
  681. uint32_t dirsteer:1; /* 0 => RSS, 1 => steer to iq */
  682. uint32_t iq:10; /* ingress queue */
  683. uint32_t maskhash:1; /* dirsteer=0: store RSS hash in TCB */
  684. uint32_t dirsteerhash:1;/* dirsteer=1: 0 => TCB contains RSS hash */
  685. /* 1 => TCB contains IQ ID */
  686. /* Switch proxy/rewrite fields. An ingress packet which matches a
  687. * filter with "switch" set will be looped back out as an egress
  688. * packet -- potentially with some Ethernet header rewriting.
  689. */
  690. uint32_t eport:2; /* egress port to switch packet out */
  691. uint32_t newdmac:1; /* rewrite destination MAC address */
  692. uint32_t newsmac:1; /* rewrite source MAC address */
  693. uint32_t newvlan:2; /* rewrite VLAN Tag */
  694. uint8_t dmac[ETH_ALEN]; /* new destination MAC address */
  695. uint8_t smac[ETH_ALEN]; /* new source MAC address */
  696. uint16_t vlan; /* VLAN Tag to insert */
  697. /* Filter rule value/mask pairs.
  698. */
  699. struct ch_filter_tuple val;
  700. struct ch_filter_tuple mask;
  701. };
  702. enum {
  703. FILTER_PASS = 0, /* default */
  704. FILTER_DROP,
  705. FILTER_SWITCH
  706. };
  707. enum {
  708. VLAN_NOCHANGE = 0, /* default */
  709. VLAN_REMOVE,
  710. VLAN_INSERT,
  711. VLAN_REWRITE
  712. };
  713. static inline int is_t5(enum chip_type chip)
  714. {
  715. return CHELSIO_CHIP_VERSION(chip) == CHELSIO_T5;
  716. }
  717. static inline int is_t4(enum chip_type chip)
  718. {
  719. return CHELSIO_CHIP_VERSION(chip) == CHELSIO_T4;
  720. }
  721. static inline u32 t4_read_reg(struct adapter *adap, u32 reg_addr)
  722. {
  723. return readl(adap->regs + reg_addr);
  724. }
  725. static inline void t4_write_reg(struct adapter *adap, u32 reg_addr, u32 val)
  726. {
  727. writel(val, adap->regs + reg_addr);
  728. }
  729. #ifndef readq
  730. static inline u64 readq(const volatile void __iomem *addr)
  731. {
  732. return readl(addr) + ((u64)readl(addr + 4) << 32);
  733. }
  734. static inline void writeq(u64 val, volatile void __iomem *addr)
  735. {
  736. writel(val, addr);
  737. writel(val >> 32, addr + 4);
  738. }
  739. #endif
  740. static inline u64 t4_read_reg64(struct adapter *adap, u32 reg_addr)
  741. {
  742. return readq(adap->regs + reg_addr);
  743. }
  744. static inline void t4_write_reg64(struct adapter *adap, u32 reg_addr, u64 val)
  745. {
  746. writeq(val, adap->regs + reg_addr);
  747. }
  748. /**
  749. * netdev2pinfo - return the port_info structure associated with a net_device
  750. * @dev: the netdev
  751. *
  752. * Return the struct port_info associated with a net_device
  753. */
  754. static inline struct port_info *netdev2pinfo(const struct net_device *dev)
  755. {
  756. return netdev_priv(dev);
  757. }
  758. /**
  759. * adap2pinfo - return the port_info of a port
  760. * @adap: the adapter
  761. * @idx: the port index
  762. *
  763. * Return the port_info structure for the port of the given index.
  764. */
  765. static inline struct port_info *adap2pinfo(struct adapter *adap, int idx)
  766. {
  767. return netdev_priv(adap->port[idx]);
  768. }
  769. /**
  770. * netdev2adap - return the adapter structure associated with a net_device
  771. * @dev: the netdev
  772. *
  773. * Return the struct adapter associated with a net_device
  774. */
  775. static inline struct adapter *netdev2adap(const struct net_device *dev)
  776. {
  777. return netdev2pinfo(dev)->adapter;
  778. }
  779. #ifdef CONFIG_NET_RX_BUSY_POLL
  780. static inline void cxgb_busy_poll_init_lock(struct sge_rspq *q)
  781. {
  782. spin_lock_init(&q->bpoll_lock);
  783. q->bpoll_state = CXGB_POLL_STATE_IDLE;
  784. }
  785. static inline bool cxgb_poll_lock_napi(struct sge_rspq *q)
  786. {
  787. bool rc = true;
  788. spin_lock(&q->bpoll_lock);
  789. if (q->bpoll_state & CXGB_POLL_LOCKED) {
  790. q->bpoll_state |= CXGB_POLL_STATE_NAPI_YIELD;
  791. rc = false;
  792. } else {
  793. q->bpoll_state = CXGB_POLL_STATE_NAPI;
  794. }
  795. spin_unlock(&q->bpoll_lock);
  796. return rc;
  797. }
  798. static inline bool cxgb_poll_unlock_napi(struct sge_rspq *q)
  799. {
  800. bool rc = false;
  801. spin_lock(&q->bpoll_lock);
  802. if (q->bpoll_state & CXGB_POLL_STATE_POLL_YIELD)
  803. rc = true;
  804. q->bpoll_state = CXGB_POLL_STATE_IDLE;
  805. spin_unlock(&q->bpoll_lock);
  806. return rc;
  807. }
  808. static inline bool cxgb_poll_lock_poll(struct sge_rspq *q)
  809. {
  810. bool rc = true;
  811. spin_lock_bh(&q->bpoll_lock);
  812. if (q->bpoll_state & CXGB_POLL_LOCKED) {
  813. q->bpoll_state |= CXGB_POLL_STATE_POLL_YIELD;
  814. rc = false;
  815. } else {
  816. q->bpoll_state |= CXGB_POLL_STATE_POLL;
  817. }
  818. spin_unlock_bh(&q->bpoll_lock);
  819. return rc;
  820. }
  821. static inline bool cxgb_poll_unlock_poll(struct sge_rspq *q)
  822. {
  823. bool rc = false;
  824. spin_lock_bh(&q->bpoll_lock);
  825. if (q->bpoll_state & CXGB_POLL_STATE_POLL_YIELD)
  826. rc = true;
  827. q->bpoll_state = CXGB_POLL_STATE_IDLE;
  828. spin_unlock_bh(&q->bpoll_lock);
  829. return rc;
  830. }
  831. static inline bool cxgb_poll_busy_polling(struct sge_rspq *q)
  832. {
  833. return q->bpoll_state & CXGB_POLL_USER_PEND;
  834. }
  835. #else
  836. static inline void cxgb_busy_poll_init_lock(struct sge_rspq *q)
  837. {
  838. }
  839. static inline bool cxgb_poll_lock_napi(struct sge_rspq *q)
  840. {
  841. return true;
  842. }
  843. static inline bool cxgb_poll_unlock_napi(struct sge_rspq *q)
  844. {
  845. return false;
  846. }
  847. static inline bool cxgb_poll_lock_poll(struct sge_rspq *q)
  848. {
  849. return false;
  850. }
  851. static inline bool cxgb_poll_unlock_poll(struct sge_rspq *q)
  852. {
  853. return false;
  854. }
  855. static inline bool cxgb_poll_busy_polling(struct sge_rspq *q)
  856. {
  857. return false;
  858. }
  859. #endif /* CONFIG_NET_RX_BUSY_POLL */
  860. void t4_os_portmod_changed(const struct adapter *adap, int port_id);
  861. void t4_os_link_changed(struct adapter *adap, int port_id, int link_stat);
  862. void *t4_alloc_mem(size_t size);
  863. void t4_free_sge_resources(struct adapter *adap);
  864. void t4_free_ofld_rxqs(struct adapter *adap, int n, struct sge_ofld_rxq *q);
  865. irq_handler_t t4_intr_handler(struct adapter *adap);
  866. netdev_tx_t t4_eth_xmit(struct sk_buff *skb, struct net_device *dev);
  867. int t4_ethrx_handler(struct sge_rspq *q, const __be64 *rsp,
  868. const struct pkt_gl *gl);
  869. int t4_mgmt_tx(struct adapter *adap, struct sk_buff *skb);
  870. int t4_ofld_send(struct adapter *adap, struct sk_buff *skb);
  871. int t4_sge_alloc_rxq(struct adapter *adap, struct sge_rspq *iq, bool fwevtq,
  872. struct net_device *dev, int intr_idx,
  873. struct sge_fl *fl, rspq_handler_t hnd);
  874. int t4_sge_alloc_eth_txq(struct adapter *adap, struct sge_eth_txq *txq,
  875. struct net_device *dev, struct netdev_queue *netdevq,
  876. unsigned int iqid);
  877. int t4_sge_alloc_ctrl_txq(struct adapter *adap, struct sge_ctrl_txq *txq,
  878. struct net_device *dev, unsigned int iqid,
  879. unsigned int cmplqid);
  880. int t4_sge_alloc_ofld_txq(struct adapter *adap, struct sge_ofld_txq *txq,
  881. struct net_device *dev, unsigned int iqid);
  882. irqreturn_t t4_sge_intr_msix(int irq, void *cookie);
  883. int t4_sge_init(struct adapter *adap);
  884. void t4_sge_start(struct adapter *adap);
  885. void t4_sge_stop(struct adapter *adap);
  886. int cxgb_busy_poll(struct napi_struct *napi);
  887. extern int dbfifo_int_thresh;
  888. #define for_each_port(adapter, iter) \
  889. for (iter = 0; iter < (adapter)->params.nports; ++iter)
  890. static inline int is_bypass(struct adapter *adap)
  891. {
  892. return adap->params.bypass;
  893. }
  894. static inline int is_bypass_device(int device)
  895. {
  896. /* this should be set based upon device capabilities */
  897. switch (device) {
  898. case 0x440b:
  899. case 0x440c:
  900. return 1;
  901. default:
  902. return 0;
  903. }
  904. }
  905. static inline unsigned int core_ticks_per_usec(const struct adapter *adap)
  906. {
  907. return adap->params.vpd.cclk / 1000;
  908. }
  909. static inline unsigned int us_to_core_ticks(const struct adapter *adap,
  910. unsigned int us)
  911. {
  912. return (us * adap->params.vpd.cclk) / 1000;
  913. }
  914. static inline unsigned int core_ticks_to_us(const struct adapter *adapter,
  915. unsigned int ticks)
  916. {
  917. /* add Core Clock / 2 to round ticks to nearest uS */
  918. return ((ticks * 1000 + adapter->params.vpd.cclk/2) /
  919. adapter->params.vpd.cclk);
  920. }
  921. void t4_set_reg_field(struct adapter *adap, unsigned int addr, u32 mask,
  922. u32 val);
  923. int t4_wr_mbox_meat(struct adapter *adap, int mbox, const void *cmd, int size,
  924. void *rpl, bool sleep_ok);
  925. static inline int t4_wr_mbox(struct adapter *adap, int mbox, const void *cmd,
  926. int size, void *rpl)
  927. {
  928. return t4_wr_mbox_meat(adap, mbox, cmd, size, rpl, true);
  929. }
  930. static inline int t4_wr_mbox_ns(struct adapter *adap, int mbox, const void *cmd,
  931. int size, void *rpl)
  932. {
  933. return t4_wr_mbox_meat(adap, mbox, cmd, size, rpl, false);
  934. }
  935. void t4_write_indirect(struct adapter *adap, unsigned int addr_reg,
  936. unsigned int data_reg, const u32 *vals,
  937. unsigned int nregs, unsigned int start_idx);
  938. void t4_read_indirect(struct adapter *adap, unsigned int addr_reg,
  939. unsigned int data_reg, u32 *vals, unsigned int nregs,
  940. unsigned int start_idx);
  941. void t4_hw_pci_read_cfg4(struct adapter *adapter, int reg, u32 *val);
  942. struct fw_filter_wr;
  943. void t4_intr_enable(struct adapter *adapter);
  944. void t4_intr_disable(struct adapter *adapter);
  945. int t4_slow_intr_handler(struct adapter *adapter);
  946. int t4_wait_dev_ready(void __iomem *regs);
  947. int t4_link_start(struct adapter *adap, unsigned int mbox, unsigned int port,
  948. struct link_config *lc);
  949. int t4_restart_aneg(struct adapter *adap, unsigned int mbox, unsigned int port);
  950. #define T4_MEMORY_WRITE 0
  951. #define T4_MEMORY_READ 1
  952. int t4_memory_rw(struct adapter *adap, int win, int mtype, u32 addr, u32 len,
  953. void *buf, int dir);
  954. static inline int t4_memory_write(struct adapter *adap, int mtype, u32 addr,
  955. u32 len, __be32 *buf)
  956. {
  957. return t4_memory_rw(adap, 0, mtype, addr, len, buf, 0);
  958. }
  959. int t4_seeprom_wp(struct adapter *adapter, bool enable);
  960. int get_vpd_params(struct adapter *adapter, struct vpd_params *p);
  961. int t4_read_flash(struct adapter *adapter, unsigned int addr,
  962. unsigned int nwords, u32 *data, int byte_oriented);
  963. int t4_load_fw(struct adapter *adapter, const u8 *fw_data, unsigned int size);
  964. int t4_fwcache(struct adapter *adap, enum fw_params_param_dev_fwcache op);
  965. int t4_fw_upgrade(struct adapter *adap, unsigned int mbox,
  966. const u8 *fw_data, unsigned int size, int force);
  967. unsigned int t4_flash_cfg_addr(struct adapter *adapter);
  968. int t4_get_fw_version(struct adapter *adapter, u32 *vers);
  969. int t4_get_tp_version(struct adapter *adapter, u32 *vers);
  970. int t4_get_exprom_version(struct adapter *adapter, u32 *vers);
  971. int t4_prep_fw(struct adapter *adap, struct fw_info *fw_info,
  972. const u8 *fw_data, unsigned int fw_size,
  973. struct fw_hdr *card_fw, enum dev_state state, int *reset);
  974. int t4_prep_adapter(struct adapter *adapter);
  975. enum t4_bar2_qtype { T4_BAR2_QTYPE_EGRESS, T4_BAR2_QTYPE_INGRESS };
  976. int cxgb4_t4_bar2_sge_qregs(struct adapter *adapter,
  977. unsigned int qid,
  978. enum t4_bar2_qtype qtype,
  979. u64 *pbar2_qoffset,
  980. unsigned int *pbar2_qid);
  981. unsigned int qtimer_val(const struct adapter *adap,
  982. const struct sge_rspq *q);
  983. int t4_init_sge_params(struct adapter *adapter);
  984. int t4_init_tp_params(struct adapter *adap);
  985. int t4_filter_field_shift(const struct adapter *adap, int filter_sel);
  986. int t4_port_init(struct adapter *adap, int mbox, int pf, int vf);
  987. void t4_fatal_err(struct adapter *adapter);
  988. int t4_config_rss_range(struct adapter *adapter, int mbox, unsigned int viid,
  989. int start, int n, const u16 *rspq, unsigned int nrspq);
  990. int t4_config_glbl_rss(struct adapter *adapter, int mbox, unsigned int mode,
  991. unsigned int flags);
  992. int t4_read_rss(struct adapter *adapter, u16 *entries);
  993. void t4_read_rss_key(struct adapter *adapter, u32 *key);
  994. void t4_write_rss_key(struct adapter *adap, const u32 *key, int idx);
  995. void t4_read_rss_pf_config(struct adapter *adapter, unsigned int index,
  996. u32 *valp);
  997. void t4_read_rss_vf_config(struct adapter *adapter, unsigned int index,
  998. u32 *vfl, u32 *vfh);
  999. u32 t4_read_rss_pf_map(struct adapter *adapter);
  1000. u32 t4_read_rss_pf_mask(struct adapter *adapter);
  1001. int t4_mc_read(struct adapter *adap, int idx, u32 addr, __be32 *data,
  1002. u64 *parity);
  1003. int t4_edc_read(struct adapter *adap, int idx, u32 addr, __be32 *data,
  1004. u64 *parity);
  1005. void t4_pmtx_get_stats(struct adapter *adap, u32 cnt[], u64 cycles[]);
  1006. void t4_pmrx_get_stats(struct adapter *adap, u32 cnt[], u64 cycles[]);
  1007. int t4_read_cim_ibq(struct adapter *adap, unsigned int qid, u32 *data,
  1008. size_t n);
  1009. int t4_read_cim_obq(struct adapter *adap, unsigned int qid, u32 *data,
  1010. size_t n);
  1011. int t4_cim_read(struct adapter *adap, unsigned int addr, unsigned int n,
  1012. unsigned int *valp);
  1013. int t4_cim_write(struct adapter *adap, unsigned int addr, unsigned int n,
  1014. const unsigned int *valp);
  1015. int t4_cim_read_la(struct adapter *adap, u32 *la_buf, unsigned int *wrptr);
  1016. void t4_read_cimq_cfg(struct adapter *adap, u16 *base, u16 *size, u16 *thres);
  1017. const char *t4_get_port_type_description(enum fw_port_type port_type);
  1018. void t4_get_port_stats(struct adapter *adap, int idx, struct port_stats *p);
  1019. void t4_read_mtu_tbl(struct adapter *adap, u16 *mtus, u8 *mtu_log);
  1020. void t4_read_cong_tbl(struct adapter *adap, u16 incr[NMTUS][NCCTRL_WIN]);
  1021. void t4_tp_wr_bits_indirect(struct adapter *adap, unsigned int addr,
  1022. unsigned int mask, unsigned int val);
  1023. void t4_tp_read_la(struct adapter *adap, u64 *la_buf, unsigned int *wrptr);
  1024. void t4_tp_get_tcp_stats(struct adapter *adap, struct tp_tcp_stats *v4,
  1025. struct tp_tcp_stats *v6);
  1026. void t4_load_mtus(struct adapter *adap, const unsigned short *mtus,
  1027. const unsigned short *alpha, const unsigned short *beta);
  1028. void t4_ulprx_read_la(struct adapter *adap, u32 *la_buf);
  1029. void t4_mk_filtdelwr(unsigned int ftid, struct fw_filter_wr *wr, int qid);
  1030. void t4_wol_magic_enable(struct adapter *adap, unsigned int port,
  1031. const u8 *addr);
  1032. int t4_wol_pat_enable(struct adapter *adap, unsigned int port, unsigned int map,
  1033. u64 mask0, u64 mask1, unsigned int crc, bool enable);
  1034. int t4_fw_hello(struct adapter *adap, unsigned int mbox, unsigned int evt_mbox,
  1035. enum dev_master master, enum dev_state *state);
  1036. int t4_fw_bye(struct adapter *adap, unsigned int mbox);
  1037. int t4_early_init(struct adapter *adap, unsigned int mbox);
  1038. int t4_fw_reset(struct adapter *adap, unsigned int mbox, int reset);
  1039. int t4_fixup_host_params(struct adapter *adap, unsigned int page_size,
  1040. unsigned int cache_line_size);
  1041. int t4_fw_initialize(struct adapter *adap, unsigned int mbox);
  1042. int t4_query_params(struct adapter *adap, unsigned int mbox, unsigned int pf,
  1043. unsigned int vf, unsigned int nparams, const u32 *params,
  1044. u32 *val);
  1045. int t4_set_params(struct adapter *adap, unsigned int mbox, unsigned int pf,
  1046. unsigned int vf, unsigned int nparams, const u32 *params,
  1047. const u32 *val);
  1048. int t4_set_params_nosleep(struct adapter *adap, unsigned int mbox,
  1049. unsigned int pf, unsigned int vf,
  1050. unsigned int nparams, const u32 *params,
  1051. const u32 *val);
  1052. int t4_cfg_pfvf(struct adapter *adap, unsigned int mbox, unsigned int pf,
  1053. unsigned int vf, unsigned int txq, unsigned int txq_eth_ctrl,
  1054. unsigned int rxqi, unsigned int rxq, unsigned int tc,
  1055. unsigned int vi, unsigned int cmask, unsigned int pmask,
  1056. unsigned int nexact, unsigned int rcaps, unsigned int wxcaps);
  1057. int t4_alloc_vi(struct adapter *adap, unsigned int mbox, unsigned int port,
  1058. unsigned int pf, unsigned int vf, unsigned int nmac, u8 *mac,
  1059. unsigned int *rss_size);
  1060. int t4_set_rxmode(struct adapter *adap, unsigned int mbox, unsigned int viid,
  1061. int mtu, int promisc, int all_multi, int bcast, int vlanex,
  1062. bool sleep_ok);
  1063. int t4_alloc_mac_filt(struct adapter *adap, unsigned int mbox,
  1064. unsigned int viid, bool free, unsigned int naddr,
  1065. const u8 **addr, u16 *idx, u64 *hash, bool sleep_ok);
  1066. int t4_change_mac(struct adapter *adap, unsigned int mbox, unsigned int viid,
  1067. int idx, const u8 *addr, bool persist, bool add_smt);
  1068. int t4_set_addr_hash(struct adapter *adap, unsigned int mbox, unsigned int viid,
  1069. bool ucast, u64 vec, bool sleep_ok);
  1070. int t4_enable_vi_params(struct adapter *adap, unsigned int mbox,
  1071. unsigned int viid, bool rx_en, bool tx_en, bool dcb_en);
  1072. int t4_enable_vi(struct adapter *adap, unsigned int mbox, unsigned int viid,
  1073. bool rx_en, bool tx_en);
  1074. int t4_identify_port(struct adapter *adap, unsigned int mbox, unsigned int viid,
  1075. unsigned int nblinks);
  1076. int t4_mdio_rd(struct adapter *adap, unsigned int mbox, unsigned int phy_addr,
  1077. unsigned int mmd, unsigned int reg, u16 *valp);
  1078. int t4_mdio_wr(struct adapter *adap, unsigned int mbox, unsigned int phy_addr,
  1079. unsigned int mmd, unsigned int reg, u16 val);
  1080. int t4_iq_free(struct adapter *adap, unsigned int mbox, unsigned int pf,
  1081. unsigned int vf, unsigned int iqtype, unsigned int iqid,
  1082. unsigned int fl0id, unsigned int fl1id);
  1083. int t4_eth_eq_free(struct adapter *adap, unsigned int mbox, unsigned int pf,
  1084. unsigned int vf, unsigned int eqid);
  1085. int t4_ctrl_eq_free(struct adapter *adap, unsigned int mbox, unsigned int pf,
  1086. unsigned int vf, unsigned int eqid);
  1087. int t4_ofld_eq_free(struct adapter *adap, unsigned int mbox, unsigned int pf,
  1088. unsigned int vf, unsigned int eqid);
  1089. int t4_handle_fw_rpl(struct adapter *adap, const __be64 *rpl);
  1090. void t4_db_full(struct adapter *adapter);
  1091. void t4_db_dropped(struct adapter *adapter);
  1092. int t4_fwaddrspace_write(struct adapter *adap, unsigned int mbox,
  1093. u32 addr, u32 val);
  1094. void t4_sge_decode_idma_state(struct adapter *adapter, int state);
  1095. void t4_free_mem(void *addr);
  1096. #endif /* __CXGB4_H__ */