bnx2x_cmn.h 35 KB

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