cxgb4.h 50 KB

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