bnx2x_cmn.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772
  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_ack_sb(struct bnx2x *bp, u8 sb_id,
  325. u8 storm, u16 index, u8 op, u8 update)
  326. {
  327. u32 hc_addr = (HC_REG_COMMAND_REG + BP_PORT(bp)*32 +
  328. COMMAND_REG_INT_ACK);
  329. struct igu_ack_register igu_ack;
  330. igu_ack.status_block_index = index;
  331. igu_ack.sb_id_and_flags =
  332. ((sb_id << IGU_ACK_REGISTER_STATUS_BLOCK_ID_SHIFT) |
  333. (storm << IGU_ACK_REGISTER_STORM_ID_SHIFT) |
  334. (update << IGU_ACK_REGISTER_UPDATE_INDEX_SHIFT) |
  335. (op << IGU_ACK_REGISTER_INTERRUPT_MODE_SHIFT));
  336. DP(BNX2X_MSG_OFF, "write 0x%08x to HC addr 0x%x\n",
  337. (*(u32 *)&igu_ack), hc_addr);
  338. REG_WR(bp, hc_addr, (*(u32 *)&igu_ack));
  339. /* Make sure that ACK is written */
  340. mmiowb();
  341. barrier();
  342. }
  343. static inline u16 bnx2x_ack_int(struct bnx2x *bp)
  344. {
  345. u32 hc_addr = (HC_REG_COMMAND_REG + BP_PORT(bp)*32 +
  346. COMMAND_REG_SIMD_MASK);
  347. u32 result = REG_RD(bp, hc_addr);
  348. DP(BNX2X_MSG_OFF, "read 0x%08x from HC addr 0x%x\n",
  349. result, hc_addr);
  350. return result;
  351. }
  352. /*
  353. * fast path service functions
  354. */
  355. static inline int bnx2x_has_tx_work_unload(struct bnx2x_fastpath *fp)
  356. {
  357. /* Tell compiler that consumer and producer can change */
  358. barrier();
  359. return fp->tx_pkt_prod != fp->tx_pkt_cons;
  360. }
  361. static inline u16 bnx2x_tx_avail(struct bnx2x_fastpath *fp)
  362. {
  363. s16 used;
  364. u16 prod;
  365. u16 cons;
  366. prod = fp->tx_bd_prod;
  367. cons = fp->tx_bd_cons;
  368. /* NUM_TX_RINGS = number of "next-page" entries
  369. It will be used as a threshold */
  370. used = SUB_S16(prod, cons) + (s16)NUM_TX_RINGS;
  371. #ifdef BNX2X_STOP_ON_ERROR
  372. WARN_ON(used < 0);
  373. WARN_ON(used > fp->bp->tx_ring_size);
  374. WARN_ON((fp->bp->tx_ring_size - used) > MAX_TX_AVAIL);
  375. #endif
  376. return (s16)(fp->bp->tx_ring_size) - used;
  377. }
  378. static inline int bnx2x_has_tx_work(struct bnx2x_fastpath *fp)
  379. {
  380. u16 hw_cons;
  381. /* Tell compiler that status block fields can change */
  382. barrier();
  383. hw_cons = le16_to_cpu(*fp->tx_cons_sb);
  384. return hw_cons != fp->tx_pkt_cons;
  385. }
  386. static inline int bnx2x_has_rx_work(struct bnx2x_fastpath *fp)
  387. {
  388. u16 rx_cons_sb;
  389. /* Tell compiler that status block fields can change */
  390. barrier();
  391. rx_cons_sb = le16_to_cpu(*fp->rx_cons_sb);
  392. if ((rx_cons_sb & MAX_RCQ_DESC_CNT) == MAX_RCQ_DESC_CNT)
  393. rx_cons_sb++;
  394. return (fp->rx_comp_cons != rx_cons_sb);
  395. }
  396. static inline void bnx2x_free_rx_sge(struct bnx2x *bp,
  397. struct bnx2x_fastpath *fp, u16 index)
  398. {
  399. struct sw_rx_page *sw_buf = &fp->rx_page_ring[index];
  400. struct page *page = sw_buf->page;
  401. struct eth_rx_sge *sge = &fp->rx_sge_ring[index];
  402. /* Skip "next page" elements */
  403. if (!page)
  404. return;
  405. dma_unmap_page(&bp->pdev->dev, dma_unmap_addr(sw_buf, mapping),
  406. SGE_PAGE_SIZE*PAGES_PER_SGE, PCI_DMA_FROMDEVICE);
  407. __free_pages(page, PAGES_PER_SGE_SHIFT);
  408. sw_buf->page = NULL;
  409. sge->addr_hi = 0;
  410. sge->addr_lo = 0;
  411. }
  412. static inline void bnx2x_clear_sge_mask_next_elems(struct bnx2x_fastpath *fp)
  413. {
  414. int i, j;
  415. for (i = 1; i <= NUM_RX_SGE_PAGES; i++) {
  416. int idx = RX_SGE_CNT * i - 1;
  417. for (j = 0; j < 2; j++) {
  418. SGE_MASK_CLEAR_BIT(fp, idx);
  419. idx--;
  420. }
  421. }
  422. }
  423. static inline void bnx2x_init_sge_ring_bit_mask(struct bnx2x_fastpath *fp)
  424. {
  425. /* Set the mask to all 1-s: it's faster to compare to 0 than to 0xf-s */
  426. memset(fp->sge_mask, 0xff,
  427. (NUM_RX_SGE >> RX_SGE_MASK_ELEM_SHIFT)*sizeof(u64));
  428. /* Clear the two last indices in the page to 1:
  429. these are the indices that correspond to the "next" element,
  430. hence will never be indicated and should be removed from
  431. the calculations. */
  432. bnx2x_clear_sge_mask_next_elems(fp);
  433. }
  434. static inline int bnx2x_alloc_rx_sge(struct bnx2x *bp,
  435. struct bnx2x_fastpath *fp, u16 index)
  436. {
  437. struct page *page = alloc_pages(GFP_ATOMIC, PAGES_PER_SGE_SHIFT);
  438. struct sw_rx_page *sw_buf = &fp->rx_page_ring[index];
  439. struct eth_rx_sge *sge = &fp->rx_sge_ring[index];
  440. dma_addr_t mapping;
  441. if (unlikely(page == NULL))
  442. return -ENOMEM;
  443. mapping = dma_map_page(&bp->pdev->dev, page, 0,
  444. SGE_PAGE_SIZE*PAGES_PER_SGE, DMA_FROM_DEVICE);
  445. if (unlikely(dma_mapping_error(&bp->pdev->dev, mapping))) {
  446. __free_pages(page, PAGES_PER_SGE_SHIFT);
  447. return -ENOMEM;
  448. }
  449. sw_buf->page = page;
  450. dma_unmap_addr_set(sw_buf, mapping, mapping);
  451. sge->addr_hi = cpu_to_le32(U64_HI(mapping));
  452. sge->addr_lo = cpu_to_le32(U64_LO(mapping));
  453. return 0;
  454. }
  455. static inline int bnx2x_alloc_rx_skb(struct bnx2x *bp,
  456. struct bnx2x_fastpath *fp, u16 index)
  457. {
  458. struct sk_buff *skb;
  459. struct sw_rx_bd *rx_buf = &fp->rx_buf_ring[index];
  460. struct eth_rx_bd *rx_bd = &fp->rx_desc_ring[index];
  461. dma_addr_t mapping;
  462. skb = netdev_alloc_skb(bp->dev, bp->rx_buf_size);
  463. if (unlikely(skb == NULL))
  464. return -ENOMEM;
  465. mapping = dma_map_single(&bp->pdev->dev, skb->data, bp->rx_buf_size,
  466. DMA_FROM_DEVICE);
  467. if (unlikely(dma_mapping_error(&bp->pdev->dev, mapping))) {
  468. dev_kfree_skb(skb);
  469. return -ENOMEM;
  470. }
  471. rx_buf->skb = skb;
  472. dma_unmap_addr_set(rx_buf, mapping, mapping);
  473. rx_bd->addr_hi = cpu_to_le32(U64_HI(mapping));
  474. rx_bd->addr_lo = cpu_to_le32(U64_LO(mapping));
  475. return 0;
  476. }
  477. /* note that we are not allocating a new skb,
  478. * we are just moving one from cons to prod
  479. * we are not creating a new mapping,
  480. * so there is no need to check for dma_mapping_error().
  481. */
  482. static inline void bnx2x_reuse_rx_skb(struct bnx2x_fastpath *fp,
  483. struct sk_buff *skb, u16 cons, u16 prod)
  484. {
  485. struct bnx2x *bp = fp->bp;
  486. struct sw_rx_bd *cons_rx_buf = &fp->rx_buf_ring[cons];
  487. struct sw_rx_bd *prod_rx_buf = &fp->rx_buf_ring[prod];
  488. struct eth_rx_bd *cons_bd = &fp->rx_desc_ring[cons];
  489. struct eth_rx_bd *prod_bd = &fp->rx_desc_ring[prod];
  490. dma_sync_single_for_device(&bp->pdev->dev,
  491. dma_unmap_addr(cons_rx_buf, mapping),
  492. RX_COPY_THRESH, DMA_FROM_DEVICE);
  493. prod_rx_buf->skb = cons_rx_buf->skb;
  494. dma_unmap_addr_set(prod_rx_buf, mapping,
  495. dma_unmap_addr(cons_rx_buf, mapping));
  496. *prod_bd = *cons_bd;
  497. }
  498. static inline void bnx2x_free_rx_sge_range(struct bnx2x *bp,
  499. struct bnx2x_fastpath *fp, int last)
  500. {
  501. int i;
  502. for (i = 0; i < last; i++)
  503. bnx2x_free_rx_sge(bp, fp, i);
  504. }
  505. static inline void bnx2x_free_tpa_pool(struct bnx2x *bp,
  506. struct bnx2x_fastpath *fp, int last)
  507. {
  508. int i;
  509. for (i = 0; i < last; i++) {
  510. struct sw_rx_bd *rx_buf = &(fp->tpa_pool[i]);
  511. struct sk_buff *skb = rx_buf->skb;
  512. if (skb == NULL) {
  513. DP(NETIF_MSG_IFDOWN, "tpa bin %d empty on free\n", i);
  514. continue;
  515. }
  516. if (fp->tpa_state[i] == BNX2X_TPA_START)
  517. dma_unmap_single(&bp->pdev->dev,
  518. dma_unmap_addr(rx_buf, mapping),
  519. bp->rx_buf_size, DMA_FROM_DEVICE);
  520. dev_kfree_skb(skb);
  521. rx_buf->skb = NULL;
  522. }
  523. }
  524. static inline void bnx2x_init_tx_rings(struct bnx2x *bp)
  525. {
  526. int i, j;
  527. for_each_queue(bp, j) {
  528. struct bnx2x_fastpath *fp = &bp->fp[j];
  529. for (i = 1; i <= NUM_TX_RINGS; i++) {
  530. struct eth_tx_next_bd *tx_next_bd =
  531. &fp->tx_desc_ring[TX_DESC_CNT * i - 1].next_bd;
  532. tx_next_bd->addr_hi =
  533. cpu_to_le32(U64_HI(fp->tx_desc_mapping +
  534. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  535. tx_next_bd->addr_lo =
  536. cpu_to_le32(U64_LO(fp->tx_desc_mapping +
  537. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  538. }
  539. SET_FLAG(fp->tx_db.data.header.header, DOORBELL_HDR_DB_TYPE, 1);
  540. fp->tx_db.data.zero_fill1 = 0;
  541. fp->tx_db.data.prod = 0;
  542. fp->tx_pkt_prod = 0;
  543. fp->tx_pkt_cons = 0;
  544. fp->tx_bd_prod = 0;
  545. fp->tx_bd_cons = 0;
  546. fp->tx_pkt = 0;
  547. }
  548. }
  549. static inline void bnx2x_set_next_page_rx_bd(struct bnx2x_fastpath *fp)
  550. {
  551. int i;
  552. for (i = 1; i <= NUM_RX_RINGS; i++) {
  553. struct eth_rx_bd *rx_bd;
  554. rx_bd = &fp->rx_desc_ring[RX_DESC_CNT * i - 2];
  555. rx_bd->addr_hi =
  556. cpu_to_le32(U64_HI(fp->rx_desc_mapping +
  557. BCM_PAGE_SIZE*(i % NUM_RX_RINGS)));
  558. rx_bd->addr_lo =
  559. cpu_to_le32(U64_LO(fp->rx_desc_mapping +
  560. BCM_PAGE_SIZE*(i % NUM_RX_RINGS)));
  561. }
  562. }
  563. static inline void bnx2x_set_next_page_sgl(struct bnx2x_fastpath *fp)
  564. {
  565. int i;
  566. for (i = 1; i <= NUM_RX_SGE_PAGES; i++) {
  567. struct eth_rx_sge *sge;
  568. sge = &fp->rx_sge_ring[RX_SGE_CNT * i - 2];
  569. sge->addr_hi =
  570. cpu_to_le32(U64_HI(fp->rx_sge_mapping +
  571. BCM_PAGE_SIZE*(i % NUM_RX_SGE_PAGES)));
  572. sge->addr_lo =
  573. cpu_to_le32(U64_LO(fp->rx_sge_mapping +
  574. BCM_PAGE_SIZE*(i % NUM_RX_SGE_PAGES)));
  575. }
  576. }
  577. static inline void bnx2x_set_next_page_rx_cq(struct bnx2x_fastpath *fp)
  578. {
  579. int i;
  580. for (i = 1; i <= NUM_RCQ_RINGS; i++) {
  581. struct eth_rx_cqe_next_page *nextpg;
  582. nextpg = (struct eth_rx_cqe_next_page *)
  583. &fp->rx_comp_ring[RCQ_DESC_CNT * i - 1];
  584. nextpg->addr_hi =
  585. cpu_to_le32(U64_HI(fp->rx_comp_mapping +
  586. BCM_PAGE_SIZE*(i % NUM_RCQ_RINGS)));
  587. nextpg->addr_lo =
  588. cpu_to_le32(U64_LO(fp->rx_comp_mapping +
  589. BCM_PAGE_SIZE*(i % NUM_RCQ_RINGS)));
  590. }
  591. }
  592. static inline void __storm_memset_struct(struct bnx2x *bp,
  593. u32 addr, size_t size, u32 *data)
  594. {
  595. int i;
  596. for (i = 0; i < size/4; i++)
  597. REG_WR(bp, addr + (i * 4), data[i]);
  598. }
  599. static inline void storm_memset_mac_filters(struct bnx2x *bp,
  600. struct tstorm_eth_mac_filter_config *mac_filters,
  601. u16 abs_fid)
  602. {
  603. size_t size = sizeof(struct tstorm_eth_mac_filter_config);
  604. u32 addr = BAR_TSTRORM_INTMEM +
  605. TSTORM_MAC_FILTER_CONFIG_OFFSET(abs_fid);
  606. __storm_memset_struct(bp, addr, size, (u32 *)mac_filters);
  607. }
  608. static inline void storm_memset_cmng(struct bnx2x *bp,
  609. struct cmng_struct_per_port *cmng,
  610. u8 port)
  611. {
  612. size_t size = sizeof(struct cmng_struct_per_port);
  613. u32 addr = BAR_XSTRORM_INTMEM +
  614. XSTORM_CMNG_PER_PORT_VARS_OFFSET(port);
  615. __storm_memset_struct(bp, addr, size, (u32 *)cmng);
  616. }
  617. /* HW Lock for shared dual port PHYs */
  618. void bnx2x_acquire_phy_lock(struct bnx2x *bp);
  619. void bnx2x_release_phy_lock(struct bnx2x *bp);
  620. void bnx2x_link_report(struct bnx2x *bp);
  621. int bnx2x_rx_int(struct bnx2x_fastpath *fp, int budget);
  622. int bnx2x_tx_int(struct bnx2x_fastpath *fp);
  623. void bnx2x_init_rx_rings(struct bnx2x *bp);
  624. netdev_tx_t bnx2x_start_xmit(struct sk_buff *skb, struct net_device *dev);
  625. int bnx2x_change_mac_addr(struct net_device *dev, void *p);
  626. void bnx2x_tx_timeout(struct net_device *dev);
  627. void bnx2x_vlan_rx_register(struct net_device *dev, struct vlan_group *vlgrp);
  628. void bnx2x_netif_start(struct bnx2x *bp);
  629. void bnx2x_netif_stop(struct bnx2x *bp, int disable_hw);
  630. void bnx2x_free_irq(struct bnx2x *bp, bool disable_only);
  631. int bnx2x_suspend(struct pci_dev *pdev, pm_message_t state);
  632. int bnx2x_resume(struct pci_dev *pdev);
  633. void bnx2x_free_skbs(struct bnx2x *bp);
  634. int bnx2x_change_mtu(struct net_device *dev, int new_mtu);
  635. int bnx2x_nic_unload(struct bnx2x *bp, int unload_mode);
  636. int bnx2x_nic_load(struct bnx2x *bp, int load_mode);
  637. int bnx2x_set_power_state(struct bnx2x *bp, pci_power_t state);
  638. /**
  639. * Allocate/release memories outsize main driver structure
  640. *
  641. * @param bp
  642. *
  643. * @return int
  644. */
  645. int __devinit bnx2x_alloc_mem_bp(struct bnx2x *bp);
  646. void bnx2x_free_mem_bp(struct bnx2x *bp);
  647. #define BNX2X_FW_IP_HDR_ALIGN_PAD 2 /* FW places hdr with this padding */
  648. #endif /* BNX2X_CMN_H */