bnx2x_cmn.h 32 KB

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