cxgb4.h 48 KB

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