bnx2x_cmn.h 41 KB

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