bnx2x_cmn.h 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403
  1. /* bnx2x_cmn.h: QLogic Everest network driver.
  2. *
  3. * Copyright (c) 2007-2013 Broadcom Corporation
  4. * Copyright (c) 2014 QLogic Corporation
  5. * All rights reserved
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation.
  10. *
  11. * Maintained by: Ariel Elior <ariel.elior@qlogic.com>
  12. * Written by: Eliezer Tamir
  13. * Based on code from Michael Chan's bnx2 driver
  14. * UDP CSUM errata workaround by Arik Gendelman
  15. * Slowpath and fastpath rework by Vladislav Zolotarov
  16. * Statistics and Link management by Yitchak Gertner
  17. *
  18. */
  19. #ifndef BNX2X_CMN_H
  20. #define BNX2X_CMN_H
  21. #include <linux/types.h>
  22. #include <linux/pci.h>
  23. #include <linux/netdevice.h>
  24. #include <linux/etherdevice.h>
  25. #include <linux/irq.h>
  26. #include "bnx2x.h"
  27. #include "bnx2x_sriov.h"
  28. /* This is used as a replacement for an MCP if it's not present */
  29. extern int bnx2x_load_count[2][3]; /* per-path: 0-common, 1-port0, 2-port1 */
  30. extern int bnx2x_num_queues;
  31. /************************ Macros ********************************/
  32. #define BNX2X_PCI_FREE(x, y, size) \
  33. do { \
  34. if (x) { \
  35. dma_free_coherent(&bp->pdev->dev, size, (void *)x, y); \
  36. x = NULL; \
  37. y = 0; \
  38. } \
  39. } while (0)
  40. #define BNX2X_FREE(x) \
  41. do { \
  42. if (x) { \
  43. kfree((void *)x); \
  44. x = NULL; \
  45. } \
  46. } while (0)
  47. #define BNX2X_PCI_ALLOC(y, size) \
  48. ({ \
  49. void *x = dma_zalloc_coherent(&bp->pdev->dev, size, y, GFP_KERNEL); \
  50. if (x) \
  51. DP(NETIF_MSG_HW, \
  52. "BNX2X_PCI_ALLOC: Physical %Lx Virtual %p\n", \
  53. (unsigned long long)(*y), x); \
  54. x; \
  55. })
  56. #define BNX2X_PCI_FALLOC(y, size) \
  57. ({ \
  58. void *x = dma_alloc_coherent(&bp->pdev->dev, size, y, GFP_KERNEL); \
  59. if (x) { \
  60. memset(x, 0xff, size); \
  61. DP(NETIF_MSG_HW, \
  62. "BNX2X_PCI_FALLOC: Physical %Lx Virtual %p\n", \
  63. (unsigned long long)(*y), x); \
  64. } \
  65. x; \
  66. })
  67. /*********************** Interfaces ****************************
  68. * Functions that need to be implemented by each driver version
  69. */
  70. /* Init */
  71. /**
  72. * bnx2x_send_unload_req - request unload mode from the MCP.
  73. *
  74. * @bp: driver handle
  75. * @unload_mode: requested function's unload mode
  76. *
  77. * Return unload mode returned by the MCP: COMMON, PORT or FUNC.
  78. */
  79. u32 bnx2x_send_unload_req(struct bnx2x *bp, int unload_mode);
  80. /**
  81. * bnx2x_send_unload_done - send UNLOAD_DONE command to the MCP.
  82. *
  83. * @bp: driver handle
  84. * @keep_link: true iff link should be kept up
  85. */
  86. void bnx2x_send_unload_done(struct bnx2x *bp, bool keep_link);
  87. /**
  88. * bnx2x_config_rss_pf - configure RSS parameters in a PF.
  89. *
  90. * @bp: driver handle
  91. * @rss_obj: RSS object to use
  92. * @ind_table: indirection table to configure
  93. * @config_hash: re-configure RSS hash keys configuration
  94. * @enable: enabled or disabled configuration
  95. */
  96. int bnx2x_rss(struct bnx2x *bp, struct bnx2x_rss_config_obj *rss_obj,
  97. bool config_hash, bool enable);
  98. /**
  99. * bnx2x__init_func_obj - init function object
  100. *
  101. * @bp: driver handle
  102. *
  103. * Initializes the Function Object with the appropriate
  104. * parameters which include a function slow path driver
  105. * interface.
  106. */
  107. void bnx2x__init_func_obj(struct bnx2x *bp);
  108. /**
  109. * bnx2x_setup_queue - setup eth queue.
  110. *
  111. * @bp: driver handle
  112. * @fp: pointer to the fastpath structure
  113. * @leading: boolean
  114. *
  115. */
  116. int bnx2x_setup_queue(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  117. bool leading);
  118. /**
  119. * bnx2x_setup_leading - bring up a leading eth queue.
  120. *
  121. * @bp: driver handle
  122. */
  123. int bnx2x_setup_leading(struct bnx2x *bp);
  124. /**
  125. * bnx2x_fw_command - send the MCP a request
  126. *
  127. * @bp: driver handle
  128. * @command: request
  129. * @param: request's parameter
  130. *
  131. * block until there is a reply
  132. */
  133. u32 bnx2x_fw_command(struct bnx2x *bp, u32 command, u32 param);
  134. /**
  135. * bnx2x_initial_phy_init - initialize link parameters structure variables.
  136. *
  137. * @bp: driver handle
  138. * @load_mode: current mode
  139. */
  140. int bnx2x_initial_phy_init(struct bnx2x *bp, int load_mode);
  141. /**
  142. * bnx2x_link_set - configure hw according to link parameters structure.
  143. *
  144. * @bp: driver handle
  145. */
  146. void bnx2x_link_set(struct bnx2x *bp);
  147. /**
  148. * bnx2x_force_link_reset - Forces link reset, and put the PHY
  149. * in reset as well.
  150. *
  151. * @bp: driver handle
  152. */
  153. void bnx2x_force_link_reset(struct bnx2x *bp);
  154. /**
  155. * bnx2x_link_test - query link status.
  156. *
  157. * @bp: driver handle
  158. * @is_serdes: bool
  159. *
  160. * Returns 0 if link is UP.
  161. */
  162. u8 bnx2x_link_test(struct bnx2x *bp, u8 is_serdes);
  163. /**
  164. * bnx2x_drv_pulse - write driver pulse to shmem
  165. *
  166. * @bp: driver handle
  167. *
  168. * writes the value in bp->fw_drv_pulse_wr_seq to drv_pulse mbox
  169. * in the shmem.
  170. */
  171. void bnx2x_drv_pulse(struct bnx2x *bp);
  172. /**
  173. * bnx2x_igu_ack_sb - update IGU with current SB value
  174. *
  175. * @bp: driver handle
  176. * @igu_sb_id: SB id
  177. * @segment: SB segment
  178. * @index: SB index
  179. * @op: SB operation
  180. * @update: is HW update required
  181. */
  182. void bnx2x_igu_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 segment,
  183. u16 index, u8 op, u8 update);
  184. /* Disable transactions from chip to host */
  185. void bnx2x_pf_disable(struct bnx2x *bp);
  186. int bnx2x_pretend_func(struct bnx2x *bp, u16 pretend_func_val);
  187. /**
  188. * bnx2x__link_status_update - handles link status change.
  189. *
  190. * @bp: driver handle
  191. */
  192. void bnx2x__link_status_update(struct bnx2x *bp);
  193. /**
  194. * bnx2x_link_report - report link status to upper layer.
  195. *
  196. * @bp: driver handle
  197. */
  198. void bnx2x_link_report(struct bnx2x *bp);
  199. /* None-atomic version of bnx2x_link_report() */
  200. void __bnx2x_link_report(struct bnx2x *bp);
  201. /**
  202. * bnx2x_get_mf_speed - calculate MF speed.
  203. *
  204. * @bp: driver handle
  205. *
  206. * Takes into account current linespeed and MF configuration.
  207. */
  208. u16 bnx2x_get_mf_speed(struct bnx2x *bp);
  209. /**
  210. * bnx2x_msix_sp_int - MSI-X slowpath interrupt handler
  211. *
  212. * @irq: irq number
  213. * @dev_instance: private instance
  214. */
  215. irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance);
  216. /**
  217. * bnx2x_interrupt - non MSI-X interrupt handler
  218. *
  219. * @irq: irq number
  220. * @dev_instance: private instance
  221. */
  222. irqreturn_t bnx2x_interrupt(int irq, void *dev_instance);
  223. /**
  224. * bnx2x_cnic_notify - send command to cnic driver
  225. *
  226. * @bp: driver handle
  227. * @cmd: command
  228. */
  229. int bnx2x_cnic_notify(struct bnx2x *bp, int cmd);
  230. /**
  231. * bnx2x_setup_cnic_irq_info - provides cnic with IRQ information
  232. *
  233. * @bp: driver handle
  234. */
  235. void bnx2x_setup_cnic_irq_info(struct bnx2x *bp);
  236. /**
  237. * bnx2x_setup_cnic_info - provides cnic with updated info
  238. *
  239. * @bp: driver handle
  240. */
  241. void bnx2x_setup_cnic_info(struct bnx2x *bp);
  242. /**
  243. * bnx2x_int_enable - enable HW interrupts.
  244. *
  245. * @bp: driver handle
  246. */
  247. void bnx2x_int_enable(struct bnx2x *bp);
  248. /**
  249. * bnx2x_int_disable_sync - disable interrupts.
  250. *
  251. * @bp: driver handle
  252. * @disable_hw: true, disable HW interrupts.
  253. *
  254. * This function ensures that there are no
  255. * ISRs or SP DPCs (sp_task) are running after it returns.
  256. */
  257. void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw);
  258. /**
  259. * bnx2x_nic_init_cnic - init driver internals for cnic.
  260. *
  261. * @bp: driver handle
  262. * @load_code: COMMON, PORT or FUNCTION
  263. *
  264. * Initializes:
  265. * - rings
  266. * - status blocks
  267. * - etc.
  268. */
  269. void bnx2x_nic_init_cnic(struct bnx2x *bp);
  270. /**
  271. * bnx2x_preirq_nic_init - init driver internals.
  272. *
  273. * @bp: driver handle
  274. *
  275. * Initializes:
  276. * - fastpath object
  277. * - fastpath rings
  278. * etc.
  279. */
  280. void bnx2x_pre_irq_nic_init(struct bnx2x *bp);
  281. /**
  282. * bnx2x_postirq_nic_init - init driver internals.
  283. *
  284. * @bp: driver handle
  285. * @load_code: COMMON, PORT or FUNCTION
  286. *
  287. * Initializes:
  288. * - status blocks
  289. * - slowpath rings
  290. * - etc.
  291. */
  292. void bnx2x_post_irq_nic_init(struct bnx2x *bp, u32 load_code);
  293. /**
  294. * bnx2x_alloc_mem_cnic - allocate driver's memory for cnic.
  295. *
  296. * @bp: driver handle
  297. */
  298. int bnx2x_alloc_mem_cnic(struct bnx2x *bp);
  299. /**
  300. * bnx2x_alloc_mem - allocate driver's memory.
  301. *
  302. * @bp: driver handle
  303. */
  304. int bnx2x_alloc_mem(struct bnx2x *bp);
  305. /**
  306. * bnx2x_free_mem_cnic - release driver's memory for cnic.
  307. *
  308. * @bp: driver handle
  309. */
  310. void bnx2x_free_mem_cnic(struct bnx2x *bp);
  311. /**
  312. * bnx2x_free_mem - release driver's memory.
  313. *
  314. * @bp: driver handle
  315. */
  316. void bnx2x_free_mem(struct bnx2x *bp);
  317. /**
  318. * bnx2x_set_num_queues - set number of queues according to mode.
  319. *
  320. * @bp: driver handle
  321. */
  322. void bnx2x_set_num_queues(struct bnx2x *bp);
  323. /**
  324. * bnx2x_chip_cleanup - cleanup chip internals.
  325. *
  326. * @bp: driver handle
  327. * @unload_mode: COMMON, PORT, FUNCTION
  328. * @keep_link: true iff link should be kept up.
  329. *
  330. * - Cleanup MAC configuration.
  331. * - Closes clients.
  332. * - etc.
  333. */
  334. void bnx2x_chip_cleanup(struct bnx2x *bp, int unload_mode, bool keep_link);
  335. /**
  336. * bnx2x_acquire_hw_lock - acquire HW lock.
  337. *
  338. * @bp: driver handle
  339. * @resource: resource bit which was locked
  340. */
  341. int bnx2x_acquire_hw_lock(struct bnx2x *bp, u32 resource);
  342. /**
  343. * bnx2x_release_hw_lock - release HW lock.
  344. *
  345. * @bp: driver handle
  346. * @resource: resource bit which was locked
  347. */
  348. int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource);
  349. /**
  350. * bnx2x_release_leader_lock - release recovery leader lock
  351. *
  352. * @bp: driver handle
  353. */
  354. int bnx2x_release_leader_lock(struct bnx2x *bp);
  355. /**
  356. * bnx2x_set_eth_mac - configure eth MAC address in the HW
  357. *
  358. * @bp: driver handle
  359. * @set: set or clear
  360. *
  361. * Configures according to the value in netdev->dev_addr.
  362. */
  363. int bnx2x_set_eth_mac(struct bnx2x *bp, bool set);
  364. /**
  365. * bnx2x_set_rx_mode - set MAC filtering configurations.
  366. *
  367. * @dev: netdevice
  368. *
  369. * called with netif_tx_lock from dev_mcast.c
  370. * If bp->state is OPEN, should be called with
  371. * netif_addr_lock_bh()
  372. */
  373. void bnx2x_set_rx_mode_inner(struct bnx2x *bp);
  374. /* Parity errors related */
  375. void bnx2x_set_pf_load(struct bnx2x *bp);
  376. bool bnx2x_clear_pf_load(struct bnx2x *bp);
  377. bool bnx2x_chk_parity_attn(struct bnx2x *bp, bool *global, bool print);
  378. bool bnx2x_reset_is_done(struct bnx2x *bp, int engine);
  379. void bnx2x_set_reset_in_progress(struct bnx2x *bp);
  380. void bnx2x_set_reset_global(struct bnx2x *bp);
  381. void bnx2x_disable_close_the_gate(struct bnx2x *bp);
  382. int bnx2x_init_hw_func_cnic(struct bnx2x *bp);
  383. /**
  384. * bnx2x_sp_event - handle ramrods completion.
  385. *
  386. * @fp: fastpath handle for the event
  387. * @rr_cqe: eth_rx_cqe
  388. */
  389. void bnx2x_sp_event(struct bnx2x_fastpath *fp, union eth_rx_cqe *rr_cqe);
  390. /**
  391. * bnx2x_ilt_set_info - prepare ILT configurations.
  392. *
  393. * @bp: driver handle
  394. */
  395. void bnx2x_ilt_set_info(struct bnx2x *bp);
  396. /**
  397. * bnx2x_ilt_set_cnic_info - prepare ILT configurations for SRC
  398. * and TM.
  399. *
  400. * @bp: driver handle
  401. */
  402. void bnx2x_ilt_set_info_cnic(struct bnx2x *bp);
  403. /**
  404. * bnx2x_dcbx_init - initialize dcbx protocol.
  405. *
  406. * @bp: driver handle
  407. */
  408. void bnx2x_dcbx_init(struct bnx2x *bp, bool update_shmem);
  409. /**
  410. * bnx2x_set_power_state - set power state to the requested value.
  411. *
  412. * @bp: driver handle
  413. * @state: required state D0 or D3hot
  414. *
  415. * Currently only D0 and D3hot are supported.
  416. */
  417. int bnx2x_set_power_state(struct bnx2x *bp, pci_power_t state);
  418. /**
  419. * bnx2x_update_max_mf_config - update MAX part of MF configuration in HW.
  420. *
  421. * @bp: driver handle
  422. * @value: new value
  423. */
  424. void bnx2x_update_max_mf_config(struct bnx2x *bp, u32 value);
  425. /* Error handling */
  426. void bnx2x_fw_dump_lvl(struct bnx2x *bp, const char *lvl);
  427. /* dev_close main block */
  428. int bnx2x_nic_unload(struct bnx2x *bp, int unload_mode, bool keep_link);
  429. /* dev_open main block */
  430. int bnx2x_nic_load(struct bnx2x *bp, int load_mode);
  431. /* hard_xmit callback */
  432. netdev_tx_t bnx2x_start_xmit(struct sk_buff *skb, struct net_device *dev);
  433. /* setup_tc callback */
  434. int bnx2x_setup_tc(struct net_device *dev, u8 num_tc);
  435. int bnx2x_get_vf_config(struct net_device *dev, int vf,
  436. struct ifla_vf_info *ivi);
  437. int bnx2x_set_vf_mac(struct net_device *dev, int queue, u8 *mac);
  438. int bnx2x_set_vf_vlan(struct net_device *netdev, int vf, u16 vlan, u8 qos);
  439. /* select_queue callback */
  440. u16 bnx2x_select_queue(struct net_device *dev, struct sk_buff *skb,
  441. void *accel_priv, select_queue_fallback_t fallback);
  442. static inline void bnx2x_update_rx_prod(struct bnx2x *bp,
  443. struct bnx2x_fastpath *fp,
  444. u16 bd_prod, u16 rx_comp_prod,
  445. u16 rx_sge_prod)
  446. {
  447. struct ustorm_eth_rx_producers rx_prods = {0};
  448. u32 i;
  449. /* Update producers */
  450. rx_prods.bd_prod = bd_prod;
  451. rx_prods.cqe_prod = rx_comp_prod;
  452. rx_prods.sge_prod = rx_sge_prod;
  453. /* Make sure that the BD and SGE data is updated before updating the
  454. * producers since FW might read the BD/SGE right after the producer
  455. * is updated.
  456. * This is only applicable for weak-ordered memory model archs such
  457. * as IA-64. The following barrier is also mandatory since FW will
  458. * assumes BDs must have buffers.
  459. */
  460. wmb();
  461. for (i = 0; i < sizeof(rx_prods)/4; i++)
  462. REG_WR(bp, fp->ustorm_rx_prods_offset + i*4,
  463. ((u32 *)&rx_prods)[i]);
  464. mmiowb(); /* keep prod updates ordered */
  465. DP(NETIF_MSG_RX_STATUS,
  466. "queue[%d]: wrote bd_prod %u cqe_prod %u sge_prod %u\n",
  467. fp->index, bd_prod, rx_comp_prod, rx_sge_prod);
  468. }
  469. /* reload helper */
  470. int bnx2x_reload_if_running(struct net_device *dev);
  471. int bnx2x_change_mac_addr(struct net_device *dev, void *p);
  472. /* NAPI poll Tx part */
  473. int bnx2x_tx_int(struct bnx2x *bp, struct bnx2x_fp_txdata *txdata);
  474. /* suspend/resume callbacks */
  475. int bnx2x_suspend(struct pci_dev *pdev, pm_message_t state);
  476. int bnx2x_resume(struct pci_dev *pdev);
  477. /* Release IRQ vectors */
  478. void bnx2x_free_irq(struct bnx2x *bp);
  479. void bnx2x_free_fp_mem(struct bnx2x *bp);
  480. void bnx2x_init_rx_rings(struct bnx2x *bp);
  481. void bnx2x_init_rx_rings_cnic(struct bnx2x *bp);
  482. void bnx2x_free_skbs(struct bnx2x *bp);
  483. void bnx2x_netif_stop(struct bnx2x *bp, int disable_hw);
  484. void bnx2x_netif_start(struct bnx2x *bp);
  485. int bnx2x_load_cnic(struct bnx2x *bp);
  486. /**
  487. * bnx2x_enable_msix - set msix configuration.
  488. *
  489. * @bp: driver handle
  490. *
  491. * fills msix_table, requests vectors, updates num_queues
  492. * according to number of available vectors.
  493. */
  494. int bnx2x_enable_msix(struct bnx2x *bp);
  495. /**
  496. * bnx2x_enable_msi - request msi mode from OS, updated internals accordingly
  497. *
  498. * @bp: driver handle
  499. */
  500. int bnx2x_enable_msi(struct bnx2x *bp);
  501. /**
  502. * bnx2x_low_latency_recv - LL callback
  503. *
  504. * @napi: napi structure
  505. */
  506. int bnx2x_low_latency_recv(struct napi_struct *napi);
  507. /**
  508. * bnx2x_alloc_mem_bp - allocate memories outsize main driver structure
  509. *
  510. * @bp: driver handle
  511. */
  512. int bnx2x_alloc_mem_bp(struct bnx2x *bp);
  513. /**
  514. * bnx2x_free_mem_bp - release memories outsize main driver structure
  515. *
  516. * @bp: driver handle
  517. */
  518. void bnx2x_free_mem_bp(struct bnx2x *bp);
  519. /**
  520. * bnx2x_change_mtu - change mtu netdev callback
  521. *
  522. * @dev: net device
  523. * @new_mtu: requested mtu
  524. *
  525. */
  526. int bnx2x_change_mtu(struct net_device *dev, int new_mtu);
  527. #ifdef NETDEV_FCOE_WWNN
  528. /**
  529. * bnx2x_fcoe_get_wwn - return the requested WWN value for this port
  530. *
  531. * @dev: net_device
  532. * @wwn: output buffer
  533. * @type: WWN type: NETDEV_FCOE_WWNN (node) or NETDEV_FCOE_WWPN (port)
  534. *
  535. */
  536. int bnx2x_fcoe_get_wwn(struct net_device *dev, u64 *wwn, int type);
  537. #endif
  538. netdev_features_t bnx2x_fix_features(struct net_device *dev,
  539. netdev_features_t features);
  540. int bnx2x_set_features(struct net_device *dev, netdev_features_t features);
  541. /**
  542. * bnx2x_tx_timeout - tx timeout netdev callback
  543. *
  544. * @dev: net device
  545. */
  546. void bnx2x_tx_timeout(struct net_device *dev);
  547. /** bnx2x_get_c2s_mapping - read inner-to-outer vlan configuration
  548. * c2s_map should have BNX2X_MAX_PRIORITY entries.
  549. * @bp: driver handle
  550. * @c2s_map: should have BNX2X_MAX_PRIORITY entries for mapping
  551. * @c2s_default: entry for non-tagged configuration
  552. */
  553. void bnx2x_get_c2s_mapping(struct bnx2x *bp, u8 *c2s_map, u8 *c2s_default);
  554. /*********************** Inlines **********************************/
  555. /*********************** Fast path ********************************/
  556. static inline void bnx2x_update_fpsb_idx(struct bnx2x_fastpath *fp)
  557. {
  558. barrier(); /* status block is written to by the chip */
  559. fp->fp_hc_idx = fp->sb_running_index[SM_RX_ID];
  560. }
  561. static inline void bnx2x_igu_ack_sb_gen(struct bnx2x *bp, u8 igu_sb_id,
  562. u8 segment, u16 index, u8 op,
  563. u8 update, u32 igu_addr)
  564. {
  565. struct igu_regular cmd_data = {0};
  566. cmd_data.sb_id_and_flags =
  567. ((index << IGU_REGULAR_SB_INDEX_SHIFT) |
  568. (segment << IGU_REGULAR_SEGMENT_ACCESS_SHIFT) |
  569. (update << IGU_REGULAR_BUPDATE_SHIFT) |
  570. (op << IGU_REGULAR_ENABLE_INT_SHIFT));
  571. DP(NETIF_MSG_INTR, "write 0x%08x to IGU addr 0x%x\n",
  572. cmd_data.sb_id_and_flags, igu_addr);
  573. REG_WR(bp, igu_addr, cmd_data.sb_id_and_flags);
  574. /* Make sure that ACK is written */
  575. mmiowb();
  576. barrier();
  577. }
  578. static inline void bnx2x_hc_ack_sb(struct bnx2x *bp, u8 sb_id,
  579. u8 storm, u16 index, u8 op, u8 update)
  580. {
  581. u32 hc_addr = (HC_REG_COMMAND_REG + BP_PORT(bp)*32 +
  582. COMMAND_REG_INT_ACK);
  583. struct igu_ack_register igu_ack;
  584. igu_ack.status_block_index = index;
  585. igu_ack.sb_id_and_flags =
  586. ((sb_id << IGU_ACK_REGISTER_STATUS_BLOCK_ID_SHIFT) |
  587. (storm << IGU_ACK_REGISTER_STORM_ID_SHIFT) |
  588. (update << IGU_ACK_REGISTER_UPDATE_INDEX_SHIFT) |
  589. (op << IGU_ACK_REGISTER_INTERRUPT_MODE_SHIFT));
  590. REG_WR(bp, hc_addr, (*(u32 *)&igu_ack));
  591. /* Make sure that ACK is written */
  592. mmiowb();
  593. barrier();
  594. }
  595. static inline void bnx2x_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 storm,
  596. u16 index, u8 op, u8 update)
  597. {
  598. if (bp->common.int_block == INT_BLOCK_HC)
  599. bnx2x_hc_ack_sb(bp, igu_sb_id, storm, index, op, update);
  600. else {
  601. u8 segment;
  602. if (CHIP_INT_MODE_IS_BC(bp))
  603. segment = storm;
  604. else if (igu_sb_id != bp->igu_dsb_id)
  605. segment = IGU_SEG_ACCESS_DEF;
  606. else if (storm == ATTENTION_ID)
  607. segment = IGU_SEG_ACCESS_ATTN;
  608. else
  609. segment = IGU_SEG_ACCESS_DEF;
  610. bnx2x_igu_ack_sb(bp, igu_sb_id, segment, index, op, update);
  611. }
  612. }
  613. static inline u16 bnx2x_hc_ack_int(struct bnx2x *bp)
  614. {
  615. u32 hc_addr = (HC_REG_COMMAND_REG + BP_PORT(bp)*32 +
  616. COMMAND_REG_SIMD_MASK);
  617. u32 result = REG_RD(bp, hc_addr);
  618. barrier();
  619. return result;
  620. }
  621. static inline u16 bnx2x_igu_ack_int(struct bnx2x *bp)
  622. {
  623. u32 igu_addr = (BAR_IGU_INTMEM + IGU_REG_SISR_MDPC_WMASK_LSB_UPPER*8);
  624. u32 result = REG_RD(bp, igu_addr);
  625. DP(NETIF_MSG_INTR, "read 0x%08x from IGU addr 0x%x\n",
  626. result, igu_addr);
  627. barrier();
  628. return result;
  629. }
  630. static inline u16 bnx2x_ack_int(struct bnx2x *bp)
  631. {
  632. barrier();
  633. if (bp->common.int_block == INT_BLOCK_HC)
  634. return bnx2x_hc_ack_int(bp);
  635. else
  636. return bnx2x_igu_ack_int(bp);
  637. }
  638. static inline int bnx2x_has_tx_work_unload(struct bnx2x_fp_txdata *txdata)
  639. {
  640. /* Tell compiler that consumer and producer can change */
  641. barrier();
  642. return txdata->tx_pkt_prod != txdata->tx_pkt_cons;
  643. }
  644. static inline u16 bnx2x_tx_avail(struct bnx2x *bp,
  645. struct bnx2x_fp_txdata *txdata)
  646. {
  647. s16 used;
  648. u16 prod;
  649. u16 cons;
  650. prod = txdata->tx_bd_prod;
  651. cons = txdata->tx_bd_cons;
  652. used = SUB_S16(prod, cons);
  653. #ifdef BNX2X_STOP_ON_ERROR
  654. WARN_ON(used < 0);
  655. WARN_ON(used > txdata->tx_ring_size);
  656. WARN_ON((txdata->tx_ring_size - used) > MAX_TX_AVAIL);
  657. #endif
  658. return (s16)(txdata->tx_ring_size) - used;
  659. }
  660. static inline int bnx2x_tx_queue_has_work(struct bnx2x_fp_txdata *txdata)
  661. {
  662. u16 hw_cons;
  663. /* Tell compiler that status block fields can change */
  664. barrier();
  665. hw_cons = le16_to_cpu(*txdata->tx_cons_sb);
  666. return hw_cons != txdata->tx_pkt_cons;
  667. }
  668. static inline bool bnx2x_has_tx_work(struct bnx2x_fastpath *fp)
  669. {
  670. u8 cos;
  671. for_each_cos_in_tx_queue(fp, cos)
  672. if (bnx2x_tx_queue_has_work(fp->txdata_ptr[cos]))
  673. return true;
  674. return false;
  675. }
  676. #define BNX2X_IS_CQE_COMPLETED(cqe_fp) (cqe_fp->marker == 0x0)
  677. #define BNX2X_SEED_CQE(cqe_fp) (cqe_fp->marker = 0xFFFFFFFF)
  678. static inline int bnx2x_has_rx_work(struct bnx2x_fastpath *fp)
  679. {
  680. u16 cons;
  681. union eth_rx_cqe *cqe;
  682. struct eth_fast_path_rx_cqe *cqe_fp;
  683. cons = RCQ_BD(fp->rx_comp_cons);
  684. cqe = &fp->rx_comp_ring[cons];
  685. cqe_fp = &cqe->fast_path_cqe;
  686. return BNX2X_IS_CQE_COMPLETED(cqe_fp);
  687. }
  688. /**
  689. * bnx2x_tx_disable - disables tx from stack point of view
  690. *
  691. * @bp: driver handle
  692. */
  693. static inline void bnx2x_tx_disable(struct bnx2x *bp)
  694. {
  695. netif_tx_disable(bp->dev);
  696. netif_carrier_off(bp->dev);
  697. }
  698. static inline void bnx2x_free_rx_sge(struct bnx2x *bp,
  699. struct bnx2x_fastpath *fp, u16 index)
  700. {
  701. struct sw_rx_page *sw_buf = &fp->rx_page_ring[index];
  702. struct page *page = sw_buf->page;
  703. struct eth_rx_sge *sge = &fp->rx_sge_ring[index];
  704. /* Skip "next page" elements */
  705. if (!page)
  706. return;
  707. /* Since many fragments can share the same page, make sure to
  708. * only unmap and free the page once.
  709. */
  710. dma_unmap_page(&bp->pdev->dev, dma_unmap_addr(sw_buf, mapping),
  711. SGE_PAGE_SIZE, DMA_FROM_DEVICE);
  712. put_page(page);
  713. sw_buf->page = NULL;
  714. sge->addr_hi = 0;
  715. sge->addr_lo = 0;
  716. }
  717. static inline void bnx2x_del_all_napi_cnic(struct bnx2x *bp)
  718. {
  719. int i;
  720. for_each_rx_queue_cnic(bp, i) {
  721. napi_hash_del(&bnx2x_fp(bp, i, napi));
  722. netif_napi_del(&bnx2x_fp(bp, i, napi));
  723. }
  724. }
  725. static inline void bnx2x_del_all_napi(struct bnx2x *bp)
  726. {
  727. int i;
  728. for_each_eth_queue(bp, i) {
  729. napi_hash_del(&bnx2x_fp(bp, i, napi));
  730. netif_napi_del(&bnx2x_fp(bp, i, napi));
  731. }
  732. }
  733. int bnx2x_set_int_mode(struct bnx2x *bp);
  734. static inline void bnx2x_disable_msi(struct bnx2x *bp)
  735. {
  736. if (bp->flags & USING_MSIX_FLAG) {
  737. pci_disable_msix(bp->pdev);
  738. bp->flags &= ~(USING_MSIX_FLAG | USING_SINGLE_MSIX_FLAG);
  739. } else if (bp->flags & USING_MSI_FLAG) {
  740. pci_disable_msi(bp->pdev);
  741. bp->flags &= ~USING_MSI_FLAG;
  742. }
  743. }
  744. static inline void bnx2x_clear_sge_mask_next_elems(struct bnx2x_fastpath *fp)
  745. {
  746. int i, j;
  747. for (i = 1; i <= NUM_RX_SGE_PAGES; i++) {
  748. int idx = RX_SGE_CNT * i - 1;
  749. for (j = 0; j < 2; j++) {
  750. BIT_VEC64_CLEAR_BIT(fp->sge_mask, idx);
  751. idx--;
  752. }
  753. }
  754. }
  755. static inline void bnx2x_init_sge_ring_bit_mask(struct bnx2x_fastpath *fp)
  756. {
  757. /* Set the mask to all 1-s: it's faster to compare to 0 than to 0xf-s */
  758. memset(fp->sge_mask, 0xff, sizeof(fp->sge_mask));
  759. /* Clear the two last indices in the page to 1:
  760. these are the indices that correspond to the "next" element,
  761. hence will never be indicated and should be removed from
  762. the calculations. */
  763. bnx2x_clear_sge_mask_next_elems(fp);
  764. }
  765. /* note that we are not allocating a new buffer,
  766. * we are just moving one from cons to prod
  767. * we are not creating a new mapping,
  768. * so there is no need to check for dma_mapping_error().
  769. */
  770. static inline void bnx2x_reuse_rx_data(struct bnx2x_fastpath *fp,
  771. u16 cons, u16 prod)
  772. {
  773. struct sw_rx_bd *cons_rx_buf = &fp->rx_buf_ring[cons];
  774. struct sw_rx_bd *prod_rx_buf = &fp->rx_buf_ring[prod];
  775. struct eth_rx_bd *cons_bd = &fp->rx_desc_ring[cons];
  776. struct eth_rx_bd *prod_bd = &fp->rx_desc_ring[prod];
  777. dma_unmap_addr_set(prod_rx_buf, mapping,
  778. dma_unmap_addr(cons_rx_buf, mapping));
  779. prod_rx_buf->data = cons_rx_buf->data;
  780. *prod_bd = *cons_bd;
  781. }
  782. /************************* Init ******************************************/
  783. /* returns func by VN for current port */
  784. static inline int func_by_vn(struct bnx2x *bp, int vn)
  785. {
  786. return 2 * vn + BP_PORT(bp);
  787. }
  788. static inline int bnx2x_config_rss_eth(struct bnx2x *bp, bool config_hash)
  789. {
  790. return bnx2x_rss(bp, &bp->rss_conf_obj, config_hash, true);
  791. }
  792. /**
  793. * bnx2x_func_start - init function
  794. *
  795. * @bp: driver handle
  796. *
  797. * Must be called before sending CLIENT_SETUP for the first client.
  798. */
  799. static inline int bnx2x_func_start(struct bnx2x *bp)
  800. {
  801. struct bnx2x_func_state_params func_params = {NULL};
  802. struct bnx2x_func_start_params *start_params =
  803. &func_params.params.start;
  804. /* Prepare parameters for function state transitions */
  805. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  806. func_params.f_obj = &bp->func_obj;
  807. func_params.cmd = BNX2X_F_CMD_START;
  808. /* Function parameters */
  809. start_params->mf_mode = bp->mf_mode;
  810. start_params->sd_vlan_tag = bp->mf_ov;
  811. /* Configure Ethertype for BD mode */
  812. if (IS_MF_BD(bp)) {
  813. DP(NETIF_MSG_IFUP, "Configuring ethertype 0x88a8 for BD\n");
  814. start_params->sd_vlan_eth_type = ETH_P_8021AD;
  815. REG_WR(bp, PRS_REG_VLAN_TYPE_0, ETH_P_8021AD);
  816. REG_WR(bp, PBF_REG_VLAN_TYPE_0, ETH_P_8021AD);
  817. REG_WR(bp, NIG_REG_LLH_E1HOV_TYPE_1, ETH_P_8021AD);
  818. bnx2x_get_c2s_mapping(bp, start_params->c2s_pri,
  819. &start_params->c2s_pri_default);
  820. start_params->c2s_pri_valid = 1;
  821. DP(NETIF_MSG_IFUP,
  822. "Inner-to-Outer priority: %02x %02x %02x %02x %02x %02x %02x %02x [Default %02x]\n",
  823. start_params->c2s_pri[0], start_params->c2s_pri[1],
  824. start_params->c2s_pri[2], start_params->c2s_pri[3],
  825. start_params->c2s_pri[4], start_params->c2s_pri[5],
  826. start_params->c2s_pri[6], start_params->c2s_pri[7],
  827. start_params->c2s_pri_default);
  828. }
  829. if (CHIP_IS_E2(bp) || CHIP_IS_E3(bp))
  830. start_params->network_cos_mode = STATIC_COS;
  831. else /* CHIP_IS_E1X */
  832. start_params->network_cos_mode = FW_WRR;
  833. start_params->vxlan_dst_port = bp->vxlan_dst_port;
  834. start_params->inner_rss = 1;
  835. if (IS_MF_UFP(bp) && BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp)) {
  836. start_params->class_fail_ethtype = ETH_P_FIP;
  837. start_params->class_fail = 1;
  838. start_params->no_added_tags = 1;
  839. }
  840. return bnx2x_func_state_change(bp, &func_params);
  841. }
  842. /**
  843. * bnx2x_set_fw_mac_addr - fill in a MAC address in FW format
  844. *
  845. * @fw_hi: pointer to upper part
  846. * @fw_mid: pointer to middle part
  847. * @fw_lo: pointer to lower part
  848. * @mac: pointer to MAC address
  849. */
  850. static inline void bnx2x_set_fw_mac_addr(__le16 *fw_hi, __le16 *fw_mid,
  851. __le16 *fw_lo, u8 *mac)
  852. {
  853. ((u8 *)fw_hi)[0] = mac[1];
  854. ((u8 *)fw_hi)[1] = mac[0];
  855. ((u8 *)fw_mid)[0] = mac[3];
  856. ((u8 *)fw_mid)[1] = mac[2];
  857. ((u8 *)fw_lo)[0] = mac[5];
  858. ((u8 *)fw_lo)[1] = mac[4];
  859. }
  860. static inline void bnx2x_free_rx_mem_pool(struct bnx2x *bp,
  861. struct bnx2x_alloc_pool *pool)
  862. {
  863. if (!pool->page)
  864. return;
  865. put_page(pool->page);
  866. pool->page = NULL;
  867. }
  868. static inline void bnx2x_free_rx_sge_range(struct bnx2x *bp,
  869. struct bnx2x_fastpath *fp, int last)
  870. {
  871. int i;
  872. if (fp->mode == TPA_MODE_DISABLED)
  873. return;
  874. for (i = 0; i < last; i++)
  875. bnx2x_free_rx_sge(bp, fp, i);
  876. bnx2x_free_rx_mem_pool(bp, &fp->page_pool);
  877. }
  878. static inline void bnx2x_set_next_page_rx_bd(struct bnx2x_fastpath *fp)
  879. {
  880. int i;
  881. for (i = 1; i <= NUM_RX_RINGS; i++) {
  882. struct eth_rx_bd *rx_bd;
  883. rx_bd = &fp->rx_desc_ring[RX_DESC_CNT * i - 2];
  884. rx_bd->addr_hi =
  885. cpu_to_le32(U64_HI(fp->rx_desc_mapping +
  886. BCM_PAGE_SIZE*(i % NUM_RX_RINGS)));
  887. rx_bd->addr_lo =
  888. cpu_to_le32(U64_LO(fp->rx_desc_mapping +
  889. BCM_PAGE_SIZE*(i % NUM_RX_RINGS)));
  890. }
  891. }
  892. /* Statistics ID are global per chip/path, while Client IDs for E1x are per
  893. * port.
  894. */
  895. static inline u8 bnx2x_stats_id(struct bnx2x_fastpath *fp)
  896. {
  897. struct bnx2x *bp = fp->bp;
  898. if (!CHIP_IS_E1x(bp)) {
  899. /* there are special statistics counters for FCoE 136..140 */
  900. if (IS_FCOE_FP(fp))
  901. return bp->cnic_base_cl_id + (bp->pf_num >> 1);
  902. return fp->cl_id;
  903. }
  904. return fp->cl_id + BP_PORT(bp) * FP_SB_MAX_E1x;
  905. }
  906. static inline void bnx2x_init_vlan_mac_fp_objs(struct bnx2x_fastpath *fp,
  907. bnx2x_obj_type obj_type)
  908. {
  909. struct bnx2x *bp = fp->bp;
  910. /* Configure classification DBs */
  911. bnx2x_init_mac_obj(bp, &bnx2x_sp_obj(bp, fp).mac_obj, fp->cl_id,
  912. fp->cid, BP_FUNC(bp), bnx2x_sp(bp, mac_rdata),
  913. bnx2x_sp_mapping(bp, mac_rdata),
  914. BNX2X_FILTER_MAC_PENDING,
  915. &bp->sp_state, obj_type,
  916. &bp->macs_pool);
  917. if (!CHIP_IS_E1x(bp))
  918. bnx2x_init_vlan_obj(bp, &bnx2x_sp_obj(bp, fp).vlan_obj,
  919. fp->cl_id, fp->cid, BP_FUNC(bp),
  920. bnx2x_sp(bp, vlan_rdata),
  921. bnx2x_sp_mapping(bp, vlan_rdata),
  922. BNX2X_FILTER_VLAN_PENDING,
  923. &bp->sp_state, obj_type,
  924. &bp->vlans_pool);
  925. }
  926. /**
  927. * bnx2x_get_path_func_num - get number of active functions
  928. *
  929. * @bp: driver handle
  930. *
  931. * Calculates the number of active (not hidden) functions on the
  932. * current path.
  933. */
  934. static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
  935. {
  936. u8 func_num = 0, i;
  937. /* 57710 has only one function per-port */
  938. if (CHIP_IS_E1(bp))
  939. return 1;
  940. /* Calculate a number of functions enabled on the current
  941. * PATH/PORT.
  942. */
  943. if (CHIP_REV_IS_SLOW(bp)) {
  944. if (IS_MF(bp))
  945. func_num = 4;
  946. else
  947. func_num = 2;
  948. } else {
  949. for (i = 0; i < E1H_FUNC_MAX / 2; i++) {
  950. u32 func_config =
  951. MF_CFG_RD(bp,
  952. func_mf_config[BP_PORT(bp) + 2 * i].
  953. config);
  954. func_num +=
  955. ((func_config & FUNC_MF_CFG_FUNC_HIDE) ? 0 : 1);
  956. }
  957. }
  958. WARN_ON(!func_num);
  959. return func_num;
  960. }
  961. static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
  962. {
  963. /* RX_MODE controlling object */
  964. bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
  965. /* multicast configuration controlling object */
  966. bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
  967. BP_FUNC(bp), BP_FUNC(bp),
  968. bnx2x_sp(bp, mcast_rdata),
  969. bnx2x_sp_mapping(bp, mcast_rdata),
  970. BNX2X_FILTER_MCAST_PENDING, &bp->sp_state,
  971. BNX2X_OBJ_TYPE_RX);
  972. /* Setup CAM credit pools */
  973. bnx2x_init_mac_credit_pool(bp, &bp->macs_pool, BP_FUNC(bp),
  974. bnx2x_get_path_func_num(bp));
  975. bnx2x_init_vlan_credit_pool(bp, &bp->vlans_pool, BP_FUNC(bp),
  976. bnx2x_get_path_func_num(bp));
  977. /* RSS configuration object */
  978. bnx2x_init_rss_config_obj(bp, &bp->rss_conf_obj, bp->fp->cl_id,
  979. bp->fp->cid, BP_FUNC(bp), BP_FUNC(bp),
  980. bnx2x_sp(bp, rss_rdata),
  981. bnx2x_sp_mapping(bp, rss_rdata),
  982. BNX2X_FILTER_RSS_CONF_PENDING, &bp->sp_state,
  983. BNX2X_OBJ_TYPE_RX);
  984. bp->vlan_credit = PF_VLAN_CREDIT_E2(bp, bnx2x_get_path_func_num(bp));
  985. }
  986. static inline u8 bnx2x_fp_qzone_id(struct bnx2x_fastpath *fp)
  987. {
  988. if (CHIP_IS_E1x(fp->bp))
  989. return fp->cl_id + BP_PORT(fp->bp) * ETH_MAX_RX_CLIENTS_E1H;
  990. else
  991. return fp->cl_id;
  992. }
  993. static inline void bnx2x_init_txdata(struct bnx2x *bp,
  994. struct bnx2x_fp_txdata *txdata, u32 cid,
  995. int txq_index, __le16 *tx_cons_sb,
  996. struct bnx2x_fastpath *fp)
  997. {
  998. txdata->cid = cid;
  999. txdata->txq_index = txq_index;
  1000. txdata->tx_cons_sb = tx_cons_sb;
  1001. txdata->parent_fp = fp;
  1002. txdata->tx_ring_size = IS_FCOE_FP(fp) ? MAX_TX_AVAIL : bp->tx_ring_size;
  1003. DP(NETIF_MSG_IFUP, "created tx data cid %d, txq %d\n",
  1004. txdata->cid, txdata->txq_index);
  1005. }
  1006. static inline u8 bnx2x_cnic_eth_cl_id(struct bnx2x *bp, u8 cl_idx)
  1007. {
  1008. return bp->cnic_base_cl_id + cl_idx +
  1009. (bp->pf_num >> 1) * BNX2X_MAX_CNIC_ETH_CL_ID_IDX;
  1010. }
  1011. static inline u8 bnx2x_cnic_fw_sb_id(struct bnx2x *bp)
  1012. {
  1013. /* the 'first' id is allocated for the cnic */
  1014. return bp->base_fw_ndsb;
  1015. }
  1016. static inline u8 bnx2x_cnic_igu_sb_id(struct bnx2x *bp)
  1017. {
  1018. return bp->igu_base_sb;
  1019. }
  1020. static inline int bnx2x_clean_tx_queue(struct bnx2x *bp,
  1021. struct bnx2x_fp_txdata *txdata)
  1022. {
  1023. int cnt = 1000;
  1024. while (bnx2x_has_tx_work_unload(txdata)) {
  1025. if (!cnt) {
  1026. BNX2X_ERR("timeout waiting for queue[%d]: txdata->tx_pkt_prod(%d) != txdata->tx_pkt_cons(%d)\n",
  1027. txdata->txq_index, txdata->tx_pkt_prod,
  1028. txdata->tx_pkt_cons);
  1029. #ifdef BNX2X_STOP_ON_ERROR
  1030. bnx2x_panic();
  1031. return -EBUSY;
  1032. #else
  1033. break;
  1034. #endif
  1035. }
  1036. cnt--;
  1037. usleep_range(1000, 2000);
  1038. }
  1039. return 0;
  1040. }
  1041. int bnx2x_get_link_cfg_idx(struct bnx2x *bp);
  1042. static inline void __storm_memset_struct(struct bnx2x *bp,
  1043. u32 addr, size_t size, u32 *data)
  1044. {
  1045. int i;
  1046. for (i = 0; i < size/4; i++)
  1047. REG_WR(bp, addr + (i * 4), data[i]);
  1048. }
  1049. /**
  1050. * bnx2x_wait_sp_comp - wait for the outstanding SP commands.
  1051. *
  1052. * @bp: driver handle
  1053. * @mask: bits that need to be cleared
  1054. */
  1055. static inline bool bnx2x_wait_sp_comp(struct bnx2x *bp, unsigned long mask)
  1056. {
  1057. int tout = 5000; /* Wait for 5 secs tops */
  1058. while (tout--) {
  1059. smp_mb();
  1060. netif_addr_lock_bh(bp->dev);
  1061. if (!(bp->sp_state & mask)) {
  1062. netif_addr_unlock_bh(bp->dev);
  1063. return true;
  1064. }
  1065. netif_addr_unlock_bh(bp->dev);
  1066. usleep_range(1000, 2000);
  1067. }
  1068. smp_mb();
  1069. netif_addr_lock_bh(bp->dev);
  1070. if (bp->sp_state & mask) {
  1071. BNX2X_ERR("Filtering completion timed out. sp_state 0x%lx, mask 0x%lx\n",
  1072. bp->sp_state, mask);
  1073. netif_addr_unlock_bh(bp->dev);
  1074. return false;
  1075. }
  1076. netif_addr_unlock_bh(bp->dev);
  1077. return true;
  1078. }
  1079. /**
  1080. * bnx2x_set_ctx_validation - set CDU context validation values
  1081. *
  1082. * @bp: driver handle
  1083. * @cxt: context of the connection on the host memory
  1084. * @cid: SW CID of the connection to be configured
  1085. */
  1086. void bnx2x_set_ctx_validation(struct bnx2x *bp, struct eth_context *cxt,
  1087. u32 cid);
  1088. void bnx2x_update_coalesce_sb_index(struct bnx2x *bp, u8 fw_sb_id,
  1089. u8 sb_index, u8 disable, u16 usec);
  1090. void bnx2x_acquire_phy_lock(struct bnx2x *bp);
  1091. void bnx2x_release_phy_lock(struct bnx2x *bp);
  1092. /**
  1093. * bnx2x_extract_max_cfg - extract MAX BW part from MF configuration.
  1094. *
  1095. * @bp: driver handle
  1096. * @mf_cfg: MF configuration
  1097. *
  1098. */
  1099. static inline u16 bnx2x_extract_max_cfg(struct bnx2x *bp, u32 mf_cfg)
  1100. {
  1101. u16 max_cfg = (mf_cfg & FUNC_MF_CFG_MAX_BW_MASK) >>
  1102. FUNC_MF_CFG_MAX_BW_SHIFT;
  1103. if (!max_cfg) {
  1104. DP(NETIF_MSG_IFUP | BNX2X_MSG_ETHTOOL,
  1105. "Max BW configured to 0 - using 100 instead\n");
  1106. max_cfg = 100;
  1107. }
  1108. return max_cfg;
  1109. }
  1110. /* checks if HW supports GRO for given MTU */
  1111. static inline bool bnx2x_mtu_allows_gro(int mtu)
  1112. {
  1113. /* gro frags per page */
  1114. int fpp = SGE_PAGE_SIZE / (mtu - ETH_MAX_TPA_HEADER_SIZE);
  1115. /*
  1116. * 1. Number of frags should not grow above MAX_SKB_FRAGS
  1117. * 2. Frag must fit the page
  1118. */
  1119. return mtu <= SGE_PAGE_SIZE && (U_ETH_SGL_SIZE * fpp) <= MAX_SKB_FRAGS;
  1120. }
  1121. /**
  1122. * bnx2x_get_iscsi_info - update iSCSI params according to licensing info.
  1123. *
  1124. * @bp: driver handle
  1125. *
  1126. */
  1127. void bnx2x_get_iscsi_info(struct bnx2x *bp);
  1128. /**
  1129. * bnx2x_link_sync_notify - send notification to other functions.
  1130. *
  1131. * @bp: driver handle
  1132. *
  1133. */
  1134. static inline void bnx2x_link_sync_notify(struct bnx2x *bp)
  1135. {
  1136. int func;
  1137. int vn;
  1138. /* Set the attention towards other drivers on the same port */
  1139. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  1140. if (vn == BP_VN(bp))
  1141. continue;
  1142. func = func_by_vn(bp, vn);
  1143. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_0 +
  1144. (LINK_SYNC_ATTENTION_BIT_FUNC_0 + func)*4, 1);
  1145. }
  1146. }
  1147. /**
  1148. * bnx2x_update_drv_flags - update flags in shmem
  1149. *
  1150. * @bp: driver handle
  1151. * @flags: flags to update
  1152. * @set: set or clear
  1153. *
  1154. */
  1155. static inline void bnx2x_update_drv_flags(struct bnx2x *bp, u32 flags, u32 set)
  1156. {
  1157. if (SHMEM2_HAS(bp, drv_flags)) {
  1158. u32 drv_flags;
  1159. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_DRV_FLAGS);
  1160. drv_flags = SHMEM2_RD(bp, drv_flags);
  1161. if (set)
  1162. SET_FLAGS(drv_flags, flags);
  1163. else
  1164. RESET_FLAGS(drv_flags, flags);
  1165. SHMEM2_WR(bp, drv_flags, drv_flags);
  1166. DP(NETIF_MSG_IFUP, "drv_flags 0x%08x\n", drv_flags);
  1167. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_DRV_FLAGS);
  1168. }
  1169. }
  1170. /**
  1171. * bnx2x_fill_fw_str - Fill buffer with FW version string
  1172. *
  1173. * @bp: driver handle
  1174. * @buf: character buffer to fill with the fw name
  1175. * @buf_len: length of the above buffer
  1176. *
  1177. */
  1178. void bnx2x_fill_fw_str(struct bnx2x *bp, char *buf, size_t buf_len);
  1179. int bnx2x_drain_tx_queues(struct bnx2x *bp);
  1180. void bnx2x_squeeze_objects(struct bnx2x *bp);
  1181. void bnx2x_schedule_sp_rtnl(struct bnx2x*, enum sp_rtnl_flag,
  1182. u32 verbose);
  1183. /**
  1184. * bnx2x_set_os_driver_state - write driver state for management FW usage
  1185. *
  1186. * @bp: driver handle
  1187. * @state: OS_DRIVER_STATE_* value reflecting current driver state
  1188. */
  1189. void bnx2x_set_os_driver_state(struct bnx2x *bp, u32 state);
  1190. /**
  1191. * bnx2x_nvram_read - reads data from nvram [might sleep]
  1192. *
  1193. * @bp: driver handle
  1194. * @offset: byte offset in nvram
  1195. * @ret_buf: pointer to buffer where data is to be stored
  1196. * @buf_size: Length of 'ret_buf' in bytes
  1197. */
  1198. int bnx2x_nvram_read(struct bnx2x *bp, u32 offset, u8 *ret_buf,
  1199. int buf_size);
  1200. #endif /* BNX2X_CMN_H */