iwl-trans.h 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169
  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_RXQ_POS 16
  116. #define FH_RSCSR_RXQ_MASK 0x3F0000
  117. struct iwl_rx_packet {
  118. /*
  119. * The first 4 bytes of the RX frame header contain both the RX frame
  120. * size and some flags.
  121. * Bit fields:
  122. * 31: flag flush RB request
  123. * 30: flag ignore TC (terminal counter) request
  124. * 29: flag fast IRQ request
  125. * 28-26: Reserved
  126. * 25: Offload enabled
  127. * 24: RPF enabled
  128. * 23: RSS enabled
  129. * 22: Checksum enabled
  130. * 21-16: RX queue
  131. * 15-14: Reserved
  132. * 13-00: RX frame size
  133. */
  134. __le32 len_n_flags;
  135. struct iwl_cmd_header hdr;
  136. u8 data[];
  137. } __packed;
  138. static inline u32 iwl_rx_packet_len(const struct iwl_rx_packet *pkt)
  139. {
  140. return le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK;
  141. }
  142. static inline u32 iwl_rx_packet_payload_len(const struct iwl_rx_packet *pkt)
  143. {
  144. return iwl_rx_packet_len(pkt) - sizeof(pkt->hdr);
  145. }
  146. /**
  147. * enum CMD_MODE - how to send the host commands ?
  148. *
  149. * @CMD_ASYNC: Return right away and don't wait for the response
  150. * @CMD_WANT_SKB: Not valid with CMD_ASYNC. The caller needs the buffer of
  151. * the response. The caller needs to call iwl_free_resp when done.
  152. * @CMD_HIGH_PRIO: The command is high priority - it goes to the front of the
  153. * command queue, but after other high priority commands. Valid only
  154. * with CMD_ASYNC.
  155. * @CMD_SEND_IN_IDLE: The command should be sent even when the trans is idle.
  156. * @CMD_MAKE_TRANS_IDLE: The command response should mark the trans as idle.
  157. * @CMD_WAKE_UP_TRANS: The command response should wake up the trans
  158. * (i.e. mark it as non-idle).
  159. * @CMD_WANT_ASYNC_CALLBACK: the op_mode's async callback function must be
  160. * called after this command completes. Valid only with CMD_ASYNC.
  161. */
  162. enum CMD_MODE {
  163. CMD_ASYNC = BIT(0),
  164. CMD_WANT_SKB = BIT(1),
  165. CMD_SEND_IN_RFKILL = BIT(2),
  166. CMD_HIGH_PRIO = BIT(3),
  167. CMD_SEND_IN_IDLE = BIT(4),
  168. CMD_MAKE_TRANS_IDLE = BIT(5),
  169. CMD_WAKE_UP_TRANS = BIT(6),
  170. CMD_WANT_ASYNC_CALLBACK = BIT(7),
  171. };
  172. #define DEF_CMD_PAYLOAD_SIZE 320
  173. /**
  174. * struct iwl_device_cmd
  175. *
  176. * For allocation of the command and tx queues, this establishes the overall
  177. * size of the largest command we send to uCode, except for commands that
  178. * aren't fully copied and use other TFD space.
  179. */
  180. struct iwl_device_cmd {
  181. union {
  182. struct {
  183. struct iwl_cmd_header hdr; /* uCode API */
  184. u8 payload[DEF_CMD_PAYLOAD_SIZE];
  185. };
  186. struct {
  187. struct iwl_cmd_header_wide hdr_wide;
  188. u8 payload_wide[DEF_CMD_PAYLOAD_SIZE -
  189. sizeof(struct iwl_cmd_header_wide) +
  190. sizeof(struct iwl_cmd_header)];
  191. };
  192. };
  193. } __packed;
  194. #define TFD_MAX_PAYLOAD_SIZE (sizeof(struct iwl_device_cmd))
  195. /*
  196. * number of transfer buffers (fragments) per transmit frame descriptor;
  197. * this is just the driver's idea, the hardware supports 20
  198. */
  199. #define IWL_MAX_CMD_TBS_PER_TFD 2
  200. /**
  201. * enum iwl_hcmd_dataflag - flag for each one of the chunks of the command
  202. *
  203. * @IWL_HCMD_DFL_NOCOPY: By default, the command is copied to the host command's
  204. * ring. The transport layer doesn't map the command's buffer to DMA, but
  205. * rather copies it to a previously allocated DMA buffer. This flag tells
  206. * the transport layer not to copy the command, but to map the existing
  207. * buffer (that is passed in) instead. This saves the memcpy and allows
  208. * commands that are bigger than the fixed buffer to be submitted.
  209. * Note that a TFD entry after a NOCOPY one cannot be a normal copied one.
  210. * @IWL_HCMD_DFL_DUP: Only valid without NOCOPY, duplicate the memory for this
  211. * chunk internally and free it again after the command completes. This
  212. * can (currently) be used only once per command.
  213. * Note that a TFD entry after a DUP one cannot be a normal copied one.
  214. */
  215. enum iwl_hcmd_dataflag {
  216. IWL_HCMD_DFL_NOCOPY = BIT(0),
  217. IWL_HCMD_DFL_DUP = BIT(1),
  218. };
  219. /**
  220. * struct iwl_host_cmd - Host command to the uCode
  221. *
  222. * @data: array of chunks that composes the data of the host command
  223. * @resp_pkt: response packet, if %CMD_WANT_SKB was set
  224. * @_rx_page_order: (internally used to free response packet)
  225. * @_rx_page_addr: (internally used to free response packet)
  226. * @flags: can be CMD_*
  227. * @len: array of the lengths of the chunks in data
  228. * @dataflags: IWL_HCMD_DFL_*
  229. * @id: command id of the host command, for wide commands encoding the
  230. * version and group as well
  231. */
  232. struct iwl_host_cmd {
  233. const void *data[IWL_MAX_CMD_TBS_PER_TFD];
  234. struct iwl_rx_packet *resp_pkt;
  235. unsigned long _rx_page_addr;
  236. u32 _rx_page_order;
  237. u32 flags;
  238. u32 id;
  239. u16 len[IWL_MAX_CMD_TBS_PER_TFD];
  240. u8 dataflags[IWL_MAX_CMD_TBS_PER_TFD];
  241. };
  242. static inline void iwl_free_resp(struct iwl_host_cmd *cmd)
  243. {
  244. free_pages(cmd->_rx_page_addr, cmd->_rx_page_order);
  245. }
  246. struct iwl_rx_cmd_buffer {
  247. struct page *_page;
  248. int _offset;
  249. bool _page_stolen;
  250. u32 _rx_page_order;
  251. unsigned int truesize;
  252. };
  253. static inline void *rxb_addr(struct iwl_rx_cmd_buffer *r)
  254. {
  255. return (void *)((unsigned long)page_address(r->_page) + r->_offset);
  256. }
  257. static inline int rxb_offset(struct iwl_rx_cmd_buffer *r)
  258. {
  259. return r->_offset;
  260. }
  261. static inline struct page *rxb_steal_page(struct iwl_rx_cmd_buffer *r)
  262. {
  263. r->_page_stolen = true;
  264. get_page(r->_page);
  265. return r->_page;
  266. }
  267. static inline void iwl_free_rxb(struct iwl_rx_cmd_buffer *r)
  268. {
  269. __free_pages(r->_page, r->_rx_page_order);
  270. }
  271. #define MAX_NO_RECLAIM_CMDS 6
  272. #define IWL_MASK(lo, hi) ((1 << (hi)) | ((1 << (hi)) - (1 << (lo))))
  273. /*
  274. * Maximum number of HW queues the transport layer
  275. * currently supports
  276. */
  277. #define IWL_MAX_HW_QUEUES 32
  278. #define IWL_MAX_TVQM_QUEUES 512
  279. #define IWL_MAX_TID_COUNT 8
  280. #define IWL_MGMT_TID 15
  281. #define IWL_FRAME_LIMIT 64
  282. #define IWL_MAX_RX_HW_QUEUES 16
  283. /**
  284. * enum iwl_wowlan_status - WoWLAN image/device status
  285. * @IWL_D3_STATUS_ALIVE: firmware is still running after resume
  286. * @IWL_D3_STATUS_RESET: device was reset while suspended
  287. */
  288. enum iwl_d3_status {
  289. IWL_D3_STATUS_ALIVE,
  290. IWL_D3_STATUS_RESET,
  291. };
  292. /**
  293. * enum iwl_trans_status: transport status flags
  294. * @STATUS_SYNC_HCMD_ACTIVE: a SYNC command is being processed
  295. * @STATUS_DEVICE_ENABLED: APM is enabled
  296. * @STATUS_TPOWER_PMI: the device might be asleep (need to wake it up)
  297. * @STATUS_INT_ENABLED: interrupts are enabled
  298. * @STATUS_RFKILL_HW: the actual HW state of the RF-kill switch
  299. * @STATUS_RFKILL_OPMODE: RF-kill state reported to opmode
  300. * @STATUS_FW_ERROR: the fw is in error state
  301. * @STATUS_TRANS_GOING_IDLE: shutting down the trans, only special commands
  302. * are sent
  303. * @STATUS_TRANS_IDLE: the trans is idle - general commands are not to be sent
  304. * @STATUS_TRANS_DEAD: trans is dead - avoid any read/write operation
  305. */
  306. enum iwl_trans_status {
  307. STATUS_SYNC_HCMD_ACTIVE,
  308. STATUS_DEVICE_ENABLED,
  309. STATUS_TPOWER_PMI,
  310. STATUS_INT_ENABLED,
  311. STATUS_RFKILL_HW,
  312. STATUS_RFKILL_OPMODE,
  313. STATUS_FW_ERROR,
  314. STATUS_TRANS_GOING_IDLE,
  315. STATUS_TRANS_IDLE,
  316. STATUS_TRANS_DEAD,
  317. };
  318. static inline int
  319. iwl_trans_get_rb_size_order(enum iwl_amsdu_size rb_size)
  320. {
  321. switch (rb_size) {
  322. case IWL_AMSDU_4K:
  323. return get_order(4 * 1024);
  324. case IWL_AMSDU_8K:
  325. return get_order(8 * 1024);
  326. case IWL_AMSDU_12K:
  327. return get_order(12 * 1024);
  328. default:
  329. WARN_ON(1);
  330. return -1;
  331. }
  332. }
  333. struct iwl_hcmd_names {
  334. u8 cmd_id;
  335. const char *const cmd_name;
  336. };
  337. #define HCMD_NAME(x) \
  338. { .cmd_id = x, .cmd_name = #x }
  339. struct iwl_hcmd_arr {
  340. const struct iwl_hcmd_names *arr;
  341. int size;
  342. };
  343. #define HCMD_ARR(x) \
  344. { .arr = x, .size = ARRAY_SIZE(x) }
  345. /**
  346. * struct iwl_trans_config - transport configuration
  347. *
  348. * @op_mode: pointer to the upper layer.
  349. * @cmd_queue: the index of the command queue.
  350. * Must be set before start_fw.
  351. * @cmd_fifo: the fifo for host commands
  352. * @cmd_q_wdg_timeout: the timeout of the watchdog timer for the command queue.
  353. * @no_reclaim_cmds: Some devices erroneously don't set the
  354. * SEQ_RX_FRAME bit on some notifications, this is the
  355. * list of such notifications to filter. Max length is
  356. * %MAX_NO_RECLAIM_CMDS.
  357. * @n_no_reclaim_cmds: # of commands in list
  358. * @rx_buf_size: RX buffer size needed for A-MSDUs
  359. * if unset 4k will be the RX buffer size
  360. * @bc_table_dword: set to true if the BC table expects the byte count to be
  361. * in DWORD (as opposed to bytes)
  362. * @scd_set_active: should the transport configure the SCD for HCMD queue
  363. * @sw_csum_tx: transport should compute the TCP checksum
  364. * @command_groups: array of command groups, each member is an array of the
  365. * commands in the group; for debugging only
  366. * @command_groups_size: number of command groups, to avoid illegal access
  367. * @cb_data_offs: offset inside skb->cb to store transport data at, must have
  368. * space for at least two pointers
  369. */
  370. struct iwl_trans_config {
  371. struct iwl_op_mode *op_mode;
  372. u8 cmd_queue;
  373. u8 cmd_fifo;
  374. unsigned int cmd_q_wdg_timeout;
  375. const u8 *no_reclaim_cmds;
  376. unsigned int n_no_reclaim_cmds;
  377. enum iwl_amsdu_size rx_buf_size;
  378. bool bc_table_dword;
  379. bool scd_set_active;
  380. bool sw_csum_tx;
  381. const struct iwl_hcmd_arr *command_groups;
  382. int command_groups_size;
  383. u8 cb_data_offs;
  384. };
  385. struct iwl_trans_dump_data {
  386. u32 len;
  387. u8 data[];
  388. };
  389. struct iwl_trans;
  390. struct iwl_trans_txq_scd_cfg {
  391. u8 fifo;
  392. u8 sta_id;
  393. u8 tid;
  394. bool aggregate;
  395. int frame_limit;
  396. };
  397. /**
  398. * struct iwl_trans_ops - transport specific operations
  399. *
  400. * All the handlers MUST be implemented
  401. *
  402. * @start_hw: starts the HW. If low_power is true, the NIC needs to be taken
  403. * out of a low power state. From that point on, the HW can send
  404. * interrupts. May sleep.
  405. * @op_mode_leave: Turn off the HW RF kill indication if on
  406. * May sleep
  407. * @start_fw: allocates and inits all the resources for the transport
  408. * layer. Also kick a fw image.
  409. * May sleep
  410. * @fw_alive: called when the fw sends alive notification. If the fw provides
  411. * the SCD base address in SRAM, then provide it here, or 0 otherwise.
  412. * May sleep
  413. * @stop_device: stops the whole device (embedded CPU put to reset) and stops
  414. * the HW. If low_power is true, the NIC will be put in low power state.
  415. * From that point on, the HW will be stopped but will still issue an
  416. * interrupt if the HW RF kill switch is triggered.
  417. * This callback must do the right thing and not crash even if %start_hw()
  418. * was called but not &start_fw(). May sleep.
  419. * @d3_suspend: put the device into the correct mode for WoWLAN during
  420. * suspend. This is optional, if not implemented WoWLAN will not be
  421. * supported. This callback may sleep.
  422. * @d3_resume: resume the device after WoWLAN, enabling the opmode to
  423. * talk to the WoWLAN image to get its status. This is optional, if not
  424. * implemented WoWLAN will not be supported. This callback may sleep.
  425. * @send_cmd:send a host command. Must return -ERFKILL if RFkill is asserted.
  426. * If RFkill is asserted in the middle of a SYNC host command, it must
  427. * return -ERFKILL straight away.
  428. * May sleep only if CMD_ASYNC is not set
  429. * @tx: send an skb. The transport relies on the op_mode to zero the
  430. * the ieee80211_tx_info->driver_data. If the MPDU is an A-MSDU, all
  431. * the CSUM will be taken care of (TCP CSUM and IP header in case of
  432. * IPv4). If the MPDU is a single MSDU, the op_mode must compute the IP
  433. * header if it is IPv4.
  434. * Must be atomic
  435. * @reclaim: free packet until ssn. Returns a list of freed packets.
  436. * Must be atomic
  437. * @txq_enable: setup a queue. To setup an AC queue, use the
  438. * iwl_trans_ac_txq_enable wrapper. fw_alive must have been called before
  439. * this one. The op_mode must not configure the HCMD queue. The scheduler
  440. * configuration may be %NULL, in which case the hardware will not be
  441. * configured. If true is returned, the operation mode needs to increment
  442. * the sequence number of the packets routed to this queue because of a
  443. * hardware scheduler bug. May sleep.
  444. * @txq_disable: de-configure a Tx queue to send AMPDUs
  445. * Must be atomic
  446. * @txq_set_shared_mode: change Tx queue shared/unshared marking
  447. * @wait_tx_queues_empty: wait until tx queues are empty. May sleep.
  448. * @wait_txq_empty: wait until specific tx queue is empty. May sleep.
  449. * @freeze_txq_timer: prevents the timer of the queue from firing until the
  450. * queue is set to awake. Must be atomic.
  451. * @block_txq_ptrs: stop updating the write pointers of the Tx queues. Note
  452. * that the transport needs to refcount the calls since this function
  453. * will be called several times with block = true, and then the queues
  454. * need to be unblocked only after the same number of calls with
  455. * block = false.
  456. * @write8: write a u8 to a register at offset ofs from the BAR
  457. * @write32: write a u32 to a register at offset ofs from the BAR
  458. * @read32: read a u32 register at offset ofs from the BAR
  459. * @read_prph: read a DWORD from a periphery register
  460. * @write_prph: write a DWORD to a periphery register
  461. * @read_mem: read device's SRAM in DWORD
  462. * @write_mem: write device's SRAM in DWORD. If %buf is %NULL, then the memory
  463. * will be zeroed.
  464. * @configure: configure parameters required by the transport layer from
  465. * the op_mode. May be called several times before start_fw, can't be
  466. * called after that.
  467. * @set_pmi: set the power pmi state
  468. * @grab_nic_access: wake the NIC to be able to access non-HBUS regs.
  469. * Sleeping is not allowed between grab_nic_access and
  470. * release_nic_access.
  471. * @release_nic_access: let the NIC go to sleep. The "flags" parameter
  472. * must be the same one that was sent before to the grab_nic_access.
  473. * @set_bits_mask - set SRAM register according to value and mask.
  474. * @ref: grab a reference to the transport/FW layers, disallowing
  475. * certain low power states
  476. * @unref: release a reference previously taken with @ref. Note that
  477. * initially the reference count is 1, making an initial @unref
  478. * necessary to allow low power states.
  479. * @dump_data: return a vmalloc'ed buffer with debug data, maybe containing last
  480. * TX'ed commands and similar. The buffer will be vfree'd by the caller.
  481. * Note that the transport must fill in the proper file headers.
  482. * @dump_regs: dump using IWL_ERR configuration space and memory mapped
  483. * registers of the device to diagnose failure, e.g., when HW becomes
  484. * inaccessible.
  485. */
  486. struct iwl_trans_ops {
  487. int (*start_hw)(struct iwl_trans *iwl_trans, bool low_power);
  488. void (*op_mode_leave)(struct iwl_trans *iwl_trans);
  489. int (*start_fw)(struct iwl_trans *trans, const struct fw_img *fw,
  490. bool run_in_rfkill);
  491. void (*fw_alive)(struct iwl_trans *trans, u32 scd_addr);
  492. void (*stop_device)(struct iwl_trans *trans, bool low_power);
  493. void (*d3_suspend)(struct iwl_trans *trans, bool test, bool reset);
  494. int (*d3_resume)(struct iwl_trans *trans, enum iwl_d3_status *status,
  495. bool test, bool reset);
  496. int (*send_cmd)(struct iwl_trans *trans, struct iwl_host_cmd *cmd);
  497. int (*tx)(struct iwl_trans *trans, struct sk_buff *skb,
  498. struct iwl_device_cmd *dev_cmd, int queue);
  499. void (*reclaim)(struct iwl_trans *trans, int queue, int ssn,
  500. struct sk_buff_head *skbs);
  501. bool (*txq_enable)(struct iwl_trans *trans, int queue, u16 ssn,
  502. const struct iwl_trans_txq_scd_cfg *cfg,
  503. unsigned int queue_wdg_timeout);
  504. void (*txq_disable)(struct iwl_trans *trans, int queue,
  505. bool configure_scd);
  506. /* a000 functions */
  507. int (*txq_alloc)(struct iwl_trans *trans,
  508. struct iwl_tx_queue_cfg_cmd *cmd,
  509. int cmd_id,
  510. unsigned int queue_wdg_timeout);
  511. void (*txq_free)(struct iwl_trans *trans, int queue);
  512. void (*txq_set_shared_mode)(struct iwl_trans *trans, u32 txq_id,
  513. bool shared);
  514. int (*wait_tx_queues_empty)(struct iwl_trans *trans, u32 txq_bm);
  515. int (*wait_txq_empty)(struct iwl_trans *trans, int queue);
  516. void (*freeze_txq_timer)(struct iwl_trans *trans, unsigned long txqs,
  517. bool freeze);
  518. void (*block_txq_ptrs)(struct iwl_trans *trans, bool block);
  519. void (*write8)(struct iwl_trans *trans, u32 ofs, u8 val);
  520. void (*write32)(struct iwl_trans *trans, u32 ofs, u32 val);
  521. u32 (*read32)(struct iwl_trans *trans, u32 ofs);
  522. u32 (*read_prph)(struct iwl_trans *trans, u32 ofs);
  523. void (*write_prph)(struct iwl_trans *trans, u32 ofs, u32 val);
  524. int (*read_mem)(struct iwl_trans *trans, u32 addr,
  525. void *buf, int dwords);
  526. int (*write_mem)(struct iwl_trans *trans, u32 addr,
  527. const void *buf, int dwords);
  528. void (*configure)(struct iwl_trans *trans,
  529. const struct iwl_trans_config *trans_cfg);
  530. void (*set_pmi)(struct iwl_trans *trans, bool state);
  531. bool (*grab_nic_access)(struct iwl_trans *trans, unsigned long *flags);
  532. void (*release_nic_access)(struct iwl_trans *trans,
  533. unsigned long *flags);
  534. void (*set_bits_mask)(struct iwl_trans *trans, u32 reg, u32 mask,
  535. u32 value);
  536. void (*ref)(struct iwl_trans *trans);
  537. void (*unref)(struct iwl_trans *trans);
  538. int (*suspend)(struct iwl_trans *trans);
  539. void (*resume)(struct iwl_trans *trans);
  540. struct iwl_trans_dump_data *(*dump_data)(struct iwl_trans *trans,
  541. const struct iwl_fw_dbg_trigger_tlv
  542. *trigger);
  543. void (*dump_regs)(struct iwl_trans *trans);
  544. };
  545. /**
  546. * enum iwl_trans_state - state of the transport layer
  547. *
  548. * @IWL_TRANS_NO_FW: no fw has sent an alive response
  549. * @IWL_TRANS_FW_ALIVE: a fw has sent an alive response
  550. */
  551. enum iwl_trans_state {
  552. IWL_TRANS_NO_FW = 0,
  553. IWL_TRANS_FW_ALIVE = 1,
  554. };
  555. /**
  556. * DOC: Platform power management
  557. *
  558. * There are two types of platform power management: system-wide
  559. * (WoWLAN) and runtime.
  560. *
  561. * In system-wide power management the entire platform goes into a low
  562. * power state (e.g. idle or suspend to RAM) at the same time and the
  563. * device is configured as a wakeup source for the entire platform.
  564. * This is usually triggered by userspace activity (e.g. the user
  565. * presses the suspend button or a power management daemon decides to
  566. * put the platform in low power mode). The device's behavior in this
  567. * mode is dictated by the wake-on-WLAN configuration.
  568. *
  569. * In runtime power management, only the devices which are themselves
  570. * idle enter a low power state. This is done at runtime, which means
  571. * that the entire system is still running normally. This mode is
  572. * usually triggered automatically by the device driver and requires
  573. * the ability to enter and exit the low power modes in a very short
  574. * time, so there is not much impact in usability.
  575. *
  576. * The terms used for the device's behavior are as follows:
  577. *
  578. * - D0: the device is fully powered and the host is awake;
  579. * - D3: the device is in low power mode and only reacts to
  580. * specific events (e.g. magic-packet received or scan
  581. * results found);
  582. * - D0I3: the device is in low power mode and reacts to any
  583. * activity (e.g. RX);
  584. *
  585. * These terms reflect the power modes in the firmware and are not to
  586. * be confused with the physical device power state. The NIC can be
  587. * in D0I3 mode even if, for instance, the PCI device is in D3 state.
  588. */
  589. /**
  590. * enum iwl_plat_pm_mode - platform power management mode
  591. *
  592. * This enumeration describes the device's platform power management
  593. * behavior when in idle mode (i.e. runtime power management) or when
  594. * in system-wide suspend (i.e WoWLAN).
  595. *
  596. * @IWL_PLAT_PM_MODE_DISABLED: power management is disabled for this
  597. * device. At runtime, this means that nothing happens and the
  598. * device always remains in active. In system-wide suspend mode,
  599. * it means that the all connections will be closed automatically
  600. * by mac80211 before the platform is suspended.
  601. * @IWL_PLAT_PM_MODE_D3: the device goes into D3 mode (i.e. WoWLAN).
  602. * For runtime power management, this mode is not officially
  603. * supported.
  604. * @IWL_PLAT_PM_MODE_D0I3: the device goes into D0I3 mode.
  605. */
  606. enum iwl_plat_pm_mode {
  607. IWL_PLAT_PM_MODE_DISABLED,
  608. IWL_PLAT_PM_MODE_D3,
  609. IWL_PLAT_PM_MODE_D0I3,
  610. };
  611. /* Max time to wait for trans to become idle/non-idle on d0i3
  612. * enter/exit (in msecs).
  613. */
  614. #define IWL_TRANS_IDLE_TIMEOUT 2000
  615. /**
  616. * struct iwl_trans - transport common data
  617. *
  618. * @ops - pointer to iwl_trans_ops
  619. * @op_mode - pointer to the op_mode
  620. * @cfg - pointer to the configuration
  621. * @drv - pointer to iwl_drv
  622. * @status: a bit-mask of transport status flags
  623. * @dev - pointer to struct device * that represents the device
  624. * @max_skb_frags: maximum number of fragments an SKB can have when transmitted.
  625. * 0 indicates that frag SKBs (NETIF_F_SG) aren't supported.
  626. * @hw_rf_id a u32 with the device RF ID
  627. * @hw_id: a u32 with the ID of the device / sub-device.
  628. * Set during transport allocation.
  629. * @hw_id_str: a string with info about HW ID. Set during transport allocation.
  630. * @pm_support: set to true in start_hw if link pm is supported
  631. * @ltr_enabled: set to true if the LTR is enabled
  632. * @wide_cmd_header: true when ucode supports wide command header format
  633. * @num_rx_queues: number of RX queues allocated by the transport;
  634. * the transport must set this before calling iwl_drv_start()
  635. * @dev_cmd_pool: pool for Tx cmd allocation - for internal use only.
  636. * The user should use iwl_trans_{alloc,free}_tx_cmd.
  637. * @rx_mpdu_cmd: MPDU RX command ID, must be assigned by opmode before
  638. * starting the firmware, used for tracing
  639. * @rx_mpdu_cmd_hdr_size: used for tracing, amount of data before the
  640. * start of the 802.11 header in the @rx_mpdu_cmd
  641. * @dflt_pwr_limit: default power limit fetched from the platform (ACPI)
  642. * @dbg_dest_tlv: points to the destination TLV for debug
  643. * @dbg_conf_tlv: array of pointers to configuration TLVs for debug
  644. * @dbg_trigger_tlv: array of pointers to triggers TLVs for debug
  645. * @dbg_dest_reg_num: num of reg_ops in %dbg_dest_tlv
  646. * @system_pm_mode: the system-wide power management mode in use.
  647. * This mode is set dynamically, depending on the WoWLAN values
  648. * configured from the userspace at runtime.
  649. * @runtime_pm_mode: the runtime power management mode in use. This
  650. * mode is set during the initialization phase and is not
  651. * supposed to change during runtime.
  652. */
  653. struct iwl_trans {
  654. const struct iwl_trans_ops *ops;
  655. struct iwl_op_mode *op_mode;
  656. const struct iwl_cfg *cfg;
  657. struct iwl_drv *drv;
  658. enum iwl_trans_state state;
  659. unsigned long status;
  660. struct device *dev;
  661. u32 max_skb_frags;
  662. u32 hw_rev;
  663. u32 hw_rf_id;
  664. u32 hw_id;
  665. char hw_id_str[52];
  666. u8 rx_mpdu_cmd, rx_mpdu_cmd_hdr_size;
  667. bool pm_support;
  668. bool ltr_enabled;
  669. const struct iwl_hcmd_arr *command_groups;
  670. int command_groups_size;
  671. bool wide_cmd_header;
  672. u8 num_rx_queues;
  673. /* The following fields are internal only */
  674. struct kmem_cache *dev_cmd_pool;
  675. char dev_cmd_pool_name[50];
  676. struct dentry *dbgfs_dir;
  677. #ifdef CONFIG_LOCKDEP
  678. struct lockdep_map sync_cmd_lockdep_map;
  679. #endif
  680. const struct iwl_fw_dbg_dest_tlv *dbg_dest_tlv;
  681. const struct iwl_fw_dbg_conf_tlv *dbg_conf_tlv[FW_DBG_CONF_MAX];
  682. struct iwl_fw_dbg_trigger_tlv * const *dbg_trigger_tlv;
  683. u8 dbg_dest_reg_num;
  684. enum iwl_plat_pm_mode system_pm_mode;
  685. enum iwl_plat_pm_mode runtime_pm_mode;
  686. bool suspending;
  687. /* pointer to trans specific struct */
  688. /*Ensure that this pointer will always be aligned to sizeof pointer */
  689. char trans_specific[0] __aligned(sizeof(void *));
  690. };
  691. const char *iwl_get_cmd_string(struct iwl_trans *trans, u32 id);
  692. int iwl_cmd_groups_verify_sorted(const struct iwl_trans_config *trans);
  693. static inline void iwl_trans_configure(struct iwl_trans *trans,
  694. const struct iwl_trans_config *trans_cfg)
  695. {
  696. trans->op_mode = trans_cfg->op_mode;
  697. trans->ops->configure(trans, trans_cfg);
  698. WARN_ON(iwl_cmd_groups_verify_sorted(trans_cfg));
  699. }
  700. static inline int _iwl_trans_start_hw(struct iwl_trans *trans, bool low_power)
  701. {
  702. might_sleep();
  703. return trans->ops->start_hw(trans, low_power);
  704. }
  705. static inline int iwl_trans_start_hw(struct iwl_trans *trans)
  706. {
  707. return trans->ops->start_hw(trans, true);
  708. }
  709. static inline void iwl_trans_op_mode_leave(struct iwl_trans *trans)
  710. {
  711. might_sleep();
  712. if (trans->ops->op_mode_leave)
  713. trans->ops->op_mode_leave(trans);
  714. trans->op_mode = NULL;
  715. trans->state = IWL_TRANS_NO_FW;
  716. }
  717. static inline void iwl_trans_fw_alive(struct iwl_trans *trans, u32 scd_addr)
  718. {
  719. might_sleep();
  720. trans->state = IWL_TRANS_FW_ALIVE;
  721. trans->ops->fw_alive(trans, scd_addr);
  722. }
  723. static inline int iwl_trans_start_fw(struct iwl_trans *trans,
  724. const struct fw_img *fw,
  725. bool run_in_rfkill)
  726. {
  727. might_sleep();
  728. WARN_ON_ONCE(!trans->rx_mpdu_cmd);
  729. clear_bit(STATUS_FW_ERROR, &trans->status);
  730. return trans->ops->start_fw(trans, fw, run_in_rfkill);
  731. }
  732. static inline void _iwl_trans_stop_device(struct iwl_trans *trans,
  733. bool low_power)
  734. {
  735. might_sleep();
  736. trans->ops->stop_device(trans, low_power);
  737. trans->state = IWL_TRANS_NO_FW;
  738. }
  739. static inline void iwl_trans_stop_device(struct iwl_trans *trans)
  740. {
  741. _iwl_trans_stop_device(trans, true);
  742. }
  743. static inline void iwl_trans_d3_suspend(struct iwl_trans *trans, bool test,
  744. bool reset)
  745. {
  746. might_sleep();
  747. if (trans->ops->d3_suspend)
  748. trans->ops->d3_suspend(trans, test, reset);
  749. }
  750. static inline int iwl_trans_d3_resume(struct iwl_trans *trans,
  751. enum iwl_d3_status *status,
  752. bool test, bool reset)
  753. {
  754. might_sleep();
  755. if (!trans->ops->d3_resume)
  756. return 0;
  757. return trans->ops->d3_resume(trans, status, test, reset);
  758. }
  759. static inline int iwl_trans_suspend(struct iwl_trans *trans)
  760. {
  761. if (!trans->ops->suspend)
  762. return 0;
  763. return trans->ops->suspend(trans);
  764. }
  765. static inline void iwl_trans_resume(struct iwl_trans *trans)
  766. {
  767. if (trans->ops->resume)
  768. trans->ops->resume(trans);
  769. }
  770. static inline struct iwl_trans_dump_data *
  771. iwl_trans_dump_data(struct iwl_trans *trans,
  772. const struct iwl_fw_dbg_trigger_tlv *trigger)
  773. {
  774. if (!trans->ops->dump_data)
  775. return NULL;
  776. return trans->ops->dump_data(trans, trigger);
  777. }
  778. static inline void iwl_trans_dump_regs(struct iwl_trans *trans)
  779. {
  780. if (trans->ops->dump_regs)
  781. trans->ops->dump_regs(trans);
  782. }
  783. static inline struct iwl_device_cmd *
  784. iwl_trans_alloc_tx_cmd(struct iwl_trans *trans)
  785. {
  786. return kmem_cache_alloc(trans->dev_cmd_pool, GFP_ATOMIC);
  787. }
  788. int iwl_trans_send_cmd(struct iwl_trans *trans, struct iwl_host_cmd *cmd);
  789. static inline void iwl_trans_free_tx_cmd(struct iwl_trans *trans,
  790. struct iwl_device_cmd *dev_cmd)
  791. {
  792. kmem_cache_free(trans->dev_cmd_pool, dev_cmd);
  793. }
  794. static inline int iwl_trans_tx(struct iwl_trans *trans, struct sk_buff *skb,
  795. struct iwl_device_cmd *dev_cmd, int queue)
  796. {
  797. if (unlikely(test_bit(STATUS_FW_ERROR, &trans->status)))
  798. return -EIO;
  799. if (WARN_ON_ONCE(trans->state != IWL_TRANS_FW_ALIVE)) {
  800. IWL_ERR(trans, "%s bad state = %d\n", __func__, trans->state);
  801. return -EIO;
  802. }
  803. return trans->ops->tx(trans, skb, dev_cmd, queue);
  804. }
  805. static inline void iwl_trans_reclaim(struct iwl_trans *trans, int queue,
  806. int ssn, struct sk_buff_head *skbs)
  807. {
  808. if (WARN_ON_ONCE(trans->state != IWL_TRANS_FW_ALIVE)) {
  809. IWL_ERR(trans, "%s bad state = %d\n", __func__, trans->state);
  810. return;
  811. }
  812. trans->ops->reclaim(trans, queue, ssn, skbs);
  813. }
  814. static inline void iwl_trans_txq_disable(struct iwl_trans *trans, int queue,
  815. bool configure_scd)
  816. {
  817. trans->ops->txq_disable(trans, queue, configure_scd);
  818. }
  819. static inline bool
  820. iwl_trans_txq_enable_cfg(struct iwl_trans *trans, int queue, u16 ssn,
  821. const struct iwl_trans_txq_scd_cfg *cfg,
  822. unsigned int queue_wdg_timeout)
  823. {
  824. might_sleep();
  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 false;
  828. }
  829. return trans->ops->txq_enable(trans, queue, ssn,
  830. cfg, queue_wdg_timeout);
  831. }
  832. static inline void
  833. iwl_trans_txq_free(struct iwl_trans *trans, int queue)
  834. {
  835. if (WARN_ON_ONCE(!trans->ops->txq_free))
  836. return;
  837. trans->ops->txq_free(trans, queue);
  838. }
  839. static inline int
  840. iwl_trans_txq_alloc(struct iwl_trans *trans,
  841. struct iwl_tx_queue_cfg_cmd *cmd,
  842. int cmd_id,
  843. unsigned int queue_wdg_timeout)
  844. {
  845. might_sleep();
  846. if (WARN_ON_ONCE(!trans->ops->txq_alloc))
  847. return -ENOTSUPP;
  848. if (WARN_ON_ONCE(trans->state != IWL_TRANS_FW_ALIVE)) {
  849. IWL_ERR(trans, "%s bad state = %d\n", __func__, trans->state);
  850. return -EIO;
  851. }
  852. return trans->ops->txq_alloc(trans, cmd, cmd_id, queue_wdg_timeout);
  853. }
  854. static inline void iwl_trans_txq_set_shared_mode(struct iwl_trans *trans,
  855. int queue, bool shared_mode)
  856. {
  857. if (trans->ops->txq_set_shared_mode)
  858. trans->ops->txq_set_shared_mode(trans, queue, shared_mode);
  859. }
  860. static inline void iwl_trans_txq_enable(struct iwl_trans *trans, int queue,
  861. int fifo, int sta_id, int tid,
  862. int frame_limit, u16 ssn,
  863. unsigned int queue_wdg_timeout)
  864. {
  865. struct iwl_trans_txq_scd_cfg cfg = {
  866. .fifo = fifo,
  867. .sta_id = sta_id,
  868. .tid = tid,
  869. .frame_limit = frame_limit,
  870. .aggregate = sta_id >= 0,
  871. };
  872. iwl_trans_txq_enable_cfg(trans, queue, ssn, &cfg, queue_wdg_timeout);
  873. }
  874. static inline
  875. void iwl_trans_ac_txq_enable(struct iwl_trans *trans, int queue, int fifo,
  876. unsigned int queue_wdg_timeout)
  877. {
  878. struct iwl_trans_txq_scd_cfg cfg = {
  879. .fifo = fifo,
  880. .sta_id = -1,
  881. .tid = IWL_MAX_TID_COUNT,
  882. .frame_limit = IWL_FRAME_LIMIT,
  883. .aggregate = false,
  884. };
  885. iwl_trans_txq_enable_cfg(trans, queue, 0, &cfg, queue_wdg_timeout);
  886. }
  887. static inline void iwl_trans_freeze_txq_timer(struct iwl_trans *trans,
  888. unsigned long txqs,
  889. bool freeze)
  890. {
  891. if (WARN_ON_ONCE(trans->state != IWL_TRANS_FW_ALIVE)) {
  892. IWL_ERR(trans, "%s bad state = %d\n", __func__, trans->state);
  893. return;
  894. }
  895. if (trans->ops->freeze_txq_timer)
  896. trans->ops->freeze_txq_timer(trans, txqs, freeze);
  897. }
  898. static inline void iwl_trans_block_txq_ptrs(struct iwl_trans *trans,
  899. bool block)
  900. {
  901. if (WARN_ON_ONCE(trans->state != IWL_TRANS_FW_ALIVE)) {
  902. IWL_ERR(trans, "%s bad state = %d\n", __func__, trans->state);
  903. return;
  904. }
  905. if (trans->ops->block_txq_ptrs)
  906. trans->ops->block_txq_ptrs(trans, block);
  907. }
  908. static inline int iwl_trans_wait_tx_queues_empty(struct iwl_trans *trans,
  909. u32 txqs)
  910. {
  911. if (WARN_ON_ONCE(!trans->ops->wait_tx_queues_empty))
  912. return -ENOTSUPP;
  913. if (WARN_ON_ONCE(trans->state != IWL_TRANS_FW_ALIVE)) {
  914. IWL_ERR(trans, "%s bad state = %d\n", __func__, trans->state);
  915. return -EIO;
  916. }
  917. return trans->ops->wait_tx_queues_empty(trans, txqs);
  918. }
  919. static inline int iwl_trans_wait_txq_empty(struct iwl_trans *trans, int queue)
  920. {
  921. if (WARN_ON_ONCE(!trans->ops->wait_txq_empty))
  922. return -ENOTSUPP;
  923. if (WARN_ON_ONCE(trans->state != IWL_TRANS_FW_ALIVE)) {
  924. IWL_ERR(trans, "%s bad state = %d\n", __func__, trans->state);
  925. return -EIO;
  926. }
  927. return trans->ops->wait_txq_empty(trans, queue);
  928. }
  929. static inline void iwl_trans_write8(struct iwl_trans *trans, u32 ofs, u8 val)
  930. {
  931. trans->ops->write8(trans, ofs, val);
  932. }
  933. static inline void iwl_trans_write32(struct iwl_trans *trans, u32 ofs, u32 val)
  934. {
  935. trans->ops->write32(trans, ofs, val);
  936. }
  937. static inline u32 iwl_trans_read32(struct iwl_trans *trans, u32 ofs)
  938. {
  939. return trans->ops->read32(trans, ofs);
  940. }
  941. static inline u32 iwl_trans_read_prph(struct iwl_trans *trans, u32 ofs)
  942. {
  943. return trans->ops->read_prph(trans, ofs);
  944. }
  945. static inline void iwl_trans_write_prph(struct iwl_trans *trans, u32 ofs,
  946. u32 val)
  947. {
  948. return trans->ops->write_prph(trans, ofs, val);
  949. }
  950. static inline int iwl_trans_read_mem(struct iwl_trans *trans, u32 addr,
  951. void *buf, int dwords)
  952. {
  953. return trans->ops->read_mem(trans, addr, buf, dwords);
  954. }
  955. #define iwl_trans_read_mem_bytes(trans, addr, buf, bufsize) \
  956. do { \
  957. if (__builtin_constant_p(bufsize)) \
  958. BUILD_BUG_ON((bufsize) % sizeof(u32)); \
  959. iwl_trans_read_mem(trans, addr, buf, (bufsize) / sizeof(u32));\
  960. } while (0)
  961. static inline u32 iwl_trans_read_mem32(struct iwl_trans *trans, u32 addr)
  962. {
  963. u32 value;
  964. if (WARN_ON(iwl_trans_read_mem(trans, addr, &value, 1)))
  965. return 0xa5a5a5a5;
  966. return value;
  967. }
  968. static inline int iwl_trans_write_mem(struct iwl_trans *trans, u32 addr,
  969. const void *buf, int dwords)
  970. {
  971. return trans->ops->write_mem(trans, addr, buf, dwords);
  972. }
  973. static inline u32 iwl_trans_write_mem32(struct iwl_trans *trans, u32 addr,
  974. u32 val)
  975. {
  976. return iwl_trans_write_mem(trans, addr, &val, 1);
  977. }
  978. static inline void iwl_trans_set_pmi(struct iwl_trans *trans, bool state)
  979. {
  980. if (trans->ops->set_pmi)
  981. trans->ops->set_pmi(trans, state);
  982. }
  983. static inline void
  984. iwl_trans_set_bits_mask(struct iwl_trans *trans, u32 reg, u32 mask, u32 value)
  985. {
  986. trans->ops->set_bits_mask(trans, reg, mask, value);
  987. }
  988. #define iwl_trans_grab_nic_access(trans, flags) \
  989. __cond_lock(nic_access, \
  990. likely((trans)->ops->grab_nic_access(trans, flags)))
  991. static inline void __releases(nic_access)
  992. iwl_trans_release_nic_access(struct iwl_trans *trans, unsigned long *flags)
  993. {
  994. trans->ops->release_nic_access(trans, flags);
  995. __release(nic_access);
  996. }
  997. static inline void iwl_trans_fw_error(struct iwl_trans *trans)
  998. {
  999. if (WARN_ON_ONCE(!trans->op_mode))
  1000. return;
  1001. /* prevent double restarts due to the same erroneous FW */
  1002. if (!test_and_set_bit(STATUS_FW_ERROR, &trans->status))
  1003. iwl_op_mode_nic_error(trans->op_mode);
  1004. }
  1005. /*****************************************************
  1006. * transport helper functions
  1007. *****************************************************/
  1008. struct iwl_trans *iwl_trans_alloc(unsigned int priv_size,
  1009. struct device *dev,
  1010. const struct iwl_cfg *cfg,
  1011. const struct iwl_trans_ops *ops);
  1012. void iwl_trans_free(struct iwl_trans *trans);
  1013. void iwl_trans_ref(struct iwl_trans *trans);
  1014. void iwl_trans_unref(struct iwl_trans *trans);
  1015. /*****************************************************
  1016. * driver (transport) register/unregister functions
  1017. ******************************************************/
  1018. int __must_check iwl_pci_register_driver(void);
  1019. void iwl_pci_unregister_driver(void);
  1020. #endif /* __iwl_trans_h__ */