This source file includes following definitions.
- snic_handle_link
- snic_ver_enc
- snic_queue_exch_ver_req
- snic_io_exch_ver_cmpl_handler
- snic_get_conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 #include <linux/errno.h>
19 #include <linux/pci.h>
20 #include <linux/slab.h>
21
22 #include <linux/interrupt.h>
23 #include <linux/workqueue.h>
24 #include <linux/spinlock.h>
25 #include <linux/mempool.h>
26 #include <scsi/scsi_tcq.h>
27 #include <linux/ctype.h>
28
29 #include "snic_io.h"
30 #include "snic.h"
31 #include "cq_enet_desc.h"
32 #include "snic_fwint.h"
33
34
35
36
37 void
38 snic_handle_link(struct work_struct *work)
39 {
40 struct snic *snic = container_of(work, struct snic, link_work);
41
42 if (snic->config.xpt_type == SNIC_DAS)
43 return;
44
45 snic->link_status = svnic_dev_link_status(snic->vdev);
46 snic->link_down_cnt = svnic_dev_link_down_cnt(snic->vdev);
47 SNIC_HOST_INFO(snic->shost, "Link Event: Link %s.\n",
48 ((snic->link_status) ? "Up" : "Down"));
49
50 SNIC_ASSERT_NOT_IMPL(1);
51 }
52
53
54
55
56
57
58 static int
59 snic_ver_enc(const char *s)
60 {
61 int v[4] = {0};
62 int i = 0, x = 0;
63 char c;
64 const char *p = s;
65
66
67 if ((strlen(s) > 15) || (strlen(s) < 7))
68 goto end;
69
70 while ((c = *p++)) {
71 if (c == '.') {
72 i++;
73 continue;
74 }
75
76 if (i > 3 || !isdigit(c))
77 goto end;
78
79 v[i] = v[i] * 10 + (c - '0');
80 }
81
82
83 for (i = 3; i >= 0; i--)
84 if (v[i] > 0xff)
85 goto end;
86
87 x |= (v[0] << 24) | v[1] << 16 | v[2] << 8 | v[3];
88
89 end:
90 if (x == 0) {
91 SNIC_ERR("Invalid version string [%s].\n", s);
92
93 return -1;
94 }
95
96 return x;
97 }
98
99
100
101
102
103
104
105 int
106 snic_queue_exch_ver_req(struct snic *snic)
107 {
108 struct snic_req_info *rqi = NULL;
109 struct snic_host_req *req = NULL;
110 u32 ver = 0;
111 int ret = 0;
112
113 SNIC_HOST_INFO(snic->shost, "Exch Ver Req Preparing...\n");
114
115 rqi = snic_req_init(snic, 0);
116 if (!rqi) {
117 SNIC_HOST_ERR(snic->shost,
118 "Queuing Exch Ver Req failed, err = %d\n",
119 ret);
120
121 ret = -ENOMEM;
122 goto error;
123 }
124
125 req = rqi_to_req(rqi);
126
127
128 snic_io_hdr_enc(&req->hdr, SNIC_REQ_EXCH_VER, 0, SCSI_NO_TAG,
129 snic->config.hid, 0, (ulong)rqi);
130 ver = snic_ver_enc(SNIC_DRV_VERSION);
131 req->u.exch_ver.drvr_ver = cpu_to_le32(ver);
132 req->u.exch_ver.os_type = cpu_to_le32(SNIC_OS_LINUX);
133
134 snic_handle_untagged_req(snic, rqi);
135
136 ret = snic_queue_wq_desc(snic, req, sizeof(*req));
137 if (ret) {
138 snic_release_untagged_req(snic, rqi);
139 SNIC_HOST_ERR(snic->shost,
140 "Queuing Exch Ver Req failed, err = %d\n",
141 ret);
142 goto error;
143 }
144
145 SNIC_HOST_INFO(snic->shost, "Exch Ver Req is issued. ret = %d\n", ret);
146
147 error:
148 return ret;
149 }
150
151
152
153
154 int
155 snic_io_exch_ver_cmpl_handler(struct snic *snic, struct snic_fw_req *fwreq)
156 {
157 struct snic_req_info *rqi = NULL;
158 struct snic_exch_ver_rsp *exv_cmpl = &fwreq->u.exch_ver_cmpl;
159 u8 typ, hdr_stat;
160 u32 cmnd_id, hid, max_sgs;
161 ulong ctx = 0;
162 unsigned long flags;
163 int ret = 0;
164
165 SNIC_HOST_INFO(snic->shost, "Exch Ver Compl Received.\n");
166 snic_io_hdr_dec(&fwreq->hdr, &typ, &hdr_stat, &cmnd_id, &hid, &ctx);
167 SNIC_BUG_ON(snic->config.hid != hid);
168 rqi = (struct snic_req_info *) ctx;
169
170 if (hdr_stat) {
171 SNIC_HOST_ERR(snic->shost,
172 "Exch Ver Completed w/ err status %d\n",
173 hdr_stat);
174
175 goto exch_cmpl_end;
176 }
177
178 spin_lock_irqsave(&snic->snic_lock, flags);
179 snic->fwinfo.fw_ver = le32_to_cpu(exv_cmpl->version);
180 snic->fwinfo.hid = le32_to_cpu(exv_cmpl->hid);
181 snic->fwinfo.max_concur_ios = le32_to_cpu(exv_cmpl->max_concur_ios);
182 snic->fwinfo.max_sgs_per_cmd = le32_to_cpu(exv_cmpl->max_sgs_per_cmd);
183 snic->fwinfo.max_io_sz = le32_to_cpu(exv_cmpl->max_io_sz);
184 snic->fwinfo.max_tgts = le32_to_cpu(exv_cmpl->max_tgts);
185 snic->fwinfo.io_tmo = le16_to_cpu(exv_cmpl->io_timeout);
186
187 SNIC_HOST_INFO(snic->shost,
188 "vers %u hid %u max_concur_ios %u max_sgs_per_cmd %u max_io_sz %u max_tgts %u fw tmo %u\n",
189 snic->fwinfo.fw_ver,
190 snic->fwinfo.hid,
191 snic->fwinfo.max_concur_ios,
192 snic->fwinfo.max_sgs_per_cmd,
193 snic->fwinfo.max_io_sz,
194 snic->fwinfo.max_tgts,
195 snic->fwinfo.io_tmo);
196
197 SNIC_HOST_INFO(snic->shost,
198 "HBA Capabilities = 0x%x\n",
199 le32_to_cpu(exv_cmpl->hba_cap));
200
201
202 max_sgs = snic->fwinfo.max_sgs_per_cmd;
203 if (max_sgs && max_sgs < SNIC_MAX_SG_DESC_CNT) {
204 snic->shost->sg_tablesize = max_sgs;
205 SNIC_HOST_INFO(snic->shost, "Max SGs set to %d\n",
206 snic->shost->sg_tablesize);
207 } else if (max_sgs > snic->shost->sg_tablesize) {
208 SNIC_HOST_INFO(snic->shost,
209 "Target type %d Supports Larger Max SGList %d than driver's Max SG List %d.\n",
210 snic->config.xpt_type, max_sgs,
211 snic->shost->sg_tablesize);
212 }
213
214 if (snic->shost->can_queue > snic->fwinfo.max_concur_ios)
215 snic->shost->can_queue = snic->fwinfo.max_concur_ios;
216
217 snic->shost->max_sectors = snic->fwinfo.max_io_sz >> 9;
218 if (snic->fwinfo.wait)
219 complete(snic->fwinfo.wait);
220
221 spin_unlock_irqrestore(&snic->snic_lock, flags);
222
223 exch_cmpl_end:
224 snic_release_untagged_req(snic, rqi);
225
226 SNIC_HOST_INFO(snic->shost, "Exch_cmpl Done, hdr_stat %d.\n", hdr_stat);
227
228 return ret;
229 }
230
231
232
233
234
235
236 int
237 snic_get_conf(struct snic *snic)
238 {
239 DECLARE_COMPLETION_ONSTACK(wait);
240 unsigned long flags;
241 int ret;
242 int nr_retries = 3;
243
244 SNIC_HOST_INFO(snic->shost, "Retrieving snic params.\n");
245 spin_lock_irqsave(&snic->snic_lock, flags);
246 memset(&snic->fwinfo, 0, sizeof(snic->fwinfo));
247 snic->fwinfo.wait = &wait;
248 spin_unlock_irqrestore(&snic->snic_lock, flags);
249
250
251 msleep(50);
252
253
254
255
256
257 do {
258 ret = snic_queue_exch_ver_req(snic);
259 if (ret)
260 return ret;
261
262 wait_for_completion_timeout(&wait, msecs_to_jiffies(2000));
263 spin_lock_irqsave(&snic->snic_lock, flags);
264 ret = (snic->fwinfo.fw_ver != 0) ? 0 : -ETIMEDOUT;
265 if (ret)
266 SNIC_HOST_ERR(snic->shost,
267 "Failed to retrieve snic params,\n");
268
269
270 if (ret == 0 || nr_retries == 1)
271 snic->fwinfo.wait = NULL;
272
273 spin_unlock_irqrestore(&snic->snic_lock, flags);
274 } while (ret && --nr_retries);
275
276 return ret;
277 }