cxgb4.h 44 KB

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