bnx2x_cmn.h 23 KB

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