bnx2x_cmn.h 35 KB

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