2 * Copyright 2014 Cisco Systems, Inc. All rights reserved.
4 * This program is free software; you may redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
8 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
9 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
10 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
11 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
12 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
13 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
14 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
18 #include <linux/errno.h>
19 #include <linux/pci.h>
20 #include <linux/slab.h>
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>
31 #include "cq_enet_desc.h"
32 #include "snic_fwint.h"
35 * snic_handle_link : Handles link flaps.
38 snic_handle_link(struct work_struct
*work
)
40 struct snic
*snic
= container_of(work
, struct snic
, link_work
);
42 if (snic
->config
.xpt_type
!= SNIC_DAS
) {
43 SNIC_HOST_INFO(snic
->shost
, "Link Event Received.\n");
44 SNIC_ASSERT_NOT_IMPL(1);
49 snic
->link_status
= svnic_dev_link_status(snic
->vdev
);
50 snic
->link_down_cnt
= svnic_dev_link_down_cnt(snic
->vdev
);
51 SNIC_HOST_INFO(snic
->shost
, "Link Event: Link %s.\n",
52 ((snic
->link_status
) ? "Up" : "Down"));
57 * snic_ver_enc : Encodes version str to int
58 * version string is similar to netmask string
61 snic_ver_enc(const char *s
)
68 /* validate version string */
69 if ((strlen(s
) > 15) || (strlen(s
) < 7))
78 if (i
> 4 || !isdigit(c
))
81 v
[i
] = v
[i
] * 10 + (c
- '0');
84 /* validate sub version numbers */
85 for (i
= 3; i
>= 0; i
--)
89 x
|= (v
[0] << 24) | v
[1] << 16 | v
[2] << 8 | v
[3];
93 SNIC_ERR("Invalid version string [%s].\n", s
);
99 } /* end of snic_ver_enc */
102 * snic_qeueue_exch_ver_req :
104 * Queues Exchange Version Request, to communicate host information
105 * in return, it gets firmware version details
108 snic_queue_exch_ver_req(struct snic
*snic
)
110 struct snic_req_info
*rqi
= NULL
;
111 struct snic_host_req
*req
= NULL
;
115 SNIC_HOST_INFO(snic
->shost
, "Exch Ver Req Preparing...\n");
117 rqi
= snic_req_init(snic
, 0);
119 SNIC_HOST_ERR(snic
->shost
,
120 "Queuing Exch Ver Req failed, err = %d\n",
127 req
= rqi_to_req(rqi
);
129 /* Initialize snic_host_req */
130 snic_io_hdr_enc(&req
->hdr
, SNIC_REQ_EXCH_VER
, 0, SCSI_NO_TAG
,
131 snic
->config
.hid
, 0, (ulong
)rqi
);
132 ver
= snic_ver_enc(SNIC_DRV_VERSION
);
133 req
->u
.exch_ver
.drvr_ver
= cpu_to_le32(ver
);
134 req
->u
.exch_ver
.os_type
= cpu_to_le32(SNIC_OS_LINUX
);
136 snic_handle_untagged_req(snic
, rqi
);
138 ret
= snic_queue_wq_desc(snic
, req
, sizeof(*req
));
140 snic_release_untagged_req(snic
, rqi
);
141 SNIC_HOST_ERR(snic
->shost
,
142 "Queuing Exch Ver Req failed, err = %d\n",
147 SNIC_HOST_INFO(snic
->shost
, "Exch Ver Req is issued. ret = %d\n", ret
);
151 } /* end of snic_queue_exch_ver_req */
154 * snic_io_exch_ver_cmpl_handler
157 snic_io_exch_ver_cmpl_handler(struct snic
*snic
, struct snic_fw_req
*fwreq
)
159 struct snic_req_info
*rqi
= NULL
;
160 struct snic_exch_ver_rsp
*exv_cmpl
= &fwreq
->u
.exch_ver_cmpl
;
162 u32 cmnd_id
, hid
, max_sgs
;
167 SNIC_HOST_INFO(snic
->shost
, "Exch Ver Compl Received.\n");
168 snic_io_hdr_dec(&fwreq
->hdr
, &typ
, &hdr_stat
, &cmnd_id
, &hid
, &ctx
);
169 SNIC_BUG_ON(snic
->config
.hid
!= hid
);
170 rqi
= (struct snic_req_info
*) ctx
;
173 SNIC_HOST_ERR(snic
->shost
,
174 "Exch Ver Completed w/ err status %d\n",
180 spin_lock_irqsave(&snic
->snic_lock
, flags
);
181 snic
->fwinfo
.fw_ver
= le32_to_cpu(exv_cmpl
->version
);
182 snic
->fwinfo
.hid
= le32_to_cpu(exv_cmpl
->hid
);
183 snic
->fwinfo
.max_concur_ios
= le32_to_cpu(exv_cmpl
->max_concur_ios
);
184 snic
->fwinfo
.max_sgs_per_cmd
= le32_to_cpu(exv_cmpl
->max_sgs_per_cmd
);
185 snic
->fwinfo
.max_io_sz
= le32_to_cpu(exv_cmpl
->max_io_sz
);
186 snic
->fwinfo
.max_tgts
= le32_to_cpu(exv_cmpl
->max_tgts
);
187 snic
->fwinfo
.io_tmo
= le16_to_cpu(exv_cmpl
->io_timeout
);
189 SNIC_HOST_INFO(snic
->shost
,
190 "vers %u hid %u max_concur_ios %u max_sgs_per_cmd %u max_io_sz %u max_tgts %u fw tmo %u\n",
193 snic
->fwinfo
.max_concur_ios
,
194 snic
->fwinfo
.max_sgs_per_cmd
,
195 snic
->fwinfo
.max_io_sz
,
196 snic
->fwinfo
.max_tgts
,
197 snic
->fwinfo
.io_tmo
);
199 SNIC_HOST_INFO(snic
->shost
,
200 "HBA Capabilities = 0x%x\n",
201 le32_to_cpu(exv_cmpl
->hba_cap
));
203 /* Updating SGList size */
204 max_sgs
= snic
->fwinfo
.max_sgs_per_cmd
;
205 if (max_sgs
&& max_sgs
< SNIC_MAX_SG_DESC_CNT
) {
206 snic
->shost
->sg_tablesize
= max_sgs
;
207 SNIC_HOST_INFO(snic
->shost
, "Max SGs set to %d\n",
208 snic
->shost
->sg_tablesize
);
209 } else if (max_sgs
> snic
->shost
->sg_tablesize
) {
210 SNIC_HOST_INFO(snic
->shost
,
211 "Target type %d Supports Larger Max SGList %d than driver's Max SG List %d.\n",
212 snic
->config
.xpt_type
, max_sgs
,
213 snic
->shost
->sg_tablesize
);
216 if (snic
->shost
->can_queue
> snic
->fwinfo
.max_concur_ios
)
217 snic
->shost
->can_queue
= snic
->fwinfo
.max_concur_ios
;
219 snic
->shost
->max_sectors
= snic
->fwinfo
.max_io_sz
>> 9;
220 if (snic
->fwinfo
.wait
)
221 complete(snic
->fwinfo
.wait
);
223 spin_unlock_irqrestore(&snic
->snic_lock
, flags
);
226 snic_release_untagged_req(snic
, rqi
);
228 SNIC_HOST_INFO(snic
->shost
, "Exch_cmpl Done, hdr_stat %d.\n", hdr_stat
);
231 } /* end of snic_io_exch_ver_cmpl_handler */
236 * Synchronous call, and Retrieves snic params.
239 snic_get_conf(struct snic
*snic
)
241 DECLARE_COMPLETION_ONSTACK(wait
);
246 SNIC_HOST_INFO(snic
->shost
, "Retrieving snic params.\n");
247 spin_lock_irqsave(&snic
->snic_lock
, flags
);
248 memset(&snic
->fwinfo
, 0, sizeof(snic
->fwinfo
));
249 snic
->fwinfo
.wait
= &wait
;
250 spin_unlock_irqrestore(&snic
->snic_lock
, flags
);
252 /* Additional delay to handle HW Resource initialization. */
256 * Exch ver req can be ignored by FW, if HW Resource initialization
257 * is in progress, Hence retry.
260 ret
= snic_queue_exch_ver_req(snic
);
264 wait_for_completion_timeout(&wait
, msecs_to_jiffies(2000));
265 spin_lock_irqsave(&snic
->snic_lock
, flags
);
266 ret
= (snic
->fwinfo
.fw_ver
!= 0) ? 0 : -ETIMEDOUT
;
268 SNIC_HOST_ERR(snic
->shost
,
269 "Failed to retrieve snic params,\n");
271 /* Unset fwinfo.wait, on success or on last retry */
272 if (ret
== 0 || nr_retries
== 1)
273 snic
->fwinfo
.wait
= NULL
;
275 spin_unlock_irqrestore(&snic
->snic_lock
, flags
);
276 } while (ret
&& --nr_retries
);
279 } /* end of snic_get_info */