iwl-trans.h 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551
  1. /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
  2. /*
  3. * Copyright (C) 2005-2014, 2018-2022 Intel Corporation
  4. * Copyright (C) 2013-2015 Intel Mobile Communications GmbH
  5. * Copyright (C) 2016-2017 Intel Deutschland GmbH
  6. */
  7. #ifndef __iwl_trans_h__
  8. #define __iwl_trans_h__
  9. #include <linux/ieee80211.h>
  10. #include <linux/mm.h> /* for page_address */
  11. #include <linux/lockdep.h>
  12. #include <linux/kernel.h>
  13. #include "iwl-debug.h"
  14. #include "iwl-config.h"
  15. #include "fw/img.h"
  16. #include "iwl-op-mode.h"
  17. #include <linux/firmware.h>
  18. #include "fw/api/cmdhdr.h"
  19. #include "fw/api/txq.h"
  20. #include "fw/api/dbg-tlv.h"
  21. #include "iwl-dbg-tlv.h"
  22. /**
  23. * DOC: Transport layer - what is it ?
  24. *
  25. * The transport layer is the layer that deals with the HW directly. It provides
  26. * an abstraction of the underlying HW to the upper layer. The transport layer
  27. * doesn't provide any policy, algorithm or anything of this kind, but only
  28. * mechanisms to make the HW do something. It is not completely stateless but
  29. * close to it.
  30. * We will have an implementation for each different supported bus.
  31. */
  32. /**
  33. * DOC: Life cycle of the transport layer
  34. *
  35. * The transport layer has a very precise life cycle.
  36. *
  37. * 1) A helper function is called during the module initialization and
  38. * registers the bus driver's ops with the transport's alloc function.
  39. * 2) Bus's probe calls to the transport layer's allocation functions.
  40. * Of course this function is bus specific.
  41. * 3) This allocation functions will spawn the upper layer which will
  42. * register mac80211.
  43. *
  44. * 4) At some point (i.e. mac80211's start call), the op_mode will call
  45. * the following sequence:
  46. * start_hw
  47. * start_fw
  48. *
  49. * 5) Then when finished (or reset):
  50. * stop_device
  51. *
  52. * 6) Eventually, the free function will be called.
  53. */
  54. /* default preset 0 (start from bit 16)*/
  55. #define IWL_FW_DBG_DOMAIN_POS 16
  56. #define IWL_FW_DBG_DOMAIN BIT(IWL_FW_DBG_DOMAIN_POS)
  57. #define IWL_TRANS_FW_DBG_DOMAIN(trans) IWL_FW_INI_DOMAIN_ALWAYS_ON
  58. #define FH_RSCSR_FRAME_SIZE_MSK 0x00003FFF /* bits 0-13 */
  59. #define FH_RSCSR_FRAME_INVALID 0x55550000
  60. #define FH_RSCSR_FRAME_ALIGN 0x40
  61. #define FH_RSCSR_RPA_EN BIT(25)
  62. #define FH_RSCSR_RADA_EN BIT(26)
  63. #define FH_RSCSR_RXQ_POS 16
  64. #define FH_RSCSR_RXQ_MASK 0x3F0000
  65. struct iwl_rx_packet {
  66. /*
  67. * The first 4 bytes of the RX frame header contain both the RX frame
  68. * size and some flags.
  69. * Bit fields:
  70. * 31: flag flush RB request
  71. * 30: flag ignore TC (terminal counter) request
  72. * 29: flag fast IRQ request
  73. * 28-27: Reserved
  74. * 26: RADA enabled
  75. * 25: Offload enabled
  76. * 24: RPF enabled
  77. * 23: RSS enabled
  78. * 22: Checksum enabled
  79. * 21-16: RX queue
  80. * 15-14: Reserved
  81. * 13-00: RX frame size
  82. */
  83. __le32 len_n_flags;
  84. struct iwl_cmd_header hdr;
  85. u8 data[];
  86. } __packed;
  87. static inline u32 iwl_rx_packet_len(const struct iwl_rx_packet *pkt)
  88. {
  89. return le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK;
  90. }
  91. static inline u32 iwl_rx_packet_payload_len(const struct iwl_rx_packet *pkt)
  92. {
  93. return iwl_rx_packet_len(pkt) - sizeof(pkt->hdr);
  94. }
  95. /**
  96. * enum CMD_MODE - how to send the host commands ?
  97. *
  98. * @CMD_ASYNC: Return right away and don't wait for the response
  99. * @CMD_WANT_SKB: Not valid with CMD_ASYNC. The caller needs the buffer of
  100. * the response. The caller needs to call iwl_free_resp when done.
  101. * @CMD_WANT_ASYNC_CALLBACK: the op_mode's async callback function must be
  102. * called after this command completes. Valid only with CMD_ASYNC.
  103. * @CMD_SEND_IN_D3: Allow the command to be sent in D3 mode, relevant to
  104. * SUSPEND and RESUME commands. We are in D3 mode when we set
  105. * trans->system_pm_mode to IWL_PLAT_PM_MODE_D3.
  106. */
  107. enum CMD_MODE {
  108. CMD_ASYNC = BIT(0),
  109. CMD_WANT_SKB = BIT(1),
  110. CMD_SEND_IN_RFKILL = BIT(2),
  111. CMD_WANT_ASYNC_CALLBACK = BIT(3),
  112. CMD_SEND_IN_D3 = BIT(4),
  113. };
  114. #define DEF_CMD_PAYLOAD_SIZE 320
  115. /**
  116. * struct iwl_device_cmd
  117. *
  118. * For allocation of the command and tx queues, this establishes the overall
  119. * size of the largest command we send to uCode, except for commands that
  120. * aren't fully copied and use other TFD space.
  121. */
  122. struct iwl_device_cmd {
  123. union {
  124. struct {
  125. struct iwl_cmd_header hdr; /* uCode API */
  126. u8 payload[DEF_CMD_PAYLOAD_SIZE];
  127. };
  128. struct {
  129. struct iwl_cmd_header_wide hdr_wide;
  130. u8 payload_wide[DEF_CMD_PAYLOAD_SIZE -
  131. sizeof(struct iwl_cmd_header_wide) +
  132. sizeof(struct iwl_cmd_header)];
  133. };
  134. };
  135. } __packed;
  136. /**
  137. * struct iwl_device_tx_cmd - buffer for TX command
  138. * @hdr: the header
  139. * @payload: the payload placeholder
  140. *
  141. * The actual structure is sized dynamically according to need.
  142. */
  143. struct iwl_device_tx_cmd {
  144. struct iwl_cmd_header hdr;
  145. u8 payload[];
  146. } __packed;
  147. #define TFD_MAX_PAYLOAD_SIZE (sizeof(struct iwl_device_cmd))
  148. /*
  149. * number of transfer buffers (fragments) per transmit frame descriptor;
  150. * this is just the driver's idea, the hardware supports 20
  151. */
  152. #define IWL_MAX_CMD_TBS_PER_TFD 2
  153. /* We need 2 entries for the TX command and header, and another one might
  154. * be needed for potential data in the SKB's head. The remaining ones can
  155. * be used for frags.
  156. */
  157. #define IWL_TRANS_MAX_FRAGS(trans) ((trans)->txqs.tfd.max_tbs - 3)
  158. /**
  159. * enum iwl_hcmd_dataflag - flag for each one of the chunks of the command
  160. *
  161. * @IWL_HCMD_DFL_NOCOPY: By default, the command is copied to the host command's
  162. * ring. The transport layer doesn't map the command's buffer to DMA, but
  163. * rather copies it to a previously allocated DMA buffer. This flag tells
  164. * the transport layer not to copy the command, but to map the existing
  165. * buffer (that is passed in) instead. This saves the memcpy and allows
  166. * commands that are bigger than the fixed buffer to be submitted.
  167. * Note that a TFD entry after a NOCOPY one cannot be a normal copied one.
  168. * @IWL_HCMD_DFL_DUP: Only valid without NOCOPY, duplicate the memory for this
  169. * chunk internally and free it again after the command completes. This
  170. * can (currently) be used only once per command.
  171. * Note that a TFD entry after a DUP one cannot be a normal copied one.
  172. */
  173. enum iwl_hcmd_dataflag {
  174. IWL_HCMD_DFL_NOCOPY = BIT(0),
  175. IWL_HCMD_DFL_DUP = BIT(1),
  176. };
  177. enum iwl_error_event_table_status {
  178. IWL_ERROR_EVENT_TABLE_LMAC1 = BIT(0),
  179. IWL_ERROR_EVENT_TABLE_LMAC2 = BIT(1),
  180. IWL_ERROR_EVENT_TABLE_UMAC = BIT(2),
  181. IWL_ERROR_EVENT_TABLE_TCM1 = BIT(3),
  182. IWL_ERROR_EVENT_TABLE_TCM2 = BIT(4),
  183. IWL_ERROR_EVENT_TABLE_RCM1 = BIT(5),
  184. IWL_ERROR_EVENT_TABLE_RCM2 = BIT(6),
  185. };
  186. /**
  187. * struct iwl_host_cmd - Host command to the uCode
  188. *
  189. * @data: array of chunks that composes the data of the host command
  190. * @resp_pkt: response packet, if %CMD_WANT_SKB was set
  191. * @_rx_page_order: (internally used to free response packet)
  192. * @_rx_page_addr: (internally used to free response packet)
  193. * @flags: can be CMD_*
  194. * @len: array of the lengths of the chunks in data
  195. * @dataflags: IWL_HCMD_DFL_*
  196. * @id: command id of the host command, for wide commands encoding the
  197. * version and group as well
  198. */
  199. struct iwl_host_cmd {
  200. const void *data[IWL_MAX_CMD_TBS_PER_TFD];
  201. struct iwl_rx_packet *resp_pkt;
  202. unsigned long _rx_page_addr;
  203. u32 _rx_page_order;
  204. u32 flags;
  205. u32 id;
  206. u16 len[IWL_MAX_CMD_TBS_PER_TFD];
  207. u8 dataflags[IWL_MAX_CMD_TBS_PER_TFD];
  208. };
  209. static inline void iwl_free_resp(struct iwl_host_cmd *cmd)
  210. {
  211. free_pages(cmd->_rx_page_addr, cmd->_rx_page_order);
  212. }
  213. struct iwl_rx_cmd_buffer {
  214. struct page *_page;
  215. int _offset;
  216. bool _page_stolen;
  217. u32 _rx_page_order;
  218. unsigned int truesize;
  219. };
  220. static inline void *rxb_addr(struct iwl_rx_cmd_buffer *r)
  221. {
  222. return (void *)((unsigned long)page_address(r->_page) + r->_offset);
  223. }
  224. static inline int rxb_offset(struct iwl_rx_cmd_buffer *r)
  225. {
  226. return r->_offset;
  227. }
  228. static inline struct page *rxb_steal_page(struct iwl_rx_cmd_buffer *r)
  229. {
  230. r->_page_stolen = true;
  231. get_page(r->_page);
  232. return r->_page;
  233. }
  234. static inline void iwl_free_rxb(struct iwl_rx_cmd_buffer *r)
  235. {
  236. __free_pages(r->_page, r->_rx_page_order);
  237. }
  238. #define MAX_NO_RECLAIM_CMDS 6
  239. #define IWL_MASK(lo, hi) ((1 << (hi)) | ((1 << (hi)) - (1 << (lo))))
  240. /*
  241. * Maximum number of HW queues the transport layer
  242. * currently supports
  243. */
  244. #define IWL_MAX_HW_QUEUES 32
  245. #define IWL_MAX_TVQM_QUEUES 512
  246. #define IWL_MAX_TID_COUNT 8
  247. #define IWL_MGMT_TID 15
  248. #define IWL_FRAME_LIMIT 64
  249. #define IWL_MAX_RX_HW_QUEUES 16
  250. #define IWL_9000_MAX_RX_HW_QUEUES 6
  251. /**
  252. * enum iwl_wowlan_status - WoWLAN image/device status
  253. * @IWL_D3_STATUS_ALIVE: firmware is still running after resume
  254. * @IWL_D3_STATUS_RESET: device was reset while suspended
  255. */
  256. enum iwl_d3_status {
  257. IWL_D3_STATUS_ALIVE,
  258. IWL_D3_STATUS_RESET,
  259. };
  260. /**
  261. * enum iwl_trans_status: transport status flags
  262. * @STATUS_SYNC_HCMD_ACTIVE: a SYNC command is being processed
  263. * @STATUS_DEVICE_ENABLED: APM is enabled
  264. * @STATUS_TPOWER_PMI: the device might be asleep (need to wake it up)
  265. * @STATUS_INT_ENABLED: interrupts are enabled
  266. * @STATUS_RFKILL_HW: the actual HW state of the RF-kill switch
  267. * @STATUS_RFKILL_OPMODE: RF-kill state reported to opmode
  268. * @STATUS_FW_ERROR: the fw is in error state
  269. * @STATUS_TRANS_GOING_IDLE: shutting down the trans, only special commands
  270. * are sent
  271. * @STATUS_TRANS_IDLE: the trans is idle - general commands are not to be sent
  272. * @STATUS_TRANS_DEAD: trans is dead - avoid any read/write operation
  273. * @STATUS_SUPPRESS_CMD_ERROR_ONCE: suppress "FW error in SYNC CMD" once,
  274. * e.g. for testing
  275. */
  276. enum iwl_trans_status {
  277. STATUS_SYNC_HCMD_ACTIVE,
  278. STATUS_DEVICE_ENABLED,
  279. STATUS_TPOWER_PMI,
  280. STATUS_INT_ENABLED,
  281. STATUS_RFKILL_HW,
  282. STATUS_RFKILL_OPMODE,
  283. STATUS_FW_ERROR,
  284. STATUS_TRANS_GOING_IDLE,
  285. STATUS_TRANS_IDLE,
  286. STATUS_TRANS_DEAD,
  287. STATUS_SUPPRESS_CMD_ERROR_ONCE,
  288. };
  289. static inline int
  290. iwl_trans_get_rb_size_order(enum iwl_amsdu_size rb_size)
  291. {
  292. switch (rb_size) {
  293. case IWL_AMSDU_2K:
  294. return get_order(2 * 1024);
  295. case IWL_AMSDU_4K:
  296. return get_order(4 * 1024);
  297. case IWL_AMSDU_8K:
  298. return get_order(8 * 1024);
  299. case IWL_AMSDU_12K:
  300. return get_order(16 * 1024);
  301. default:
  302. WARN_ON(1);
  303. return -1;
  304. }
  305. }
  306. static inline int
  307. iwl_trans_get_rb_size(enum iwl_amsdu_size rb_size)
  308. {
  309. switch (rb_size) {
  310. case IWL_AMSDU_2K:
  311. return 2 * 1024;
  312. case IWL_AMSDU_4K:
  313. return 4 * 1024;
  314. case IWL_AMSDU_8K:
  315. return 8 * 1024;
  316. case IWL_AMSDU_12K:
  317. return 16 * 1024;
  318. default:
  319. WARN_ON(1);
  320. return 0;
  321. }
  322. }
  323. struct iwl_hcmd_names {
  324. u8 cmd_id;
  325. const char *const cmd_name;
  326. };
  327. #define HCMD_NAME(x) \
  328. { .cmd_id = x, .cmd_name = #x }
  329. struct iwl_hcmd_arr {
  330. const struct iwl_hcmd_names *arr;
  331. int size;
  332. };
  333. #define HCMD_ARR(x) \
  334. { .arr = x, .size = ARRAY_SIZE(x) }
  335. /**
  336. * struct iwl_dump_sanitize_ops - dump sanitization operations
  337. * @frob_txf: Scrub the TX FIFO data
  338. * @frob_hcmd: Scrub a host command, the %hcmd pointer is to the header
  339. * but that might be short or long (&struct iwl_cmd_header or
  340. * &struct iwl_cmd_header_wide)
  341. * @frob_mem: Scrub memory data
  342. */
  343. struct iwl_dump_sanitize_ops {
  344. void (*frob_txf)(void *ctx, void *buf, size_t buflen);
  345. void (*frob_hcmd)(void *ctx, void *hcmd, size_t buflen);
  346. void (*frob_mem)(void *ctx, u32 mem_addr, void *mem, size_t buflen);
  347. };
  348. /**
  349. * struct iwl_trans_config - transport configuration
  350. *
  351. * @op_mode: pointer to the upper layer.
  352. * @cmd_queue: the index of the command queue.
  353. * Must be set before start_fw.
  354. * @cmd_fifo: the fifo for host commands
  355. * @cmd_q_wdg_timeout: the timeout of the watchdog timer for the command queue.
  356. * @no_reclaim_cmds: Some devices erroneously don't set the
  357. * SEQ_RX_FRAME bit on some notifications, this is the
  358. * list of such notifications to filter. Max length is
  359. * %MAX_NO_RECLAIM_CMDS.
  360. * @n_no_reclaim_cmds: # of commands in list
  361. * @rx_buf_size: RX buffer size needed for A-MSDUs
  362. * if unset 4k will be the RX buffer size
  363. * @bc_table_dword: set to true if the BC table expects the byte count to be
  364. * in DWORD (as opposed to bytes)
  365. * @scd_set_active: should the transport configure the SCD for HCMD queue
  366. * @command_groups: array of command groups, each member is an array of the
  367. * commands in the group; for debugging only
  368. * @command_groups_size: number of command groups, to avoid illegal access
  369. * @cb_data_offs: offset inside skb->cb to store transport data at, must have
  370. * space for at least two pointers
  371. * @fw_reset_handshake: firmware supports reset flow handshake
  372. * @queue_alloc_cmd_ver: queue allocation command version, set to 0
  373. * for using the older SCD_QUEUE_CFG, set to the version of
  374. * SCD_QUEUE_CONFIG_CMD otherwise.
  375. */
  376. struct iwl_trans_config {
  377. struct iwl_op_mode *op_mode;
  378. u8 cmd_queue;
  379. u8 cmd_fifo;
  380. unsigned int cmd_q_wdg_timeout;
  381. const u8 *no_reclaim_cmds;
  382. unsigned int n_no_reclaim_cmds;
  383. enum iwl_amsdu_size rx_buf_size;
  384. bool bc_table_dword;
  385. bool scd_set_active;
  386. const struct iwl_hcmd_arr *command_groups;
  387. int command_groups_size;
  388. u8 cb_data_offs;
  389. bool fw_reset_handshake;
  390. u8 queue_alloc_cmd_ver;
  391. };
  392. struct iwl_trans_dump_data {
  393. u32 len;
  394. u8 data[];
  395. };
  396. struct iwl_trans;
  397. struct iwl_trans_txq_scd_cfg {
  398. u8 fifo;
  399. u8 sta_id;
  400. u8 tid;
  401. bool aggregate;
  402. int frame_limit;
  403. };
  404. /**
  405. * struct iwl_trans_rxq_dma_data - RX queue DMA data
  406. * @fr_bd_cb: DMA address of free BD cyclic buffer
  407. * @fr_bd_wid: Initial write index of the free BD cyclic buffer
  408. * @urbd_stts_wrptr: DMA address of urbd_stts_wrptr
  409. * @ur_bd_cb: DMA address of used BD cyclic buffer
  410. */
  411. struct iwl_trans_rxq_dma_data {
  412. u64 fr_bd_cb;
  413. u32 fr_bd_wid;
  414. u64 urbd_stts_wrptr;
  415. u64 ur_bd_cb;
  416. };
  417. /**
  418. * struct iwl_trans_ops - transport specific operations
  419. *
  420. * All the handlers MUST be implemented
  421. *
  422. * @start_hw: starts the HW. From that point on, the HW can send interrupts.
  423. * May sleep.
  424. * @op_mode_leave: Turn off the HW RF kill indication if on
  425. * May sleep
  426. * @start_fw: allocates and inits all the resources for the transport
  427. * layer. Also kick a fw image.
  428. * May sleep
  429. * @fw_alive: called when the fw sends alive notification. If the fw provides
  430. * the SCD base address in SRAM, then provide it here, or 0 otherwise.
  431. * May sleep
  432. * @stop_device: stops the whole device (embedded CPU put to reset) and stops
  433. * the HW. From that point on, the HW will be stopped but will still issue
  434. * an interrupt if the HW RF kill switch is triggered.
  435. * This callback must do the right thing and not crash even if %start_hw()
  436. * was called but not &start_fw(). May sleep.
  437. * @d3_suspend: put the device into the correct mode for WoWLAN during
  438. * suspend. This is optional, if not implemented WoWLAN will not be
  439. * supported. This callback may sleep.
  440. * @d3_resume: resume the device after WoWLAN, enabling the opmode to
  441. * talk to the WoWLAN image to get its status. This is optional, if not
  442. * implemented WoWLAN will not be supported. This callback may sleep.
  443. * @send_cmd:send a host command. Must return -ERFKILL if RFkill is asserted.
  444. * If RFkill is asserted in the middle of a SYNC host command, it must
  445. * return -ERFKILL straight away.
  446. * May sleep only if CMD_ASYNC is not set
  447. * @tx: send an skb. The transport relies on the op_mode to zero the
  448. * the ieee80211_tx_info->driver_data. If the MPDU is an A-MSDU, all
  449. * the CSUM will be taken care of (TCP CSUM and IP header in case of
  450. * IPv4). If the MPDU is a single MSDU, the op_mode must compute the IP
  451. * header if it is IPv4.
  452. * Must be atomic
  453. * @reclaim: free packet until ssn. Returns a list of freed packets.
  454. * Must be atomic
  455. * @txq_enable: setup a queue. To setup an AC queue, use the
  456. * iwl_trans_ac_txq_enable wrapper. fw_alive must have been called before
  457. * this one. The op_mode must not configure the HCMD queue. The scheduler
  458. * configuration may be %NULL, in which case the hardware will not be
  459. * configured. If true is returned, the operation mode needs to increment
  460. * the sequence number of the packets routed to this queue because of a
  461. * hardware scheduler bug. May sleep.
  462. * @txq_disable: de-configure a Tx queue to send AMPDUs
  463. * Must be atomic
  464. * @txq_set_shared_mode: change Tx queue shared/unshared marking
  465. * @wait_tx_queues_empty: wait until tx queues are empty. May sleep.
  466. * @wait_txq_empty: wait until specific tx queue is empty. May sleep.
  467. * @freeze_txq_timer: prevents the timer of the queue from firing until the
  468. * queue is set to awake. Must be atomic.
  469. * @block_txq_ptrs: stop updating the write pointers of the Tx queues. Note
  470. * that the transport needs to refcount the calls since this function
  471. * will be called several times with block = true, and then the queues
  472. * need to be unblocked only after the same number of calls with
  473. * block = false.
  474. * @write8: write a u8 to a register at offset ofs from the BAR
  475. * @write32: write a u32 to a register at offset ofs from the BAR
  476. * @read32: read a u32 register at offset ofs from the BAR
  477. * @read_prph: read a DWORD from a periphery register
  478. * @write_prph: write a DWORD to a periphery register
  479. * @read_mem: read device's SRAM in DWORD
  480. * @write_mem: write device's SRAM in DWORD. If %buf is %NULL, then the memory
  481. * will be zeroed.
  482. * @read_config32: read a u32 value from the device's config space at
  483. * the given offset.
  484. * @configure: configure parameters required by the transport layer from
  485. * the op_mode. May be called several times before start_fw, can't be
  486. * called after that.
  487. * @set_pmi: set the power pmi state
  488. * @grab_nic_access: wake the NIC to be able to access non-HBUS regs.
  489. * Sleeping is not allowed between grab_nic_access and
  490. * release_nic_access.
  491. * @release_nic_access: let the NIC go to sleep. The "flags" parameter
  492. * must be the same one that was sent before to the grab_nic_access.
  493. * @set_bits_mask - set SRAM register according to value and mask.
  494. * @dump_data: return a vmalloc'ed buffer with debug data, maybe containing last
  495. * TX'ed commands and similar. The buffer will be vfree'd by the caller.
  496. * Note that the transport must fill in the proper file headers.
  497. * @debugfs_cleanup: used in the driver unload flow to make a proper cleanup
  498. * of the trans debugfs
  499. * @set_pnvm: set the pnvm data in the prph scratch buffer, inside the
  500. * context info.
  501. * @interrupts: disable/enable interrupts to transport
  502. */
  503. struct iwl_trans_ops {
  504. int (*start_hw)(struct iwl_trans *iwl_trans);
  505. void (*op_mode_leave)(struct iwl_trans *iwl_trans);
  506. int (*start_fw)(struct iwl_trans *trans, const struct fw_img *fw,
  507. bool run_in_rfkill);
  508. void (*fw_alive)(struct iwl_trans *trans, u32 scd_addr);
  509. void (*stop_device)(struct iwl_trans *trans);
  510. int (*d3_suspend)(struct iwl_trans *trans, bool test, bool reset);
  511. int (*d3_resume)(struct iwl_trans *trans, enum iwl_d3_status *status,
  512. bool test, bool reset);
  513. int (*send_cmd)(struct iwl_trans *trans, struct iwl_host_cmd *cmd);
  514. int (*tx)(struct iwl_trans *trans, struct sk_buff *skb,
  515. struct iwl_device_tx_cmd *dev_cmd, int queue);
  516. void (*reclaim)(struct iwl_trans *trans, int queue, int ssn,
  517. struct sk_buff_head *skbs, bool is_flush);
  518. void (*set_q_ptrs)(struct iwl_trans *trans, int queue, int ptr);
  519. bool (*txq_enable)(struct iwl_trans *trans, int queue, u16 ssn,
  520. const struct iwl_trans_txq_scd_cfg *cfg,
  521. unsigned int queue_wdg_timeout);
  522. void (*txq_disable)(struct iwl_trans *trans, int queue,
  523. bool configure_scd);
  524. /* 22000 functions */
  525. int (*txq_alloc)(struct iwl_trans *trans, u32 flags,
  526. u32 sta_mask, u8 tid,
  527. int size, unsigned int queue_wdg_timeout);
  528. void (*txq_free)(struct iwl_trans *trans, int queue);
  529. int (*rxq_dma_data)(struct iwl_trans *trans, int queue,
  530. struct iwl_trans_rxq_dma_data *data);
  531. void (*txq_set_shared_mode)(struct iwl_trans *trans, u32 txq_id,
  532. bool shared);
  533. int (*wait_tx_queues_empty)(struct iwl_trans *trans, u32 txq_bm);
  534. int (*wait_txq_empty)(struct iwl_trans *trans, int queue);
  535. void (*freeze_txq_timer)(struct iwl_trans *trans, unsigned long txqs,
  536. bool freeze);
  537. void (*block_txq_ptrs)(struct iwl_trans *trans, bool block);
  538. void (*write8)(struct iwl_trans *trans, u32 ofs, u8 val);
  539. void (*write32)(struct iwl_trans *trans, u32 ofs, u32 val);
  540. u32 (*read32)(struct iwl_trans *trans, u32 ofs);
  541. u32 (*read_prph)(struct iwl_trans *trans, u32 ofs);
  542. void (*write_prph)(struct iwl_trans *trans, u32 ofs, u32 val);
  543. int (*read_mem)(struct iwl_trans *trans, u32 addr,
  544. void *buf, int dwords);
  545. int (*write_mem)(struct iwl_trans *trans, u32 addr,
  546. const void *buf, int dwords);
  547. int (*read_config32)(struct iwl_trans *trans, u32 ofs, u32 *val);
  548. void (*configure)(struct iwl_trans *trans,
  549. const struct iwl_trans_config *trans_cfg);
  550. void (*set_pmi)(struct iwl_trans *trans, bool state);
  551. int (*sw_reset)(struct iwl_trans *trans, bool retake_ownership);
  552. bool (*grab_nic_access)(struct iwl_trans *trans);
  553. void (*release_nic_access)(struct iwl_trans *trans);
  554. void (*set_bits_mask)(struct iwl_trans *trans, u32 reg, u32 mask,
  555. u32 value);
  556. struct iwl_trans_dump_data *(*dump_data)(struct iwl_trans *trans,
  557. u32 dump_mask,
  558. const struct iwl_dump_sanitize_ops *sanitize_ops,
  559. void *sanitize_ctx);
  560. void (*debugfs_cleanup)(struct iwl_trans *trans);
  561. void (*sync_nmi)(struct iwl_trans *trans);
  562. int (*set_pnvm)(struct iwl_trans *trans, const void *data, u32 len);
  563. int (*set_reduce_power)(struct iwl_trans *trans,
  564. const void *data, u32 len);
  565. void (*interrupts)(struct iwl_trans *trans, bool enable);
  566. int (*imr_dma_data)(struct iwl_trans *trans,
  567. u32 dst_addr, u64 src_addr,
  568. u32 byte_cnt);
  569. };
  570. /**
  571. * enum iwl_trans_state - state of the transport layer
  572. *
  573. * @IWL_TRANS_NO_FW: firmware wasn't started yet, or crashed
  574. * @IWL_TRANS_FW_STARTED: FW was started, but not alive yet
  575. * @IWL_TRANS_FW_ALIVE: FW has sent an alive response
  576. */
  577. enum iwl_trans_state {
  578. IWL_TRANS_NO_FW,
  579. IWL_TRANS_FW_STARTED,
  580. IWL_TRANS_FW_ALIVE,
  581. };
  582. /**
  583. * DOC: Platform power management
  584. *
  585. * In system-wide power management the entire platform goes into a low
  586. * power state (e.g. idle or suspend to RAM) at the same time and the
  587. * device is configured as a wakeup source for the entire platform.
  588. * This is usually triggered by userspace activity (e.g. the user
  589. * presses the suspend button or a power management daemon decides to
  590. * put the platform in low power mode). The device's behavior in this
  591. * mode is dictated by the wake-on-WLAN configuration.
  592. *
  593. * The terms used for the device's behavior are as follows:
  594. *
  595. * - D0: the device is fully powered and the host is awake;
  596. * - D3: the device is in low power mode and only reacts to
  597. * specific events (e.g. magic-packet received or scan
  598. * results found);
  599. *
  600. * These terms reflect the power modes in the firmware and are not to
  601. * be confused with the physical device power state.
  602. */
  603. /**
  604. * enum iwl_plat_pm_mode - platform power management mode
  605. *
  606. * This enumeration describes the device's platform power management
  607. * behavior when in system-wide suspend (i.e WoWLAN).
  608. *
  609. * @IWL_PLAT_PM_MODE_DISABLED: power management is disabled for this
  610. * device. In system-wide suspend mode, it means that the all
  611. * connections will be closed automatically by mac80211 before
  612. * the platform is suspended.
  613. * @IWL_PLAT_PM_MODE_D3: the device goes into D3 mode (i.e. WoWLAN).
  614. */
  615. enum iwl_plat_pm_mode {
  616. IWL_PLAT_PM_MODE_DISABLED,
  617. IWL_PLAT_PM_MODE_D3,
  618. };
  619. /**
  620. * enum iwl_ini_cfg_state
  621. * @IWL_INI_CFG_STATE_NOT_LOADED: no debug cfg was given
  622. * @IWL_INI_CFG_STATE_LOADED: debug cfg was found and loaded
  623. * @IWL_INI_CFG_STATE_CORRUPTED: debug cfg was found and some of the TLVs
  624. * are corrupted. The rest of the debug TLVs will still be used
  625. */
  626. enum iwl_ini_cfg_state {
  627. IWL_INI_CFG_STATE_NOT_LOADED,
  628. IWL_INI_CFG_STATE_LOADED,
  629. IWL_INI_CFG_STATE_CORRUPTED,
  630. };
  631. /* Max time to wait for nmi interrupt */
  632. #define IWL_TRANS_NMI_TIMEOUT (HZ / 4)
  633. /**
  634. * struct iwl_dram_data
  635. * @physical: page phy pointer
  636. * @block: pointer to the allocated block/page
  637. * @size: size of the block/page
  638. */
  639. struct iwl_dram_data {
  640. dma_addr_t physical;
  641. void *block;
  642. int size;
  643. };
  644. /**
  645. * struct iwl_fw_mon - fw monitor per allocation id
  646. * @num_frags: number of fragments
  647. * @frags: an array of DRAM buffer fragments
  648. */
  649. struct iwl_fw_mon {
  650. u32 num_frags;
  651. struct iwl_dram_data *frags;
  652. };
  653. /**
  654. * struct iwl_self_init_dram - dram data used by self init process
  655. * @fw: lmac and umac dram data
  656. * @fw_cnt: total number of items in array
  657. * @paging: paging dram data
  658. * @paging_cnt: total number of items in array
  659. */
  660. struct iwl_self_init_dram {
  661. struct iwl_dram_data *fw;
  662. int fw_cnt;
  663. struct iwl_dram_data *paging;
  664. int paging_cnt;
  665. };
  666. /**
  667. * struct iwl_imr_data - imr dram data used during debug process
  668. * @imr_enable: imr enable status received from fw
  669. * @imr_size: imr dram size received from fw
  670. * @sram_addr: sram address from debug tlv
  671. * @sram_size: sram size from debug tlv
  672. * @imr2sram_remainbyte`: size remained after each dma transfer
  673. * @imr_curr_addr: current dst address used during dma transfer
  674. * @imr_base_addr: imr address received from fw
  675. */
  676. struct iwl_imr_data {
  677. u32 imr_enable;
  678. u32 imr_size;
  679. u32 sram_addr;
  680. u32 sram_size;
  681. u32 imr2sram_remainbyte;
  682. u64 imr_curr_addr;
  683. __le64 imr_base_addr;
  684. };
  685. /**
  686. * struct iwl_trans_debug - transport debug related data
  687. *
  688. * @n_dest_reg: num of reg_ops in %dbg_dest_tlv
  689. * @rec_on: true iff there is a fw debug recording currently active
  690. * @dest_tlv: points to the destination TLV for debug
  691. * @conf_tlv: array of pointers to configuration TLVs for debug
  692. * @trigger_tlv: array of pointers to triggers TLVs for debug
  693. * @lmac_error_event_table: addrs of lmacs error tables
  694. * @umac_error_event_table: addr of umac error table
  695. * @tcm_error_event_table: address(es) of TCM error table(s)
  696. * @rcm_error_event_table: address(es) of RCM error table(s)
  697. * @error_event_table_tlv_status: bitmap that indicates what error table
  698. * pointers was recevied via TLV. uses enum &iwl_error_event_table_status
  699. * @internal_ini_cfg: internal debug cfg state. Uses &enum iwl_ini_cfg_state
  700. * @external_ini_cfg: external debug cfg state. Uses &enum iwl_ini_cfg_state
  701. * @fw_mon_cfg: debug buffer allocation configuration
  702. * @fw_mon_ini: DRAM buffer fragments per allocation id
  703. * @fw_mon: DRAM buffer for firmware monitor
  704. * @hw_error: equals true if hw error interrupt was received from the FW
  705. * @ini_dest: debug monitor destination uses &enum iwl_fw_ini_buffer_location
  706. * @active_regions: active regions
  707. * @debug_info_tlv_list: list of debug info TLVs
  708. * @time_point: array of debug time points
  709. * @periodic_trig_list: periodic triggers list
  710. * @domains_bitmap: bitmap of active domains other than &IWL_FW_INI_DOMAIN_ALWAYS_ON
  711. * @ucode_preset: preset based on ucode
  712. */
  713. struct iwl_trans_debug {
  714. u8 n_dest_reg;
  715. bool rec_on;
  716. const struct iwl_fw_dbg_dest_tlv_v1 *dest_tlv;
  717. const struct iwl_fw_dbg_conf_tlv *conf_tlv[FW_DBG_CONF_MAX];
  718. struct iwl_fw_dbg_trigger_tlv * const *trigger_tlv;
  719. u32 lmac_error_event_table[2];
  720. u32 umac_error_event_table;
  721. u32 tcm_error_event_table[2];
  722. u32 rcm_error_event_table[2];
  723. unsigned int error_event_table_tlv_status;
  724. enum iwl_ini_cfg_state internal_ini_cfg;
  725. enum iwl_ini_cfg_state external_ini_cfg;
  726. struct iwl_fw_ini_allocation_tlv fw_mon_cfg[IWL_FW_INI_ALLOCATION_NUM];
  727. struct iwl_fw_mon fw_mon_ini[IWL_FW_INI_ALLOCATION_NUM];
  728. struct iwl_dram_data fw_mon;
  729. bool hw_error;
  730. enum iwl_fw_ini_buffer_location ini_dest;
  731. u64 unsupported_region_msk;
  732. struct iwl_ucode_tlv *active_regions[IWL_FW_INI_MAX_REGION_ID];
  733. struct list_head debug_info_tlv_list;
  734. struct iwl_dbg_tlv_time_point_data
  735. time_point[IWL_FW_INI_TIME_POINT_NUM];
  736. struct list_head periodic_trig_list;
  737. u32 domains_bitmap;
  738. u32 ucode_preset;
  739. bool restart_required;
  740. u32 last_tp_resetfw;
  741. struct iwl_imr_data imr_data;
  742. };
  743. struct iwl_dma_ptr {
  744. dma_addr_t dma;
  745. void *addr;
  746. size_t size;
  747. };
  748. struct iwl_cmd_meta {
  749. /* only for SYNC commands, iff the reply skb is wanted */
  750. struct iwl_host_cmd *source;
  751. u32 flags;
  752. u32 tbs;
  753. };
  754. /*
  755. * The FH will write back to the first TB only, so we need to copy some data
  756. * into the buffer regardless of whether it should be mapped or not.
  757. * This indicates how big the first TB must be to include the scratch buffer
  758. * and the assigned PN.
  759. * Since PN location is 8 bytes at offset 12, it's 20 now.
  760. * If we make it bigger then allocations will be bigger and copy slower, so
  761. * that's probably not useful.
  762. */
  763. #define IWL_FIRST_TB_SIZE 20
  764. #define IWL_FIRST_TB_SIZE_ALIGN ALIGN(IWL_FIRST_TB_SIZE, 64)
  765. struct iwl_pcie_txq_entry {
  766. void *cmd;
  767. struct sk_buff *skb;
  768. /* buffer to free after command completes */
  769. const void *free_buf;
  770. struct iwl_cmd_meta meta;
  771. };
  772. struct iwl_pcie_first_tb_buf {
  773. u8 buf[IWL_FIRST_TB_SIZE_ALIGN];
  774. };
  775. /**
  776. * struct iwl_txq - Tx Queue for DMA
  777. * @q: generic Rx/Tx queue descriptor
  778. * @tfds: transmit frame descriptors (DMA memory)
  779. * @first_tb_bufs: start of command headers, including scratch buffers, for
  780. * the writeback -- this is DMA memory and an array holding one buffer
  781. * for each command on the queue
  782. * @first_tb_dma: DMA address for the first_tb_bufs start
  783. * @entries: transmit entries (driver state)
  784. * @lock: queue lock
  785. * @stuck_timer: timer that fires if queue gets stuck
  786. * @trans: pointer back to transport (for timer)
  787. * @need_update: indicates need to update read/write index
  788. * @ampdu: true if this queue is an ampdu queue for an specific RA/TID
  789. * @wd_timeout: queue watchdog timeout (jiffies) - per queue
  790. * @frozen: tx stuck queue timer is frozen
  791. * @frozen_expiry_remainder: remember how long until the timer fires
  792. * @bc_tbl: byte count table of the queue (relevant only for gen2 transport)
  793. * @write_ptr: 1-st empty entry (index) host_w
  794. * @read_ptr: last used entry (index) host_r
  795. * @dma_addr: physical addr for BD's
  796. * @n_window: safe queue window
  797. * @id: queue id
  798. * @low_mark: low watermark, resume queue if free space more than this
  799. * @high_mark: high watermark, stop queue if free space less than this
  800. *
  801. * A Tx queue consists of circular buffer of BDs (a.k.a. TFDs, transmit frame
  802. * descriptors) and required locking structures.
  803. *
  804. * Note the difference between TFD_QUEUE_SIZE_MAX and n_window: the hardware
  805. * always assumes 256 descriptors, so TFD_QUEUE_SIZE_MAX is always 256 (unless
  806. * there might be HW changes in the future). For the normal TX
  807. * queues, n_window, which is the size of the software queue data
  808. * is also 256; however, for the command queue, n_window is only
  809. * 32 since we don't need so many commands pending. Since the HW
  810. * still uses 256 BDs for DMA though, TFD_QUEUE_SIZE_MAX stays 256.
  811. * This means that we end up with the following:
  812. * HW entries: | 0 | ... | N * 32 | ... | N * 32 + 31 | ... | 255 |
  813. * SW entries: | 0 | ... | 31 |
  814. * where N is a number between 0 and 7. This means that the SW
  815. * data is a window overlayed over the HW queue.
  816. */
  817. struct iwl_txq {
  818. void *tfds;
  819. struct iwl_pcie_first_tb_buf *first_tb_bufs;
  820. dma_addr_t first_tb_dma;
  821. struct iwl_pcie_txq_entry *entries;
  822. /* lock for syncing changes on the queue */
  823. spinlock_t lock;
  824. unsigned long frozen_expiry_remainder;
  825. struct timer_list stuck_timer;
  826. struct iwl_trans *trans;
  827. bool need_update;
  828. bool frozen;
  829. bool ampdu;
  830. int block;
  831. unsigned long wd_timeout;
  832. struct sk_buff_head overflow_q;
  833. struct iwl_dma_ptr bc_tbl;
  834. int write_ptr;
  835. int read_ptr;
  836. dma_addr_t dma_addr;
  837. int n_window;
  838. u32 id;
  839. int low_mark;
  840. int high_mark;
  841. bool overflow_tx;
  842. };
  843. /**
  844. * struct iwl_trans_txqs - transport tx queues data
  845. *
  846. * @bc_table_dword: true if the BC table expects DWORD (as opposed to bytes)
  847. * @page_offs: offset from skb->cb to mac header page pointer
  848. * @dev_cmd_offs: offset from skb->cb to iwl_device_tx_cmd pointer
  849. * @queue_used - bit mask of used queues
  850. * @queue_stopped - bit mask of stopped queues
  851. * @scd_bc_tbls: gen1 pointer to the byte count table of the scheduler
  852. * @queue_alloc_cmd_ver: queue allocation command version
  853. */
  854. struct iwl_trans_txqs {
  855. unsigned long queue_used[BITS_TO_LONGS(IWL_MAX_TVQM_QUEUES)];
  856. unsigned long queue_stopped[BITS_TO_LONGS(IWL_MAX_TVQM_QUEUES)];
  857. struct iwl_txq *txq[IWL_MAX_TVQM_QUEUES];
  858. struct dma_pool *bc_pool;
  859. size_t bc_tbl_size;
  860. bool bc_table_dword;
  861. u8 page_offs;
  862. u8 dev_cmd_offs;
  863. struct iwl_tso_hdr_page __percpu *tso_hdr_page;
  864. struct {
  865. u8 fifo;
  866. u8 q_id;
  867. unsigned int wdg_timeout;
  868. } cmd;
  869. struct {
  870. u8 max_tbs;
  871. u16 size;
  872. u8 addr_size;
  873. } tfd;
  874. struct iwl_dma_ptr scd_bc_tbls;
  875. u8 queue_alloc_cmd_ver;
  876. };
  877. /**
  878. * struct iwl_trans - transport common data
  879. *
  880. * @csme_own - true if we couldn't get ownership on the device
  881. * @ops - pointer to iwl_trans_ops
  882. * @op_mode - pointer to the op_mode
  883. * @trans_cfg: the trans-specific configuration part
  884. * @cfg - pointer to the configuration
  885. * @drv - pointer to iwl_drv
  886. * @status: a bit-mask of transport status flags
  887. * @dev - pointer to struct device * that represents the device
  888. * @max_skb_frags: maximum number of fragments an SKB can have when transmitted.
  889. * 0 indicates that frag SKBs (NETIF_F_SG) aren't supported.
  890. * @hw_rf_id a u32 with the device RF ID
  891. * @hw_id: a u32 with the ID of the device / sub-device.
  892. * Set during transport allocation.
  893. * @hw_id_str: a string with info about HW ID. Set during transport allocation.
  894. * @hw_rev_step: The mac step of the HW
  895. * @pm_support: set to true in start_hw if link pm is supported
  896. * @ltr_enabled: set to true if the LTR is enabled
  897. * @wide_cmd_header: true when ucode supports wide command header format
  898. * @wait_command_queue: wait queue for sync commands
  899. * @num_rx_queues: number of RX queues allocated by the transport;
  900. * the transport must set this before calling iwl_drv_start()
  901. * @iml_len: the length of the image loader
  902. * @iml: a pointer to the image loader itself
  903. * @dev_cmd_pool: pool for Tx cmd allocation - for internal use only.
  904. * The user should use iwl_trans_{alloc,free}_tx_cmd.
  905. * @rx_mpdu_cmd: MPDU RX command ID, must be assigned by opmode before
  906. * starting the firmware, used for tracing
  907. * @rx_mpdu_cmd_hdr_size: used for tracing, amount of data before the
  908. * start of the 802.11 header in the @rx_mpdu_cmd
  909. * @dflt_pwr_limit: default power limit fetched from the platform (ACPI)
  910. * @system_pm_mode: the system-wide power management mode in use.
  911. * This mode is set dynamically, depending on the WoWLAN values
  912. * configured from the userspace at runtime.
  913. * @iwl_trans_txqs: transport tx queues data.
  914. */
  915. struct iwl_trans {
  916. bool csme_own;
  917. const struct iwl_trans_ops *ops;
  918. struct iwl_op_mode *op_mode;
  919. const struct iwl_cfg_trans_params *trans_cfg;
  920. const struct iwl_cfg *cfg;
  921. struct iwl_drv *drv;
  922. enum iwl_trans_state state;
  923. unsigned long status;
  924. struct device *dev;
  925. u32 max_skb_frags;
  926. u32 hw_rev;
  927. u32 hw_rev_step;
  928. u32 hw_rf_id;
  929. u32 hw_id;
  930. char hw_id_str[52];
  931. u32 sku_id[3];
  932. u8 rx_mpdu_cmd, rx_mpdu_cmd_hdr_size;
  933. bool pm_support;
  934. bool ltr_enabled;
  935. u8 pnvm_loaded:1;
  936. u8 reduce_power_loaded:1;
  937. const struct iwl_hcmd_arr *command_groups;
  938. int command_groups_size;
  939. bool wide_cmd_header;
  940. wait_queue_head_t wait_command_queue;
  941. u8 num_rx_queues;
  942. size_t iml_len;
  943. u8 *iml;
  944. /* The following fields are internal only */
  945. struct kmem_cache *dev_cmd_pool;
  946. char dev_cmd_pool_name[50];
  947. struct dentry *dbgfs_dir;
  948. #ifdef CONFIG_LOCKDEP
  949. struct lockdep_map sync_cmd_lockdep_map;
  950. #endif
  951. struct iwl_trans_debug dbg;
  952. struct iwl_self_init_dram init_dram;
  953. enum iwl_plat_pm_mode system_pm_mode;
  954. const char *name;
  955. struct iwl_trans_txqs txqs;
  956. /* pointer to trans specific struct */
  957. /*Ensure that this pointer will always be aligned to sizeof pointer */
  958. char trans_specific[] __aligned(sizeof(void *));
  959. };
  960. const char *iwl_get_cmd_string(struct iwl_trans *trans, u32 id);
  961. int iwl_cmd_groups_verify_sorted(const struct iwl_trans_config *trans);
  962. static inline void iwl_trans_configure(struct iwl_trans *trans,
  963. const struct iwl_trans_config *trans_cfg)
  964. {
  965. trans->op_mode = trans_cfg->op_mode;
  966. trans->ops->configure(trans, trans_cfg);
  967. WARN_ON(iwl_cmd_groups_verify_sorted(trans_cfg));
  968. }
  969. static inline int iwl_trans_start_hw(struct iwl_trans *trans)
  970. {
  971. might_sleep();
  972. return trans->ops->start_hw(trans);
  973. }
  974. static inline void iwl_trans_op_mode_leave(struct iwl_trans *trans)
  975. {
  976. might_sleep();
  977. if (trans->ops->op_mode_leave)
  978. trans->ops->op_mode_leave(trans);
  979. trans->op_mode = NULL;
  980. trans->state = IWL_TRANS_NO_FW;
  981. }
  982. static inline void iwl_trans_fw_alive(struct iwl_trans *trans, u32 scd_addr)
  983. {
  984. might_sleep();
  985. trans->state = IWL_TRANS_FW_ALIVE;
  986. trans->ops->fw_alive(trans, scd_addr);
  987. }
  988. static inline int iwl_trans_start_fw(struct iwl_trans *trans,
  989. const struct fw_img *fw,
  990. bool run_in_rfkill)
  991. {
  992. int ret;
  993. might_sleep();
  994. WARN_ON_ONCE(!trans->rx_mpdu_cmd);
  995. clear_bit(STATUS_FW_ERROR, &trans->status);
  996. ret = trans->ops->start_fw(trans, fw, run_in_rfkill);
  997. if (ret == 0)
  998. trans->state = IWL_TRANS_FW_STARTED;
  999. return ret;
  1000. }
  1001. static inline void iwl_trans_stop_device(struct iwl_trans *trans)
  1002. {
  1003. might_sleep();
  1004. trans->ops->stop_device(trans);
  1005. trans->state = IWL_TRANS_NO_FW;
  1006. }
  1007. static inline int iwl_trans_d3_suspend(struct iwl_trans *trans, bool test,
  1008. bool reset)
  1009. {
  1010. might_sleep();
  1011. if (!trans->ops->d3_suspend)
  1012. return 0;
  1013. return trans->ops->d3_suspend(trans, test, reset);
  1014. }
  1015. static inline int iwl_trans_d3_resume(struct iwl_trans *trans,
  1016. enum iwl_d3_status *status,
  1017. bool test, bool reset)
  1018. {
  1019. might_sleep();
  1020. if (!trans->ops->d3_resume)
  1021. return 0;
  1022. return trans->ops->d3_resume(trans, status, test, reset);
  1023. }
  1024. static inline struct iwl_trans_dump_data *
  1025. iwl_trans_dump_data(struct iwl_trans *trans, u32 dump_mask,
  1026. const struct iwl_dump_sanitize_ops *sanitize_ops,
  1027. void *sanitize_ctx)
  1028. {
  1029. if (!trans->ops->dump_data)
  1030. return NULL;
  1031. return trans->ops->dump_data(trans, dump_mask,
  1032. sanitize_ops, sanitize_ctx);
  1033. }
  1034. static inline struct iwl_device_tx_cmd *
  1035. iwl_trans_alloc_tx_cmd(struct iwl_trans *trans)
  1036. {
  1037. return kmem_cache_zalloc(trans->dev_cmd_pool, GFP_ATOMIC);
  1038. }
  1039. int iwl_trans_send_cmd(struct iwl_trans *trans, struct iwl_host_cmd *cmd);
  1040. static inline void iwl_trans_free_tx_cmd(struct iwl_trans *trans,
  1041. struct iwl_device_tx_cmd *dev_cmd)
  1042. {
  1043. kmem_cache_free(trans->dev_cmd_pool, dev_cmd);
  1044. }
  1045. static inline int iwl_trans_tx(struct iwl_trans *trans, struct sk_buff *skb,
  1046. struct iwl_device_tx_cmd *dev_cmd, int queue)
  1047. {
  1048. if (unlikely(test_bit(STATUS_FW_ERROR, &trans->status)))
  1049. return -EIO;
  1050. if (WARN_ON_ONCE(trans->state != IWL_TRANS_FW_ALIVE)) {
  1051. IWL_ERR(trans, "%s bad state = %d\n", __func__, trans->state);
  1052. return -EIO;
  1053. }
  1054. return trans->ops->tx(trans, skb, dev_cmd, queue);
  1055. }
  1056. static inline void iwl_trans_reclaim(struct iwl_trans *trans, int queue,
  1057. int ssn, struct sk_buff_head *skbs,
  1058. bool is_flush)
  1059. {
  1060. if (WARN_ON_ONCE(trans->state != IWL_TRANS_FW_ALIVE)) {
  1061. IWL_ERR(trans, "%s bad state = %d\n", __func__, trans->state);
  1062. return;
  1063. }
  1064. trans->ops->reclaim(trans, queue, ssn, skbs, is_flush);
  1065. }
  1066. static inline void iwl_trans_set_q_ptrs(struct iwl_trans *trans, int queue,
  1067. int ptr)
  1068. {
  1069. if (WARN_ON_ONCE(trans->state != IWL_TRANS_FW_ALIVE)) {
  1070. IWL_ERR(trans, "%s bad state = %d\n", __func__, trans->state);
  1071. return;
  1072. }
  1073. trans->ops->set_q_ptrs(trans, queue, ptr);
  1074. }
  1075. static inline void iwl_trans_txq_disable(struct iwl_trans *trans, int queue,
  1076. bool configure_scd)
  1077. {
  1078. trans->ops->txq_disable(trans, queue, configure_scd);
  1079. }
  1080. static inline bool
  1081. iwl_trans_txq_enable_cfg(struct iwl_trans *trans, int queue, u16 ssn,
  1082. const struct iwl_trans_txq_scd_cfg *cfg,
  1083. unsigned int queue_wdg_timeout)
  1084. {
  1085. might_sleep();
  1086. if (WARN_ON_ONCE(trans->state != IWL_TRANS_FW_ALIVE)) {
  1087. IWL_ERR(trans, "%s bad state = %d\n", __func__, trans->state);
  1088. return false;
  1089. }
  1090. return trans->ops->txq_enable(trans, queue, ssn,
  1091. cfg, queue_wdg_timeout);
  1092. }
  1093. static inline int
  1094. iwl_trans_get_rxq_dma_data(struct iwl_trans *trans, int queue,
  1095. struct iwl_trans_rxq_dma_data *data)
  1096. {
  1097. if (WARN_ON_ONCE(!trans->ops->rxq_dma_data))
  1098. return -ENOTSUPP;
  1099. return trans->ops->rxq_dma_data(trans, queue, data);
  1100. }
  1101. static inline void
  1102. iwl_trans_txq_free(struct iwl_trans *trans, int queue)
  1103. {
  1104. if (WARN_ON_ONCE(!trans->ops->txq_free))
  1105. return;
  1106. trans->ops->txq_free(trans, queue);
  1107. }
  1108. static inline int
  1109. iwl_trans_txq_alloc(struct iwl_trans *trans,
  1110. u32 flags, u32 sta_mask, u8 tid,
  1111. int size, unsigned int wdg_timeout)
  1112. {
  1113. might_sleep();
  1114. if (WARN_ON_ONCE(!trans->ops->txq_alloc))
  1115. return -ENOTSUPP;
  1116. if (WARN_ON_ONCE(trans->state != IWL_TRANS_FW_ALIVE)) {
  1117. IWL_ERR(trans, "%s bad state = %d\n", __func__, trans->state);
  1118. return -EIO;
  1119. }
  1120. return trans->ops->txq_alloc(trans, flags, sta_mask, tid,
  1121. size, wdg_timeout);
  1122. }
  1123. static inline void iwl_trans_txq_set_shared_mode(struct iwl_trans *trans,
  1124. int queue, bool shared_mode)
  1125. {
  1126. if (trans->ops->txq_set_shared_mode)
  1127. trans->ops->txq_set_shared_mode(trans, queue, shared_mode);
  1128. }
  1129. static inline void iwl_trans_txq_enable(struct iwl_trans *trans, int queue,
  1130. int fifo, int sta_id, int tid,
  1131. int frame_limit, u16 ssn,
  1132. unsigned int queue_wdg_timeout)
  1133. {
  1134. struct iwl_trans_txq_scd_cfg cfg = {
  1135. .fifo = fifo,
  1136. .sta_id = sta_id,
  1137. .tid = tid,
  1138. .frame_limit = frame_limit,
  1139. .aggregate = sta_id >= 0,
  1140. };
  1141. iwl_trans_txq_enable_cfg(trans, queue, ssn, &cfg, queue_wdg_timeout);
  1142. }
  1143. static inline
  1144. void iwl_trans_ac_txq_enable(struct iwl_trans *trans, int queue, int fifo,
  1145. unsigned int queue_wdg_timeout)
  1146. {
  1147. struct iwl_trans_txq_scd_cfg cfg = {
  1148. .fifo = fifo,
  1149. .sta_id = -1,
  1150. .tid = IWL_MAX_TID_COUNT,
  1151. .frame_limit = IWL_FRAME_LIMIT,
  1152. .aggregate = false,
  1153. };
  1154. iwl_trans_txq_enable_cfg(trans, queue, 0, &cfg, queue_wdg_timeout);
  1155. }
  1156. static inline void iwl_trans_freeze_txq_timer(struct iwl_trans *trans,
  1157. unsigned long txqs,
  1158. bool freeze)
  1159. {
  1160. if (WARN_ON_ONCE(trans->state != IWL_TRANS_FW_ALIVE)) {
  1161. IWL_ERR(trans, "%s bad state = %d\n", __func__, trans->state);
  1162. return;
  1163. }
  1164. if (trans->ops->freeze_txq_timer)
  1165. trans->ops->freeze_txq_timer(trans, txqs, freeze);
  1166. }
  1167. static inline void iwl_trans_block_txq_ptrs(struct iwl_trans *trans,
  1168. bool block)
  1169. {
  1170. if (WARN_ON_ONCE(trans->state != IWL_TRANS_FW_ALIVE)) {
  1171. IWL_ERR(trans, "%s bad state = %d\n", __func__, trans->state);
  1172. return;
  1173. }
  1174. if (trans->ops->block_txq_ptrs)
  1175. trans->ops->block_txq_ptrs(trans, block);
  1176. }
  1177. static inline int iwl_trans_wait_tx_queues_empty(struct iwl_trans *trans,
  1178. u32 txqs)
  1179. {
  1180. if (WARN_ON_ONCE(!trans->ops->wait_tx_queues_empty))
  1181. return -ENOTSUPP;
  1182. /* No need to wait if the firmware is not alive */
  1183. if (trans->state != IWL_TRANS_FW_ALIVE) {
  1184. IWL_ERR(trans, "%s bad state = %d\n", __func__, trans->state);
  1185. return -EIO;
  1186. }
  1187. return trans->ops->wait_tx_queues_empty(trans, txqs);
  1188. }
  1189. static inline int iwl_trans_wait_txq_empty(struct iwl_trans *trans, int queue)
  1190. {
  1191. if (WARN_ON_ONCE(!trans->ops->wait_txq_empty))
  1192. return -ENOTSUPP;
  1193. if (WARN_ON_ONCE(trans->state != IWL_TRANS_FW_ALIVE)) {
  1194. IWL_ERR(trans, "%s bad state = %d\n", __func__, trans->state);
  1195. return -EIO;
  1196. }
  1197. return trans->ops->wait_txq_empty(trans, queue);
  1198. }
  1199. static inline void iwl_trans_write8(struct iwl_trans *trans, u32 ofs, u8 val)
  1200. {
  1201. trans->ops->write8(trans, ofs, val);
  1202. }
  1203. static inline void iwl_trans_write32(struct iwl_trans *trans, u32 ofs, u32 val)
  1204. {
  1205. trans->ops->write32(trans, ofs, val);
  1206. }
  1207. static inline u32 iwl_trans_read32(struct iwl_trans *trans, u32 ofs)
  1208. {
  1209. return trans->ops->read32(trans, ofs);
  1210. }
  1211. static inline u32 iwl_trans_read_prph(struct iwl_trans *trans, u32 ofs)
  1212. {
  1213. return trans->ops->read_prph(trans, ofs);
  1214. }
  1215. static inline void iwl_trans_write_prph(struct iwl_trans *trans, u32 ofs,
  1216. u32 val)
  1217. {
  1218. return trans->ops->write_prph(trans, ofs, val);
  1219. }
  1220. static inline int iwl_trans_read_mem(struct iwl_trans *trans, u32 addr,
  1221. void *buf, int dwords)
  1222. {
  1223. return trans->ops->read_mem(trans, addr, buf, dwords);
  1224. }
  1225. #define iwl_trans_read_mem_bytes(trans, addr, buf, bufsize) \
  1226. do { \
  1227. if (__builtin_constant_p(bufsize)) \
  1228. BUILD_BUG_ON((bufsize) % sizeof(u32)); \
  1229. iwl_trans_read_mem(trans, addr, buf, (bufsize) / sizeof(u32));\
  1230. } while (0)
  1231. static inline int iwl_trans_write_imr_mem(struct iwl_trans *trans,
  1232. u32 dst_addr, u64 src_addr,
  1233. u32 byte_cnt)
  1234. {
  1235. if (trans->ops->imr_dma_data)
  1236. return trans->ops->imr_dma_data(trans, dst_addr, src_addr, byte_cnt);
  1237. return 0;
  1238. }
  1239. static inline u32 iwl_trans_read_mem32(struct iwl_trans *trans, u32 addr)
  1240. {
  1241. u32 value;
  1242. if (WARN_ON(iwl_trans_read_mem(trans, addr, &value, 1)))
  1243. return 0xa5a5a5a5;
  1244. return value;
  1245. }
  1246. static inline int iwl_trans_write_mem(struct iwl_trans *trans, u32 addr,
  1247. const void *buf, int dwords)
  1248. {
  1249. return trans->ops->write_mem(trans, addr, buf, dwords);
  1250. }
  1251. static inline u32 iwl_trans_write_mem32(struct iwl_trans *trans, u32 addr,
  1252. u32 val)
  1253. {
  1254. return iwl_trans_write_mem(trans, addr, &val, 1);
  1255. }
  1256. static inline void iwl_trans_set_pmi(struct iwl_trans *trans, bool state)
  1257. {
  1258. if (trans->ops->set_pmi)
  1259. trans->ops->set_pmi(trans, state);
  1260. }
  1261. static inline int iwl_trans_sw_reset(struct iwl_trans *trans,
  1262. bool retake_ownership)
  1263. {
  1264. if (trans->ops->sw_reset)
  1265. return trans->ops->sw_reset(trans, retake_ownership);
  1266. return 0;
  1267. }
  1268. static inline void
  1269. iwl_trans_set_bits_mask(struct iwl_trans *trans, u32 reg, u32 mask, u32 value)
  1270. {
  1271. trans->ops->set_bits_mask(trans, reg, mask, value);
  1272. }
  1273. #define iwl_trans_grab_nic_access(trans) \
  1274. __cond_lock(nic_access, \
  1275. likely((trans)->ops->grab_nic_access(trans)))
  1276. static inline void __releases(nic_access)
  1277. iwl_trans_release_nic_access(struct iwl_trans *trans)
  1278. {
  1279. trans->ops->release_nic_access(trans);
  1280. __release(nic_access);
  1281. }
  1282. static inline void iwl_trans_fw_error(struct iwl_trans *trans, bool sync)
  1283. {
  1284. if (WARN_ON_ONCE(!trans->op_mode))
  1285. return;
  1286. /* prevent double restarts due to the same erroneous FW */
  1287. if (!test_and_set_bit(STATUS_FW_ERROR, &trans->status)) {
  1288. iwl_op_mode_nic_error(trans->op_mode, sync);
  1289. trans->state = IWL_TRANS_NO_FW;
  1290. }
  1291. }
  1292. static inline bool iwl_trans_fw_running(struct iwl_trans *trans)
  1293. {
  1294. return trans->state == IWL_TRANS_FW_ALIVE;
  1295. }
  1296. static inline void iwl_trans_sync_nmi(struct iwl_trans *trans)
  1297. {
  1298. if (trans->ops->sync_nmi)
  1299. trans->ops->sync_nmi(trans);
  1300. }
  1301. void iwl_trans_sync_nmi_with_addr(struct iwl_trans *trans, u32 inta_addr,
  1302. u32 sw_err_bit);
  1303. static inline int iwl_trans_set_pnvm(struct iwl_trans *trans,
  1304. const void *data, u32 len)
  1305. {
  1306. if (trans->ops->set_pnvm) {
  1307. int ret = trans->ops->set_pnvm(trans, data, len);
  1308. if (ret)
  1309. return ret;
  1310. }
  1311. trans->pnvm_loaded = true;
  1312. return 0;
  1313. }
  1314. static inline int iwl_trans_set_reduce_power(struct iwl_trans *trans,
  1315. const void *data, u32 len)
  1316. {
  1317. if (trans->ops->set_reduce_power) {
  1318. int ret = trans->ops->set_reduce_power(trans, data, len);
  1319. if (ret)
  1320. return ret;
  1321. }
  1322. trans->reduce_power_loaded = true;
  1323. return 0;
  1324. }
  1325. static inline bool iwl_trans_dbg_ini_valid(struct iwl_trans *trans)
  1326. {
  1327. return trans->dbg.internal_ini_cfg != IWL_INI_CFG_STATE_NOT_LOADED ||
  1328. trans->dbg.external_ini_cfg != IWL_INI_CFG_STATE_NOT_LOADED;
  1329. }
  1330. static inline void iwl_trans_interrupts(struct iwl_trans *trans, bool enable)
  1331. {
  1332. if (trans->ops->interrupts)
  1333. trans->ops->interrupts(trans, enable);
  1334. }
  1335. /*****************************************************
  1336. * transport helper functions
  1337. *****************************************************/
  1338. struct iwl_trans *iwl_trans_alloc(unsigned int priv_size,
  1339. struct device *dev,
  1340. const struct iwl_trans_ops *ops,
  1341. const struct iwl_cfg_trans_params *cfg_trans);
  1342. int iwl_trans_init(struct iwl_trans *trans);
  1343. void iwl_trans_free(struct iwl_trans *trans);
  1344. /*****************************************************
  1345. * driver (transport) register/unregister functions
  1346. ******************************************************/
  1347. int __must_check iwl_pci_register_driver(void);
  1348. void iwl_pci_unregister_driver(void);
  1349. #endif /* __iwl_trans_h__ */