bnx2x_cmn.h 25 KB

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