bnx2x_cmn.h 37 KB

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