be.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894
  1. /*
  2. * Copyright (C) 2005 - 2014 Emulex
  3. * All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License version 2
  7. * as published by the Free Software Foundation. The full GNU General
  8. * Public License is included in this distribution in the file called COPYING.
  9. *
  10. * Contact Information:
  11. * linux-drivers@emulex.com
  12. *
  13. * Emulex
  14. * 3333 Susan Street
  15. * Costa Mesa, CA 92626
  16. */
  17. #ifndef BE_H
  18. #define BE_H
  19. #include <linux/pci.h>
  20. #include <linux/etherdevice.h>
  21. #include <linux/delay.h>
  22. #include <net/tcp.h>
  23. #include <net/ip.h>
  24. #include <net/ipv6.h>
  25. #include <linux/if_vlan.h>
  26. #include <linux/workqueue.h>
  27. #include <linux/interrupt.h>
  28. #include <linux/firmware.h>
  29. #include <linux/slab.h>
  30. #include <linux/u64_stats_sync.h>
  31. #include "be_hw.h"
  32. #include "be_roce.h"
  33. #define DRV_VER "10.2u"
  34. #define DRV_NAME "be2net"
  35. #define BE_NAME "Emulex BladeEngine2"
  36. #define BE3_NAME "Emulex BladeEngine3"
  37. #define OC_NAME "Emulex OneConnect"
  38. #define OC_NAME_BE OC_NAME "(be3)"
  39. #define OC_NAME_LANCER OC_NAME "(Lancer)"
  40. #define OC_NAME_SH OC_NAME "(Skyhawk)"
  41. #define DRV_DESC "Emulex OneConnect NIC Driver"
  42. #define BE_VENDOR_ID 0x19a2
  43. #define EMULEX_VENDOR_ID 0x10df
  44. #define BE_DEVICE_ID1 0x211
  45. #define BE_DEVICE_ID2 0x221
  46. #define OC_DEVICE_ID1 0x700 /* Device Id for BE2 cards */
  47. #define OC_DEVICE_ID2 0x710 /* Device Id for BE3 cards */
  48. #define OC_DEVICE_ID3 0xe220 /* Device id for Lancer cards */
  49. #define OC_DEVICE_ID4 0xe228 /* Device id for VF in Lancer */
  50. #define OC_DEVICE_ID5 0x720 /* Device Id for Skyhawk cards */
  51. #define OC_DEVICE_ID6 0x728 /* Device id for VF in SkyHawk */
  52. #define OC_SUBSYS_DEVICE_ID1 0xE602
  53. #define OC_SUBSYS_DEVICE_ID2 0xE642
  54. #define OC_SUBSYS_DEVICE_ID3 0xE612
  55. #define OC_SUBSYS_DEVICE_ID4 0xE652
  56. static inline char *nic_name(struct pci_dev *pdev)
  57. {
  58. switch (pdev->device) {
  59. case OC_DEVICE_ID1:
  60. return OC_NAME;
  61. case OC_DEVICE_ID2:
  62. return OC_NAME_BE;
  63. case OC_DEVICE_ID3:
  64. case OC_DEVICE_ID4:
  65. return OC_NAME_LANCER;
  66. case BE_DEVICE_ID2:
  67. return BE3_NAME;
  68. case OC_DEVICE_ID5:
  69. case OC_DEVICE_ID6:
  70. return OC_NAME_SH;
  71. default:
  72. return BE_NAME;
  73. }
  74. }
  75. /* Number of bytes of an RX frame that are copied to skb->data */
  76. #define BE_HDR_LEN ((u16) 64)
  77. /* allocate extra space to allow tunneling decapsulation without head reallocation */
  78. #define BE_RX_SKB_ALLOC_SIZE (BE_HDR_LEN + 64)
  79. #define BE_MAX_JUMBO_FRAME_SIZE 9018
  80. #define BE_MIN_MTU 256
  81. #define BE_NUM_VLANS_SUPPORTED 64
  82. #define BE_MAX_EQD 128u
  83. #define BE_MAX_TX_FRAG_COUNT 30
  84. #define EVNT_Q_LEN 1024
  85. #define TX_Q_LEN 2048
  86. #define TX_CQ_LEN 1024
  87. #define RX_Q_LEN 1024 /* Does not support any other value */
  88. #define RX_CQ_LEN 1024
  89. #define MCC_Q_LEN 128 /* total size not to exceed 8 pages */
  90. #define MCC_CQ_LEN 256
  91. #define BE2_MAX_RSS_QS 4
  92. #define BE3_MAX_RSS_QS 16
  93. #define BE3_MAX_TX_QS 16
  94. #define BE3_MAX_EVT_QS 16
  95. #define BE3_SRIOV_MAX_EVT_QS 8
  96. #define MAX_RX_QS 32
  97. #define MAX_EVT_QS 32
  98. #define MAX_TX_QS 32
  99. #define MAX_ROCE_EQS 5
  100. #define MAX_MSIX_VECTORS 32
  101. #define MIN_MSIX_VECTORS 1
  102. #define BE_TX_BUDGET 256
  103. #define BE_NAPI_WEIGHT 64
  104. #define MAX_RX_POST BE_NAPI_WEIGHT /* Frags posted at a time */
  105. #define RX_FRAGS_REFILL_WM (RX_Q_LEN - MAX_RX_POST)
  106. #define MAX_VFS 30 /* Max VFs supported by BE3 FW */
  107. #define FW_VER_LEN 32
  108. #define RSS_INDIR_TABLE_LEN 128
  109. #define RSS_HASH_KEY_LEN 40
  110. struct be_dma_mem {
  111. void *va;
  112. dma_addr_t dma;
  113. u32 size;
  114. };
  115. struct be_queue_info {
  116. struct be_dma_mem dma_mem;
  117. u16 len;
  118. u16 entry_size; /* Size of an element in the queue */
  119. u16 id;
  120. u16 tail, head;
  121. bool created;
  122. atomic_t used; /* Number of valid elements in the queue */
  123. };
  124. static inline u32 MODULO(u16 val, u16 limit)
  125. {
  126. BUG_ON(limit & (limit - 1));
  127. return val & (limit - 1);
  128. }
  129. static inline void index_adv(u16 *index, u16 val, u16 limit)
  130. {
  131. *index = MODULO((*index + val), limit);
  132. }
  133. static inline void index_inc(u16 *index, u16 limit)
  134. {
  135. *index = MODULO((*index + 1), limit);
  136. }
  137. static inline void *queue_head_node(struct be_queue_info *q)
  138. {
  139. return q->dma_mem.va + q->head * q->entry_size;
  140. }
  141. static inline void *queue_tail_node(struct be_queue_info *q)
  142. {
  143. return q->dma_mem.va + q->tail * q->entry_size;
  144. }
  145. static inline void *queue_index_node(struct be_queue_info *q, u16 index)
  146. {
  147. return q->dma_mem.va + index * q->entry_size;
  148. }
  149. static inline void queue_head_inc(struct be_queue_info *q)
  150. {
  151. index_inc(&q->head, q->len);
  152. }
  153. static inline void index_dec(u16 *index, u16 limit)
  154. {
  155. *index = MODULO((*index - 1), limit);
  156. }
  157. static inline void queue_tail_inc(struct be_queue_info *q)
  158. {
  159. index_inc(&q->tail, q->len);
  160. }
  161. struct be_eq_obj {
  162. struct be_queue_info q;
  163. char desc[32];
  164. /* Adaptive interrupt coalescing (AIC) info */
  165. bool enable_aic;
  166. u32 min_eqd; /* in usecs */
  167. u32 max_eqd; /* in usecs */
  168. u32 eqd; /* configured val when aic is off */
  169. u32 cur_eqd; /* in usecs */
  170. u8 idx; /* array index */
  171. u8 msix_idx;
  172. u16 tx_budget;
  173. u16 spurious_intr;
  174. struct napi_struct napi;
  175. struct be_adapter *adapter;
  176. #ifdef CONFIG_NET_RX_BUSY_POLL
  177. #define BE_EQ_IDLE 0
  178. #define BE_EQ_NAPI 1 /* napi owns this EQ */
  179. #define BE_EQ_POLL 2 /* poll owns this EQ */
  180. #define BE_EQ_LOCKED (BE_EQ_NAPI | BE_EQ_POLL)
  181. #define BE_EQ_NAPI_YIELD 4 /* napi yielded this EQ */
  182. #define BE_EQ_POLL_YIELD 8 /* poll yielded this EQ */
  183. #define BE_EQ_YIELD (BE_EQ_NAPI_YIELD | BE_EQ_POLL_YIELD)
  184. #define BE_EQ_USER_PEND (BE_EQ_POLL | BE_EQ_POLL_YIELD)
  185. unsigned int state;
  186. spinlock_t lock; /* lock to serialize napi and busy-poll */
  187. #endif /* CONFIG_NET_RX_BUSY_POLL */
  188. } ____cacheline_aligned_in_smp;
  189. struct be_aic_obj { /* Adaptive interrupt coalescing (AIC) info */
  190. bool enable;
  191. u32 min_eqd; /* in usecs */
  192. u32 max_eqd; /* in usecs */
  193. u32 prev_eqd; /* in usecs */
  194. u32 et_eqd; /* configured val when aic is off */
  195. ulong jiffies;
  196. u64 rx_pkts_prev; /* Used to calculate RX pps */
  197. u64 tx_reqs_prev; /* Used to calculate TX pps */
  198. };
  199. enum {
  200. NAPI_POLLING,
  201. BUSY_POLLING
  202. };
  203. struct be_mcc_obj {
  204. struct be_queue_info q;
  205. struct be_queue_info cq;
  206. bool rearm_cq;
  207. };
  208. struct be_tx_stats {
  209. u64 tx_bytes;
  210. u64 tx_pkts;
  211. u64 tx_reqs;
  212. u64 tx_wrbs;
  213. u64 tx_compl;
  214. ulong tx_jiffies;
  215. u32 tx_stops;
  216. u32 tx_drv_drops; /* pkts dropped by driver */
  217. struct u64_stats_sync sync;
  218. struct u64_stats_sync sync_compl;
  219. };
  220. struct be_tx_obj {
  221. u32 db_offset;
  222. struct be_queue_info q;
  223. struct be_queue_info cq;
  224. /* Remember the skbs that were transmitted */
  225. struct sk_buff *sent_skb_list[TX_Q_LEN];
  226. struct be_tx_stats stats;
  227. } ____cacheline_aligned_in_smp;
  228. /* Struct to remember the pages posted for rx frags */
  229. struct be_rx_page_info {
  230. struct page *page;
  231. /* set to page-addr for last frag of the page & frag-addr otherwise */
  232. DEFINE_DMA_UNMAP_ADDR(bus);
  233. u16 page_offset;
  234. bool last_frag; /* last frag of the page */
  235. };
  236. struct be_rx_stats {
  237. u64 rx_bytes;
  238. u64 rx_pkts;
  239. u32 rx_drops_no_skbs; /* skb allocation errors */
  240. u32 rx_drops_no_frags; /* HW has no fetched frags */
  241. u32 rx_post_fail; /* page post alloc failures */
  242. u32 rx_compl;
  243. u32 rx_mcast_pkts;
  244. u32 rx_compl_err; /* completions with err set */
  245. struct u64_stats_sync sync;
  246. };
  247. struct be_rx_compl_info {
  248. u32 rss_hash;
  249. u16 vlan_tag;
  250. u16 pkt_size;
  251. u16 port;
  252. u8 vlanf;
  253. u8 num_rcvd;
  254. u8 err;
  255. u8 ipf;
  256. u8 tcpf;
  257. u8 udpf;
  258. u8 ip_csum;
  259. u8 l4_csum;
  260. u8 ipv6;
  261. u8 qnq;
  262. u8 pkt_type;
  263. u8 ip_frag;
  264. u8 tunneled;
  265. };
  266. struct be_rx_obj {
  267. struct be_adapter *adapter;
  268. struct be_queue_info q;
  269. struct be_queue_info cq;
  270. struct be_rx_compl_info rxcp;
  271. struct be_rx_page_info page_info_tbl[RX_Q_LEN];
  272. struct be_rx_stats stats;
  273. u8 rss_id;
  274. bool rx_post_starved; /* Zero rx frags have been posted to BE */
  275. } ____cacheline_aligned_in_smp;
  276. struct be_drv_stats {
  277. u32 be_on_die_temperature;
  278. u32 eth_red_drops;
  279. u32 rx_drops_no_pbuf;
  280. u32 rx_drops_no_txpb;
  281. u32 rx_drops_no_erx_descr;
  282. u32 rx_drops_no_tpre_descr;
  283. u32 rx_drops_too_many_frags;
  284. u32 forwarded_packets;
  285. u32 rx_drops_mtu;
  286. u32 rx_crc_errors;
  287. u32 rx_alignment_symbol_errors;
  288. u32 rx_pause_frames;
  289. u32 rx_priority_pause_frames;
  290. u32 rx_control_frames;
  291. u32 rx_in_range_errors;
  292. u32 rx_out_range_errors;
  293. u32 rx_frame_too_long;
  294. u32 rx_address_filtered;
  295. u32 rx_dropped_too_small;
  296. u32 rx_dropped_too_short;
  297. u32 rx_dropped_header_too_small;
  298. u32 rx_dropped_tcp_length;
  299. u32 rx_dropped_runt;
  300. u32 rx_ip_checksum_errs;
  301. u32 rx_tcp_checksum_errs;
  302. u32 rx_udp_checksum_errs;
  303. u32 tx_pauseframes;
  304. u32 tx_priority_pauseframes;
  305. u32 tx_controlframes;
  306. u32 rxpp_fifo_overflow_drop;
  307. u32 rx_input_fifo_overflow_drop;
  308. u32 pmem_fifo_overflow_drop;
  309. u32 jabber_events;
  310. u32 rx_roce_bytes_lsd;
  311. u32 rx_roce_bytes_msd;
  312. u32 rx_roce_frames;
  313. u32 roce_drops_payload_len;
  314. u32 roce_drops_crc;
  315. };
  316. /* A vlan-id of 0xFFFF must be used to clear transparent vlan-tagging */
  317. #define BE_RESET_VLAN_TAG_ID 0xFFFF
  318. struct be_vf_cfg {
  319. unsigned char mac_addr[ETH_ALEN];
  320. int if_handle;
  321. int pmac_id;
  322. u16 vlan_tag;
  323. u32 tx_rate;
  324. u32 plink_tracking;
  325. };
  326. enum vf_state {
  327. ENABLED = 0,
  328. ASSIGNED = 1
  329. };
  330. #define BE_FLAGS_LINK_STATUS_INIT 1
  331. #define BE_FLAGS_WORKER_SCHEDULED (1 << 3)
  332. #define BE_FLAGS_VLAN_PROMISC (1 << 4)
  333. #define BE_FLAGS_MCAST_PROMISC (1 << 5)
  334. #define BE_FLAGS_NAPI_ENABLED (1 << 9)
  335. #define BE_FLAGS_QNQ_ASYNC_EVT_RCVD (1 << 11)
  336. #define BE_FLAGS_VXLAN_OFFLOADS (1 << 12)
  337. #define BE_FLAGS_SETUP_DONE (1 << 13)
  338. #define BE_UC_PMAC_COUNT 30
  339. #define BE_VF_UC_PMAC_COUNT 2
  340. /* Ethtool set_dump flags */
  341. #define LANCER_INITIATE_FW_DUMP 0x1
  342. struct phy_info {
  343. u8 transceiver;
  344. u8 autoneg;
  345. u8 fc_autoneg;
  346. u8 port_type;
  347. u16 phy_type;
  348. u16 interface_type;
  349. u32 misc_params;
  350. u16 auto_speeds_supported;
  351. u16 fixed_speeds_supported;
  352. int link_speed;
  353. u32 dac_cable_len;
  354. u32 advertising;
  355. u32 supported;
  356. };
  357. struct be_resources {
  358. u16 max_vfs; /* Total VFs "really" supported by FW/HW */
  359. u16 max_mcast_mac;
  360. u16 max_tx_qs;
  361. u16 max_rss_qs;
  362. u16 max_rx_qs;
  363. u16 max_uc_mac; /* Max UC MACs programmable */
  364. u16 max_vlans; /* Number of vlans supported */
  365. u16 max_evt_qs;
  366. u32 if_cap_flags;
  367. };
  368. struct rss_info {
  369. u64 rss_flags;
  370. u8 rsstable[RSS_INDIR_TABLE_LEN];
  371. u8 rss_queue[RSS_INDIR_TABLE_LEN];
  372. u8 rss_hkey[RSS_HASH_KEY_LEN];
  373. };
  374. struct be_adapter {
  375. struct pci_dev *pdev;
  376. struct net_device *netdev;
  377. u8 __iomem *csr; /* CSR BAR used only for BE2/3 */
  378. u8 __iomem *db; /* Door Bell */
  379. struct mutex mbox_lock; /* For serializing mbox cmds to BE card */
  380. struct be_dma_mem mbox_mem;
  381. /* Mbox mem is adjusted to align to 16 bytes. The allocated addr
  382. * is stored for freeing purpose */
  383. struct be_dma_mem mbox_mem_alloced;
  384. struct be_mcc_obj mcc_obj;
  385. spinlock_t mcc_lock; /* For serializing mcc cmds to BE card */
  386. spinlock_t mcc_cq_lock;
  387. u16 cfg_num_qs; /* configured via set-channels */
  388. u16 num_evt_qs;
  389. u16 num_msix_vec;
  390. struct be_eq_obj eq_obj[MAX_EVT_QS];
  391. struct msix_entry msix_entries[MAX_MSIX_VECTORS];
  392. bool isr_registered;
  393. /* TX Rings */
  394. u16 num_tx_qs;
  395. struct be_tx_obj tx_obj[MAX_TX_QS];
  396. /* Rx rings */
  397. u16 num_rx_qs;
  398. struct be_rx_obj rx_obj[MAX_RX_QS];
  399. u32 big_page_size; /* Compounded page size shared by rx wrbs */
  400. struct be_drv_stats drv_stats;
  401. struct be_aic_obj aic_obj[MAX_EVT_QS];
  402. u16 vlans_added;
  403. unsigned long vids[BITS_TO_LONGS(VLAN_N_VID)];
  404. u8 vlan_prio_bmap; /* Available Priority BitMap */
  405. u16 recommended_prio; /* Recommended Priority */
  406. struct be_dma_mem rx_filter; /* Cmd DMA mem for rx-filter */
  407. struct be_dma_mem stats_cmd;
  408. /* Work queue used to perform periodic tasks like getting statistics */
  409. struct delayed_work work;
  410. u16 work_counter;
  411. struct delayed_work func_recovery_work;
  412. u32 flags;
  413. u32 cmd_privileges;
  414. /* Ethtool knobs and info */
  415. char fw_ver[FW_VER_LEN];
  416. char fw_on_flash[FW_VER_LEN];
  417. int if_handle; /* Used to configure filtering */
  418. u32 *pmac_id; /* MAC addr handle used by BE card */
  419. u32 beacon_state; /* for set_phys_id */
  420. bool eeh_error;
  421. bool fw_timeout;
  422. bool hw_error;
  423. u32 port_num;
  424. bool promiscuous;
  425. u8 mc_type;
  426. u32 function_mode;
  427. u32 function_caps;
  428. u32 rx_fc; /* Rx flow control */
  429. u32 tx_fc; /* Tx flow control */
  430. bool stats_cmd_sent;
  431. struct {
  432. u32 size;
  433. u32 total_size;
  434. u64 io_addr;
  435. } roce_db;
  436. u32 num_msix_roce_vec;
  437. struct ocrdma_dev *ocrdma_dev;
  438. struct list_head entry;
  439. u32 flash_status;
  440. struct completion et_cmd_compl;
  441. struct be_resources res; /* resources available for the func */
  442. u16 num_vfs; /* Number of VFs provisioned by PF */
  443. u8 virtfn;
  444. struct be_vf_cfg *vf_cfg;
  445. bool be3_native;
  446. u32 sli_family;
  447. u8 hba_port_num;
  448. u16 pvid;
  449. __be16 vxlan_port;
  450. struct phy_info phy;
  451. u8 wol_cap;
  452. bool wol_en;
  453. u32 uc_macs; /* Count of secondary UC MAC programmed */
  454. u16 asic_rev;
  455. u16 qnq_vid;
  456. u32 msg_enable;
  457. int be_get_temp_freq;
  458. u8 pf_number;
  459. struct rss_info rss_info;
  460. };
  461. #define be_physfn(adapter) (!adapter->virtfn)
  462. #define be_virtfn(adapter) (adapter->virtfn)
  463. #define sriov_enabled(adapter) (adapter->num_vfs > 0)
  464. #define sriov_want(adapter) (be_physfn(adapter) && \
  465. (num_vfs || pci_num_vf(adapter->pdev)))
  466. #define for_all_vfs(adapter, vf_cfg, i) \
  467. for (i = 0, vf_cfg = &adapter->vf_cfg[i]; i < adapter->num_vfs; \
  468. i++, vf_cfg++)
  469. #define ON 1
  470. #define OFF 0
  471. #define be_max_vlans(adapter) (adapter->res.max_vlans)
  472. #define be_max_uc(adapter) (adapter->res.max_uc_mac)
  473. #define be_max_mc(adapter) (adapter->res.max_mcast_mac)
  474. #define be_max_vfs(adapter) (adapter->res.max_vfs)
  475. #define be_max_rss(adapter) (adapter->res.max_rss_qs)
  476. #define be_max_txqs(adapter) (adapter->res.max_tx_qs)
  477. #define be_max_prio_txqs(adapter) (adapter->res.max_prio_tx_qs)
  478. #define be_max_rxqs(adapter) (adapter->res.max_rx_qs)
  479. #define be_max_eqs(adapter) (adapter->res.max_evt_qs)
  480. #define be_if_cap_flags(adapter) (adapter->res.if_cap_flags)
  481. static inline u16 be_max_qs(struct be_adapter *adapter)
  482. {
  483. /* If no RSS, need atleast the one def RXQ */
  484. u16 num = max_t(u16, be_max_rss(adapter), 1);
  485. num = min(num, be_max_eqs(adapter));
  486. return min_t(u16, num, num_online_cpus());
  487. }
  488. /* Is BE in pvid_tagging mode */
  489. #define be_pvid_tagging_enabled(adapter) (adapter->pvid)
  490. /* Is BE in QNQ multi-channel mode */
  491. #define be_is_qnq_mode(adapter) (adapter->function_mode & QNQ_MODE)
  492. #define lancer_chip(adapter) (adapter->pdev->device == OC_DEVICE_ID3 || \
  493. adapter->pdev->device == OC_DEVICE_ID4)
  494. #define skyhawk_chip(adapter) (adapter->pdev->device == OC_DEVICE_ID5 || \
  495. adapter->pdev->device == OC_DEVICE_ID6)
  496. #define BE3_chip(adapter) (adapter->pdev->device == BE_DEVICE_ID2 || \
  497. adapter->pdev->device == OC_DEVICE_ID2)
  498. #define BE2_chip(adapter) (adapter->pdev->device == BE_DEVICE_ID1 || \
  499. adapter->pdev->device == OC_DEVICE_ID1)
  500. #define BEx_chip(adapter) (BE3_chip(adapter) || BE2_chip(adapter))
  501. #define be_roce_supported(adapter) (skyhawk_chip(adapter) && \
  502. (adapter->function_mode & RDMA_ENABLED))
  503. extern const struct ethtool_ops be_ethtool_ops;
  504. #define msix_enabled(adapter) (adapter->num_msix_vec > 0)
  505. #define num_irqs(adapter) (msix_enabled(adapter) ? \
  506. adapter->num_msix_vec : 1)
  507. #define tx_stats(txo) (&(txo)->stats)
  508. #define rx_stats(rxo) (&(rxo)->stats)
  509. /* The default RXQ is the last RXQ */
  510. #define default_rxo(adpt) (&adpt->rx_obj[adpt->num_rx_qs - 1])
  511. #define for_all_rx_queues(adapter, rxo, i) \
  512. for (i = 0, rxo = &adapter->rx_obj[i]; i < adapter->num_rx_qs; \
  513. i++, rxo++)
  514. /* Skip the default non-rss queue (last one)*/
  515. #define for_all_rss_queues(adapter, rxo, i) \
  516. for (i = 0, rxo = &adapter->rx_obj[i]; i < (adapter->num_rx_qs - 1);\
  517. i++, rxo++)
  518. #define for_all_tx_queues(adapter, txo, i) \
  519. for (i = 0, txo = &adapter->tx_obj[i]; i < adapter->num_tx_qs; \
  520. i++, txo++)
  521. #define for_all_evt_queues(adapter, eqo, i) \
  522. for (i = 0, eqo = &adapter->eq_obj[i]; i < adapter->num_evt_qs; \
  523. i++, eqo++)
  524. #define for_all_rx_queues_on_eq(adapter, eqo, rxo, i) \
  525. for (i = eqo->idx, rxo = &adapter->rx_obj[i]; i < adapter->num_rx_qs;\
  526. i += adapter->num_evt_qs, rxo += adapter->num_evt_qs)
  527. #define is_mcc_eqo(eqo) (eqo->idx == 0)
  528. #define mcc_eqo(adapter) (&adapter->eq_obj[0])
  529. #define PAGE_SHIFT_4K 12
  530. #define PAGE_SIZE_4K (1 << PAGE_SHIFT_4K)
  531. /* Returns number of pages spanned by the data starting at the given addr */
  532. #define PAGES_4K_SPANNED(_address, size) \
  533. ((u32)((((size_t)(_address) & (PAGE_SIZE_4K - 1)) + \
  534. (size) + (PAGE_SIZE_4K - 1)) >> PAGE_SHIFT_4K))
  535. /* Returns bit offset within a DWORD of a bitfield */
  536. #define AMAP_BIT_OFFSET(_struct, field) \
  537. (((size_t)&(((_struct *)0)->field))%32)
  538. /* Returns the bit mask of the field that is NOT shifted into location. */
  539. static inline u32 amap_mask(u32 bitsize)
  540. {
  541. return (bitsize == 32 ? 0xFFFFFFFF : (1 << bitsize) - 1);
  542. }
  543. static inline void
  544. amap_set(void *ptr, u32 dw_offset, u32 mask, u32 offset, u32 value)
  545. {
  546. u32 *dw = (u32 *) ptr + dw_offset;
  547. *dw &= ~(mask << offset);
  548. *dw |= (mask & value) << offset;
  549. }
  550. #define AMAP_SET_BITS(_struct, field, ptr, val) \
  551. amap_set(ptr, \
  552. offsetof(_struct, field)/32, \
  553. amap_mask(sizeof(((_struct *)0)->field)), \
  554. AMAP_BIT_OFFSET(_struct, field), \
  555. val)
  556. static inline u32 amap_get(void *ptr, u32 dw_offset, u32 mask, u32 offset)
  557. {
  558. u32 *dw = (u32 *) ptr;
  559. return mask & (*(dw + dw_offset) >> offset);
  560. }
  561. #define AMAP_GET_BITS(_struct, field, ptr) \
  562. amap_get(ptr, \
  563. offsetof(_struct, field)/32, \
  564. amap_mask(sizeof(((_struct *)0)->field)), \
  565. AMAP_BIT_OFFSET(_struct, field))
  566. #define be_dws_cpu_to_le(wrb, len) swap_dws(wrb, len)
  567. #define be_dws_le_to_cpu(wrb, len) swap_dws(wrb, len)
  568. static inline void swap_dws(void *wrb, int len)
  569. {
  570. #ifdef __BIG_ENDIAN
  571. u32 *dw = wrb;
  572. BUG_ON(len % 4);
  573. do {
  574. *dw = cpu_to_le32(*dw);
  575. dw++;
  576. len -= 4;
  577. } while (len);
  578. #endif /* __BIG_ENDIAN */
  579. }
  580. static inline u8 is_tcp_pkt(struct sk_buff *skb)
  581. {
  582. u8 val = 0;
  583. if (ip_hdr(skb)->version == 4)
  584. val = (ip_hdr(skb)->protocol == IPPROTO_TCP);
  585. else if (ip_hdr(skb)->version == 6)
  586. val = (ipv6_hdr(skb)->nexthdr == NEXTHDR_TCP);
  587. return val;
  588. }
  589. static inline u8 is_udp_pkt(struct sk_buff *skb)
  590. {
  591. u8 val = 0;
  592. if (ip_hdr(skb)->version == 4)
  593. val = (ip_hdr(skb)->protocol == IPPROTO_UDP);
  594. else if (ip_hdr(skb)->version == 6)
  595. val = (ipv6_hdr(skb)->nexthdr == NEXTHDR_UDP);
  596. return val;
  597. }
  598. static inline bool is_ipv4_pkt(struct sk_buff *skb)
  599. {
  600. return skb->protocol == htons(ETH_P_IP) && ip_hdr(skb)->version == 4;
  601. }
  602. static inline void be_vf_eth_addr_generate(struct be_adapter *adapter, u8 *mac)
  603. {
  604. u32 addr;
  605. addr = jhash(adapter->netdev->dev_addr, ETH_ALEN, 0);
  606. mac[5] = (u8)(addr & 0xFF);
  607. mac[4] = (u8)((addr >> 8) & 0xFF);
  608. mac[3] = (u8)((addr >> 16) & 0xFF);
  609. /* Use the OUI from the current MAC address */
  610. memcpy(mac, adapter->netdev->dev_addr, 3);
  611. }
  612. static inline bool be_multi_rxq(const struct be_adapter *adapter)
  613. {
  614. return adapter->num_rx_qs > 1;
  615. }
  616. static inline bool be_error(struct be_adapter *adapter)
  617. {
  618. return adapter->eeh_error || adapter->hw_error || adapter->fw_timeout;
  619. }
  620. static inline bool be_hw_error(struct be_adapter *adapter)
  621. {
  622. return adapter->eeh_error || adapter->hw_error;
  623. }
  624. static inline void be_clear_all_error(struct be_adapter *adapter)
  625. {
  626. adapter->eeh_error = false;
  627. adapter->hw_error = false;
  628. adapter->fw_timeout = false;
  629. }
  630. static inline bool be_is_wol_excluded(struct be_adapter *adapter)
  631. {
  632. struct pci_dev *pdev = adapter->pdev;
  633. if (!be_physfn(adapter))
  634. return true;
  635. switch (pdev->subsystem_device) {
  636. case OC_SUBSYS_DEVICE_ID1:
  637. case OC_SUBSYS_DEVICE_ID2:
  638. case OC_SUBSYS_DEVICE_ID3:
  639. case OC_SUBSYS_DEVICE_ID4:
  640. return true;
  641. default:
  642. return false;
  643. }
  644. }
  645. static inline int qnq_async_evt_rcvd(struct be_adapter *adapter)
  646. {
  647. return adapter->flags & BE_FLAGS_QNQ_ASYNC_EVT_RCVD;
  648. }
  649. #ifdef CONFIG_NET_RX_BUSY_POLL
  650. static inline bool be_lock_napi(struct be_eq_obj *eqo)
  651. {
  652. bool status = true;
  653. spin_lock(&eqo->lock); /* BH is already disabled */
  654. if (eqo->state & BE_EQ_LOCKED) {
  655. WARN_ON(eqo->state & BE_EQ_NAPI);
  656. eqo->state |= BE_EQ_NAPI_YIELD;
  657. status = false;
  658. } else {
  659. eqo->state = BE_EQ_NAPI;
  660. }
  661. spin_unlock(&eqo->lock);
  662. return status;
  663. }
  664. static inline void be_unlock_napi(struct be_eq_obj *eqo)
  665. {
  666. spin_lock(&eqo->lock); /* BH is already disabled */
  667. WARN_ON(eqo->state & (BE_EQ_POLL | BE_EQ_NAPI_YIELD));
  668. eqo->state = BE_EQ_IDLE;
  669. spin_unlock(&eqo->lock);
  670. }
  671. static inline bool be_lock_busy_poll(struct be_eq_obj *eqo)
  672. {
  673. bool status = true;
  674. spin_lock_bh(&eqo->lock);
  675. if (eqo->state & BE_EQ_LOCKED) {
  676. eqo->state |= BE_EQ_POLL_YIELD;
  677. status = false;
  678. } else {
  679. eqo->state |= BE_EQ_POLL;
  680. }
  681. spin_unlock_bh(&eqo->lock);
  682. return status;
  683. }
  684. static inline void be_unlock_busy_poll(struct be_eq_obj *eqo)
  685. {
  686. spin_lock_bh(&eqo->lock);
  687. WARN_ON(eqo->state & (BE_EQ_NAPI));
  688. eqo->state = BE_EQ_IDLE;
  689. spin_unlock_bh(&eqo->lock);
  690. }
  691. static inline void be_enable_busy_poll(struct be_eq_obj *eqo)
  692. {
  693. spin_lock_init(&eqo->lock);
  694. eqo->state = BE_EQ_IDLE;
  695. }
  696. static inline void be_disable_busy_poll(struct be_eq_obj *eqo)
  697. {
  698. local_bh_disable();
  699. /* It's enough to just acquire napi lock on the eqo to stop
  700. * be_busy_poll() from processing any queueus.
  701. */
  702. while (!be_lock_napi(eqo))
  703. mdelay(1);
  704. local_bh_enable();
  705. }
  706. #else /* CONFIG_NET_RX_BUSY_POLL */
  707. static inline bool be_lock_napi(struct be_eq_obj *eqo)
  708. {
  709. return true;
  710. }
  711. static inline void be_unlock_napi(struct be_eq_obj *eqo)
  712. {
  713. }
  714. static inline bool be_lock_busy_poll(struct be_eq_obj *eqo)
  715. {
  716. return false;
  717. }
  718. static inline void be_unlock_busy_poll(struct be_eq_obj *eqo)
  719. {
  720. }
  721. static inline void be_enable_busy_poll(struct be_eq_obj *eqo)
  722. {
  723. }
  724. static inline void be_disable_busy_poll(struct be_eq_obj *eqo)
  725. {
  726. }
  727. #endif /* CONFIG_NET_RX_BUSY_POLL */
  728. void be_cq_notify(struct be_adapter *adapter, u16 qid, bool arm,
  729. u16 num_popped);
  730. void be_link_status_update(struct be_adapter *adapter, u8 link_status);
  731. void be_parse_stats(struct be_adapter *adapter);
  732. int be_load_fw(struct be_adapter *adapter, u8 *func);
  733. bool be_is_wol_supported(struct be_adapter *adapter);
  734. bool be_pause_supported(struct be_adapter *adapter);
  735. u32 be_get_fw_log_level(struct be_adapter *adapter);
  736. static inline int fw_major_num(const char *fw_ver)
  737. {
  738. int fw_major = 0;
  739. sscanf(fw_ver, "%d.", &fw_major);
  740. return fw_major;
  741. }
  742. int be_update_queues(struct be_adapter *adapter);
  743. int be_poll(struct napi_struct *napi, int budget);
  744. /*
  745. * internal function to initialize-cleanup roce device.
  746. */
  747. void be_roce_dev_add(struct be_adapter *);
  748. void be_roce_dev_remove(struct be_adapter *);
  749. /*
  750. * internal function to open-close roce device during ifup-ifdown.
  751. */
  752. void be_roce_dev_open(struct be_adapter *);
  753. void be_roce_dev_close(struct be_adapter *);
  754. #endif /* BE_H */