bnx2x_cmn.h 32 KB

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