bnx2x_cmn.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980
  1. /* bnx2x_cmn.h: Broadcom Everest network driver.
  2. *
  3. * Copyright (c) 2007-2010 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/netdevice.h>
  21. #include "bnx2x.h"
  22. extern int num_queues;
  23. /*********************** Interfaces ****************************
  24. * Functions that need to be implemented by each driver version
  25. */
  26. /**
  27. * Initialize link parameters structure variables.
  28. *
  29. * @param bp
  30. * @param load_mode
  31. *
  32. * @return u8
  33. */
  34. u8 bnx2x_initial_phy_init(struct bnx2x *bp, int load_mode);
  35. /**
  36. * Configure hw according to link parameters structure.
  37. *
  38. * @param bp
  39. */
  40. void bnx2x_link_set(struct bnx2x *bp);
  41. /**
  42. * Query link status
  43. *
  44. * @param bp
  45. * @param is_serdes
  46. *
  47. * @return 0 - link is UP
  48. */
  49. u8 bnx2x_link_test(struct bnx2x *bp, u8 is_serdes);
  50. /**
  51. * Handles link status change
  52. *
  53. * @param bp
  54. */
  55. void bnx2x__link_status_update(struct bnx2x *bp);
  56. /**
  57. * Report link status to upper layer
  58. *
  59. * @param bp
  60. *
  61. * @return int
  62. */
  63. void bnx2x_link_report(struct bnx2x *bp);
  64. /**
  65. * MSI-X slowpath interrupt handler
  66. *
  67. * @param irq
  68. * @param dev_instance
  69. *
  70. * @return irqreturn_t
  71. */
  72. irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance);
  73. /**
  74. * non MSI-X interrupt handler
  75. *
  76. * @param irq
  77. * @param dev_instance
  78. *
  79. * @return irqreturn_t
  80. */
  81. irqreturn_t bnx2x_interrupt(int irq, void *dev_instance);
  82. #ifdef BCM_CNIC
  83. /**
  84. * Send command to cnic driver
  85. *
  86. * @param bp
  87. * @param cmd
  88. */
  89. int bnx2x_cnic_notify(struct bnx2x *bp, int cmd);
  90. /**
  91. * Provides cnic information for proper interrupt handling
  92. *
  93. * @param bp
  94. */
  95. void bnx2x_setup_cnic_irq_info(struct bnx2x *bp);
  96. #endif
  97. /**
  98. * Enable HW interrupts.
  99. *
  100. * @param bp
  101. */
  102. void bnx2x_int_enable(struct bnx2x *bp);
  103. /**
  104. * Disable interrupts. This function ensures that there are no
  105. * ISRs or SP DPCs (sp_task) are running after it returns.
  106. *
  107. * @param bp
  108. * @param disable_hw if true, disable HW interrupts.
  109. */
  110. void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw);
  111. /**
  112. * Loads device firmware
  113. *
  114. * @param bp
  115. *
  116. * @return int
  117. */
  118. int bnx2x_init_firmware(struct bnx2x *bp);
  119. /**
  120. * Init HW blocks according to current initialization stage:
  121. * COMMON, PORT or FUNCTION.
  122. *
  123. * @param bp
  124. * @param load_code: COMMON, PORT or FUNCTION
  125. *
  126. * @return int
  127. */
  128. int bnx2x_init_hw(struct bnx2x *bp, u32 load_code);
  129. /**
  130. * Init driver internals:
  131. * - rings
  132. * - status blocks
  133. * - etc.
  134. *
  135. * @param bp
  136. * @param load_code COMMON, PORT or FUNCTION
  137. */
  138. void bnx2x_nic_init(struct bnx2x *bp, u32 load_code);
  139. /**
  140. * Allocate driver's memory.
  141. *
  142. * @param bp
  143. *
  144. * @return int
  145. */
  146. int bnx2x_alloc_mem(struct bnx2x *bp);
  147. /**
  148. * Release driver's memory.
  149. *
  150. * @param bp
  151. */
  152. void bnx2x_free_mem(struct bnx2x *bp);
  153. /**
  154. * Setup eth Client.
  155. *
  156. * @param bp
  157. * @param fp
  158. * @param is_leading
  159. *
  160. * @return int
  161. */
  162. int bnx2x_setup_client(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  163. int is_leading);
  164. /**
  165. * Set number of queues according to mode
  166. *
  167. * @param bp
  168. *
  169. */
  170. void bnx2x_set_num_queues(struct bnx2x *bp);
  171. /**
  172. * Cleanup chip internals:
  173. * - Cleanup MAC configuration.
  174. * - Close clients.
  175. * - etc.
  176. *
  177. * @param bp
  178. * @param unload_mode
  179. */
  180. void bnx2x_chip_cleanup(struct bnx2x *bp, int unload_mode);
  181. /**
  182. * Acquire HW lock.
  183. *
  184. * @param bp
  185. * @param resource Resource bit which was locked
  186. *
  187. * @return int
  188. */
  189. int bnx2x_acquire_hw_lock(struct bnx2x *bp, u32 resource);
  190. /**
  191. * Release HW lock.
  192. *
  193. * @param bp driver handle
  194. * @param resource Resource bit which was locked
  195. *
  196. * @return int
  197. */
  198. int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource);
  199. /**
  200. * Configure eth MAC address in the HW according to the value in
  201. * netdev->dev_addr.
  202. *
  203. * @param bp driver handle
  204. * @param set
  205. */
  206. void bnx2x_set_eth_mac(struct bnx2x *bp, int set);
  207. /**
  208. * Set MAC filtering configurations.
  209. *
  210. * @remarks called with netif_tx_lock from dev_mcast.c
  211. *
  212. * @param dev net_device
  213. */
  214. void bnx2x_set_rx_mode(struct net_device *dev);
  215. /**
  216. * Configure MAC filtering rules in a FW.
  217. *
  218. * @param bp driver handle
  219. */
  220. void bnx2x_set_storm_rx_mode(struct bnx2x *bp);
  221. /* Parity errors related */
  222. void bnx2x_inc_load_cnt(struct bnx2x *bp);
  223. u32 bnx2x_dec_load_cnt(struct bnx2x *bp);
  224. bool bnx2x_chk_parity_attn(struct bnx2x *bp);
  225. bool bnx2x_reset_is_done(struct bnx2x *bp);
  226. void bnx2x_disable_close_the_gate(struct bnx2x *bp);
  227. /**
  228. * Perform statistics handling according to event
  229. *
  230. * @param bp driver handle
  231. * @param event bnx2x_stats_event
  232. */
  233. void bnx2x_stats_handle(struct bnx2x *bp, enum bnx2x_stats_event event);
  234. /**
  235. * Handle ramrods completion
  236. *
  237. * @param fp fastpath handle for the event
  238. * @param rr_cqe eth_rx_cqe
  239. */
  240. void bnx2x_sp_event(struct bnx2x_fastpath *fp, union eth_rx_cqe *rr_cqe);
  241. /**
  242. * Init/halt function before/after sending
  243. * CLIENT_SETUP/CFC_DEL for the first/last client.
  244. *
  245. * @param bp
  246. *
  247. * @return int
  248. */
  249. int bnx2x_func_start(struct bnx2x *bp);
  250. /**
  251. * Prepare ILT configurations according to current driver
  252. * parameters.
  253. *
  254. * @param bp
  255. */
  256. void bnx2x_ilt_set_info(struct bnx2x *bp);
  257. /**
  258. * Set power state to the requested value. Currently only D0 and
  259. * D3hot are supported.
  260. *
  261. * @param bp
  262. * @param state D0 or D3hot
  263. *
  264. * @return int
  265. */
  266. int bnx2x_set_power_state(struct bnx2x *bp, pci_power_t state);
  267. /* dev_close main block */
  268. int bnx2x_nic_unload(struct bnx2x *bp, int unload_mode);
  269. /* dev_open main block */
  270. int bnx2x_nic_load(struct bnx2x *bp, int load_mode);
  271. /* hard_xmit callback */
  272. netdev_tx_t bnx2x_start_xmit(struct sk_buff *skb, struct net_device *dev);
  273. int bnx2x_change_mac_addr(struct net_device *dev, void *p);
  274. /* NAPI poll Rx part */
  275. int bnx2x_rx_int(struct bnx2x_fastpath *fp, int budget);
  276. /* NAPI poll Tx part */
  277. int bnx2x_tx_int(struct bnx2x_fastpath *fp);
  278. /* suspend/resume callbacks */
  279. int bnx2x_suspend(struct pci_dev *pdev, pm_message_t state);
  280. int bnx2x_resume(struct pci_dev *pdev);
  281. /* Release IRQ vectors */
  282. void bnx2x_free_irq(struct bnx2x *bp);
  283. void bnx2x_init_rx_rings(struct bnx2x *bp);
  284. void bnx2x_free_skbs(struct bnx2x *bp);
  285. void bnx2x_netif_stop(struct bnx2x *bp, int disable_hw);
  286. void bnx2x_netif_start(struct bnx2x *bp);
  287. /**
  288. * Fill msix_table, request vectors, update num_queues according
  289. * to number of available vectors
  290. *
  291. * @param bp
  292. *
  293. * @return int
  294. */
  295. int bnx2x_enable_msix(struct bnx2x *bp);
  296. /**
  297. * Request msi mode from OS, updated internals accordingly
  298. *
  299. * @param bp
  300. *
  301. * @return int
  302. */
  303. int bnx2x_enable_msi(struct bnx2x *bp);
  304. /**
  305. * NAPI callback
  306. *
  307. * @param napi
  308. * @param budget
  309. *
  310. * @return int
  311. */
  312. int bnx2x_poll(struct napi_struct *napi, int budget);
  313. /**
  314. * Allocate/release memories outsize main driver structure
  315. *
  316. * @param bp
  317. *
  318. * @return int
  319. */
  320. int __devinit bnx2x_alloc_mem_bp(struct bnx2x *bp);
  321. void bnx2x_free_mem_bp(struct bnx2x *bp);
  322. /**
  323. * Change mtu netdev callback
  324. *
  325. * @param dev
  326. * @param new_mtu
  327. *
  328. * @return int
  329. */
  330. int bnx2x_change_mtu(struct net_device *dev, int new_mtu);
  331. /**
  332. * tx timeout netdev callback
  333. *
  334. * @param dev
  335. * @param new_mtu
  336. *
  337. * @return int
  338. */
  339. void bnx2x_tx_timeout(struct net_device *dev);
  340. #ifdef BCM_VLAN
  341. /**
  342. * vlan rx register netdev callback
  343. *
  344. * @param dev
  345. * @param new_mtu
  346. *
  347. * @return int
  348. */
  349. void bnx2x_vlan_rx_register(struct net_device *dev,
  350. struct vlan_group *vlgrp);
  351. #endif
  352. static inline void bnx2x_update_fpsb_idx(struct bnx2x_fastpath *fp)
  353. {
  354. barrier(); /* status block is written to by the chip */
  355. fp->fp_hc_idx = fp->sb_running_index[SM_RX_ID];
  356. }
  357. static inline void bnx2x_update_rx_prod(struct bnx2x *bp,
  358. struct bnx2x_fastpath *fp,
  359. u16 bd_prod, u16 rx_comp_prod,
  360. u16 rx_sge_prod)
  361. {
  362. struct ustorm_eth_rx_producers rx_prods = {0};
  363. int i;
  364. /* Update producers */
  365. rx_prods.bd_prod = bd_prod;
  366. rx_prods.cqe_prod = rx_comp_prod;
  367. rx_prods.sge_prod = rx_sge_prod;
  368. /*
  369. * Make sure that the BD and SGE data is updated before updating the
  370. * producers since FW might read the BD/SGE right after the producer
  371. * is updated.
  372. * This is only applicable for weak-ordered memory model archs such
  373. * as IA-64. The following barrier is also mandatory since FW will
  374. * assumes BDs must have buffers.
  375. */
  376. wmb();
  377. for (i = 0; i < sizeof(struct ustorm_eth_rx_producers)/4; i++)
  378. REG_WR(bp,
  379. BAR_USTRORM_INTMEM + fp->ustorm_rx_prods_offset + i*4,
  380. ((u32 *)&rx_prods)[i]);
  381. mmiowb(); /* keep prod updates ordered */
  382. DP(NETIF_MSG_RX_STATUS,
  383. "queue[%d]: wrote bd_prod %u cqe_prod %u sge_prod %u\n",
  384. fp->index, bd_prod, rx_comp_prod, rx_sge_prod);
  385. }
  386. static inline void bnx2x_igu_ack_sb_gen(struct bnx2x *bp, u8 igu_sb_id,
  387. u8 segment, u16 index, u8 op,
  388. u8 update, u32 igu_addr)
  389. {
  390. struct igu_regular cmd_data = {0};
  391. cmd_data.sb_id_and_flags =
  392. ((index << IGU_REGULAR_SB_INDEX_SHIFT) |
  393. (segment << IGU_REGULAR_SEGMENT_ACCESS_SHIFT) |
  394. (update << IGU_REGULAR_BUPDATE_SHIFT) |
  395. (op << IGU_REGULAR_ENABLE_INT_SHIFT));
  396. DP(NETIF_MSG_HW, "write 0x%08x to IGU addr 0x%x\n",
  397. cmd_data.sb_id_and_flags, igu_addr);
  398. REG_WR(bp, igu_addr, cmd_data.sb_id_and_flags);
  399. /* Make sure that ACK is written */
  400. mmiowb();
  401. barrier();
  402. }
  403. static inline void bnx2x_igu_clear_sb_gen(struct bnx2x *bp,
  404. u8 idu_sb_id, bool is_Pf)
  405. {
  406. u32 data, ctl, cnt = 100;
  407. u32 igu_addr_data = IGU_REG_COMMAND_REG_32LSB_DATA;
  408. u32 igu_addr_ctl = IGU_REG_COMMAND_REG_CTRL;
  409. u32 igu_addr_ack = IGU_REG_CSTORM_TYPE_0_SB_CLEANUP + (idu_sb_id/32)*4;
  410. u32 sb_bit = 1 << (idu_sb_id%32);
  411. u32 func_encode = BP_FUNC(bp) |
  412. ((is_Pf == true ? 1 : 0) << IGU_FID_ENCODE_IS_PF_SHIFT);
  413. u32 addr_encode = IGU_CMD_E2_PROD_UPD_BASE + idu_sb_id;
  414. /* Not supported in BC mode */
  415. if (CHIP_INT_MODE_IS_BC(bp))
  416. return;
  417. data = (IGU_USE_REGISTER_cstorm_type_0_sb_cleanup
  418. << IGU_REGULAR_CLEANUP_TYPE_SHIFT) |
  419. IGU_REGULAR_CLEANUP_SET |
  420. IGU_REGULAR_BCLEANUP;
  421. ctl = addr_encode << IGU_CTRL_REG_ADDRESS_SHIFT |
  422. func_encode << IGU_CTRL_REG_FID_SHIFT |
  423. IGU_CTRL_CMD_TYPE_WR << IGU_CTRL_REG_TYPE_SHIFT;
  424. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  425. data, igu_addr_data);
  426. REG_WR(bp, igu_addr_data, data);
  427. mmiowb();
  428. barrier();
  429. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  430. ctl, igu_addr_ctl);
  431. REG_WR(bp, igu_addr_ctl, ctl);
  432. mmiowb();
  433. barrier();
  434. /* wait for clean up to finish */
  435. while (!(REG_RD(bp, igu_addr_ack) & sb_bit) && --cnt)
  436. msleep(20);
  437. if (!(REG_RD(bp, igu_addr_ack) & sb_bit)) {
  438. DP(NETIF_MSG_HW, "Unable to finish IGU cleanup: "
  439. "idu_sb_id %d offset %d bit %d (cnt %d)\n",
  440. idu_sb_id, idu_sb_id/32, idu_sb_id%32, cnt);
  441. }
  442. }
  443. static inline void bnx2x_hc_ack_sb(struct bnx2x *bp, u8 sb_id,
  444. u8 storm, u16 index, u8 op, u8 update)
  445. {
  446. u32 hc_addr = (HC_REG_COMMAND_REG + BP_PORT(bp)*32 +
  447. COMMAND_REG_INT_ACK);
  448. struct igu_ack_register igu_ack;
  449. igu_ack.status_block_index = index;
  450. igu_ack.sb_id_and_flags =
  451. ((sb_id << IGU_ACK_REGISTER_STATUS_BLOCK_ID_SHIFT) |
  452. (storm << IGU_ACK_REGISTER_STORM_ID_SHIFT) |
  453. (update << IGU_ACK_REGISTER_UPDATE_INDEX_SHIFT) |
  454. (op << IGU_ACK_REGISTER_INTERRUPT_MODE_SHIFT));
  455. DP(BNX2X_MSG_OFF, "write 0x%08x to HC addr 0x%x\n",
  456. (*(u32 *)&igu_ack), hc_addr);
  457. REG_WR(bp, hc_addr, (*(u32 *)&igu_ack));
  458. /* Make sure that ACK is written */
  459. mmiowb();
  460. barrier();
  461. }
  462. static inline void bnx2x_igu_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 segment,
  463. u16 index, u8 op, u8 update)
  464. {
  465. u32 igu_addr = BAR_IGU_INTMEM + (IGU_CMD_INT_ACK_BASE + igu_sb_id)*8;
  466. bnx2x_igu_ack_sb_gen(bp, igu_sb_id, segment, index, op, update,
  467. igu_addr);
  468. }
  469. static inline void bnx2x_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 storm,
  470. u16 index, u8 op, u8 update)
  471. {
  472. if (bp->common.int_block == INT_BLOCK_HC)
  473. bnx2x_hc_ack_sb(bp, igu_sb_id, storm, index, op, update);
  474. else {
  475. u8 segment;
  476. if (CHIP_INT_MODE_IS_BC(bp))
  477. segment = storm;
  478. else if (igu_sb_id != bp->igu_dsb_id)
  479. segment = IGU_SEG_ACCESS_DEF;
  480. else if (storm == ATTENTION_ID)
  481. segment = IGU_SEG_ACCESS_ATTN;
  482. else
  483. segment = IGU_SEG_ACCESS_DEF;
  484. bnx2x_igu_ack_sb(bp, igu_sb_id, segment, index, op, update);
  485. }
  486. }
  487. static inline u16 bnx2x_hc_ack_int(struct bnx2x *bp)
  488. {
  489. u32 hc_addr = (HC_REG_COMMAND_REG + BP_PORT(bp)*32 +
  490. COMMAND_REG_SIMD_MASK);
  491. u32 result = REG_RD(bp, hc_addr);
  492. DP(BNX2X_MSG_OFF, "read 0x%08x from HC addr 0x%x\n",
  493. result, hc_addr);
  494. barrier();
  495. return result;
  496. }
  497. static inline u16 bnx2x_igu_ack_int(struct bnx2x *bp)
  498. {
  499. u32 igu_addr = (BAR_IGU_INTMEM + IGU_REG_SISR_MDPC_WMASK_LSB_UPPER*8);
  500. u32 result = REG_RD(bp, igu_addr);
  501. DP(NETIF_MSG_HW, "read 0x%08x from IGU addr 0x%x\n",
  502. result, igu_addr);
  503. barrier();
  504. return result;
  505. }
  506. static inline u16 bnx2x_ack_int(struct bnx2x *bp)
  507. {
  508. barrier();
  509. if (bp->common.int_block == INT_BLOCK_HC)
  510. return bnx2x_hc_ack_int(bp);
  511. else
  512. return bnx2x_igu_ack_int(bp);
  513. }
  514. static inline int bnx2x_has_tx_work_unload(struct bnx2x_fastpath *fp)
  515. {
  516. /* Tell compiler that consumer and producer can change */
  517. barrier();
  518. return fp->tx_pkt_prod != fp->tx_pkt_cons;
  519. }
  520. static inline u16 bnx2x_tx_avail(struct bnx2x_fastpath *fp)
  521. {
  522. s16 used;
  523. u16 prod;
  524. u16 cons;
  525. prod = fp->tx_bd_prod;
  526. cons = fp->tx_bd_cons;
  527. /* NUM_TX_RINGS = number of "next-page" entries
  528. It will be used as a threshold */
  529. used = SUB_S16(prod, cons) + (s16)NUM_TX_RINGS;
  530. #ifdef BNX2X_STOP_ON_ERROR
  531. WARN_ON(used < 0);
  532. WARN_ON(used > fp->bp->tx_ring_size);
  533. WARN_ON((fp->bp->tx_ring_size - used) > MAX_TX_AVAIL);
  534. #endif
  535. return (s16)(fp->bp->tx_ring_size) - used;
  536. }
  537. static inline int bnx2x_has_tx_work(struct bnx2x_fastpath *fp)
  538. {
  539. u16 hw_cons;
  540. /* Tell compiler that status block fields can change */
  541. barrier();
  542. hw_cons = le16_to_cpu(*fp->tx_cons_sb);
  543. return hw_cons != fp->tx_pkt_cons;
  544. }
  545. static inline int bnx2x_has_rx_work(struct bnx2x_fastpath *fp)
  546. {
  547. u16 rx_cons_sb;
  548. /* Tell compiler that status block fields can change */
  549. barrier();
  550. rx_cons_sb = le16_to_cpu(*fp->rx_cons_sb);
  551. if ((rx_cons_sb & MAX_RCQ_DESC_CNT) == MAX_RCQ_DESC_CNT)
  552. rx_cons_sb++;
  553. return (fp->rx_comp_cons != rx_cons_sb);
  554. }
  555. /**
  556. * disables tx from stack point of view
  557. *
  558. * @param bp
  559. */
  560. static inline void bnx2x_tx_disable(struct bnx2x *bp)
  561. {
  562. netif_tx_disable(bp->dev);
  563. netif_carrier_off(bp->dev);
  564. }
  565. static inline void bnx2x_free_rx_sge(struct bnx2x *bp,
  566. struct bnx2x_fastpath *fp, u16 index)
  567. {
  568. struct sw_rx_page *sw_buf = &fp->rx_page_ring[index];
  569. struct page *page = sw_buf->page;
  570. struct eth_rx_sge *sge = &fp->rx_sge_ring[index];
  571. /* Skip "next page" elements */
  572. if (!page)
  573. return;
  574. dma_unmap_page(&bp->pdev->dev, dma_unmap_addr(sw_buf, mapping),
  575. SGE_PAGE_SIZE*PAGES_PER_SGE, DMA_FROM_DEVICE);
  576. __free_pages(page, PAGES_PER_SGE_SHIFT);
  577. sw_buf->page = NULL;
  578. sge->addr_hi = 0;
  579. sge->addr_lo = 0;
  580. }
  581. static inline void bnx2x_add_all_napi(struct bnx2x *bp)
  582. {
  583. int i;
  584. /* Add NAPI objects */
  585. for_each_queue(bp, i)
  586. netif_napi_add(bp->dev, &bnx2x_fp(bp, i, napi),
  587. bnx2x_poll, BNX2X_NAPI_WEIGHT);
  588. }
  589. static inline void bnx2x_del_all_napi(struct bnx2x *bp)
  590. {
  591. int i;
  592. for_each_queue(bp, i)
  593. netif_napi_del(&bnx2x_fp(bp, i, napi));
  594. }
  595. static inline void bnx2x_disable_msi(struct bnx2x *bp)
  596. {
  597. if (bp->flags & USING_MSIX_FLAG) {
  598. pci_disable_msix(bp->pdev);
  599. bp->flags &= ~USING_MSIX_FLAG;
  600. } else if (bp->flags & USING_MSI_FLAG) {
  601. pci_disable_msi(bp->pdev);
  602. bp->flags &= ~USING_MSI_FLAG;
  603. }
  604. }
  605. static inline int bnx2x_calc_num_queues(struct bnx2x *bp)
  606. {
  607. return num_queues ?
  608. min_t(int, num_queues, BNX2X_MAX_QUEUES(bp)) :
  609. min_t(int, num_online_cpus(), BNX2X_MAX_QUEUES(bp));
  610. }
  611. static inline void bnx2x_clear_sge_mask_next_elems(struct bnx2x_fastpath *fp)
  612. {
  613. int i, j;
  614. for (i = 1; i <= NUM_RX_SGE_PAGES; i++) {
  615. int idx = RX_SGE_CNT * i - 1;
  616. for (j = 0; j < 2; j++) {
  617. SGE_MASK_CLEAR_BIT(fp, idx);
  618. idx--;
  619. }
  620. }
  621. }
  622. static inline void bnx2x_init_sge_ring_bit_mask(struct bnx2x_fastpath *fp)
  623. {
  624. /* Set the mask to all 1-s: it's faster to compare to 0 than to 0xf-s */
  625. memset(fp->sge_mask, 0xff,
  626. (NUM_RX_SGE >> RX_SGE_MASK_ELEM_SHIFT)*sizeof(u64));
  627. /* Clear the two last indices in the page to 1:
  628. these are the indices that correspond to the "next" element,
  629. hence will never be indicated and should be removed from
  630. the calculations. */
  631. bnx2x_clear_sge_mask_next_elems(fp);
  632. }
  633. static inline int bnx2x_alloc_rx_sge(struct bnx2x *bp,
  634. struct bnx2x_fastpath *fp, u16 index)
  635. {
  636. struct page *page = alloc_pages(GFP_ATOMIC, PAGES_PER_SGE_SHIFT);
  637. struct sw_rx_page *sw_buf = &fp->rx_page_ring[index];
  638. struct eth_rx_sge *sge = &fp->rx_sge_ring[index];
  639. dma_addr_t mapping;
  640. if (unlikely(page == NULL))
  641. return -ENOMEM;
  642. mapping = dma_map_page(&bp->pdev->dev, page, 0,
  643. SGE_PAGE_SIZE*PAGES_PER_SGE, DMA_FROM_DEVICE);
  644. if (unlikely(dma_mapping_error(&bp->pdev->dev, mapping))) {
  645. __free_pages(page, PAGES_PER_SGE_SHIFT);
  646. return -ENOMEM;
  647. }
  648. sw_buf->page = page;
  649. dma_unmap_addr_set(sw_buf, mapping, mapping);
  650. sge->addr_hi = cpu_to_le32(U64_HI(mapping));
  651. sge->addr_lo = cpu_to_le32(U64_LO(mapping));
  652. return 0;
  653. }
  654. static inline int bnx2x_alloc_rx_skb(struct bnx2x *bp,
  655. struct bnx2x_fastpath *fp, u16 index)
  656. {
  657. struct sk_buff *skb;
  658. struct sw_rx_bd *rx_buf = &fp->rx_buf_ring[index];
  659. struct eth_rx_bd *rx_bd = &fp->rx_desc_ring[index];
  660. dma_addr_t mapping;
  661. skb = netdev_alloc_skb(bp->dev, bp->rx_buf_size);
  662. if (unlikely(skb == NULL))
  663. return -ENOMEM;
  664. mapping = dma_map_single(&bp->pdev->dev, skb->data, bp->rx_buf_size,
  665. DMA_FROM_DEVICE);
  666. if (unlikely(dma_mapping_error(&bp->pdev->dev, mapping))) {
  667. dev_kfree_skb(skb);
  668. return -ENOMEM;
  669. }
  670. rx_buf->skb = skb;
  671. dma_unmap_addr_set(rx_buf, mapping, mapping);
  672. rx_bd->addr_hi = cpu_to_le32(U64_HI(mapping));
  673. rx_bd->addr_lo = cpu_to_le32(U64_LO(mapping));
  674. return 0;
  675. }
  676. /* note that we are not allocating a new skb,
  677. * we are just moving one from cons to prod
  678. * we are not creating a new mapping,
  679. * so there is no need to check for dma_mapping_error().
  680. */
  681. static inline void bnx2x_reuse_rx_skb(struct bnx2x_fastpath *fp,
  682. u16 cons, u16 prod)
  683. {
  684. struct bnx2x *bp = fp->bp;
  685. struct sw_rx_bd *cons_rx_buf = &fp->rx_buf_ring[cons];
  686. struct sw_rx_bd *prod_rx_buf = &fp->rx_buf_ring[prod];
  687. struct eth_rx_bd *cons_bd = &fp->rx_desc_ring[cons];
  688. struct eth_rx_bd *prod_bd = &fp->rx_desc_ring[prod];
  689. dma_sync_single_for_device(&bp->pdev->dev,
  690. dma_unmap_addr(cons_rx_buf, mapping),
  691. RX_COPY_THRESH, DMA_FROM_DEVICE);
  692. prod_rx_buf->skb = cons_rx_buf->skb;
  693. dma_unmap_addr_set(prod_rx_buf, mapping,
  694. dma_unmap_addr(cons_rx_buf, mapping));
  695. *prod_bd = *cons_bd;
  696. }
  697. static inline void bnx2x_free_rx_sge_range(struct bnx2x *bp,
  698. struct bnx2x_fastpath *fp, int last)
  699. {
  700. int i;
  701. for (i = 0; i < last; i++)
  702. bnx2x_free_rx_sge(bp, fp, i);
  703. }
  704. static inline void bnx2x_free_tpa_pool(struct bnx2x *bp,
  705. struct bnx2x_fastpath *fp, int last)
  706. {
  707. int i;
  708. for (i = 0; i < last; i++) {
  709. struct sw_rx_bd *rx_buf = &(fp->tpa_pool[i]);
  710. struct sk_buff *skb = rx_buf->skb;
  711. if (skb == NULL) {
  712. DP(NETIF_MSG_IFDOWN, "tpa bin %d empty on free\n", i);
  713. continue;
  714. }
  715. if (fp->tpa_state[i] == BNX2X_TPA_START)
  716. dma_unmap_single(&bp->pdev->dev,
  717. dma_unmap_addr(rx_buf, mapping),
  718. bp->rx_buf_size, DMA_FROM_DEVICE);
  719. dev_kfree_skb(skb);
  720. rx_buf->skb = NULL;
  721. }
  722. }
  723. static inline void bnx2x_init_tx_rings(struct bnx2x *bp)
  724. {
  725. int i, j;
  726. for_each_queue(bp, j) {
  727. struct bnx2x_fastpath *fp = &bp->fp[j];
  728. for (i = 1; i <= NUM_TX_RINGS; i++) {
  729. struct eth_tx_next_bd *tx_next_bd =
  730. &fp->tx_desc_ring[TX_DESC_CNT * i - 1].next_bd;
  731. tx_next_bd->addr_hi =
  732. cpu_to_le32(U64_HI(fp->tx_desc_mapping +
  733. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  734. tx_next_bd->addr_lo =
  735. cpu_to_le32(U64_LO(fp->tx_desc_mapping +
  736. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  737. }
  738. SET_FLAG(fp->tx_db.data.header.header, DOORBELL_HDR_DB_TYPE, 1);
  739. fp->tx_db.data.zero_fill1 = 0;
  740. fp->tx_db.data.prod = 0;
  741. fp->tx_pkt_prod = 0;
  742. fp->tx_pkt_cons = 0;
  743. fp->tx_bd_prod = 0;
  744. fp->tx_bd_cons = 0;
  745. fp->tx_pkt = 0;
  746. }
  747. }
  748. static inline void bnx2x_set_next_page_rx_bd(struct bnx2x_fastpath *fp)
  749. {
  750. int i;
  751. for (i = 1; i <= NUM_RX_RINGS; i++) {
  752. struct eth_rx_bd *rx_bd;
  753. rx_bd = &fp->rx_desc_ring[RX_DESC_CNT * i - 2];
  754. rx_bd->addr_hi =
  755. cpu_to_le32(U64_HI(fp->rx_desc_mapping +
  756. BCM_PAGE_SIZE*(i % NUM_RX_RINGS)));
  757. rx_bd->addr_lo =
  758. cpu_to_le32(U64_LO(fp->rx_desc_mapping +
  759. BCM_PAGE_SIZE*(i % NUM_RX_RINGS)));
  760. }
  761. }
  762. static inline void bnx2x_set_next_page_sgl(struct bnx2x_fastpath *fp)
  763. {
  764. int i;
  765. for (i = 1; i <= NUM_RX_SGE_PAGES; i++) {
  766. struct eth_rx_sge *sge;
  767. sge = &fp->rx_sge_ring[RX_SGE_CNT * i - 2];
  768. sge->addr_hi =
  769. cpu_to_le32(U64_HI(fp->rx_sge_mapping +
  770. BCM_PAGE_SIZE*(i % NUM_RX_SGE_PAGES)));
  771. sge->addr_lo =
  772. cpu_to_le32(U64_LO(fp->rx_sge_mapping +
  773. BCM_PAGE_SIZE*(i % NUM_RX_SGE_PAGES)));
  774. }
  775. }
  776. static inline void bnx2x_set_next_page_rx_cq(struct bnx2x_fastpath *fp)
  777. {
  778. int i;
  779. for (i = 1; i <= NUM_RCQ_RINGS; i++) {
  780. struct eth_rx_cqe_next_page *nextpg;
  781. nextpg = (struct eth_rx_cqe_next_page *)
  782. &fp->rx_comp_ring[RCQ_DESC_CNT * i - 1];
  783. nextpg->addr_hi =
  784. cpu_to_le32(U64_HI(fp->rx_comp_mapping +
  785. BCM_PAGE_SIZE*(i % NUM_RCQ_RINGS)));
  786. nextpg->addr_lo =
  787. cpu_to_le32(U64_LO(fp->rx_comp_mapping +
  788. BCM_PAGE_SIZE*(i % NUM_RCQ_RINGS)));
  789. }
  790. }
  791. static inline void __storm_memset_struct(struct bnx2x *bp,
  792. u32 addr, size_t size, u32 *data)
  793. {
  794. int i;
  795. for (i = 0; i < size/4; i++)
  796. REG_WR(bp, addr + (i * 4), data[i]);
  797. }
  798. static inline void storm_memset_mac_filters(struct bnx2x *bp,
  799. struct tstorm_eth_mac_filter_config *mac_filters,
  800. u16 abs_fid)
  801. {
  802. size_t size = sizeof(struct tstorm_eth_mac_filter_config);
  803. u32 addr = BAR_TSTRORM_INTMEM +
  804. TSTORM_MAC_FILTER_CONFIG_OFFSET(abs_fid);
  805. __storm_memset_struct(bp, addr, size, (u32 *)mac_filters);
  806. }
  807. static inline void storm_memset_cmng(struct bnx2x *bp,
  808. struct cmng_struct_per_port *cmng,
  809. u8 port)
  810. {
  811. size_t size = sizeof(struct cmng_struct_per_port);
  812. u32 addr = BAR_XSTRORM_INTMEM +
  813. XSTORM_CMNG_PER_PORT_VARS_OFFSET(port);
  814. __storm_memset_struct(bp, addr, size, (u32 *)cmng);
  815. }
  816. /* HW Lock for shared dual port PHYs */
  817. void bnx2x_acquire_phy_lock(struct bnx2x *bp);
  818. void bnx2x_release_phy_lock(struct bnx2x *bp);
  819. #endif /* BNX2X_CMN_H */