This source file includes following definitions.
- octeon_alloc_soft_command_resp
- octnet_send_nic_data_pkt
- octnic_alloc_ctrl_pkt_sc
- octnet_send_nic_ctrl_pkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 #include <linux/pci.h>
20 #include <linux/netdevice.h>
21 #include "liquidio_common.h"
22 #include "octeon_droq.h"
23 #include "octeon_iq.h"
24 #include "response_manager.h"
25 #include "octeon_device.h"
26 #include "octeon_nic.h"
27 #include "octeon_main.h"
28
29 void *
30 octeon_alloc_soft_command_resp(struct octeon_device *oct,
31 union octeon_instr_64B *cmd,
32 u32 rdatasize)
33 {
34 struct octeon_soft_command *sc;
35 struct octeon_instr_ih3 *ih3;
36 struct octeon_instr_ih2 *ih2;
37 struct octeon_instr_irh *irh;
38 struct octeon_instr_rdp *rdp;
39
40 sc = (struct octeon_soft_command *)
41 octeon_alloc_soft_command(oct, 0, rdatasize, 0);
42
43 if (!sc)
44 return NULL;
45
46
47 memcpy(&sc->cmd, cmd, sizeof(union octeon_instr_64B));
48
49
50
51
52 if (OCTEON_CN23XX_PF(oct) || OCTEON_CN23XX_VF(oct)) {
53 ih3 = (struct octeon_instr_ih3 *)&sc->cmd.cmd3.ih3;
54 rdp = (struct octeon_instr_rdp *)&sc->cmd.cmd3.rdp;
55 irh = (struct octeon_instr_irh *)&sc->cmd.cmd3.irh;
56
57 ih3->fsz = LIO_SOFTCMDRESP_IH3;
58 } else {
59 ih2 = (struct octeon_instr_ih2 *)&sc->cmd.cmd2.ih2;
60 rdp = (struct octeon_instr_rdp *)&sc->cmd.cmd2.rdp;
61 irh = (struct octeon_instr_irh *)&sc->cmd.cmd2.irh;
62
63 ih2->fsz = LIO_SOFTCMDRESP_IH2;
64 }
65
66 irh->rflag = 1;
67
68 rdp->pcie_port = oct->pcie_port;
69 rdp->rlen = rdatasize;
70
71 *sc->status_word = COMPLETION_WORD_INIT;
72
73 if (OCTEON_CN23XX_PF(oct) || OCTEON_CN23XX_VF(oct))
74 sc->cmd.cmd3.rptr = sc->dmarptr;
75 else
76 sc->cmd.cmd2.rptr = sc->dmarptr;
77
78 sc->expiry_time = jiffies + msecs_to_jiffies(LIO_SC_MAX_TMO_MS);
79
80 return sc;
81 }
82
83 int octnet_send_nic_data_pkt(struct octeon_device *oct,
84 struct octnic_data_pkt *ndata,
85 int xmit_more)
86 {
87 int ring_doorbell = !xmit_more;
88
89 return octeon_send_command(oct, ndata->q_no, ring_doorbell, &ndata->cmd,
90 ndata->buf, ndata->datasize,
91 ndata->reqtype);
92 }
93
94 static inline struct octeon_soft_command
95 *octnic_alloc_ctrl_pkt_sc(struct octeon_device *oct,
96 struct octnic_ctrl_pkt *nctrl)
97 {
98 struct octeon_soft_command *sc = NULL;
99 u8 *data;
100 u32 rdatasize;
101 u32 uddsize = 0, datasize = 0;
102
103 uddsize = (u32)(nctrl->ncmd.s.more * 8);
104
105 datasize = OCTNET_CMD_SIZE + uddsize;
106 rdatasize = 16;
107
108 sc = (struct octeon_soft_command *)
109 octeon_alloc_soft_command(oct, datasize, rdatasize, 0);
110
111 if (!sc)
112 return NULL;
113
114 data = (u8 *)sc->virtdptr;
115
116 memcpy(data, &nctrl->ncmd, OCTNET_CMD_SIZE);
117
118 octeon_swap_8B_data((u64 *)data, (OCTNET_CMD_SIZE >> 3));
119
120 if (uddsize) {
121
122 memcpy(data + OCTNET_CMD_SIZE, nctrl->udd, uddsize);
123 }
124
125 sc->iq_no = (u32)nctrl->iq_no;
126
127 octeon_prepare_soft_command(oct, sc, OPCODE_NIC, OPCODE_NIC_CMD,
128 0, 0, 0);
129
130 init_completion(&sc->complete);
131 sc->sc_status = OCTEON_REQUEST_PENDING;
132
133 return sc;
134 }
135
136 int
137 octnet_send_nic_ctrl_pkt(struct octeon_device *oct,
138 struct octnic_ctrl_pkt *nctrl)
139 {
140 int retval;
141 struct octeon_soft_command *sc = NULL;
142
143 spin_lock_bh(&oct->cmd_resp_wqlock);
144
145
146
147 if ((oct->cmd_resp_state == OCT_DRV_OFFLINE) &&
148 (nctrl->ncmd.s.cmd != OCTNET_CMD_RX_CTL)) {
149 spin_unlock_bh(&oct->cmd_resp_wqlock);
150 dev_err(&oct->pci_dev->dev,
151 "%s cmd:%d not processed since driver offline\n",
152 __func__, nctrl->ncmd.s.cmd);
153 return -1;
154 }
155
156 sc = octnic_alloc_ctrl_pkt_sc(oct, nctrl);
157 if (!sc) {
158 dev_err(&oct->pci_dev->dev, "%s soft command alloc failed\n",
159 __func__);
160 spin_unlock_bh(&oct->cmd_resp_wqlock);
161 return -1;
162 }
163
164 retval = octeon_send_soft_command(oct, sc);
165 if (retval == IQ_SEND_FAILED) {
166 octeon_free_soft_command(oct, sc);
167 dev_err(&oct->pci_dev->dev, "%s pf_num:%d soft command:%d send failed status: %x\n",
168 __func__, oct->pf_num, nctrl->ncmd.s.cmd, retval);
169 spin_unlock_bh(&oct->cmd_resp_wqlock);
170 return -1;
171 }
172
173 spin_unlock_bh(&oct->cmd_resp_wqlock);
174
175 if (nctrl->ncmd.s.cmdgroup == 0) {
176 switch (nctrl->ncmd.s.cmd) {
177
178 case OCTNET_CMD_CHANGE_DEVFLAGS:
179 case OCTNET_CMD_SET_MULTI_LIST:
180 case OCTNET_CMD_SET_UC_LIST:
181 WRITE_ONCE(sc->caller_is_done, true);
182 return retval;
183 }
184 }
185
186 retval = wait_for_sc_completion_timeout(oct, sc, 0);
187 if (retval)
188 return (retval);
189
190 nctrl->sc_status = sc->sc_status;
191 retval = nctrl->sc_status;
192 if (nctrl->cb_fn)
193 nctrl->cb_fn(nctrl);
194
195 WRITE_ONCE(sc->caller_is_done, true);
196
197 return retval;
198 }