bnx2x_cmn.h 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407
  1. /* bnx2x_cmn.h: QLogic Everest network driver.
  2. *
  3. * Copyright (c) 2007-2013 Broadcom Corporation
  4. * Copyright (c) 2014 QLogic Corporation
  5. * All rights reserved
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation.
  10. *
  11. * Maintained by: Ariel Elior <ariel.elior@qlogic.com>
  12. * Written by: Eliezer Tamir
  13. * Based on code from Michael Chan's bnx2 driver
  14. * UDP CSUM errata workaround by Arik Gendelman
  15. * Slowpath and fastpath rework by Vladislav Zolotarov
  16. * Statistics and Link management by Yitchak Gertner
  17. *
  18. */
  19. #ifndef BNX2X_CMN_H
  20. #define BNX2X_CMN_H
  21. #include <linux/types.h>
  22. #include <linux/pci.h>
  23. #include <linux/netdevice.h>
  24. #include <linux/etherdevice.h>
  25. #include <linux/irq.h>
  26. #include "bnx2x.h"
  27. #include "bnx2x_sriov.h"
  28. /* This is used as a replacement for an MCP if it's not present */
  29. extern int bnx2x_load_count[2][3]; /* per-path: 0-common, 1-port0, 2-port1 */
  30. extern int bnx2x_num_queues;
  31. /************************ Macros ********************************/
  32. #define BNX2X_PCI_FREE(x, y, size) \
  33. do { \
  34. if (x) { \
  35. dma_free_coherent(&bp->pdev->dev, size, (void *)x, y); \
  36. x = NULL; \
  37. y = 0; \
  38. } \
  39. } while (0)
  40. #define BNX2X_FREE(x) \
  41. do { \
  42. if (x) { \
  43. kfree((void *)x); \
  44. x = NULL; \
  45. } \
  46. } while (0)
  47. #define BNX2X_PCI_ALLOC(y, size) \
  48. ({ \
  49. void *x = dma_zalloc_coherent(&bp->pdev->dev, size, y, GFP_KERNEL); \
  50. if (x) \
  51. DP(NETIF_MSG_HW, \
  52. "BNX2X_PCI_ALLOC: Physical %Lx Virtual %p\n", \
  53. (unsigned long long)(*y), x); \
  54. x; \
  55. })
  56. #define BNX2X_PCI_FALLOC(y, size) \
  57. ({ \
  58. void *x = dma_alloc_coherent(&bp->pdev->dev, size, y, GFP_KERNEL); \
  59. if (x) { \
  60. memset(x, 0xff, size); \
  61. DP(NETIF_MSG_HW, \
  62. "BNX2X_PCI_FALLOC: Physical %Lx Virtual %p\n", \
  63. (unsigned long long)(*y), x); \
  64. } \
  65. x; \
  66. })
  67. /*********************** Interfaces ****************************
  68. * Functions that need to be implemented by each driver version
  69. */
  70. /* Init */
  71. /**
  72. * bnx2x_send_unload_req - request unload mode from the MCP.
  73. *
  74. * @bp: driver handle
  75. * @unload_mode: requested function's unload mode
  76. *
  77. * Return unload mode returned by the MCP: COMMON, PORT or FUNC.
  78. */
  79. u32 bnx2x_send_unload_req(struct bnx2x *bp, int unload_mode);
  80. /**
  81. * bnx2x_send_unload_done - send UNLOAD_DONE command to the MCP.
  82. *
  83. * @bp: driver handle
  84. * @keep_link: true iff link should be kept up
  85. */
  86. void bnx2x_send_unload_done(struct bnx2x *bp, bool keep_link);
  87. /**
  88. * bnx2x_config_rss_pf - configure RSS parameters in a PF.
  89. *
  90. * @bp: driver handle
  91. * @rss_obj: RSS object to use
  92. * @ind_table: indirection table to configure
  93. * @config_hash: re-configure RSS hash keys configuration
  94. * @enable: enabled or disabled configuration
  95. */
  96. int bnx2x_rss(struct bnx2x *bp, struct bnx2x_rss_config_obj *rss_obj,
  97. bool config_hash, bool enable);
  98. /**
  99. * bnx2x__init_func_obj - init function object
  100. *
  101. * @bp: driver handle
  102. *
  103. * Initializes the Function Object with the appropriate
  104. * parameters which include a function slow path driver
  105. * interface.
  106. */
  107. void bnx2x__init_func_obj(struct bnx2x *bp);
  108. /**
  109. * bnx2x_setup_queue - setup eth queue.
  110. *
  111. * @bp: driver handle
  112. * @fp: pointer to the fastpath structure
  113. * @leading: boolean
  114. *
  115. */
  116. int bnx2x_setup_queue(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  117. bool leading);
  118. /**
  119. * bnx2x_setup_leading - bring up a leading eth queue.
  120. *
  121. * @bp: driver handle
  122. */
  123. int bnx2x_setup_leading(struct bnx2x *bp);
  124. /**
  125. * bnx2x_fw_command - send the MCP a request
  126. *
  127. * @bp: driver handle
  128. * @command: request
  129. * @param: request's parameter
  130. *
  131. * block until there is a reply
  132. */
  133. u32 bnx2x_fw_command(struct bnx2x *bp, u32 command, u32 param);
  134. /**
  135. * bnx2x_initial_phy_init - initialize link parameters structure variables.
  136. *
  137. * @bp: driver handle
  138. * @load_mode: current mode
  139. */
  140. int bnx2x_initial_phy_init(struct bnx2x *bp, int load_mode);
  141. /**
  142. * bnx2x_link_set - configure hw according to link parameters structure.
  143. *
  144. * @bp: driver handle
  145. */
  146. void bnx2x_link_set(struct bnx2x *bp);
  147. /**
  148. * bnx2x_force_link_reset - Forces link reset, and put the PHY
  149. * in reset as well.
  150. *
  151. * @bp: driver handle
  152. */
  153. void bnx2x_force_link_reset(struct bnx2x *bp);
  154. /**
  155. * bnx2x_link_test - query link status.
  156. *
  157. * @bp: driver handle
  158. * @is_serdes: bool
  159. *
  160. * Returns 0 if link is UP.
  161. */
  162. u8 bnx2x_link_test(struct bnx2x *bp, u8 is_serdes);
  163. /**
  164. * bnx2x_drv_pulse - write driver pulse to shmem
  165. *
  166. * @bp: driver handle
  167. *
  168. * writes the value in bp->fw_drv_pulse_wr_seq to drv_pulse mbox
  169. * in the shmem.
  170. */
  171. void bnx2x_drv_pulse(struct bnx2x *bp);
  172. /**
  173. * bnx2x_igu_ack_sb - update IGU with current SB value
  174. *
  175. * @bp: driver handle
  176. * @igu_sb_id: SB id
  177. * @segment: SB segment
  178. * @index: SB index
  179. * @op: SB operation
  180. * @update: is HW update required
  181. */
  182. void bnx2x_igu_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 segment,
  183. u16 index, u8 op, u8 update);
  184. /* Disable transactions from chip to host */
  185. void bnx2x_pf_disable(struct bnx2x *bp);
  186. int bnx2x_pretend_func(struct bnx2x *bp, u16 pretend_func_val);
  187. /**
  188. * bnx2x__link_status_update - handles link status change.
  189. *
  190. * @bp: driver handle
  191. */
  192. void bnx2x__link_status_update(struct bnx2x *bp);
  193. /**
  194. * bnx2x_link_report - report link status to upper layer.
  195. *
  196. * @bp: driver handle
  197. */
  198. void bnx2x_link_report(struct bnx2x *bp);
  199. /* None-atomic version of bnx2x_link_report() */
  200. void __bnx2x_link_report(struct bnx2x *bp);
  201. /**
  202. * bnx2x_get_mf_speed - calculate MF speed.
  203. *
  204. * @bp: driver handle
  205. *
  206. * Takes into account current linespeed and MF configuration.
  207. */
  208. u16 bnx2x_get_mf_speed(struct bnx2x *bp);
  209. /**
  210. * bnx2x_msix_sp_int - MSI-X slowpath interrupt handler
  211. *
  212. * @irq: irq number
  213. * @dev_instance: private instance
  214. */
  215. irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance);
  216. /**
  217. * bnx2x_interrupt - non MSI-X interrupt handler
  218. *
  219. * @irq: irq number
  220. * @dev_instance: private instance
  221. */
  222. irqreturn_t bnx2x_interrupt(int irq, void *dev_instance);
  223. /**
  224. * bnx2x_cnic_notify - send command to cnic driver
  225. *
  226. * @bp: driver handle
  227. * @cmd: command
  228. */
  229. int bnx2x_cnic_notify(struct bnx2x *bp, int cmd);
  230. /**
  231. * bnx2x_setup_cnic_irq_info - provides cnic with IRQ information
  232. *
  233. * @bp: driver handle
  234. */
  235. void bnx2x_setup_cnic_irq_info(struct bnx2x *bp);
  236. /**
  237. * bnx2x_setup_cnic_info - provides cnic with updated info
  238. *
  239. * @bp: driver handle
  240. */
  241. void bnx2x_setup_cnic_info(struct bnx2x *bp);
  242. /**
  243. * bnx2x_int_enable - enable HW interrupts.
  244. *
  245. * @bp: driver handle
  246. */
  247. void bnx2x_int_enable(struct bnx2x *bp);
  248. /**
  249. * bnx2x_int_disable_sync - disable interrupts.
  250. *
  251. * @bp: driver handle
  252. * @disable_hw: true, disable HW interrupts.
  253. *
  254. * This function ensures that there are no
  255. * ISRs or SP DPCs (sp_task) are running after it returns.
  256. */
  257. void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw);
  258. /**
  259. * bnx2x_nic_init_cnic - init driver internals for cnic.
  260. *
  261. * @bp: driver handle
  262. * @load_code: COMMON, PORT or FUNCTION
  263. *
  264. * Initializes:
  265. * - rings
  266. * - status blocks
  267. * - etc.
  268. */
  269. void bnx2x_nic_init_cnic(struct bnx2x *bp);
  270. /**
  271. * bnx2x_preirq_nic_init - init driver internals.
  272. *
  273. * @bp: driver handle
  274. *
  275. * Initializes:
  276. * - fastpath object
  277. * - fastpath rings
  278. * etc.
  279. */
  280. void bnx2x_pre_irq_nic_init(struct bnx2x *bp);
  281. /**
  282. * bnx2x_postirq_nic_init - init driver internals.
  283. *
  284. * @bp: driver handle
  285. * @load_code: COMMON, PORT or FUNCTION
  286. *
  287. * Initializes:
  288. * - status blocks
  289. * - slowpath rings
  290. * - etc.
  291. */
  292. void bnx2x_post_irq_nic_init(struct bnx2x *bp, u32 load_code);
  293. /**
  294. * bnx2x_alloc_mem_cnic - allocate driver's memory for cnic.
  295. *
  296. * @bp: driver handle
  297. */
  298. int bnx2x_alloc_mem_cnic(struct bnx2x *bp);
  299. /**
  300. * bnx2x_alloc_mem - allocate driver's memory.
  301. *
  302. * @bp: driver handle
  303. */
  304. int bnx2x_alloc_mem(struct bnx2x *bp);
  305. /**
  306. * bnx2x_free_mem_cnic - release driver's memory for cnic.
  307. *
  308. * @bp: driver handle
  309. */
  310. void bnx2x_free_mem_cnic(struct bnx2x *bp);
  311. /**
  312. * bnx2x_free_mem - release driver's memory.
  313. *
  314. * @bp: driver handle
  315. */
  316. void bnx2x_free_mem(struct bnx2x *bp);
  317. /**
  318. * bnx2x_set_num_queues - set number of queues according to mode.
  319. *
  320. * @bp: driver handle
  321. */
  322. void bnx2x_set_num_queues(struct bnx2x *bp);
  323. /**
  324. * bnx2x_chip_cleanup - cleanup chip internals.
  325. *
  326. * @bp: driver handle
  327. * @unload_mode: COMMON, PORT, FUNCTION
  328. * @keep_link: true iff link should be kept up.
  329. *
  330. * - Cleanup MAC configuration.
  331. * - Closes clients.
  332. * - etc.
  333. */
  334. void bnx2x_chip_cleanup(struct bnx2x *bp, int unload_mode, bool keep_link);
  335. /**
  336. * bnx2x_acquire_hw_lock - acquire HW lock.
  337. *
  338. * @bp: driver handle
  339. * @resource: resource bit which was locked
  340. */
  341. int bnx2x_acquire_hw_lock(struct bnx2x *bp, u32 resource);
  342. /**
  343. * bnx2x_release_hw_lock - release HW lock.
  344. *
  345. * @bp: driver handle
  346. * @resource: resource bit which was locked
  347. */
  348. int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource);
  349. /**
  350. * bnx2x_release_leader_lock - release recovery leader lock
  351. *
  352. * @bp: driver handle
  353. */
  354. int bnx2x_release_leader_lock(struct bnx2x *bp);
  355. /**
  356. * bnx2x_set_eth_mac - configure eth MAC address in the HW
  357. *
  358. * @bp: driver handle
  359. * @set: set or clear
  360. *
  361. * Configures according to the value in netdev->dev_addr.
  362. */
  363. int bnx2x_set_eth_mac(struct bnx2x *bp, bool set);
  364. /**
  365. * bnx2x_set_rx_mode - set MAC filtering configurations.
  366. *
  367. * @dev: netdevice
  368. *
  369. * called with netif_tx_lock from dev_mcast.c
  370. * If bp->state is OPEN, should be called with
  371. * netif_addr_lock_bh()
  372. */
  373. void bnx2x_set_rx_mode_inner(struct bnx2x *bp);
  374. /* Parity errors related */
  375. void bnx2x_set_pf_load(struct bnx2x *bp);
  376. bool bnx2x_clear_pf_load(struct bnx2x *bp);
  377. bool bnx2x_chk_parity_attn(struct bnx2x *bp, bool *global, bool print);
  378. bool bnx2x_reset_is_done(struct bnx2x *bp, int engine);
  379. void bnx2x_set_reset_in_progress(struct bnx2x *bp);
  380. void bnx2x_set_reset_global(struct bnx2x *bp);
  381. void bnx2x_disable_close_the_gate(struct bnx2x *bp);
  382. int bnx2x_init_hw_func_cnic(struct bnx2x *bp);
  383. /**
  384. * bnx2x_sp_event - handle ramrods completion.
  385. *
  386. * @fp: fastpath handle for the event
  387. * @rr_cqe: eth_rx_cqe
  388. */
  389. void bnx2x_sp_event(struct bnx2x_fastpath *fp, union eth_rx_cqe *rr_cqe);
  390. /**
  391. * bnx2x_ilt_set_info - prepare ILT configurations.
  392. *
  393. * @bp: driver handle
  394. */
  395. void bnx2x_ilt_set_info(struct bnx2x *bp);
  396. /**
  397. * bnx2x_ilt_set_cnic_info - prepare ILT configurations for SRC
  398. * and TM.
  399. *
  400. * @bp: driver handle
  401. */
  402. void bnx2x_ilt_set_info_cnic(struct bnx2x *bp);
  403. /**
  404. * bnx2x_dcbx_init - initialize dcbx protocol.
  405. *
  406. * @bp: driver handle
  407. */
  408. void bnx2x_dcbx_init(struct bnx2x *bp, bool update_shmem);
  409. /**
  410. * bnx2x_set_power_state - set power state to the requested value.
  411. *
  412. * @bp: driver handle
  413. * @state: required state D0 or D3hot
  414. *
  415. * Currently only D0 and D3hot are supported.
  416. */
  417. int bnx2x_set_power_state(struct bnx2x *bp, pci_power_t state);
  418. /**
  419. * bnx2x_update_max_mf_config - update MAX part of MF configuration in HW.
  420. *
  421. * @bp: driver handle
  422. * @value: new value
  423. */
  424. void bnx2x_update_max_mf_config(struct bnx2x *bp, u32 value);
  425. /* Error handling */
  426. void bnx2x_fw_dump_lvl(struct bnx2x *bp, const char *lvl);
  427. /* dev_close main block */
  428. int bnx2x_nic_unload(struct bnx2x *bp, int unload_mode, bool keep_link);
  429. /* dev_open main block */
  430. int bnx2x_nic_load(struct bnx2x *bp, int load_mode);
  431. /* hard_xmit callback */
  432. netdev_tx_t bnx2x_start_xmit(struct sk_buff *skb, struct net_device *dev);
  433. /* setup_tc callback */
  434. int bnx2x_setup_tc(struct net_device *dev, u8 num_tc);
  435. int __bnx2x_setup_tc(struct net_device *dev, u32 handle, __be16 proto,
  436. struct tc_to_netdev *tc);
  437. int bnx2x_get_vf_config(struct net_device *dev, int vf,
  438. struct ifla_vf_info *ivi);
  439. int bnx2x_set_vf_mac(struct net_device *dev, int queue, u8 *mac);
  440. int bnx2x_set_vf_vlan(struct net_device *netdev, int vf, u16 vlan, u8 qos,
  441. __be16 vlan_proto);
  442. /* select_queue callback */
  443. u16 bnx2x_select_queue(struct net_device *dev, struct sk_buff *skb,
  444. void *accel_priv, select_queue_fallback_t fallback);
  445. static inline void bnx2x_update_rx_prod(struct bnx2x *bp,
  446. struct bnx2x_fastpath *fp,
  447. u16 bd_prod, u16 rx_comp_prod,
  448. u16 rx_sge_prod)
  449. {
  450. struct ustorm_eth_rx_producers rx_prods = {0};
  451. u32 i;
  452. /* Update producers */
  453. rx_prods.bd_prod = bd_prod;
  454. rx_prods.cqe_prod = rx_comp_prod;
  455. rx_prods.sge_prod = rx_sge_prod;
  456. /* Make sure that the BD and SGE data is updated before updating the
  457. * producers since FW might read the BD/SGE right after the producer
  458. * is updated.
  459. * This is only applicable for weak-ordered memory model archs such
  460. * as IA-64. The following barrier is also mandatory since FW will
  461. * assumes BDs must have buffers.
  462. */
  463. wmb();
  464. for (i = 0; i < sizeof(rx_prods)/4; i++)
  465. REG_WR(bp, fp->ustorm_rx_prods_offset + i*4,
  466. ((u32 *)&rx_prods)[i]);
  467. mmiowb(); /* keep prod updates ordered */
  468. DP(NETIF_MSG_RX_STATUS,
  469. "queue[%d]: wrote bd_prod %u cqe_prod %u sge_prod %u\n",
  470. fp->index, bd_prod, rx_comp_prod, rx_sge_prod);
  471. }
  472. /* reload helper */
  473. int bnx2x_reload_if_running(struct net_device *dev);
  474. int bnx2x_change_mac_addr(struct net_device *dev, void *p);
  475. /* NAPI poll Tx part */
  476. int bnx2x_tx_int(struct bnx2x *bp, struct bnx2x_fp_txdata *txdata);
  477. /* suspend/resume callbacks */
  478. int bnx2x_suspend(struct pci_dev *pdev, pm_message_t state);
  479. int bnx2x_resume(struct pci_dev *pdev);
  480. /* Release IRQ vectors */
  481. void bnx2x_free_irq(struct bnx2x *bp);
  482. void bnx2x_free_fp_mem(struct bnx2x *bp);
  483. void bnx2x_init_rx_rings(struct bnx2x *bp);
  484. void bnx2x_init_rx_rings_cnic(struct bnx2x *bp);
  485. void bnx2x_free_skbs(struct bnx2x *bp);
  486. void bnx2x_netif_stop(struct bnx2x *bp, int disable_hw);
  487. void bnx2x_netif_start(struct bnx2x *bp);
  488. int bnx2x_load_cnic(struct bnx2x *bp);
  489. /**
  490. * bnx2x_enable_msix - set msix configuration.
  491. *
  492. * @bp: driver handle
  493. *
  494. * fills msix_table, requests vectors, updates num_queues
  495. * according to number of available vectors.
  496. */
  497. int bnx2x_enable_msix(struct bnx2x *bp);
  498. /**
  499. * bnx2x_enable_msi - request msi mode from OS, updated internals accordingly
  500. *
  501. * @bp: driver handle
  502. */
  503. int bnx2x_enable_msi(struct bnx2x *bp);
  504. /**
  505. * bnx2x_alloc_mem_bp - allocate memories outsize main driver structure
  506. *
  507. * @bp: driver handle
  508. */
  509. int bnx2x_alloc_mem_bp(struct bnx2x *bp);
  510. /**
  511. * bnx2x_free_mem_bp - release memories outsize main driver structure
  512. *
  513. * @bp: driver handle
  514. */
  515. void bnx2x_free_mem_bp(struct bnx2x *bp);
  516. /**
  517. * bnx2x_change_mtu - change mtu netdev callback
  518. *
  519. * @dev: net device
  520. * @new_mtu: requested mtu
  521. *
  522. */
  523. int bnx2x_change_mtu(struct net_device *dev, int new_mtu);
  524. #ifdef NETDEV_FCOE_WWNN
  525. /**
  526. * bnx2x_fcoe_get_wwn - return the requested WWN value for this port
  527. *
  528. * @dev: net_device
  529. * @wwn: output buffer
  530. * @type: WWN type: NETDEV_FCOE_WWNN (node) or NETDEV_FCOE_WWPN (port)
  531. *
  532. */
  533. int bnx2x_fcoe_get_wwn(struct net_device *dev, u64 *wwn, int type);
  534. #endif
  535. netdev_features_t bnx2x_fix_features(struct net_device *dev,
  536. netdev_features_t features);
  537. int bnx2x_set_features(struct net_device *dev, netdev_features_t features);
  538. /**
  539. * bnx2x_tx_timeout - tx timeout netdev callback
  540. *
  541. * @dev: net device
  542. */
  543. void bnx2x_tx_timeout(struct net_device *dev);
  544. /** bnx2x_get_c2s_mapping - read inner-to-outer vlan configuration
  545. * c2s_map should have BNX2X_MAX_PRIORITY entries.
  546. * @bp: driver handle
  547. * @c2s_map: should have BNX2X_MAX_PRIORITY entries for mapping
  548. * @c2s_default: entry for non-tagged configuration
  549. */
  550. void bnx2x_get_c2s_mapping(struct bnx2x *bp, u8 *c2s_map, u8 *c2s_default);
  551. /*********************** Inlines **********************************/
  552. /*********************** Fast path ********************************/
  553. static inline void bnx2x_update_fpsb_idx(struct bnx2x_fastpath *fp)
  554. {
  555. barrier(); /* status block is written to by the chip */
  556. fp->fp_hc_idx = fp->sb_running_index[SM_RX_ID];
  557. }
  558. static inline void bnx2x_igu_ack_sb_gen(struct bnx2x *bp, u8 igu_sb_id,
  559. u8 segment, u16 index, u8 op,
  560. u8 update, u32 igu_addr)
  561. {
  562. struct igu_regular cmd_data = {0};
  563. cmd_data.sb_id_and_flags =
  564. ((index << IGU_REGULAR_SB_INDEX_SHIFT) |
  565. (segment << IGU_REGULAR_SEGMENT_ACCESS_SHIFT) |
  566. (update << IGU_REGULAR_BUPDATE_SHIFT) |
  567. (op << IGU_REGULAR_ENABLE_INT_SHIFT));
  568. DP(NETIF_MSG_INTR, "write 0x%08x to IGU addr 0x%x\n",
  569. cmd_data.sb_id_and_flags, igu_addr);
  570. REG_WR(bp, igu_addr, cmd_data.sb_id_and_flags);
  571. /* Make sure that ACK is written */
  572. mmiowb();
  573. barrier();
  574. }
  575. static inline void bnx2x_hc_ack_sb(struct bnx2x *bp, u8 sb_id,
  576. u8 storm, u16 index, u8 op, u8 update)
  577. {
  578. u32 hc_addr = (HC_REG_COMMAND_REG + BP_PORT(bp)*32 +
  579. COMMAND_REG_INT_ACK);
  580. struct igu_ack_register igu_ack;
  581. igu_ack.status_block_index = index;
  582. igu_ack.sb_id_and_flags =
  583. ((sb_id << IGU_ACK_REGISTER_STATUS_BLOCK_ID_SHIFT) |
  584. (storm << IGU_ACK_REGISTER_STORM_ID_SHIFT) |
  585. (update << IGU_ACK_REGISTER_UPDATE_INDEX_SHIFT) |
  586. (op << IGU_ACK_REGISTER_INTERRUPT_MODE_SHIFT));
  587. REG_WR(bp, hc_addr, (*(u32 *)&igu_ack));
  588. /* Make sure that ACK is written */
  589. mmiowb();
  590. barrier();
  591. }
  592. static inline void bnx2x_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 storm,
  593. u16 index, u8 op, u8 update)
  594. {
  595. if (bp->common.int_block == INT_BLOCK_HC)
  596. bnx2x_hc_ack_sb(bp, igu_sb_id, storm, index, op, update);
  597. else {
  598. u8 segment;
  599. if (CHIP_INT_MODE_IS_BC(bp))
  600. segment = storm;
  601. else if (igu_sb_id != bp->igu_dsb_id)
  602. segment = IGU_SEG_ACCESS_DEF;
  603. else if (storm == ATTENTION_ID)
  604. segment = IGU_SEG_ACCESS_ATTN;
  605. else
  606. segment = IGU_SEG_ACCESS_DEF;
  607. bnx2x_igu_ack_sb(bp, igu_sb_id, segment, index, op, update);
  608. }
  609. }
  610. static inline u16 bnx2x_hc_ack_int(struct bnx2x *bp)
  611. {
  612. u32 hc_addr = (HC_REG_COMMAND_REG + BP_PORT(bp)*32 +
  613. COMMAND_REG_SIMD_MASK);
  614. u32 result = REG_RD(bp, hc_addr);
  615. barrier();
  616. return result;
  617. }
  618. static inline u16 bnx2x_igu_ack_int(struct bnx2x *bp)
  619. {
  620. u32 igu_addr = (BAR_IGU_INTMEM + IGU_REG_SISR_MDPC_WMASK_LSB_UPPER*8);
  621. u32 result = REG_RD(bp, igu_addr);
  622. DP(NETIF_MSG_INTR, "read 0x%08x from IGU addr 0x%x\n",
  623. result, igu_addr);
  624. barrier();
  625. return result;
  626. }
  627. static inline u16 bnx2x_ack_int(struct bnx2x *bp)
  628. {
  629. barrier();
  630. if (bp->common.int_block == INT_BLOCK_HC)
  631. return bnx2x_hc_ack_int(bp);
  632. else
  633. return bnx2x_igu_ack_int(bp);
  634. }
  635. static inline int bnx2x_has_tx_work_unload(struct bnx2x_fp_txdata *txdata)
  636. {
  637. /* Tell compiler that consumer and producer can change */
  638. barrier();
  639. return txdata->tx_pkt_prod != txdata->tx_pkt_cons;
  640. }
  641. static inline u16 bnx2x_tx_avail(struct bnx2x *bp,
  642. struct bnx2x_fp_txdata *txdata)
  643. {
  644. s16 used;
  645. u16 prod;
  646. u16 cons;
  647. prod = txdata->tx_bd_prod;
  648. cons = txdata->tx_bd_cons;
  649. used = SUB_S16(prod, cons);
  650. #ifdef BNX2X_STOP_ON_ERROR
  651. WARN_ON(used < 0);
  652. WARN_ON(used > txdata->tx_ring_size);
  653. WARN_ON((txdata->tx_ring_size - used) > MAX_TX_AVAIL);
  654. #endif
  655. return (s16)(txdata->tx_ring_size) - used;
  656. }
  657. static inline int bnx2x_tx_queue_has_work(struct bnx2x_fp_txdata *txdata)
  658. {
  659. u16 hw_cons;
  660. /* Tell compiler that status block fields can change */
  661. barrier();
  662. hw_cons = le16_to_cpu(*txdata->tx_cons_sb);
  663. return hw_cons != txdata->tx_pkt_cons;
  664. }
  665. static inline bool bnx2x_has_tx_work(struct bnx2x_fastpath *fp)
  666. {
  667. u8 cos;
  668. for_each_cos_in_tx_queue(fp, cos)
  669. if (bnx2x_tx_queue_has_work(fp->txdata_ptr[cos]))
  670. return true;
  671. return false;
  672. }
  673. #define BNX2X_IS_CQE_COMPLETED(cqe_fp) (cqe_fp->marker == 0x0)
  674. #define BNX2X_SEED_CQE(cqe_fp) (cqe_fp->marker = 0xFFFFFFFF)
  675. static inline int bnx2x_has_rx_work(struct bnx2x_fastpath *fp)
  676. {
  677. u16 cons;
  678. union eth_rx_cqe *cqe;
  679. struct eth_fast_path_rx_cqe *cqe_fp;
  680. cons = RCQ_BD(fp->rx_comp_cons);
  681. cqe = &fp->rx_comp_ring[cons];
  682. cqe_fp = &cqe->fast_path_cqe;
  683. return BNX2X_IS_CQE_COMPLETED(cqe_fp);
  684. }
  685. /**
  686. * bnx2x_tx_disable - disables tx from stack point of view
  687. *
  688. * @bp: driver handle
  689. */
  690. static inline void bnx2x_tx_disable(struct bnx2x *bp)
  691. {
  692. netif_tx_disable(bp->dev);
  693. netif_carrier_off(bp->dev);
  694. }
  695. static inline void bnx2x_free_rx_sge(struct bnx2x *bp,
  696. struct bnx2x_fastpath *fp, u16 index)
  697. {
  698. struct sw_rx_page *sw_buf = &fp->rx_page_ring[index];
  699. struct page *page = sw_buf->page;
  700. struct eth_rx_sge *sge = &fp->rx_sge_ring[index];
  701. /* Skip "next page" elements */
  702. if (!page)
  703. return;
  704. /* Since many fragments can share the same page, make sure to
  705. * only unmap and free the page once.
  706. */
  707. dma_unmap_page(&bp->pdev->dev, dma_unmap_addr(sw_buf, mapping),
  708. SGE_PAGE_SIZE, DMA_FROM_DEVICE);
  709. put_page(page);
  710. sw_buf->page = NULL;
  711. sge->addr_hi = 0;
  712. sge->addr_lo = 0;
  713. }
  714. static inline void bnx2x_del_all_napi_cnic(struct bnx2x *bp)
  715. {
  716. int i;
  717. for_each_rx_queue_cnic(bp, i) {
  718. napi_hash_del(&bnx2x_fp(bp, i, napi));
  719. netif_napi_del(&bnx2x_fp(bp, i, napi));
  720. }
  721. }
  722. static inline void bnx2x_del_all_napi(struct bnx2x *bp)
  723. {
  724. int i;
  725. for_each_eth_queue(bp, i) {
  726. napi_hash_del(&bnx2x_fp(bp, i, napi));
  727. netif_napi_del(&bnx2x_fp(bp, i, napi));
  728. }
  729. }
  730. int bnx2x_set_int_mode(struct bnx2x *bp);
  731. static inline void bnx2x_disable_msi(struct bnx2x *bp)
  732. {
  733. if (bp->flags & USING_MSIX_FLAG) {
  734. pci_disable_msix(bp->pdev);
  735. bp->flags &= ~(USING_MSIX_FLAG | USING_SINGLE_MSIX_FLAG);
  736. } else if (bp->flags & USING_MSI_FLAG) {
  737. pci_disable_msi(bp->pdev);
  738. bp->flags &= ~USING_MSI_FLAG;
  739. }
  740. }
  741. static inline void bnx2x_clear_sge_mask_next_elems(struct bnx2x_fastpath *fp)
  742. {
  743. int i, j;
  744. for (i = 1; i <= NUM_RX_SGE_PAGES; i++) {
  745. int idx = RX_SGE_CNT * i - 1;
  746. for (j = 0; j < 2; j++) {
  747. BIT_VEC64_CLEAR_BIT(fp->sge_mask, idx);
  748. idx--;
  749. }
  750. }
  751. }
  752. static inline void bnx2x_init_sge_ring_bit_mask(struct bnx2x_fastpath *fp)
  753. {
  754. /* Set the mask to all 1-s: it's faster to compare to 0 than to 0xf-s */
  755. memset(fp->sge_mask, 0xff, sizeof(fp->sge_mask));
  756. /* Clear the two last indices in the page to 1:
  757. these are the indices that correspond to the "next" element,
  758. hence will never be indicated and should be removed from
  759. the calculations. */
  760. bnx2x_clear_sge_mask_next_elems(fp);
  761. }
  762. /* note that we are not allocating a new buffer,
  763. * we are just moving one from cons to prod
  764. * we are not creating a new mapping,
  765. * so there is no need to check for dma_mapping_error().
  766. */
  767. static inline void bnx2x_reuse_rx_data(struct bnx2x_fastpath *fp,
  768. u16 cons, u16 prod)
  769. {
  770. struct sw_rx_bd *cons_rx_buf = &fp->rx_buf_ring[cons];
  771. struct sw_rx_bd *prod_rx_buf = &fp->rx_buf_ring[prod];
  772. struct eth_rx_bd *cons_bd = &fp->rx_desc_ring[cons];
  773. struct eth_rx_bd *prod_bd = &fp->rx_desc_ring[prod];
  774. dma_unmap_addr_set(prod_rx_buf, mapping,
  775. dma_unmap_addr(cons_rx_buf, mapping));
  776. prod_rx_buf->data = cons_rx_buf->data;
  777. *prod_bd = *cons_bd;
  778. }
  779. /************************* Init ******************************************/
  780. /* returns func by VN for current port */
  781. static inline int func_by_vn(struct bnx2x *bp, int vn)
  782. {
  783. return 2 * vn + BP_PORT(bp);
  784. }
  785. static inline int bnx2x_config_rss_eth(struct bnx2x *bp, bool config_hash)
  786. {
  787. return bnx2x_rss(bp, &bp->rss_conf_obj, config_hash, true);
  788. }
  789. /**
  790. * bnx2x_func_start - init function
  791. *
  792. * @bp: driver handle
  793. *
  794. * Must be called before sending CLIENT_SETUP for the first client.
  795. */
  796. static inline int bnx2x_func_start(struct bnx2x *bp)
  797. {
  798. struct bnx2x_func_state_params func_params = {NULL};
  799. struct bnx2x_func_start_params *start_params =
  800. &func_params.params.start;
  801. u16 port;
  802. /* Prepare parameters for function state transitions */
  803. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  804. func_params.f_obj = &bp->func_obj;
  805. func_params.cmd = BNX2X_F_CMD_START;
  806. /* Function parameters */
  807. start_params->mf_mode = bp->mf_mode;
  808. start_params->sd_vlan_tag = bp->mf_ov;
  809. /* Configure Ethertype for BD mode */
  810. if (IS_MF_BD(bp)) {
  811. DP(NETIF_MSG_IFUP, "Configuring ethertype 0x88a8 for BD\n");
  812. start_params->sd_vlan_eth_type = ETH_P_8021AD;
  813. REG_WR(bp, PRS_REG_VLAN_TYPE_0, ETH_P_8021AD);
  814. REG_WR(bp, PBF_REG_VLAN_TYPE_0, ETH_P_8021AD);
  815. REG_WR(bp, NIG_REG_LLH_E1HOV_TYPE_1, ETH_P_8021AD);
  816. bnx2x_get_c2s_mapping(bp, start_params->c2s_pri,
  817. &start_params->c2s_pri_default);
  818. start_params->c2s_pri_valid = 1;
  819. DP(NETIF_MSG_IFUP,
  820. "Inner-to-Outer priority: %02x %02x %02x %02x %02x %02x %02x %02x [Default %02x]\n",
  821. start_params->c2s_pri[0], start_params->c2s_pri[1],
  822. start_params->c2s_pri[2], start_params->c2s_pri[3],
  823. start_params->c2s_pri[4], start_params->c2s_pri[5],
  824. start_params->c2s_pri[6], start_params->c2s_pri[7],
  825. start_params->c2s_pri_default);
  826. }
  827. if (CHIP_IS_E2(bp) || CHIP_IS_E3(bp))
  828. start_params->network_cos_mode = STATIC_COS;
  829. else /* CHIP_IS_E1X */
  830. start_params->network_cos_mode = FW_WRR;
  831. if (bp->udp_tunnel_ports[BNX2X_UDP_PORT_VXLAN].count) {
  832. port = bp->udp_tunnel_ports[BNX2X_UDP_PORT_VXLAN].dst_port;
  833. start_params->vxlan_dst_port = port;
  834. }
  835. if (bp->udp_tunnel_ports[BNX2X_UDP_PORT_GENEVE].count) {
  836. port = bp->udp_tunnel_ports[BNX2X_UDP_PORT_GENEVE].dst_port;
  837. start_params->geneve_dst_port = port;
  838. }
  839. start_params->inner_rss = 1;
  840. if (IS_MF_UFP(bp) && BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp)) {
  841. start_params->class_fail_ethtype = ETH_P_FIP;
  842. start_params->class_fail = 1;
  843. start_params->no_added_tags = 1;
  844. }
  845. return bnx2x_func_state_change(bp, &func_params);
  846. }
  847. /**
  848. * bnx2x_set_fw_mac_addr - fill in a MAC address in FW format
  849. *
  850. * @fw_hi: pointer to upper part
  851. * @fw_mid: pointer to middle part
  852. * @fw_lo: pointer to lower part
  853. * @mac: pointer to MAC address
  854. */
  855. static inline void bnx2x_set_fw_mac_addr(__le16 *fw_hi, __le16 *fw_mid,
  856. __le16 *fw_lo, u8 *mac)
  857. {
  858. ((u8 *)fw_hi)[0] = mac[1];
  859. ((u8 *)fw_hi)[1] = mac[0];
  860. ((u8 *)fw_mid)[0] = mac[3];
  861. ((u8 *)fw_mid)[1] = mac[2];
  862. ((u8 *)fw_lo)[0] = mac[5];
  863. ((u8 *)fw_lo)[1] = mac[4];
  864. }
  865. static inline void bnx2x_free_rx_mem_pool(struct bnx2x *bp,
  866. struct bnx2x_alloc_pool *pool)
  867. {
  868. if (!pool->page)
  869. return;
  870. put_page(pool->page);
  871. pool->page = NULL;
  872. }
  873. static inline void bnx2x_free_rx_sge_range(struct bnx2x *bp,
  874. struct bnx2x_fastpath *fp, int last)
  875. {
  876. int i;
  877. if (fp->mode == TPA_MODE_DISABLED)
  878. return;
  879. for (i = 0; i < last; i++)
  880. bnx2x_free_rx_sge(bp, fp, i);
  881. bnx2x_free_rx_mem_pool(bp, &fp->page_pool);
  882. }
  883. static inline void bnx2x_set_next_page_rx_bd(struct bnx2x_fastpath *fp)
  884. {
  885. int i;
  886. for (i = 1; i <= NUM_RX_RINGS; i++) {
  887. struct eth_rx_bd *rx_bd;
  888. rx_bd = &fp->rx_desc_ring[RX_DESC_CNT * i - 2];
  889. rx_bd->addr_hi =
  890. cpu_to_le32(U64_HI(fp->rx_desc_mapping +
  891. BCM_PAGE_SIZE*(i % NUM_RX_RINGS)));
  892. rx_bd->addr_lo =
  893. cpu_to_le32(U64_LO(fp->rx_desc_mapping +
  894. BCM_PAGE_SIZE*(i % NUM_RX_RINGS)));
  895. }
  896. }
  897. /* Statistics ID are global per chip/path, while Client IDs for E1x are per
  898. * port.
  899. */
  900. static inline u8 bnx2x_stats_id(struct bnx2x_fastpath *fp)
  901. {
  902. struct bnx2x *bp = fp->bp;
  903. if (!CHIP_IS_E1x(bp)) {
  904. /* there are special statistics counters for FCoE 136..140 */
  905. if (IS_FCOE_FP(fp))
  906. return bp->cnic_base_cl_id + (bp->pf_num >> 1);
  907. return fp->cl_id;
  908. }
  909. return fp->cl_id + BP_PORT(bp) * FP_SB_MAX_E1x;
  910. }
  911. static inline void bnx2x_init_vlan_mac_fp_objs(struct bnx2x_fastpath *fp,
  912. bnx2x_obj_type obj_type)
  913. {
  914. struct bnx2x *bp = fp->bp;
  915. /* Configure classification DBs */
  916. bnx2x_init_mac_obj(bp, &bnx2x_sp_obj(bp, fp).mac_obj, fp->cl_id,
  917. fp->cid, BP_FUNC(bp), bnx2x_sp(bp, mac_rdata),
  918. bnx2x_sp_mapping(bp, mac_rdata),
  919. BNX2X_FILTER_MAC_PENDING,
  920. &bp->sp_state, obj_type,
  921. &bp->macs_pool);
  922. if (!CHIP_IS_E1x(bp))
  923. bnx2x_init_vlan_obj(bp, &bnx2x_sp_obj(bp, fp).vlan_obj,
  924. fp->cl_id, fp->cid, BP_FUNC(bp),
  925. bnx2x_sp(bp, vlan_rdata),
  926. bnx2x_sp_mapping(bp, vlan_rdata),
  927. BNX2X_FILTER_VLAN_PENDING,
  928. &bp->sp_state, obj_type,
  929. &bp->vlans_pool);
  930. }
  931. /**
  932. * bnx2x_get_path_func_num - get number of active functions
  933. *
  934. * @bp: driver handle
  935. *
  936. * Calculates the number of active (not hidden) functions on the
  937. * current path.
  938. */
  939. static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
  940. {
  941. u8 func_num = 0, i;
  942. /* 57710 has only one function per-port */
  943. if (CHIP_IS_E1(bp))
  944. return 1;
  945. /* Calculate a number of functions enabled on the current
  946. * PATH/PORT.
  947. */
  948. if (CHIP_REV_IS_SLOW(bp)) {
  949. if (IS_MF(bp))
  950. func_num = 4;
  951. else
  952. func_num = 2;
  953. } else {
  954. for (i = 0; i < E1H_FUNC_MAX / 2; i++) {
  955. u32 func_config =
  956. MF_CFG_RD(bp,
  957. func_mf_config[BP_PORT(bp) + 2 * i].
  958. config);
  959. func_num +=
  960. ((func_config & FUNC_MF_CFG_FUNC_HIDE) ? 0 : 1);
  961. }
  962. }
  963. WARN_ON(!func_num);
  964. return func_num;
  965. }
  966. static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
  967. {
  968. /* RX_MODE controlling object */
  969. bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
  970. /* multicast configuration controlling object */
  971. bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
  972. BP_FUNC(bp), BP_FUNC(bp),
  973. bnx2x_sp(bp, mcast_rdata),
  974. bnx2x_sp_mapping(bp, mcast_rdata),
  975. BNX2X_FILTER_MCAST_PENDING, &bp->sp_state,
  976. BNX2X_OBJ_TYPE_RX);
  977. /* Setup CAM credit pools */
  978. bnx2x_init_mac_credit_pool(bp, &bp->macs_pool, BP_FUNC(bp),
  979. bnx2x_get_path_func_num(bp));
  980. bnx2x_init_vlan_credit_pool(bp, &bp->vlans_pool, BP_FUNC(bp),
  981. bnx2x_get_path_func_num(bp));
  982. /* RSS configuration object */
  983. bnx2x_init_rss_config_obj(bp, &bp->rss_conf_obj, bp->fp->cl_id,
  984. bp->fp->cid, BP_FUNC(bp), BP_FUNC(bp),
  985. bnx2x_sp(bp, rss_rdata),
  986. bnx2x_sp_mapping(bp, rss_rdata),
  987. BNX2X_FILTER_RSS_CONF_PENDING, &bp->sp_state,
  988. BNX2X_OBJ_TYPE_RX);
  989. bp->vlan_credit = PF_VLAN_CREDIT_E2(bp, bnx2x_get_path_func_num(bp));
  990. }
  991. static inline u8 bnx2x_fp_qzone_id(struct bnx2x_fastpath *fp)
  992. {
  993. if (CHIP_IS_E1x(fp->bp))
  994. return fp->cl_id + BP_PORT(fp->bp) * ETH_MAX_RX_CLIENTS_E1H;
  995. else
  996. return fp->cl_id;
  997. }
  998. static inline void bnx2x_init_txdata(struct bnx2x *bp,
  999. struct bnx2x_fp_txdata *txdata, u32 cid,
  1000. int txq_index, __le16 *tx_cons_sb,
  1001. struct bnx2x_fastpath *fp)
  1002. {
  1003. txdata->cid = cid;
  1004. txdata->txq_index = txq_index;
  1005. txdata->tx_cons_sb = tx_cons_sb;
  1006. txdata->parent_fp = fp;
  1007. txdata->tx_ring_size = IS_FCOE_FP(fp) ? MAX_TX_AVAIL : bp->tx_ring_size;
  1008. DP(NETIF_MSG_IFUP, "created tx data cid %d, txq %d\n",
  1009. txdata->cid, txdata->txq_index);
  1010. }
  1011. static inline u8 bnx2x_cnic_eth_cl_id(struct bnx2x *bp, u8 cl_idx)
  1012. {
  1013. return bp->cnic_base_cl_id + cl_idx +
  1014. (bp->pf_num >> 1) * BNX2X_MAX_CNIC_ETH_CL_ID_IDX;
  1015. }
  1016. static inline u8 bnx2x_cnic_fw_sb_id(struct bnx2x *bp)
  1017. {
  1018. /* the 'first' id is allocated for the cnic */
  1019. return bp->base_fw_ndsb;
  1020. }
  1021. static inline u8 bnx2x_cnic_igu_sb_id(struct bnx2x *bp)
  1022. {
  1023. return bp->igu_base_sb;
  1024. }
  1025. static inline int bnx2x_clean_tx_queue(struct bnx2x *bp,
  1026. struct bnx2x_fp_txdata *txdata)
  1027. {
  1028. int cnt = 1000;
  1029. while (bnx2x_has_tx_work_unload(txdata)) {
  1030. if (!cnt) {
  1031. BNX2X_ERR("timeout waiting for queue[%d]: txdata->tx_pkt_prod(%d) != txdata->tx_pkt_cons(%d)\n",
  1032. txdata->txq_index, txdata->tx_pkt_prod,
  1033. txdata->tx_pkt_cons);
  1034. #ifdef BNX2X_STOP_ON_ERROR
  1035. bnx2x_panic();
  1036. return -EBUSY;
  1037. #else
  1038. break;
  1039. #endif
  1040. }
  1041. cnt--;
  1042. usleep_range(1000, 2000);
  1043. }
  1044. return 0;
  1045. }
  1046. int bnx2x_get_link_cfg_idx(struct bnx2x *bp);
  1047. static inline void __storm_memset_struct(struct bnx2x *bp,
  1048. u32 addr, size_t size, u32 *data)
  1049. {
  1050. int i;
  1051. for (i = 0; i < size/4; i++)
  1052. REG_WR(bp, addr + (i * 4), data[i]);
  1053. }
  1054. /**
  1055. * bnx2x_wait_sp_comp - wait for the outstanding SP commands.
  1056. *
  1057. * @bp: driver handle
  1058. * @mask: bits that need to be cleared
  1059. */
  1060. static inline bool bnx2x_wait_sp_comp(struct bnx2x *bp, unsigned long mask)
  1061. {
  1062. int tout = 5000; /* Wait for 5 secs tops */
  1063. while (tout--) {
  1064. smp_mb();
  1065. netif_addr_lock_bh(bp->dev);
  1066. if (!(bp->sp_state & mask)) {
  1067. netif_addr_unlock_bh(bp->dev);
  1068. return true;
  1069. }
  1070. netif_addr_unlock_bh(bp->dev);
  1071. usleep_range(1000, 2000);
  1072. }
  1073. smp_mb();
  1074. netif_addr_lock_bh(bp->dev);
  1075. if (bp->sp_state & mask) {
  1076. BNX2X_ERR("Filtering completion timed out. sp_state 0x%lx, mask 0x%lx\n",
  1077. bp->sp_state, mask);
  1078. netif_addr_unlock_bh(bp->dev);
  1079. return false;
  1080. }
  1081. netif_addr_unlock_bh(bp->dev);
  1082. return true;
  1083. }
  1084. /**
  1085. * bnx2x_set_ctx_validation - set CDU context validation values
  1086. *
  1087. * @bp: driver handle
  1088. * @cxt: context of the connection on the host memory
  1089. * @cid: SW CID of the connection to be configured
  1090. */
  1091. void bnx2x_set_ctx_validation(struct bnx2x *bp, struct eth_context *cxt,
  1092. u32 cid);
  1093. void bnx2x_update_coalesce_sb_index(struct bnx2x *bp, u8 fw_sb_id,
  1094. u8 sb_index, u8 disable, u16 usec);
  1095. void bnx2x_acquire_phy_lock(struct bnx2x *bp);
  1096. void bnx2x_release_phy_lock(struct bnx2x *bp);
  1097. /**
  1098. * bnx2x_extract_max_cfg - extract MAX BW part from MF configuration.
  1099. *
  1100. * @bp: driver handle
  1101. * @mf_cfg: MF configuration
  1102. *
  1103. */
  1104. static inline u16 bnx2x_extract_max_cfg(struct bnx2x *bp, u32 mf_cfg)
  1105. {
  1106. u16 max_cfg = (mf_cfg & FUNC_MF_CFG_MAX_BW_MASK) >>
  1107. FUNC_MF_CFG_MAX_BW_SHIFT;
  1108. if (!max_cfg) {
  1109. DP(NETIF_MSG_IFUP | BNX2X_MSG_ETHTOOL,
  1110. "Max BW configured to 0 - using 100 instead\n");
  1111. max_cfg = 100;
  1112. }
  1113. return max_cfg;
  1114. }
  1115. /* checks if HW supports GRO for given MTU */
  1116. static inline bool bnx2x_mtu_allows_gro(int mtu)
  1117. {
  1118. /* gro frags per page */
  1119. int fpp = SGE_PAGE_SIZE / (mtu - ETH_MAX_TPA_HEADER_SIZE);
  1120. /*
  1121. * 1. Number of frags should not grow above MAX_SKB_FRAGS
  1122. * 2. Frag must fit the page
  1123. */
  1124. return mtu <= SGE_PAGE_SIZE && (U_ETH_SGL_SIZE * fpp) <= MAX_SKB_FRAGS;
  1125. }
  1126. /**
  1127. * bnx2x_get_iscsi_info - update iSCSI params according to licensing info.
  1128. *
  1129. * @bp: driver handle
  1130. *
  1131. */
  1132. void bnx2x_get_iscsi_info(struct bnx2x *bp);
  1133. /**
  1134. * bnx2x_link_sync_notify - send notification to other functions.
  1135. *
  1136. * @bp: driver handle
  1137. *
  1138. */
  1139. static inline void bnx2x_link_sync_notify(struct bnx2x *bp)
  1140. {
  1141. int func;
  1142. int vn;
  1143. /* Set the attention towards other drivers on the same port */
  1144. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  1145. if (vn == BP_VN(bp))
  1146. continue;
  1147. func = func_by_vn(bp, vn);
  1148. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_0 +
  1149. (LINK_SYNC_ATTENTION_BIT_FUNC_0 + func)*4, 1);
  1150. }
  1151. }
  1152. /**
  1153. * bnx2x_update_drv_flags - update flags in shmem
  1154. *
  1155. * @bp: driver handle
  1156. * @flags: flags to update
  1157. * @set: set or clear
  1158. *
  1159. */
  1160. static inline void bnx2x_update_drv_flags(struct bnx2x *bp, u32 flags, u32 set)
  1161. {
  1162. if (SHMEM2_HAS(bp, drv_flags)) {
  1163. u32 drv_flags;
  1164. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_DRV_FLAGS);
  1165. drv_flags = SHMEM2_RD(bp, drv_flags);
  1166. if (set)
  1167. SET_FLAGS(drv_flags, flags);
  1168. else
  1169. RESET_FLAGS(drv_flags, flags);
  1170. SHMEM2_WR(bp, drv_flags, drv_flags);
  1171. DP(NETIF_MSG_IFUP, "drv_flags 0x%08x\n", drv_flags);
  1172. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_DRV_FLAGS);
  1173. }
  1174. }
  1175. /**
  1176. * bnx2x_fill_fw_str - Fill buffer with FW version string
  1177. *
  1178. * @bp: driver handle
  1179. * @buf: character buffer to fill with the fw name
  1180. * @buf_len: length of the above buffer
  1181. *
  1182. */
  1183. void bnx2x_fill_fw_str(struct bnx2x *bp, char *buf, size_t buf_len);
  1184. int bnx2x_drain_tx_queues(struct bnx2x *bp);
  1185. void bnx2x_squeeze_objects(struct bnx2x *bp);
  1186. void bnx2x_schedule_sp_rtnl(struct bnx2x*, enum sp_rtnl_flag,
  1187. u32 verbose);
  1188. /**
  1189. * bnx2x_set_os_driver_state - write driver state for management FW usage
  1190. *
  1191. * @bp: driver handle
  1192. * @state: OS_DRIVER_STATE_* value reflecting current driver state
  1193. */
  1194. void bnx2x_set_os_driver_state(struct bnx2x *bp, u32 state);
  1195. /**
  1196. * bnx2x_nvram_read - reads data from nvram [might sleep]
  1197. *
  1198. * @bp: driver handle
  1199. * @offset: byte offset in nvram
  1200. * @ret_buf: pointer to buffer where data is to be stored
  1201. * @buf_size: Length of 'ret_buf' in bytes
  1202. */
  1203. int bnx2x_nvram_read(struct bnx2x *bp, u32 offset, u8 *ret_buf,
  1204. int buf_size);
  1205. #endif /* BNX2X_CMN_H */