[image] Allow for zero embedded images
[people/asdlkf/gpxe.git] / src / drivers / net / mlx_ipoib / cmdif_mt25218.c
1 /*
2   This software is available to you under a choice of one of two
3   licenses.  You may choose to be licensed under the terms of the GNU
4   General Public License (GPL) Version 2, available at
5   <http://www.fsf.org/copyleft/gpl.html>, or the OpenIB.org BSD
6   license, available in the LICENSE.TXT file accompanying this
7   software.  These details are also available at
8   <http://openib.org/license.html>.
9
10   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
11   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
12   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
13   NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
14   BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
15   ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
16   CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   SOFTWARE.
18
19   Copyright (c) 2004 Mellanox Technologies Ltd.  All rights reserved.
20 */
21 #include "cmdif.h"
22 #include "cmdif_priv.h"
23 #include "mt25218.h"
24
25 /*
26  *  cmd_sys_dis
27  */
28 static int cmd_sys_dis(void)
29 {
30         return 0;
31 }
32
33 /*
34  *  cmd_write_mgm
35  */
36 static int cmd_write_mgm(void *mg, __u16 index)
37 {
38         int rc;
39         command_fields_t cmd_desc;
40
41         memset(&cmd_desc, 0, sizeof cmd_desc);
42         cmd_desc.opcode = MEMFREE_CMD_WRITE_MGM;
43         cmd_desc.in_trans = TRANS_MAILBOX;
44         cmd_desc.in_param_size = MT_STRUCT_SIZE(arbelprm_mgm_entry_st);
45         cmd_desc.in_param = (__u32 *) mg;
46         cmd_desc.input_modifier = index;
47
48         rc = cmd_invoke(&cmd_desc);
49
50         return rc;
51 }
52
53 /*
54  *  cmd_mod_stat_cfg
55  */
56 static int cmd_mod_stat_cfg(void)
57 {
58         int rc;
59         command_fields_t cmd_desc;
60
61         memset(&cmd_desc, 0, sizeof cmd_desc);
62         cmd_desc.opcode = MEMFREE_CMD_MOD_STAT_CFG;
63         cmd_desc.in_trans = TRANS_MAILBOX;
64         cmd_desc.in_param_size = MT_STRUCT_SIZE(arbelprm_mod_stat_cfg_st);
65         cmd_desc.in_param = get_inprm_buf();
66         memset(cmd_desc.in_param, 0, cmd_desc.in_param_size);
67
68         rc = cmd_invoke(&cmd_desc);
69
70         return rc;
71 }
72
73 /*
74  *  cmd_query_fw
75  */
76 static int cmd_query_fw(struct query_fw_st *qfw)
77 {
78         int rc;
79         command_fields_t cmd_desc;
80
81         memset(&cmd_desc, 0, sizeof cmd_desc);
82
83         cmd_desc.opcode = MEMFREE_CMD_QUERY_FW;
84         cmd_desc.out_trans = TRANS_MAILBOX;
85         cmd_desc.out_param = get_outprm_buf();
86         cmd_desc.out_param_size = MT_STRUCT_SIZE(arbelprm_query_fw_st);
87
88         rc = cmd_invoke(&cmd_desc);
89         if (!rc) {
90                 qfw->fw_rev_major =
91                     EX_FLD(cmd_desc.out_param, arbelprm_query_fw_st, fw_rev_major);
92                 qfw->fw_rev_minor =
93                     EX_FLD(cmd_desc.out_param, arbelprm_query_fw_st, fw_rev_minor);
94                 qfw->fw_rev_subminor =
95                     EX_FLD(cmd_desc.out_param, arbelprm_query_fw_st, fw_rev_subminor);
96
97                 qfw->error_buf_start_h =
98                     EX_FLD(cmd_desc.out_param, arbelprm_query_fw_st, error_buf_start_h);
99                 qfw->error_buf_start_l =
100                     EX_FLD(cmd_desc.out_param, arbelprm_query_fw_st, error_buf_start_l);
101                 qfw->error_buf_size =
102                     EX_FLD(cmd_desc.out_param, arbelprm_query_fw_st, error_buf_size);
103
104                 qfw->fw_pages =
105                     EX_FLD(cmd_desc.out_param, arbelprm_query_fw_st, fw_pages);
106                 qfw->eq_ci_table.addr_h =
107                     EX_FLD(cmd_desc.out_param, arbelprm_query_fw_st,
108                            eq_set_ci_base_addr_h);
109                 qfw->eq_ci_table.addr_l =
110                     EX_FLD(cmd_desc.out_param, arbelprm_query_fw_st,
111                            eq_set_ci_base_addr_l);
112                 qfw->clear_int_addr.addr_h =
113                     EX_FLD(cmd_desc.out_param, arbelprm_query_fw_st,
114                            clr_int_base_addr_h);
115                 qfw->clear_int_addr.addr_l =
116                     EX_FLD(cmd_desc.out_param, arbelprm_query_fw_st,
117                            clr_int_base_addr_l);
118         }
119
120         return rc;
121 }
122
123 /*
124  *  cmd_query_adapter
125  */
126 static int cmd_query_adapter(struct query_adapter_st *qa)
127 {
128         int rc;
129         command_fields_t cmd_desc;
130
131         memset(&cmd_desc, 0, sizeof cmd_desc);
132
133         cmd_desc.opcode = MEMFREE_CMD_QUERY_ADAPTER;
134         cmd_desc.out_trans = TRANS_MAILBOX;
135         cmd_desc.out_param = get_outprm_buf();
136         cmd_desc.out_param_size = MT_STRUCT_SIZE(arbelprm_query_adapter_st);
137
138         rc = cmd_invoke(&cmd_desc);
139         if (!rc) {
140                 qa->intapin =
141                     EX_FLD(cmd_desc.out_param, arbelprm_query_adapter_st,
142                            intapin);
143         }
144
145         return rc;
146 }
147
148 /*
149  *  cmd_enable_lam
150  */
151 static int cmd_enable_lam(void)
152 {
153         int rc;
154         command_fields_t cmd_desc;
155
156         memset(&cmd_desc, 0, sizeof cmd_desc);
157
158         cmd_desc.opcode = MEMFREE_CMD_ENABLE_LAM;
159         cmd_desc.opcode_modifier = 1;   /* zero locally attached memory */
160         cmd_desc.input_modifier = 0;    /* disable fast refresh */
161         cmd_desc.out_trans = TRANS_MAILBOX;
162         cmd_desc.out_param = get_outprm_buf();
163         cmd_desc.out_param_size = MT_STRUCT_SIZE(arbelprm_enable_lam_st);
164
165         rc = cmd_invoke(&cmd_desc);
166         if (rc) {
167         }
168
169         return rc;
170 }
171
172 /*
173  *  cmd_map_fa
174  */
175 static int cmd_map_fa(struct map_icm_st *map_fa_p)
176 {
177         int rc;
178         command_fields_t cmd_desc;
179         unsigned int in_param_size, i;
180         unsigned long off;
181
182         if (map_fa_p->num_vpm > MAX_VPM_PER_CALL) {
183                 return -1;
184         }
185
186         memset(&cmd_desc, 0, sizeof cmd_desc);
187
188         cmd_desc.opcode = MEMFREE_CMD_MAP_FA;
189         cmd_desc.input_modifier = map_fa_p->num_vpm;
190         cmd_desc.in_trans = TRANS_MAILBOX;
191         cmd_desc.in_param = get_inprm_buf();
192         in_param_size =
193             MT_STRUCT_SIZE(arbelprm_virtual_physical_mapping_st) *
194             map_fa_p->num_vpm;
195         cmd_desc.in_param_size = in_param_size;
196         memset(cmd_desc.in_param, 0, in_param_size);
197
198         for (i = 0; i < map_fa_p->num_vpm; ++i) {
199                 off = (unsigned long)(cmd_desc.in_param) +
200                     MT_STRUCT_SIZE(arbelprm_virtual_physical_mapping_st) * i;
201                 INS_FLD(map_fa_p->vpm_arr[i].va_h, off,
202                         arbelprm_virtual_physical_mapping_st, va_h);
203                 INS_FLD(map_fa_p->vpm_arr[i].va_l >> 12, off,
204                         arbelprm_virtual_physical_mapping_st, va_l);
205                 INS_FLD(map_fa_p->vpm_arr[i].pa_h, off,
206                         arbelprm_virtual_physical_mapping_st, pa_h);
207                 INS_FLD(map_fa_p->vpm_arr[i].pa_l >> 12, off,
208                         arbelprm_virtual_physical_mapping_st, pa_l);
209                 INS_FLD(map_fa_p->vpm_arr[i].log2_size, off,
210                         arbelprm_virtual_physical_mapping_st, log2size);
211         }
212
213         rc = cmd_invoke(&cmd_desc);
214
215         return rc;
216 }
217
218 /*
219  *  cmd_unmap_fa
220  */
221 static int cmd_unmap_fa(void)
222 {
223         int rc;
224         command_fields_t cmd_desc;
225
226         memset(&cmd_desc, 0, sizeof cmd_desc);
227
228         cmd_desc.opcode = MEMFREE_CMD_UNMAP_FA;
229
230         rc = cmd_invoke(&cmd_desc);
231
232         return rc;
233 }
234
235 /*
236  *  cmd_run_fw
237  */
238 static int cmd_run_fw(void)
239 {
240         int rc;
241         command_fields_t cmd_desc;
242
243         memset(&cmd_desc, 0, sizeof cmd_desc);
244
245         cmd_desc.opcode = MEMFREE_CMD_RUN_FW;
246         rc = cmd_invoke(&cmd_desc);
247
248         return rc;
249 }
250
251 /*
252  *  cmd_set_icm_size
253  */
254 static int cmd_set_icm_size(__u32 icm_size, __u32 * aux_pages_p)
255 {
256         int rc;
257         command_fields_t cmd_desc;
258         __u32 iprm[2], oprm[2];
259
260         memset(&cmd_desc, 0, sizeof cmd_desc);
261
262         cmd_desc.opcode = MEMFREE_CMD_SET_ICM_SIZE;
263
264         iprm[1] = icm_size;
265         iprm[0] = 0;
266         cmd_desc.in_trans = TRANS_IMMEDIATE;
267         cmd_desc.in_param = iprm;
268         cmd_desc.out_trans = TRANS_IMMEDIATE;
269         cmd_desc.out_param = oprm;
270         rc = cmd_invoke(&cmd_desc);
271         if (!rc) {
272                 if (oprm[0]) {
273                         /* too many pages required */
274                         return -1;
275                 }
276                 *aux_pages_p = oprm[1];
277         }
278
279         return rc;
280 }
281
282 /*
283  *  cmd_map_icm_aux
284  */
285 static int cmd_map_icm_aux(struct map_icm_st *map_icm_aux_p)
286 {
287         int rc;
288         command_fields_t cmd_desc;
289         unsigned int in_param_size, i;
290         unsigned long off;
291
292         if (map_icm_aux_p->num_vpm > MAX_VPM_PER_CALL) {
293                 return -1;
294         }
295
296         memset(&cmd_desc, 0, sizeof cmd_desc);
297
298         cmd_desc.opcode = MEMFREE_CMD_MAP_ICM_AUX;
299         cmd_desc.input_modifier = map_icm_aux_p->num_vpm;
300         cmd_desc.in_trans = TRANS_MAILBOX;
301         cmd_desc.in_param = get_inprm_buf();
302         in_param_size =
303             MT_STRUCT_SIZE(arbelprm_virtual_physical_mapping_st) *
304             map_icm_aux_p->num_vpm;
305         cmd_desc.in_param_size = in_param_size;
306         memset(cmd_desc.in_param, 0, in_param_size);
307
308         for (i = 0; i < map_icm_aux_p->num_vpm; ++i) {
309                 off = (unsigned long)(cmd_desc.in_param) +
310                     MT_STRUCT_SIZE(arbelprm_virtual_physical_mapping_st) * i;
311                 INS_FLD(map_icm_aux_p->vpm_arr[i].va_h, off,
312                         arbelprm_virtual_physical_mapping_st, va_h);
313                 INS_FLD(map_icm_aux_p->vpm_arr[i].va_l >> 12, off,
314                         arbelprm_virtual_physical_mapping_st, va_l);
315                 INS_FLD(map_icm_aux_p->vpm_arr[i].pa_h, off,
316                         arbelprm_virtual_physical_mapping_st, pa_h);
317                 INS_FLD(map_icm_aux_p->vpm_arr[i].pa_l >> 12, off,
318                         arbelprm_virtual_physical_mapping_st, pa_l);
319                 INS_FLD(map_icm_aux_p->vpm_arr[i].log2_size, off,
320                         arbelprm_virtual_physical_mapping_st, log2size);
321         }
322
323         rc = cmd_invoke(&cmd_desc);
324
325         return rc;
326 }
327
328 /*
329  *  cmd_map_icm
330  */
331 static int cmd_map_icm(struct map_icm_st *map_icm_p)
332 {
333         int rc;
334         command_fields_t cmd_desc;
335         unsigned int in_param_size, i;
336         unsigned long off;
337
338         if (map_icm_p->num_vpm > MAX_VPM_PER_CALL) {
339                 return -1;
340         }
341
342         memset(&cmd_desc, 0, sizeof cmd_desc);
343
344         cmd_desc.opcode = MEMFREE_CMD_MAP_ICM;
345         cmd_desc.input_modifier = map_icm_p->num_vpm;
346         cmd_desc.in_trans = TRANS_MAILBOX;
347         cmd_desc.in_param = get_inprm_buf();
348         in_param_size =
349             MT_STRUCT_SIZE(arbelprm_virtual_physical_mapping_st) *
350             map_icm_p->num_vpm;
351         cmd_desc.in_param_size = in_param_size;
352         memset(cmd_desc.in_param, 0, in_param_size);
353
354         for (i = 0; i < map_icm_p->num_vpm; ++i) {
355                 off = (unsigned long)(cmd_desc.in_param) +
356                     MT_STRUCT_SIZE(arbelprm_virtual_physical_mapping_st) * i;
357                 INS_FLD(map_icm_p->vpm_arr[i].va_h, off,
358                         arbelprm_virtual_physical_mapping_st, va_h);
359                 INS_FLD(map_icm_p->vpm_arr[i].va_l >> 12, off,
360                         arbelprm_virtual_physical_mapping_st, va_l);
361                 INS_FLD(map_icm_p->vpm_arr[i].pa_h, off,
362                         arbelprm_virtual_physical_mapping_st, pa_h);
363                 INS_FLD(map_icm_p->vpm_arr[i].pa_l >> 12, off,
364                         arbelprm_virtual_physical_mapping_st, pa_l);
365                 INS_FLD(map_icm_p->vpm_arr[i].log2_size, off,
366                         arbelprm_virtual_physical_mapping_st, log2size);
367         }
368
369         rc = cmd_invoke(&cmd_desc);
370
371         return rc;
372 }
373
374 /*
375  *  cmd_query_dev_lim
376  */
377 static int cmd_query_dev_lim(struct dev_lim_st *dev_lim_p)
378 {
379         int rc;
380         command_fields_t cmd_desc;
381
382         memset(&cmd_desc, 0, sizeof cmd_desc);
383
384         cmd_desc.opcode = MEMFREE_CMD_QUERY_DEV_LIM;
385         cmd_desc.out_trans = TRANS_MAILBOX;
386         cmd_desc.out_param = get_outprm_buf();
387         cmd_desc.out_param_size = MT_STRUCT_SIZE(arbelprm_query_dev_lim_st);
388
389         rc = cmd_invoke(&cmd_desc);
390         if (!rc) {
391                 dev_lim_p->log2_rsvd_qps =
392                     EX_FLD(cmd_desc.out_param, arbelprm_query_dev_lim_st,
393                            log2_rsvd_qps);
394                 dev_lim_p->qpc_entry_sz =
395                     EX_FLD(cmd_desc.out_param, arbelprm_query_dev_lim_st,
396                            qpc_entry_sz);
397
398                 dev_lim_p->log2_rsvd_srqs =
399                     EX_FLD(cmd_desc.out_param, arbelprm_query_dev_lim_st,
400                            log2_rsvd_srqs);
401                 dev_lim_p->srq_entry_sz =
402                     EX_FLD(cmd_desc.out_param, arbelprm_query_dev_lim_st,
403                            srq_entry_sz);
404
405                 dev_lim_p->log2_rsvd_ees =
406                     EX_FLD(cmd_desc.out_param, arbelprm_query_dev_lim_st,
407                            log2_rsvd_ees);
408                 dev_lim_p->eec_entry_sz =
409                     EX_FLD(cmd_desc.out_param, arbelprm_query_dev_lim_st,
410                            eec_entry_sz);
411
412                 dev_lim_p->log2_rsvd_cqs =
413                     EX_FLD(cmd_desc.out_param, arbelprm_query_dev_lim_st,
414                            log2_rsvd_cqs);
415                 dev_lim_p->cqc_entry_sz =
416                     EX_FLD(cmd_desc.out_param, arbelprm_query_dev_lim_st,
417                            cqc_entry_sz);
418
419                 dev_lim_p->log2_rsvd_mtts =
420                     EX_FLD(cmd_desc.out_param, arbelprm_query_dev_lim_st,
421                            log2_rsvd_mtts);
422                 dev_lim_p->mtt_entry_sz =
423                     EX_FLD(cmd_desc.out_param, arbelprm_query_dev_lim_st,
424                            mtt_entry_sz);
425
426                 dev_lim_p->log2_rsvd_mrws =
427                     EX_FLD(cmd_desc.out_param, arbelprm_query_dev_lim_st,
428                            log2_rsvd_mrws);
429                 dev_lim_p->mpt_entry_sz =
430                     EX_FLD(cmd_desc.out_param, arbelprm_query_dev_lim_st,
431                            mpt_entry_sz);
432
433                 dev_lim_p->log2_rsvd_rdbs =
434                     EX_FLD(cmd_desc.out_param, arbelprm_query_dev_lim_st,
435                            log2_rsvd_rdbs);
436
437                 dev_lim_p->eqc_entry_sz =
438                     EX_FLD(cmd_desc.out_param, arbelprm_query_dev_lim_st,
439                            eqc_entry_sz);
440
441                 dev_lim_p->max_icm_size_l =
442                     EX_FLD(cmd_desc.out_param, arbelprm_query_dev_lim_st,
443                            max_icm_size_l);
444                 dev_lim_p->max_icm_size_h =
445                     EX_FLD(cmd_desc.out_param, arbelprm_query_dev_lim_st,
446                            max_icm_size_h);
447
448                 dev_lim_p->num_rsvd_uars =
449                     EX_FLD(cmd_desc.out_param, arbelprm_query_dev_lim_st,
450                            num_rsvd_uars);
451                 dev_lim_p->uar_sz =
452                     EX_FLD(cmd_desc.out_param, arbelprm_query_dev_lim_st,
453                            uar_sz);
454         }
455
456         return rc;
457 }