bnx2x_cmn.h 21 KB

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