bnx2x_cmn.h 33 KB

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