bnx2x_cmn.h 34 KB

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