This source file includes following definitions.
- iwl_trans_alloc
- iwl_trans_free
- iwl_trans_send_cmd
- iwl_hcmd_names_cmp
- iwl_get_cmd_string
- iwl_cmd_groups_verify_sorted
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60 #include <linux/kernel.h>
61 #include <linux/bsearch.h>
62
63 #include "iwl-trans.h"
64 #include "iwl-drv.h"
65 #include "iwl-fh.h"
66
67 struct iwl_trans *iwl_trans_alloc(unsigned int priv_size,
68 struct device *dev,
69 const struct iwl_trans_ops *ops,
70 unsigned int cmd_pool_size,
71 unsigned int cmd_pool_align)
72 {
73 struct iwl_trans *trans;
74 #ifdef CONFIG_LOCKDEP
75 static struct lock_class_key __key;
76 #endif
77
78 trans = devm_kzalloc(dev, sizeof(*trans) + priv_size, GFP_KERNEL);
79 if (!trans)
80 return NULL;
81
82 #ifdef CONFIG_LOCKDEP
83 lockdep_init_map(&trans->sync_cmd_lockdep_map, "sync_cmd_lockdep_map",
84 &__key, 0);
85 #endif
86
87 trans->dev = dev;
88 trans->ops = ops;
89 trans->num_rx_queues = 1;
90
91 snprintf(trans->dev_cmd_pool_name, sizeof(trans->dev_cmd_pool_name),
92 "iwl_cmd_pool:%s", dev_name(trans->dev));
93 trans->dev_cmd_pool =
94 kmem_cache_create(trans->dev_cmd_pool_name,
95 cmd_pool_size, cmd_pool_align,
96 SLAB_HWCACHE_ALIGN, NULL);
97 if (!trans->dev_cmd_pool)
98 return NULL;
99
100 WARN_ON(!ops->wait_txq_empty && !ops->wait_tx_queues_empty);
101
102 return trans;
103 }
104
105 void iwl_trans_free(struct iwl_trans *trans)
106 {
107 kmem_cache_destroy(trans->dev_cmd_pool);
108 }
109
110 int iwl_trans_send_cmd(struct iwl_trans *trans, struct iwl_host_cmd *cmd)
111 {
112 int ret;
113
114 if (unlikely(!(cmd->flags & CMD_SEND_IN_RFKILL) &&
115 test_bit(STATUS_RFKILL_OPMODE, &trans->status)))
116 return -ERFKILL;
117
118 if (unlikely(test_bit(STATUS_FW_ERROR, &trans->status)))
119 return -EIO;
120
121 if (unlikely(trans->state != IWL_TRANS_FW_ALIVE)) {
122 IWL_ERR(trans, "%s bad state = %d\n", __func__, trans->state);
123 return -EIO;
124 }
125
126 if (WARN_ON((cmd->flags & CMD_WANT_ASYNC_CALLBACK) &&
127 !(cmd->flags & CMD_ASYNC)))
128 return -EINVAL;
129
130 if (!(cmd->flags & CMD_ASYNC))
131 lock_map_acquire_read(&trans->sync_cmd_lockdep_map);
132
133 if (trans->wide_cmd_header && !iwl_cmd_groupid(cmd->id))
134 cmd->id = DEF_ID(cmd->id);
135
136 ret = trans->ops->send_cmd(trans, cmd);
137
138 if (!(cmd->flags & CMD_ASYNC))
139 lock_map_release(&trans->sync_cmd_lockdep_map);
140
141 if (WARN_ON((cmd->flags & CMD_WANT_SKB) && !ret && !cmd->resp_pkt))
142 return -EIO;
143
144 return ret;
145 }
146 IWL_EXPORT_SYMBOL(iwl_trans_send_cmd);
147
148
149
150
151
152
153
154
155
156 static int iwl_hcmd_names_cmp(const void *key, const void *elt)
157 {
158 const struct iwl_hcmd_names *name = elt;
159 u8 cmd1 = *(u8 *)key;
160 u8 cmd2 = name->cmd_id;
161
162 return (cmd1 - cmd2);
163 }
164
165 const char *iwl_get_cmd_string(struct iwl_trans *trans, u32 id)
166 {
167 u8 grp, cmd;
168 struct iwl_hcmd_names *ret;
169 const struct iwl_hcmd_arr *arr;
170 size_t size = sizeof(struct iwl_hcmd_names);
171
172 grp = iwl_cmd_groupid(id);
173 cmd = iwl_cmd_opcode(id);
174
175 if (!trans->command_groups || grp >= trans->command_groups_size ||
176 !trans->command_groups[grp].arr)
177 return "UNKNOWN";
178
179 arr = &trans->command_groups[grp];
180 ret = bsearch(&cmd, arr->arr, arr->size, size, iwl_hcmd_names_cmp);
181 if (!ret)
182 return "UNKNOWN";
183 return ret->cmd_name;
184 }
185 IWL_EXPORT_SYMBOL(iwl_get_cmd_string);
186
187 int iwl_cmd_groups_verify_sorted(const struct iwl_trans_config *trans)
188 {
189 int i, j;
190 const struct iwl_hcmd_arr *arr;
191
192 for (i = 0; i < trans->command_groups_size; i++) {
193 arr = &trans->command_groups[i];
194 if (!arr->arr)
195 continue;
196 for (j = 0; j < arr->size - 1; j++)
197 if (arr->arr[j].cmd_id > arr->arr[j + 1].cmd_id)
198 return -1;
199 }
200 return 0;
201 }
202 IWL_EXPORT_SYMBOL(iwl_cmd_groups_verify_sorted);