bnx2x_cmn.h 41 KB

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