bnx2x_cmn.h 42 KB

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