iwl-trans.h 40 KB

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