iwl-trans.h 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213
  1. /******************************************************************************
  2. *
  3. * This file is provided under a dual BSD/GPLv2 license. When using or
  4. * redistributing this file, you may do so under either license.
  5. *
  6. * GPL LICENSE SUMMARY
  7. *
  8. * Copyright(c) 2007 - 2014 Intel Corporation. All rights reserved.
  9. * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
  10. * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of version 2 of the GNU General Public License as
  14. * published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful, but
  17. * WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. * General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
  24. * USA
  25. *
  26. * The full GNU General Public License is included in this distribution
  27. * in the file called COPYING.
  28. *
  29. * Contact Information:
  30. * Intel Linux Wireless <linuxwifi@intel.com>
  31. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  32. *
  33. * BSD LICENSE
  34. *
  35. * Copyright(c) 2005 - 2014 Intel Corporation. All rights reserved.
  36. * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
  37. * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
  38. * All rights reserved.
  39. *
  40. * Redistribution and use in source and binary forms, with or without
  41. * modification, are permitted provided that the following conditions
  42. * are met:
  43. *
  44. * * Redistributions of source code must retain the above copyright
  45. * notice, this list of conditions and the following disclaimer.
  46. * * Redistributions in binary form must reproduce the above copyright
  47. * notice, this list of conditions and the following disclaimer in
  48. * the documentation and/or other materials provided with the
  49. * distribution.
  50. * * Neither the name Intel Corporation nor the names of its
  51. * contributors may be used to endorse or promote products derived
  52. * from this software without specific prior written permission.
  53. *
  54. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  55. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  56. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  57. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  58. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  59. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  60. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  61. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  62. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  63. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  64. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  65. *
  66. *****************************************************************************/
  67. #ifndef __iwl_trans_h__
  68. #define __iwl_trans_h__
  69. #include <linux/ieee80211.h>
  70. #include <linux/mm.h> /* for page_address */
  71. #include <linux/lockdep.h>
  72. #include <linux/kernel.h>
  73. #include "iwl-debug.h"
  74. #include "iwl-config.h"
  75. #include "fw/img.h"
  76. #include "iwl-op-mode.h"
  77. #include "fw/api/cmdhdr.h"
  78. #include "fw/api/txq.h"
  79. /**
  80. * DOC: Transport layer - what is it ?
  81. *
  82. * The transport layer is the layer that deals with the HW directly. It provides
  83. * an abstraction of the underlying HW to the upper layer. The transport layer
  84. * doesn't provide any policy, algorithm or anything of this kind, but only
  85. * mechanisms to make the HW do something. It is not completely stateless but
  86. * close to it.
  87. * We will have an implementation for each different supported bus.
  88. */
  89. /**
  90. * DOC: Life cycle of the transport layer
  91. *
  92. * The transport layer has a very precise life cycle.
  93. *
  94. * 1) A helper function is called during the module initialization and
  95. * registers the bus driver's ops with the transport's alloc function.
  96. * 2) Bus's probe calls to the transport layer's allocation functions.
  97. * Of course this function is bus specific.
  98. * 3) This allocation functions will spawn the upper layer which will
  99. * register mac80211.
  100. *
  101. * 4) At some point (i.e. mac80211's start call), the op_mode will call
  102. * the following sequence:
  103. * start_hw
  104. * start_fw
  105. *
  106. * 5) Then when finished (or reset):
  107. * stop_device
  108. *
  109. * 6) Eventually, the free function will be called.
  110. */
  111. #define FH_RSCSR_FRAME_SIZE_MSK 0x00003FFF /* bits 0-13 */
  112. #define FH_RSCSR_FRAME_INVALID 0x55550000
  113. #define FH_RSCSR_FRAME_ALIGN 0x40
  114. #define FH_RSCSR_RPA_EN BIT(25)
  115. #define FH_RSCSR_RADA_EN BIT(26)
  116. #define FH_RSCSR_RXQ_POS 16
  117. #define FH_RSCSR_RXQ_MASK 0x3F0000
  118. struct iwl_rx_packet {
  119. /*
  120. * The first 4 bytes of the RX frame header contain both the RX frame
  121. * size and some flags.
  122. * Bit fields:
  123. * 31: flag flush RB request
  124. * 30: flag ignore TC (terminal counter) request
  125. * 29: flag fast IRQ request
  126. * 28-27: Reserved
  127. * 26: RADA enabled
  128. * 25: Offload enabled
  129. * 24: RPF enabled
  130. * 23: RSS enabled
  131. * 22: Checksum enabled
  132. * 21-16: RX queue
  133. * 15-14: Reserved
  134. * 13-00: RX frame size
  135. */
  136. __le32 len_n_flags;
  137. struct iwl_cmd_header hdr;
  138. u8 data[];
  139. } __packed;
  140. static inline u32 iwl_rx_packet_len(const struct iwl_rx_packet *pkt)
  141. {
  142. return le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK;
  143. }
  144. static inline u32 iwl_rx_packet_payload_len(const struct iwl_rx_packet *pkt)
  145. {
  146. return iwl_rx_packet_len(pkt) - sizeof(pkt->hdr);
  147. }
  148. /**
  149. * enum CMD_MODE - how to send the host commands ?
  150. *
  151. * @CMD_ASYNC: Return right away and don't wait for the response
  152. * @CMD_WANT_SKB: Not valid with CMD_ASYNC. The caller needs the buffer of
  153. * the response. The caller needs to call iwl_free_resp when done.
  154. * @CMD_HIGH_PRIO: The command is high priority - it goes to the front of the
  155. * command queue, but after other high priority commands. Valid only
  156. * with CMD_ASYNC.
  157. * @CMD_SEND_IN_IDLE: The command should be sent even when the trans is idle.
  158. * @CMD_MAKE_TRANS_IDLE: The command response should mark the trans as idle.
  159. * @CMD_WAKE_UP_TRANS: The command response should wake up the trans
  160. * (i.e. mark it as non-idle).
  161. * @CMD_WANT_ASYNC_CALLBACK: the op_mode's async callback function must be
  162. * called after this command completes. Valid only with CMD_ASYNC.
  163. */
  164. enum CMD_MODE {
  165. CMD_ASYNC = BIT(0),
  166. CMD_WANT_SKB = BIT(1),
  167. CMD_SEND_IN_RFKILL = BIT(2),
  168. CMD_HIGH_PRIO = BIT(3),
  169. CMD_SEND_IN_IDLE = BIT(4),
  170. CMD_MAKE_TRANS_IDLE = BIT(5),
  171. CMD_WAKE_UP_TRANS = BIT(6),
  172. CMD_WANT_ASYNC_CALLBACK = BIT(7),
  173. };
  174. #define DEF_CMD_PAYLOAD_SIZE 320
  175. /**
  176. * struct iwl_device_cmd
  177. *
  178. * For allocation of the command and tx queues, this establishes the overall
  179. * size of the largest command we send to uCode, except for commands that
  180. * aren't fully copied and use other TFD space.
  181. */
  182. struct iwl_device_cmd {
  183. union {
  184. struct {
  185. struct iwl_cmd_header hdr; /* uCode API */
  186. u8 payload[DEF_CMD_PAYLOAD_SIZE];
  187. };
  188. struct {
  189. struct iwl_cmd_header_wide hdr_wide;
  190. u8 payload_wide[DEF_CMD_PAYLOAD_SIZE -
  191. sizeof(struct iwl_cmd_header_wide) +
  192. sizeof(struct iwl_cmd_header)];
  193. };
  194. };
  195. } __packed;
  196. #define TFD_MAX_PAYLOAD_SIZE (sizeof(struct iwl_device_cmd))
  197. /*
  198. * number of transfer buffers (fragments) per transmit frame descriptor;
  199. * this is just the driver's idea, the hardware supports 20
  200. */
  201. #define IWL_MAX_CMD_TBS_PER_TFD 2
  202. /**
  203. * enum iwl_hcmd_dataflag - flag for each one of the chunks of the command
  204. *
  205. * @IWL_HCMD_DFL_NOCOPY: By default, the command is copied to the host command's
  206. * ring. The transport layer doesn't map the command's buffer to DMA, but
  207. * rather copies it to a previously allocated DMA buffer. This flag tells
  208. * the transport layer not to copy the command, but to map the existing
  209. * buffer (that is passed in) instead. This saves the memcpy and allows
  210. * commands that are bigger than the fixed buffer to be submitted.
  211. * Note that a TFD entry after a NOCOPY one cannot be a normal copied one.
  212. * @IWL_HCMD_DFL_DUP: Only valid without NOCOPY, duplicate the memory for this
  213. * chunk internally and free it again after the command completes. This
  214. * can (currently) be used only once per command.
  215. * Note that a TFD entry after a DUP one cannot be a normal copied one.
  216. */
  217. enum iwl_hcmd_dataflag {
  218. IWL_HCMD_DFL_NOCOPY = BIT(0),
  219. IWL_HCMD_DFL_DUP = BIT(1),
  220. };
  221. /**
  222. * struct iwl_host_cmd - Host command to the uCode
  223. *
  224. * @data: array of chunks that composes the data of the host command
  225. * @resp_pkt: response packet, if %CMD_WANT_SKB was set
  226. * @_rx_page_order: (internally used to free response packet)
  227. * @_rx_page_addr: (internally used to free response packet)
  228. * @flags: can be CMD_*
  229. * @len: array of the lengths of the chunks in data
  230. * @dataflags: IWL_HCMD_DFL_*
  231. * @id: command id of the host command, for wide commands encoding the
  232. * version and group as well
  233. */
  234. struct iwl_host_cmd {
  235. const void *data[IWL_MAX_CMD_TBS_PER_TFD];
  236. struct iwl_rx_packet *resp_pkt;
  237. unsigned long _rx_page_addr;
  238. u32 _rx_page_order;
  239. u32 flags;
  240. u32 id;
  241. u16 len[IWL_MAX_CMD_TBS_PER_TFD];
  242. u8 dataflags[IWL_MAX_CMD_TBS_PER_TFD];
  243. };
  244. static inline void iwl_free_resp(struct iwl_host_cmd *cmd)
  245. {
  246. free_pages(cmd->_rx_page_addr, cmd->_rx_page_order);
  247. }
  248. struct iwl_rx_cmd_buffer {
  249. struct page *_page;
  250. int _offset;
  251. bool _page_stolen;
  252. u32 _rx_page_order;
  253. unsigned int truesize;
  254. u8 status;
  255. };
  256. static inline void *rxb_addr(struct iwl_rx_cmd_buffer *r)
  257. {
  258. return (void *)((unsigned long)page_address(r->_page) + r->_offset);
  259. }
  260. static inline int rxb_offset(struct iwl_rx_cmd_buffer *r)
  261. {
  262. return r->_offset;
  263. }
  264. static inline struct page *rxb_steal_page(struct iwl_rx_cmd_buffer *r)
  265. {
  266. r->_page_stolen = true;
  267. get_page(r->_page);
  268. return r->_page;
  269. }
  270. static inline void iwl_free_rxb(struct iwl_rx_cmd_buffer *r)
  271. {
  272. __free_pages(r->_page, r->_rx_page_order);
  273. }
  274. #define MAX_NO_RECLAIM_CMDS 6
  275. #define IWL_MASK(lo, hi) ((1 << (hi)) | ((1 << (hi)) - (1 << (lo))))
  276. /*
  277. * Maximum number of HW queues the transport layer
  278. * currently supports
  279. */
  280. #define IWL_MAX_HW_QUEUES 32
  281. #define IWL_MAX_TVQM_QUEUES 512
  282. #define IWL_MAX_TID_COUNT 8
  283. #define IWL_MGMT_TID 15
  284. #define IWL_FRAME_LIMIT 64
  285. #define IWL_MAX_RX_HW_QUEUES 16
  286. /**
  287. * enum iwl_wowlan_status - WoWLAN image/device status
  288. * @IWL_D3_STATUS_ALIVE: firmware is still running after resume
  289. * @IWL_D3_STATUS_RESET: device was reset while suspended
  290. */
  291. enum iwl_d3_status {
  292. IWL_D3_STATUS_ALIVE,
  293. IWL_D3_STATUS_RESET,
  294. };
  295. /**
  296. * enum iwl_trans_status: transport status flags
  297. * @STATUS_SYNC_HCMD_ACTIVE: a SYNC command is being processed
  298. * @STATUS_DEVICE_ENABLED: APM is enabled
  299. * @STATUS_TPOWER_PMI: the device might be asleep (need to wake it up)
  300. * @STATUS_INT_ENABLED: interrupts are enabled
  301. * @STATUS_RFKILL_HW: the actual HW state of the RF-kill switch
  302. * @STATUS_RFKILL_OPMODE: RF-kill state reported to opmode
  303. * @STATUS_FW_ERROR: the fw is in error state
  304. * @STATUS_TRANS_GOING_IDLE: shutting down the trans, only special commands
  305. * are sent
  306. * @STATUS_TRANS_IDLE: the trans is idle - general commands are not to be sent
  307. * @STATUS_TRANS_DEAD: trans is dead - avoid any read/write operation
  308. */
  309. enum iwl_trans_status {
  310. STATUS_SYNC_HCMD_ACTIVE,
  311. STATUS_DEVICE_ENABLED,
  312. STATUS_TPOWER_PMI,
  313. STATUS_INT_ENABLED,
  314. STATUS_RFKILL_HW,
  315. STATUS_RFKILL_OPMODE,
  316. STATUS_FW_ERROR,
  317. STATUS_TRANS_GOING_IDLE,
  318. STATUS_TRANS_IDLE,
  319. STATUS_TRANS_DEAD,
  320. };
  321. static inline int
  322. iwl_trans_get_rb_size_order(enum iwl_amsdu_size rb_size)
  323. {
  324. switch (rb_size) {
  325. case IWL_AMSDU_2K:
  326. return get_order(2 * 1024);
  327. case IWL_AMSDU_4K:
  328. return get_order(4 * 1024);
  329. case IWL_AMSDU_8K:
  330. return get_order(8 * 1024);
  331. case IWL_AMSDU_12K:
  332. return get_order(12 * 1024);
  333. default:
  334. WARN_ON(1);
  335. return -1;
  336. }
  337. }
  338. struct iwl_hcmd_names {
  339. u8 cmd_id;
  340. const char *const cmd_name;
  341. };
  342. #define HCMD_NAME(x) \
  343. { .cmd_id = x, .cmd_name = #x }
  344. struct iwl_hcmd_arr {
  345. const struct iwl_hcmd_names *arr;
  346. int size;
  347. };
  348. #define HCMD_ARR(x) \
  349. { .arr = x, .size = ARRAY_SIZE(x) }
  350. /**
  351. * struct iwl_trans_config - transport configuration
  352. *
  353. * @op_mode: pointer to the upper layer.
  354. * @cmd_queue: the index of the command queue.
  355. * Must be set before start_fw.
  356. * @cmd_fifo: the fifo for host commands
  357. * @cmd_q_wdg_timeout: the timeout of the watchdog timer for the command queue.
  358. * @no_reclaim_cmds: Some devices erroneously don't set the
  359. * SEQ_RX_FRAME bit on some notifications, this is the
  360. * list of such notifications to filter. Max length is
  361. * %MAX_NO_RECLAIM_CMDS.
  362. * @n_no_reclaim_cmds: # of commands in list
  363. * @rx_buf_size: RX buffer size needed for A-MSDUs
  364. * if unset 4k will be the RX buffer size
  365. * @bc_table_dword: set to true if the BC table expects the byte count to be
  366. * in DWORD (as opposed to bytes)
  367. * @scd_set_active: should the transport configure the SCD for HCMD queue
  368. * @sw_csum_tx: transport should compute the TCP checksum
  369. * @command_groups: array of command groups, each member is an array of the
  370. * commands in the group; for debugging only
  371. * @command_groups_size: number of command groups, to avoid illegal access
  372. * @cb_data_offs: offset inside skb->cb to store transport data at, must have
  373. * space for at least two pointers
  374. */
  375. struct iwl_trans_config {
  376. struct iwl_op_mode *op_mode;
  377. u8 cmd_queue;
  378. u8 cmd_fifo;
  379. unsigned int cmd_q_wdg_timeout;
  380. const u8 *no_reclaim_cmds;
  381. unsigned int n_no_reclaim_cmds;
  382. enum iwl_amsdu_size rx_buf_size;
  383. bool bc_table_dword;
  384. bool scd_set_active;
  385. bool sw_csum_tx;
  386. const struct iwl_hcmd_arr *command_groups;
  387. int command_groups_size;
  388. u8 cb_data_offs;
  389. };
  390. struct iwl_trans_dump_data {
  391. u32 len;
  392. u8 data[];
  393. };
  394. struct iwl_trans;
  395. struct iwl_trans_txq_scd_cfg {
  396. u8 fifo;
  397. u8 sta_id;
  398. u8 tid;
  399. bool aggregate;
  400. int frame_limit;
  401. };
  402. /**
  403. * struct iwl_trans_rxq_dma_data - RX queue DMA data
  404. * @fr_bd_cb: DMA address of free BD cyclic buffer
  405. * @fr_bd_wid: Initial write index of the free BD cyclic buffer
  406. * @urbd_stts_wrptr: DMA address of urbd_stts_wrptr
  407. * @ur_bd_cb: DMA address of used BD cyclic buffer
  408. */
  409. struct iwl_trans_rxq_dma_data {
  410. u64 fr_bd_cb;
  411. u32 fr_bd_wid;
  412. u64 urbd_stts_wrptr;
  413. u64 ur_bd_cb;
  414. };
  415. /**
  416. * struct iwl_trans_ops - transport specific operations
  417. *
  418. * All the handlers MUST be implemented
  419. *
  420. * @start_hw: starts the HW. If low_power is true, the NIC needs to be taken
  421. * out of a low power state. From that point on, the HW can send
  422. * interrupts. May sleep.
  423. * @op_mode_leave: Turn off the HW RF kill indication if on
  424. * May sleep
  425. * @start_fw: allocates and inits all the resources for the transport
  426. * layer. Also kick a fw image.
  427. * May sleep
  428. * @fw_alive: called when the fw sends alive notification. If the fw provides
  429. * the SCD base address in SRAM, then provide it here, or 0 otherwise.
  430. * May sleep
  431. * @stop_device: stops the whole device (embedded CPU put to reset) and stops
  432. * the HW. If low_power is true, the NIC will be put in low power state.
  433. * From that point on, the HW will be stopped but will still issue an
  434. * 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. * @configure: configure parameters required by the transport layer from
  483. * the op_mode. May be called several times before start_fw, can't be
  484. * called after that.
  485. * @set_pmi: set the power pmi state
  486. * @grab_nic_access: wake the NIC to be able to access non-HBUS regs.
  487. * Sleeping is not allowed between grab_nic_access and
  488. * release_nic_access.
  489. * @release_nic_access: let the NIC go to sleep. The "flags" parameter
  490. * must be the same one that was sent before to the grab_nic_access.
  491. * @set_bits_mask - set SRAM register according to value and mask.
  492. * @ref: grab a reference to the transport/FW layers, disallowing
  493. * certain low power states
  494. * @unref: release a reference previously taken with @ref. Note that
  495. * initially the reference count is 1, making an initial @unref
  496. * necessary to allow low power states.
  497. * @dump_data: return a vmalloc'ed buffer with debug data, maybe containing last
  498. * TX'ed commands and similar. The buffer will be vfree'd by the caller.
  499. * Note that the transport must fill in the proper file headers.
  500. * @dump_regs: dump using IWL_ERR configuration space and memory mapped
  501. * registers of the device to diagnose failure, e.g., when HW becomes
  502. * inaccessible.
  503. */
  504. struct iwl_trans_ops {
  505. int (*start_hw)(struct iwl_trans *iwl_trans, bool low_power);
  506. void (*op_mode_leave)(struct iwl_trans *iwl_trans);
  507. int (*start_fw)(struct iwl_trans *trans, const struct fw_img *fw,
  508. bool run_in_rfkill);
  509. void (*fw_alive)(struct iwl_trans *trans, u32 scd_addr);
  510. void (*stop_device)(struct iwl_trans *trans, bool low_power);
  511. void (*d3_suspend)(struct iwl_trans *trans, bool test, bool reset);
  512. int (*d3_resume)(struct iwl_trans *trans, enum iwl_d3_status *status,
  513. bool test, bool reset);
  514. int (*send_cmd)(struct iwl_trans *trans, struct iwl_host_cmd *cmd);
  515. int (*tx)(struct iwl_trans *trans, struct sk_buff *skb,
  516. struct iwl_device_cmd *dev_cmd, int queue);
  517. void (*reclaim)(struct iwl_trans *trans, int queue, int ssn,
  518. struct sk_buff_head *skbs);
  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,
  526. struct iwl_tx_queue_cfg_cmd *cmd,
  527. int cmd_id, int size,
  528. unsigned int queue_wdg_timeout);
  529. void (*txq_free)(struct iwl_trans *trans, int queue);
  530. int (*rxq_dma_data)(struct iwl_trans *trans, int queue,
  531. struct iwl_trans_rxq_dma_data *data);
  532. void (*txq_set_shared_mode)(struct iwl_trans *trans, u32 txq_id,
  533. bool shared);
  534. int (*wait_tx_queues_empty)(struct iwl_trans *trans, u32 txq_bm);
  535. int (*wait_txq_empty)(struct iwl_trans *trans, int queue);
  536. void (*freeze_txq_timer)(struct iwl_trans *trans, unsigned long txqs,
  537. bool freeze);
  538. void (*block_txq_ptrs)(struct iwl_trans *trans, bool block);
  539. void (*write8)(struct iwl_trans *trans, u32 ofs, u8 val);
  540. void (*write32)(struct iwl_trans *trans, u32 ofs, u32 val);
  541. u32 (*read32)(struct iwl_trans *trans, u32 ofs);
  542. u32 (*read_prph)(struct iwl_trans *trans, u32 ofs);
  543. void (*write_prph)(struct iwl_trans *trans, u32 ofs, u32 val);
  544. int (*read_mem)(struct iwl_trans *trans, u32 addr,
  545. void *buf, int dwords);
  546. int (*write_mem)(struct iwl_trans *trans, u32 addr,
  547. const void *buf, int dwords);
  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. void (*sw_reset)(struct iwl_trans *trans);
  552. bool (*grab_nic_access)(struct iwl_trans *trans, unsigned long *flags);
  553. void (*release_nic_access)(struct iwl_trans *trans,
  554. unsigned long *flags);
  555. void (*set_bits_mask)(struct iwl_trans *trans, u32 reg, u32 mask,
  556. u32 value);
  557. void (*ref)(struct iwl_trans *trans);
  558. void (*unref)(struct iwl_trans *trans);
  559. int (*suspend)(struct iwl_trans *trans);
  560. void (*resume)(struct iwl_trans *trans);
  561. struct iwl_trans_dump_data *(*dump_data)(struct iwl_trans *trans,
  562. const struct iwl_fw_dbg_trigger_tlv
  563. *trigger);
  564. void (*dump_regs)(struct iwl_trans *trans);
  565. };
  566. /**
  567. * enum iwl_trans_state - state of the transport layer
  568. *
  569. * @IWL_TRANS_NO_FW: no fw has sent an alive response
  570. * @IWL_TRANS_FW_ALIVE: a fw has sent an alive response
  571. */
  572. enum iwl_trans_state {
  573. IWL_TRANS_NO_FW = 0,
  574. IWL_TRANS_FW_ALIVE = 1,
  575. };
  576. /**
  577. * DOC: Platform power management
  578. *
  579. * There are two types of platform power management: system-wide
  580. * (WoWLAN) and runtime.
  581. *
  582. * In system-wide power management the entire platform goes into a low
  583. * power state (e.g. idle or suspend to RAM) at the same time and the
  584. * device is configured as a wakeup source for the entire platform.
  585. * This is usually triggered by userspace activity (e.g. the user
  586. * presses the suspend button or a power management daemon decides to
  587. * put the platform in low power mode). The device's behavior in this
  588. * mode is dictated by the wake-on-WLAN configuration.
  589. *
  590. * In runtime power management, only the devices which are themselves
  591. * idle enter a low power state. This is done at runtime, which means
  592. * that the entire system is still running normally. This mode is
  593. * usually triggered automatically by the device driver and requires
  594. * the ability to enter and exit the low power modes in a very short
  595. * time, so there is not much impact in usability.
  596. *
  597. * The terms used for the device's behavior are as follows:
  598. *
  599. * - D0: the device is fully powered and the host is awake;
  600. * - D3: the device is in low power mode and only reacts to
  601. * specific events (e.g. magic-packet received or scan
  602. * results found);
  603. * - D0I3: the device is in low power mode and reacts to any
  604. * activity (e.g. RX);
  605. *
  606. * These terms reflect the power modes in the firmware and are not to
  607. * be confused with the physical device power state. The NIC can be
  608. * in D0I3 mode even if, for instance, the PCI device is in D3 state.
  609. */
  610. /**
  611. * enum iwl_plat_pm_mode - platform power management mode
  612. *
  613. * This enumeration describes the device's platform power management
  614. * behavior when in idle mode (i.e. runtime power management) or when
  615. * in system-wide suspend (i.e WoWLAN).
  616. *
  617. * @IWL_PLAT_PM_MODE_DISABLED: power management is disabled for this
  618. * device. At runtime, this means that nothing happens and the
  619. * device always remains in active. In system-wide suspend mode,
  620. * it means that the all connections will be closed automatically
  621. * by mac80211 before the platform is suspended.
  622. * @IWL_PLAT_PM_MODE_D3: the device goes into D3 mode (i.e. WoWLAN).
  623. * For runtime power management, this mode is not officially
  624. * supported.
  625. * @IWL_PLAT_PM_MODE_D0I3: the device goes into D0I3 mode.
  626. */
  627. enum iwl_plat_pm_mode {
  628. IWL_PLAT_PM_MODE_DISABLED,
  629. IWL_PLAT_PM_MODE_D3,
  630. IWL_PLAT_PM_MODE_D0I3,
  631. };
  632. /* Max time to wait for trans to become idle/non-idle on d0i3
  633. * enter/exit (in msecs).
  634. */
  635. #define IWL_TRANS_IDLE_TIMEOUT 2000
  636. /**
  637. * struct iwl_trans - transport common data
  638. *
  639. * @ops - pointer to iwl_trans_ops
  640. * @op_mode - pointer to the op_mode
  641. * @cfg - pointer to the configuration
  642. * @drv - pointer to iwl_drv
  643. * @status: a bit-mask of transport status flags
  644. * @dev - pointer to struct device * that represents the device
  645. * @max_skb_frags: maximum number of fragments an SKB can have when transmitted.
  646. * 0 indicates that frag SKBs (NETIF_F_SG) aren't supported.
  647. * @hw_rf_id a u32 with the device RF ID
  648. * @hw_id: a u32 with the ID of the device / sub-device.
  649. * Set during transport allocation.
  650. * @hw_id_str: a string with info about HW ID. Set during transport allocation.
  651. * @pm_support: set to true in start_hw if link pm is supported
  652. * @ltr_enabled: set to true if the LTR is enabled
  653. * @wide_cmd_header: true when ucode supports wide command header format
  654. * @num_rx_queues: number of RX queues allocated by the transport;
  655. * the transport must set this before calling iwl_drv_start()
  656. * @iml_len: the length of the image loader
  657. * @iml: a pointer to the image loader itself
  658. * @dev_cmd_pool: pool for Tx cmd allocation - for internal use only.
  659. * The user should use iwl_trans_{alloc,free}_tx_cmd.
  660. * @rx_mpdu_cmd: MPDU RX command ID, must be assigned by opmode before
  661. * starting the firmware, used for tracing
  662. * @rx_mpdu_cmd_hdr_size: used for tracing, amount of data before the
  663. * start of the 802.11 header in the @rx_mpdu_cmd
  664. * @dflt_pwr_limit: default power limit fetched from the platform (ACPI)
  665. * @dbg_dest_tlv: points to the destination TLV for debug
  666. * @dbg_conf_tlv: array of pointers to configuration TLVs for debug
  667. * @dbg_trigger_tlv: array of pointers to triggers TLVs for debug
  668. * @dbg_dest_reg_num: num of reg_ops in %dbg_dest_tlv
  669. * @system_pm_mode: the system-wide power management mode in use.
  670. * This mode is set dynamically, depending on the WoWLAN values
  671. * configured from the userspace at runtime.
  672. * @runtime_pm_mode: the runtime power management mode in use. This
  673. * mode is set during the initialization phase and is not
  674. * supposed to change during runtime.
  675. */
  676. struct iwl_trans {
  677. const struct iwl_trans_ops *ops;
  678. struct iwl_op_mode *op_mode;
  679. const struct iwl_cfg *cfg;
  680. struct iwl_drv *drv;
  681. enum iwl_trans_state state;
  682. unsigned long status;
  683. struct device *dev;
  684. u32 max_skb_frags;
  685. u32 hw_rev;
  686. u32 hw_rf_id;
  687. u32 hw_id;
  688. char hw_id_str[52];
  689. u8 rx_mpdu_cmd, rx_mpdu_cmd_hdr_size;
  690. bool pm_support;
  691. bool ltr_enabled;
  692. const struct iwl_hcmd_arr *command_groups;
  693. int command_groups_size;
  694. bool wide_cmd_header;
  695. u8 num_rx_queues;
  696. size_t iml_len;
  697. u8 *iml;
  698. /* The following fields are internal only */
  699. struct kmem_cache *dev_cmd_pool;
  700. char dev_cmd_pool_name[50];
  701. struct dentry *dbgfs_dir;
  702. #ifdef CONFIG_LOCKDEP
  703. struct lockdep_map sync_cmd_lockdep_map;
  704. #endif
  705. const struct iwl_fw_dbg_dest_tlv_v1 *dbg_dest_tlv;
  706. const struct iwl_fw_dbg_conf_tlv *dbg_conf_tlv[FW_DBG_CONF_MAX];
  707. struct iwl_fw_dbg_trigger_tlv * const *dbg_trigger_tlv;
  708. u32 dbg_dump_mask;
  709. u8 dbg_dest_reg_num;
  710. enum iwl_plat_pm_mode system_pm_mode;
  711. enum iwl_plat_pm_mode runtime_pm_mode;
  712. bool suspending;
  713. /* pointer to trans specific struct */
  714. /*Ensure that this pointer will always be aligned to sizeof pointer */
  715. char trans_specific[0] __aligned(sizeof(void *));
  716. };
  717. const char *iwl_get_cmd_string(struct iwl_trans *trans, u32 id);
  718. int iwl_cmd_groups_verify_sorted(const struct iwl_trans_config *trans);
  719. static inline void iwl_trans_configure(struct iwl_trans *trans,
  720. const struct iwl_trans_config *trans_cfg)
  721. {
  722. trans->op_mode = trans_cfg->op_mode;
  723. trans->ops->configure(trans, trans_cfg);
  724. WARN_ON(iwl_cmd_groups_verify_sorted(trans_cfg));
  725. }
  726. static inline int _iwl_trans_start_hw(struct iwl_trans *trans, bool low_power)
  727. {
  728. might_sleep();
  729. return trans->ops->start_hw(trans, low_power);
  730. }
  731. static inline int iwl_trans_start_hw(struct iwl_trans *trans)
  732. {
  733. return trans->ops->start_hw(trans, true);
  734. }
  735. static inline void iwl_trans_op_mode_leave(struct iwl_trans *trans)
  736. {
  737. might_sleep();
  738. if (trans->ops->op_mode_leave)
  739. trans->ops->op_mode_leave(trans);
  740. trans->op_mode = NULL;
  741. trans->state = IWL_TRANS_NO_FW;
  742. }
  743. static inline void iwl_trans_fw_alive(struct iwl_trans *trans, u32 scd_addr)
  744. {
  745. might_sleep();
  746. trans->state = IWL_TRANS_FW_ALIVE;
  747. trans->ops->fw_alive(trans, scd_addr);
  748. }
  749. static inline int iwl_trans_start_fw(struct iwl_trans *trans,
  750. const struct fw_img *fw,
  751. bool run_in_rfkill)
  752. {
  753. might_sleep();
  754. WARN_ON_ONCE(!trans->rx_mpdu_cmd);
  755. clear_bit(STATUS_FW_ERROR, &trans->status);
  756. return trans->ops->start_fw(trans, fw, run_in_rfkill);
  757. }
  758. static inline void _iwl_trans_stop_device(struct iwl_trans *trans,
  759. bool low_power)
  760. {
  761. might_sleep();
  762. trans->ops->stop_device(trans, low_power);
  763. trans->state = IWL_TRANS_NO_FW;
  764. }
  765. static inline void iwl_trans_stop_device(struct iwl_trans *trans)
  766. {
  767. _iwl_trans_stop_device(trans, true);
  768. }
  769. static inline void iwl_trans_d3_suspend(struct iwl_trans *trans, bool test,
  770. bool reset)
  771. {
  772. might_sleep();
  773. if (trans->ops->d3_suspend)
  774. trans->ops->d3_suspend(trans, test, reset);
  775. }
  776. static inline int iwl_trans_d3_resume(struct iwl_trans *trans,
  777. enum iwl_d3_status *status,
  778. bool test, bool reset)
  779. {
  780. might_sleep();
  781. if (!trans->ops->d3_resume)
  782. return 0;
  783. return trans->ops->d3_resume(trans, status, test, reset);
  784. }
  785. static inline int iwl_trans_suspend(struct iwl_trans *trans)
  786. {
  787. if (!trans->ops->suspend)
  788. return 0;
  789. return trans->ops->suspend(trans);
  790. }
  791. static inline void iwl_trans_resume(struct iwl_trans *trans)
  792. {
  793. if (trans->ops->resume)
  794. trans->ops->resume(trans);
  795. }
  796. static inline struct iwl_trans_dump_data *
  797. iwl_trans_dump_data(struct iwl_trans *trans,
  798. const struct iwl_fw_dbg_trigger_tlv *trigger)
  799. {
  800. if (!trans->ops->dump_data)
  801. return NULL;
  802. return trans->ops->dump_data(trans, trigger);
  803. }
  804. static inline void iwl_trans_dump_regs(struct iwl_trans *trans)
  805. {
  806. if (trans->ops->dump_regs)
  807. trans->ops->dump_regs(trans);
  808. }
  809. static inline struct iwl_device_cmd *
  810. iwl_trans_alloc_tx_cmd(struct iwl_trans *trans)
  811. {
  812. return kmem_cache_alloc(trans->dev_cmd_pool, GFP_ATOMIC);
  813. }
  814. int iwl_trans_send_cmd(struct iwl_trans *trans, struct iwl_host_cmd *cmd);
  815. static inline void iwl_trans_free_tx_cmd(struct iwl_trans *trans,
  816. struct iwl_device_cmd *dev_cmd)
  817. {
  818. kmem_cache_free(trans->dev_cmd_pool, dev_cmd);
  819. }
  820. static inline int iwl_trans_tx(struct iwl_trans *trans, struct sk_buff *skb,
  821. struct iwl_device_cmd *dev_cmd, int queue)
  822. {
  823. if (unlikely(test_bit(STATUS_FW_ERROR, &trans->status)))
  824. return -EIO;
  825. if (WARN_ON_ONCE(trans->state != IWL_TRANS_FW_ALIVE)) {
  826. IWL_ERR(trans, "%s bad state = %d\n", __func__, trans->state);
  827. return -EIO;
  828. }
  829. return trans->ops->tx(trans, skb, dev_cmd, queue);
  830. }
  831. static inline void iwl_trans_reclaim(struct iwl_trans *trans, int queue,
  832. int ssn, struct sk_buff_head *skbs)
  833. {
  834. if (WARN_ON_ONCE(trans->state != IWL_TRANS_FW_ALIVE)) {
  835. IWL_ERR(trans, "%s bad state = %d\n", __func__, trans->state);
  836. return;
  837. }
  838. trans->ops->reclaim(trans, queue, ssn, skbs);
  839. }
  840. static inline void iwl_trans_txq_disable(struct iwl_trans *trans, int queue,
  841. bool configure_scd)
  842. {
  843. trans->ops->txq_disable(trans, queue, configure_scd);
  844. }
  845. static inline bool
  846. iwl_trans_txq_enable_cfg(struct iwl_trans *trans, int queue, u16 ssn,
  847. const struct iwl_trans_txq_scd_cfg *cfg,
  848. unsigned int queue_wdg_timeout)
  849. {
  850. might_sleep();
  851. if (WARN_ON_ONCE(trans->state != IWL_TRANS_FW_ALIVE)) {
  852. IWL_ERR(trans, "%s bad state = %d\n", __func__, trans->state);
  853. return false;
  854. }
  855. return trans->ops->txq_enable(trans, queue, ssn,
  856. cfg, queue_wdg_timeout);
  857. }
  858. static inline int
  859. iwl_trans_get_rxq_dma_data(struct iwl_trans *trans, int queue,
  860. struct iwl_trans_rxq_dma_data *data)
  861. {
  862. if (WARN_ON_ONCE(!trans->ops->rxq_dma_data))
  863. return -ENOTSUPP;
  864. return trans->ops->rxq_dma_data(trans, queue, data);
  865. }
  866. static inline void
  867. iwl_trans_txq_free(struct iwl_trans *trans, int queue)
  868. {
  869. if (WARN_ON_ONCE(!trans->ops->txq_free))
  870. return;
  871. trans->ops->txq_free(trans, queue);
  872. }
  873. static inline int
  874. iwl_trans_txq_alloc(struct iwl_trans *trans,
  875. struct iwl_tx_queue_cfg_cmd *cmd,
  876. int cmd_id, int size,
  877. unsigned int wdg_timeout)
  878. {
  879. might_sleep();
  880. if (WARN_ON_ONCE(!trans->ops->txq_alloc))
  881. return -ENOTSUPP;
  882. if (WARN_ON_ONCE(trans->state != IWL_TRANS_FW_ALIVE)) {
  883. IWL_ERR(trans, "%s bad state = %d\n", __func__, trans->state);
  884. return -EIO;
  885. }
  886. return trans->ops->txq_alloc(trans, cmd, cmd_id, size, wdg_timeout);
  887. }
  888. static inline void iwl_trans_txq_set_shared_mode(struct iwl_trans *trans,
  889. int queue, bool shared_mode)
  890. {
  891. if (trans->ops->txq_set_shared_mode)
  892. trans->ops->txq_set_shared_mode(trans, queue, shared_mode);
  893. }
  894. static inline void iwl_trans_txq_enable(struct iwl_trans *trans, int queue,
  895. int fifo, int sta_id, int tid,
  896. int frame_limit, u16 ssn,
  897. unsigned int queue_wdg_timeout)
  898. {
  899. struct iwl_trans_txq_scd_cfg cfg = {
  900. .fifo = fifo,
  901. .sta_id = sta_id,
  902. .tid = tid,
  903. .frame_limit = frame_limit,
  904. .aggregate = sta_id >= 0,
  905. };
  906. iwl_trans_txq_enable_cfg(trans, queue, ssn, &cfg, queue_wdg_timeout);
  907. }
  908. static inline
  909. void iwl_trans_ac_txq_enable(struct iwl_trans *trans, int queue, int fifo,
  910. unsigned int queue_wdg_timeout)
  911. {
  912. struct iwl_trans_txq_scd_cfg cfg = {
  913. .fifo = fifo,
  914. .sta_id = -1,
  915. .tid = IWL_MAX_TID_COUNT,
  916. .frame_limit = IWL_FRAME_LIMIT,
  917. .aggregate = false,
  918. };
  919. iwl_trans_txq_enable_cfg(trans, queue, 0, &cfg, queue_wdg_timeout);
  920. }
  921. static inline void iwl_trans_freeze_txq_timer(struct iwl_trans *trans,
  922. unsigned long txqs,
  923. bool freeze)
  924. {
  925. if (WARN_ON_ONCE(trans->state != IWL_TRANS_FW_ALIVE)) {
  926. IWL_ERR(trans, "%s bad state = %d\n", __func__, trans->state);
  927. return;
  928. }
  929. if (trans->ops->freeze_txq_timer)
  930. trans->ops->freeze_txq_timer(trans, txqs, freeze);
  931. }
  932. static inline void iwl_trans_block_txq_ptrs(struct iwl_trans *trans,
  933. bool block)
  934. {
  935. if (WARN_ON_ONCE(trans->state != IWL_TRANS_FW_ALIVE)) {
  936. IWL_ERR(trans, "%s bad state = %d\n", __func__, trans->state);
  937. return;
  938. }
  939. if (trans->ops->block_txq_ptrs)
  940. trans->ops->block_txq_ptrs(trans, block);
  941. }
  942. static inline int iwl_trans_wait_tx_queues_empty(struct iwl_trans *trans,
  943. u32 txqs)
  944. {
  945. if (WARN_ON_ONCE(!trans->ops->wait_tx_queues_empty))
  946. return -ENOTSUPP;
  947. if (WARN_ON_ONCE(trans->state != IWL_TRANS_FW_ALIVE)) {
  948. IWL_ERR(trans, "%s bad state = %d\n", __func__, trans->state);
  949. return -EIO;
  950. }
  951. return trans->ops->wait_tx_queues_empty(trans, txqs);
  952. }
  953. static inline int iwl_trans_wait_txq_empty(struct iwl_trans *trans, int queue)
  954. {
  955. if (WARN_ON_ONCE(!trans->ops->wait_txq_empty))
  956. return -ENOTSUPP;
  957. if (WARN_ON_ONCE(trans->state != IWL_TRANS_FW_ALIVE)) {
  958. IWL_ERR(trans, "%s bad state = %d\n", __func__, trans->state);
  959. return -EIO;
  960. }
  961. return trans->ops->wait_txq_empty(trans, queue);
  962. }
  963. static inline void iwl_trans_write8(struct iwl_trans *trans, u32 ofs, u8 val)
  964. {
  965. trans->ops->write8(trans, ofs, val);
  966. }
  967. static inline void iwl_trans_write32(struct iwl_trans *trans, u32 ofs, u32 val)
  968. {
  969. trans->ops->write32(trans, ofs, val);
  970. }
  971. static inline u32 iwl_trans_read32(struct iwl_trans *trans, u32 ofs)
  972. {
  973. return trans->ops->read32(trans, ofs);
  974. }
  975. static inline u32 iwl_trans_read_prph(struct iwl_trans *trans, u32 ofs)
  976. {
  977. return trans->ops->read_prph(trans, ofs);
  978. }
  979. static inline void iwl_trans_write_prph(struct iwl_trans *trans, u32 ofs,
  980. u32 val)
  981. {
  982. return trans->ops->write_prph(trans, ofs, val);
  983. }
  984. static inline int iwl_trans_read_mem(struct iwl_trans *trans, u32 addr,
  985. void *buf, int dwords)
  986. {
  987. return trans->ops->read_mem(trans, addr, buf, dwords);
  988. }
  989. #define iwl_trans_read_mem_bytes(trans, addr, buf, bufsize) \
  990. do { \
  991. if (__builtin_constant_p(bufsize)) \
  992. BUILD_BUG_ON((bufsize) % sizeof(u32)); \
  993. iwl_trans_read_mem(trans, addr, buf, (bufsize) / sizeof(u32));\
  994. } while (0)
  995. static inline u32 iwl_trans_read_mem32(struct iwl_trans *trans, u32 addr)
  996. {
  997. u32 value;
  998. if (WARN_ON(iwl_trans_read_mem(trans, addr, &value, 1)))
  999. return 0xa5a5a5a5;
  1000. return value;
  1001. }
  1002. static inline int iwl_trans_write_mem(struct iwl_trans *trans, u32 addr,
  1003. const void *buf, int dwords)
  1004. {
  1005. return trans->ops->write_mem(trans, addr, buf, dwords);
  1006. }
  1007. static inline u32 iwl_trans_write_mem32(struct iwl_trans *trans, u32 addr,
  1008. u32 val)
  1009. {
  1010. return iwl_trans_write_mem(trans, addr, &val, 1);
  1011. }
  1012. static inline void iwl_trans_set_pmi(struct iwl_trans *trans, bool state)
  1013. {
  1014. if (trans->ops->set_pmi)
  1015. trans->ops->set_pmi(trans, state);
  1016. }
  1017. static inline void iwl_trans_sw_reset(struct iwl_trans *trans)
  1018. {
  1019. if (trans->ops->sw_reset)
  1020. trans->ops->sw_reset(trans);
  1021. }
  1022. static inline void
  1023. iwl_trans_set_bits_mask(struct iwl_trans *trans, u32 reg, u32 mask, u32 value)
  1024. {
  1025. trans->ops->set_bits_mask(trans, reg, mask, value);
  1026. }
  1027. #define iwl_trans_grab_nic_access(trans, flags) \
  1028. __cond_lock(nic_access, \
  1029. likely((trans)->ops->grab_nic_access(trans, flags)))
  1030. static inline void __releases(nic_access)
  1031. iwl_trans_release_nic_access(struct iwl_trans *trans, unsigned long *flags)
  1032. {
  1033. trans->ops->release_nic_access(trans, flags);
  1034. __release(nic_access);
  1035. }
  1036. static inline void iwl_trans_fw_error(struct iwl_trans *trans)
  1037. {
  1038. if (WARN_ON_ONCE(!trans->op_mode))
  1039. return;
  1040. /* prevent double restarts due to the same erroneous FW */
  1041. if (!test_and_set_bit(STATUS_FW_ERROR, &trans->status))
  1042. iwl_op_mode_nic_error(trans->op_mode);
  1043. }
  1044. /*****************************************************
  1045. * transport helper functions
  1046. *****************************************************/
  1047. struct iwl_trans *iwl_trans_alloc(unsigned int priv_size,
  1048. struct device *dev,
  1049. const struct iwl_cfg *cfg,
  1050. const struct iwl_trans_ops *ops);
  1051. void iwl_trans_free(struct iwl_trans *trans);
  1052. void iwl_trans_ref(struct iwl_trans *trans);
  1053. void iwl_trans_unref(struct iwl_trans *trans);
  1054. /*****************************************************
  1055. * driver (transport) register/unregister functions
  1056. ******************************************************/
  1057. int __must_check iwl_pci_register_driver(void);
  1058. void iwl_pci_unregister_driver(void);
  1059. #endif /* __iwl_trans_h__ */