iwl-trans.h 40 KB

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