blob: 6238be37d7bb2e7a9bd100c442ed75d0aaba6b1b [file] [log] [blame]
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001/*
Andrew Vasquez01e58d82008-04-03 13:13:13 -07002 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2008 QLogic Corporation
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004 *
Andrew Vasquez01e58d82008-04-03 13:13:13 -07005 * See LICENSE.qla2xxx for copyright and licensing details.
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07006 */
7#include "qla_def.h"
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08008#include "qla_gbl.h"
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07009
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070010#include <linux/moduleparam.h>
11#include <linux/vmalloc.h>
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070012#include <linux/list.h>
13
14#include <scsi/scsi_tcq.h>
15#include <scsi/scsicam.h>
16#include <linux/delay.h>
17
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070018void
19qla2x00_vp_stop_timer(scsi_qla_host_t *vha)
20{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080021 if (vha->vp_idx && vha->timer_active) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070022 del_timer_sync(&vha->timer);
23 vha->timer_active = 0;
24 }
25}
26
Adrian Bunka824ebb2008-01-17 09:02:15 -080027static uint32_t
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070028qla24xx_allocate_vp_id(scsi_qla_host_t *vha)
29{
30 uint32_t vp_id;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080031 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070032
33 /* Find an empty slot and assign an vp_id */
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -070034 mutex_lock(&ha->vport_lock);
Andrew Vasquezeb66dc62007-11-12 10:30:58 -080035 vp_id = find_first_zero_bit(ha->vp_idx_map, ha->max_npiv_vports + 1);
36 if (vp_id > ha->max_npiv_vports) {
37 DEBUG15(printk ("vp_id %d is bigger than max-supported %d.\n",
38 vp_id, ha->max_npiv_vports));
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -070039 mutex_unlock(&ha->vport_lock);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070040 return vp_id;
41 }
42
Andrew Vasquezeb66dc62007-11-12 10:30:58 -080043 set_bit(vp_id, ha->vp_idx_map);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070044 ha->num_vhosts++;
Seokmann Ju711c1d92008-07-10 16:55:51 -070045 ha->cur_vport_count++;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070046 vha->vp_idx = vp_id;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080047 list_add_tail(&vha->list, &ha->vp_list);
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -070048 mutex_unlock(&ha->vport_lock);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070049 return vp_id;
50}
51
52void
53qla24xx_deallocate_vp_id(scsi_qla_host_t *vha)
54{
55 uint16_t vp_id;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080056 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070057
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -070058 mutex_lock(&ha->vport_lock);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070059 vp_id = vha->vp_idx;
60 ha->num_vhosts--;
Seokmann Ju711c1d92008-07-10 16:55:51 -070061 ha->cur_vport_count--;
Andrew Vasquezeb66dc62007-11-12 10:30:58 -080062 clear_bit(vp_id, ha->vp_idx_map);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080063 list_del(&vha->list);
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -070064 mutex_unlock(&ha->vport_lock);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070065}
66
Adrian Bunka824ebb2008-01-17 09:02:15 -080067static scsi_qla_host_t *
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080068qla24xx_find_vhost_by_name(struct qla_hw_data *ha, uint8_t *port_name)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070069{
70 scsi_qla_host_t *vha;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -080071 struct scsi_qla_host *tvha;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070072
73 /* Locate matching device in database. */
Anirban Chakrabortyee546b62009-03-05 11:07:02 -080074 list_for_each_entry_safe(vha, tvha, &ha->vp_list, list) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070075 if (!memcmp(port_name, vha->port_name, WWN_SIZE))
76 return vha;
77 }
78 return NULL;
79}
80
81/*
82 * qla2x00_mark_vp_devices_dead
83 * Updates fcport state when device goes offline.
84 *
85 * Input:
86 * ha = adapter block pointer.
87 * fcport = port structure pointer.
88 *
89 * Return:
90 * None.
91 *
92 * Context:
93 */
Andrew Vasquez26ff7762007-09-20 14:07:47 -070094static void
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070095qla2x00_mark_vp_devices_dead(scsi_qla_host_t *vha)
96{
97 fc_port_t *fcport;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070098
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080099 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700100 DEBUG15(printk("scsi(%ld): Marking port dead, "
101 "loop_id=0x%04x :%x\n",
102 vha->host_no, fcport->loop_id, fcport->vp_idx));
103
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800104 atomic_set(&fcport->state, FCS_DEVICE_DEAD);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700105 qla2x00_mark_device_lost(vha, fcport, 0, 0);
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -0700106 atomic_set(&fcport->state, FCS_UNCONFIGURED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700107 }
108}
109
110int
111qla24xx_disable_vp(scsi_qla_host_t *vha)
112{
113 int ret;
114
115 ret = qla24xx_control_vp(vha, VCE_COMMAND_DISABLE_VPS_LOGO_ALL);
116 atomic_set(&vha->loop_state, LOOP_DOWN);
117 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
118
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700119 qla2x00_mark_vp_devices_dead(vha);
120 atomic_set(&vha->vp_state, VP_FAILED);
121 vha->flags.management_server_logged_in = 0;
122 if (ret == QLA_SUCCESS) {
123 fc_vport_set_state(vha->fc_vport, FC_VPORT_DISABLED);
124 } else {
125 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
126 return -1;
127 }
128 return 0;
129}
130
131int
132qla24xx_enable_vp(scsi_qla_host_t *vha)
133{
134 int ret;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800135 struct qla_hw_data *ha = vha->hw;
136 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700137
138 /* Check if physical ha port is Up */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800139 if (atomic_read(&base_vha->loop_state) == LOOP_DOWN ||
140 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700141 vha->vp_err_state = VP_ERR_PORTDWN;
142 fc_vport_set_state(vha->fc_vport, FC_VPORT_LINKDOWN);
143 goto enable_failed;
144 }
145
146 /* Initialize the new vport unless it is a persistent port */
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -0700147 mutex_lock(&ha->vport_lock);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700148 ret = qla24xx_modify_vp_config(vha);
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -0700149 mutex_unlock(&ha->vport_lock);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700150
151 if (ret != QLA_SUCCESS) {
152 fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED);
153 goto enable_failed;
154 }
155
156 DEBUG15(qla_printk(KERN_INFO, ha,
157 "Virtual port with id: %d - Enabled\n", vha->vp_idx));
158 return 0;
159
160enable_failed:
161 DEBUG15(qla_printk(KERN_INFO, ha,
162 "Virtual port with id: %d - Disabled\n", vha->vp_idx));
163 return 1;
164}
165
Andrew Vasquez26ff7762007-09-20 14:07:47 -0700166static void
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700167qla24xx_configure_vp(scsi_qla_host_t *vha)
168{
169 struct fc_vport *fc_vport;
170 int ret;
171
172 fc_vport = vha->fc_vport;
173
174 DEBUG15(printk("scsi(%ld): %s: change request #3 for this host.\n",
175 vha->host_no, __func__));
176 ret = qla2x00_send_change_request(vha, 0x3, vha->vp_idx);
177 if (ret != QLA_SUCCESS) {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800178 DEBUG15(qla_printk(KERN_ERR, vha->hw, "Failed to enable "
179 "receiving of RSCN requests: 0x%x\n", ret));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700180 return;
181 } else {
182 /* Corresponds to SCR enabled */
183 clear_bit(VP_SCR_NEEDED, &vha->vp_flags);
184 }
185
186 vha->flags.online = 1;
187 if (qla24xx_configure_vhba(vha))
188 return;
189
190 atomic_set(&vha->vp_state, VP_ACTIVE);
191 fc_vport_set_state(fc_vport, FC_VPORT_ACTIVE);
192}
193
194void
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800195qla2x00_alert_all_vps(struct rsp_que *rsp, uint16_t *mb)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700196{
Anirban Chakrabortyee546b62009-03-05 11:07:02 -0800197 scsi_qla_host_t *vha, *tvha;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800198 struct qla_hw_data *ha = rsp->hw;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800199 int i = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700200
Anirban Chakrabortyee546b62009-03-05 11:07:02 -0800201 list_for_each_entry_safe(vha, tvha, &ha->vp_list, list) {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800202 if (vha->vp_idx) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700203 switch (mb[0]) {
204 case MBA_LIP_OCCURRED:
205 case MBA_LOOP_UP:
206 case MBA_LOOP_DOWN:
207 case MBA_LIP_RESET:
208 case MBA_POINT_TO_POINT:
209 case MBA_CHG_IN_CONNECTION:
210 case MBA_PORT_UPDATE:
211 case MBA_RSCN_UPDATE:
212 DEBUG15(printk("scsi(%ld)%s: Async_event for"
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800213 " VP[%d], mb = 0x%x, vha=%p\n",
214 vha->host_no, __func__, i, *mb, vha));
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800215 qla2x00_async_event(vha, rsp, mb);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700216 break;
217 }
218 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800219 i++;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700220 }
221}
222
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800223int
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700224qla2x00_vp_abort_isp(scsi_qla_host_t *vha)
225{
226 /*
227 * Physical port will do most of the abort and recovery work. We can
228 * just treat it as a loop down
229 */
230 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
231 atomic_set(&vha->loop_state, LOOP_DOWN);
232 qla2x00_mark_all_devices_lost(vha, 0);
233 } else {
234 if (!atomic_read(&vha->loop_down_timer))
235 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
236 }
237
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800238 /* To exclusively reset vport, we need to log it out first.*/
239 if (!test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))
240 qla24xx_control_vp(vha, VCE_COMMAND_DISABLE_VPS_LOGO_ALL);
241
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700242 DEBUG15(printk("scsi(%ld): Scheduling enable of Vport %d...\n",
243 vha->host_no, vha->vp_idx));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800244 return qla24xx_enable_vp(vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700245}
246
Adrian Bunka824ebb2008-01-17 09:02:15 -0800247static int
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700248qla2x00_do_dpc_vp(scsi_qla_host_t *vha)
249{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800250 struct qla_hw_data *ha = vha->hw;
251 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Seokmann Ju221726d2008-04-03 13:13:31 -0700252
Lalit Chandivade4b785242009-07-31 15:09:27 -0700253 if (!(ha->current_topology & ISP_CFG_F))
254 return 0;
255
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700256 if (test_and_clear_bit(VP_IDX_ACQUIRED, &vha->vp_flags)) {
257 /* VP acquired. complete port configuration */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800258 if (atomic_read(&base_vha->loop_state) == LOOP_READY) {
Seokmann Ju221726d2008-04-03 13:13:31 -0700259 qla24xx_configure_vp(vha);
260 } else {
261 set_bit(VP_IDX_ACQUIRED, &vha->vp_flags);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800262 set_bit(VP_DPC_NEEDED, &base_vha->dpc_flags);
Seokmann Ju221726d2008-04-03 13:13:31 -0700263 }
264
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700265 return 0;
266 }
267
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800268 if (test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags)) {
269 qla2x00_update_fcports(vha);
270 clear_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags);
271 }
272
273 if ((test_and_clear_bit(RELOGIN_NEEDED, &vha->dpc_flags)) &&
274 !test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) &&
275 atomic_read(&vha->loop_state) != LOOP_DOWN) {
276
277 DEBUG(printk("scsi(%ld): qla2x00_port_login()\n",
278 vha->host_no));
279 qla2x00_relogin(vha);
280
281 DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n",
282 vha->host_no));
283 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700284
285 if (test_and_clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) &&
286 (!(test_and_set_bit(RESET_ACTIVE, &vha->dpc_flags)))) {
287 clear_bit(RESET_ACTIVE, &vha->dpc_flags);
288 }
289
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800290 if (test_and_clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700291 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags))) {
292 qla2x00_loop_resync(vha);
293 clear_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags);
294 }
295 }
296
297 return 0;
298}
299
300void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800301qla2x00_do_dpc_all_vps(scsi_qla_host_t *vha)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700302{
303 int ret;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800304 struct qla_hw_data *ha = vha->hw;
305 scsi_qla_host_t *vp;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -0800306 struct scsi_qla_host *tvp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700307
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800308 if (vha->vp_idx)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700309 return;
310 if (list_empty(&ha->vp_list))
311 return;
312
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800313 clear_bit(VP_DPC_NEEDED, &vha->dpc_flags);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700314
Anirban Chakrabortyee546b62009-03-05 11:07:02 -0800315 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800316 if (vp->vp_idx)
317 ret = qla2x00_do_dpc_vp(vp);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700318 }
319}
320
321int
322qla24xx_vport_create_req_sanity_check(struct fc_vport *fc_vport)
323{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800324 scsi_qla_host_t *base_vha = shost_priv(fc_vport->shost);
325 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700326 scsi_qla_host_t *vha;
327 uint8_t port_name[WWN_SIZE];
328
329 if (fc_vport->roles != FC_PORT_ROLE_FCP_INITIATOR)
330 return VPCERR_UNSUPPORTED;
331
332 /* Check up the F/W and H/W support NPIV */
333 if (!ha->flags.npiv_supported)
334 return VPCERR_UNSUPPORTED;
335
336 /* Check up whether npiv supported switch presented */
337 if (!(ha->switch_cap & FLOGI_MID_SUPPORT))
338 return VPCERR_NO_FABRIC_SUPP;
339
340 /* Check up unique WWPN */
341 u64_to_wwn(fc_vport->port_name, port_name);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800342 if (!memcmp(port_name, base_vha->port_name, WWN_SIZE))
Seokmann Ju50db6b12008-01-17 09:02:14 -0800343 return VPCERR_BAD_WWN;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700344 vha = qla24xx_find_vhost_by_name(ha, port_name);
345 if (vha)
346 return VPCERR_BAD_WWN;
347
348 /* Check up max-npiv-supports */
349 if (ha->num_vhosts > ha->max_npiv_vports) {
Andrew Vasquezeb66dc62007-11-12 10:30:58 -0800350 DEBUG15(printk("scsi(%ld): num_vhosts %ud is bigger than "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800351 "max_npv_vports %ud.\n", base_vha->host_no,
Andrew Vasquezeb66dc62007-11-12 10:30:58 -0800352 ha->num_vhosts, ha->max_npiv_vports));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700353 return VPCERR_UNSUPPORTED;
354 }
355 return 0;
356}
357
358scsi_qla_host_t *
359qla24xx_create_vhost(struct fc_vport *fc_vport)
360{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800361 scsi_qla_host_t *base_vha = shost_priv(fc_vport->shost);
362 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700363 scsi_qla_host_t *vha;
Giridhar Malavalia5326f82009-03-24 09:07:56 -0700364 struct scsi_host_template *sht = &qla2xxx_driver_template;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700365 struct Scsi_Host *host;
366
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800367 vha = qla2x00_create_host(sht, ha);
368 if (!vha) {
369 DEBUG(printk("qla2xxx: scsi_host_alloc() failed for vport\n"));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700370 return(NULL);
371 }
372
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800373 host = vha->host;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700374 fc_vport->dd_data = vha;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700375 /* New host info */
376 u64_to_wwn(fc_vport->node_name, vha->node_name);
377 u64_to_wwn(fc_vport->port_name, vha->port_name);
378
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700379 vha->fc_vport = fc_vport;
380 vha->device_flags = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700381 vha->vp_idx = qla24xx_allocate_vp_id(vha);
382 if (vha->vp_idx > ha->max_npiv_vports) {
383 DEBUG15(printk("scsi(%ld): Couldn't allocate vp_id.\n",
384 vha->host_no));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800385 goto create_vhost_failed;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700386 }
387 vha->mgmt_svr_loop_id = 10 + vha->vp_idx;
388
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700389 vha->dpc_flags = 0L;
390 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
391 set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags);
392
393 /*
394 * To fix the issue of processing a parent's RSCN for the vport before
395 * its SCR is complete.
396 */
397 set_bit(VP_SCR_NEEDED, &vha->vp_flags);
398 atomic_set(&vha->loop_state, LOOP_DOWN);
399 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
400
401 qla2x00_start_timer(vha, qla2x00_timer, WATCH_INTERVAL);
402
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700403 vha->req = base_vha->req;
404 host->can_queue = base_vha->req->length + 128;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700405 host->this_id = 255;
406 host->cmd_per_lun = 3;
407 host->max_cmd_len = MAX_CMDSZ;
408 host->max_channel = MAX_BUSES - 1;
409 host->max_lun = MAX_LUNS;
Seokmann Ju711c1d92008-07-10 16:55:51 -0700410 host->unique_id = host->host_no;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700411 host->max_id = MAX_TARGETS_2200;
412 host->transportt = qla2xxx_transport_vport_template;
413
414 DEBUG15(printk("DEBUG: detect vport hba %ld at address = %p\n",
415 vha->host_no, vha));
416
417 vha->flags.init_done = 1;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700418
419 return vha;
420
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800421create_vhost_failed:
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700422 return NULL;
423}
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800424
425static void
426qla25xx_free_req_que(struct scsi_qla_host *vha, struct req_que *req)
427{
428 struct qla_hw_data *ha = vha->hw;
429 uint16_t que_id = req->id;
430
431 dma_free_coherent(&ha->pdev->dev, (req->length + 1) *
432 sizeof(request_t), req->ring, req->dma);
433 req->ring = NULL;
434 req->dma = 0;
435 if (que_id) {
436 ha->req_q_map[que_id] = NULL;
437 mutex_lock(&ha->vport_lock);
438 clear_bit(que_id, ha->req_qid_map);
439 mutex_unlock(&ha->vport_lock);
440 }
441 kfree(req);
442 req = NULL;
443}
444
445static void
446qla25xx_free_rsp_que(struct scsi_qla_host *vha, struct rsp_que *rsp)
447{
448 struct qla_hw_data *ha = vha->hw;
449 uint16_t que_id = rsp->id;
450
451 if (rsp->msix && rsp->msix->have_irq) {
452 free_irq(rsp->msix->vector, rsp);
453 rsp->msix->have_irq = 0;
454 rsp->msix->rsp = NULL;
455 }
456 dma_free_coherent(&ha->pdev->dev, (rsp->length + 1) *
457 sizeof(response_t), rsp->ring, rsp->dma);
458 rsp->ring = NULL;
459 rsp->dma = 0;
460 if (que_id) {
461 ha->rsp_q_map[que_id] = NULL;
462 mutex_lock(&ha->vport_lock);
463 clear_bit(que_id, ha->rsp_qid_map);
464 mutex_unlock(&ha->vport_lock);
465 }
466 kfree(rsp);
467 rsp = NULL;
468}
469
470int
471qla25xx_delete_req_que(struct scsi_qla_host *vha, struct req_que *req)
472{
473 int ret = -1;
474
475 if (req) {
476 req->options |= BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -0800477 ret = qla25xx_init_req_que(vha, req);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800478 }
479 if (ret == QLA_SUCCESS)
480 qla25xx_free_req_que(vha, req);
481
482 return ret;
483}
484
485int
486qla25xx_delete_rsp_que(struct scsi_qla_host *vha, struct rsp_que *rsp)
487{
488 int ret = -1;
489
490 if (rsp) {
491 rsp->options |= BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -0800492 ret = qla25xx_init_rsp_que(vha, rsp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800493 }
494 if (ret == QLA_SUCCESS)
495 qla25xx_free_rsp_que(vha, rsp);
496
497 return ret;
498}
499
500int qla25xx_update_req_que(struct scsi_qla_host *vha, uint8_t que, uint8_t qos)
501{
502 int ret = 0;
503 struct qla_hw_data *ha = vha->hw;
504 struct req_que *req = ha->req_q_map[que];
505
506 req->options |= BIT_3;
507 req->qos = qos;
Anirban Chakraborty618a7522009-02-08 20:50:11 -0800508 ret = qla25xx_init_req_que(vha, req);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800509 if (ret != QLA_SUCCESS)
510 DEBUG2_17(printk(KERN_WARNING "%s failed\n", __func__));
511 /* restore options bit */
512 req->options &= ~BIT_3;
513 return ret;
514}
515
516
517/* Delete all queues for a given vhost */
518int
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700519qla25xx_delete_queues(struct scsi_qla_host *vha)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800520{
521 int cnt, ret = 0;
522 struct req_que *req = NULL;
523 struct rsp_que *rsp = NULL;
524 struct qla_hw_data *ha = vha->hw;
525
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700526 /* Delete request queues */
527 for (cnt = 1; cnt < ha->max_req_queues; cnt++) {
528 req = ha->req_q_map[cnt];
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800529 if (req) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800530 ret = qla25xx_delete_req_que(vha, req);
531 if (ret != QLA_SUCCESS) {
532 qla_printk(KERN_WARNING, ha,
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700533 "Couldn't delete req que %d\n",
534 req->id);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800535 return ret;
536 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800537 }
538 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700539
540 /* Delete response queues */
541 for (cnt = 1; cnt < ha->max_rsp_queues; cnt++) {
542 rsp = ha->rsp_q_map[cnt];
543 if (rsp) {
544 ret = qla25xx_delete_rsp_que(vha, rsp);
545 if (ret != QLA_SUCCESS) {
546 qla_printk(KERN_WARNING, ha,
547 "Couldn't delete rsp que %d\n",
548 rsp->id);
549 return ret;
550 }
551 }
552 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800553 return ret;
554}
555
556int
557qla25xx_create_req_que(struct qla_hw_data *ha, uint16_t options,
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700558 uint8_t vp_idx, uint16_t rid, int rsp_que, uint8_t qos)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800559{
560 int ret = 0;
561 struct req_que *req = NULL;
562 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
563 uint16_t que_id = 0;
Andrew Vasquez08029992009-03-24 09:07:55 -0700564 device_reg_t __iomem *reg;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700565 uint32_t cnt;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800566
567 req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
568 if (req == NULL) {
569 qla_printk(KERN_WARNING, ha, "could not allocate memory"
570 "for request que\n");
571 goto que_failed;
572 }
573
574 req->length = REQUEST_ENTRY_CNT_24XX;
575 req->ring = dma_alloc_coherent(&ha->pdev->dev,
576 (req->length + 1) * sizeof(request_t),
577 &req->dma, GFP_KERNEL);
578 if (req->ring == NULL) {
579 qla_printk(KERN_WARNING, ha,
580 "Memory Allocation failed - request_ring\n");
581 goto que_failed;
582 }
583
584 mutex_lock(&ha->vport_lock);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700585 que_id = find_first_zero_bit(ha->req_qid_map, ha->max_req_queues);
586 if (que_id >= ha->max_req_queues) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800587 mutex_unlock(&ha->vport_lock);
588 qla_printk(KERN_INFO, ha, "No resources to create "
589 "additional request queue\n");
590 goto que_failed;
591 }
592 set_bit(que_id, ha->req_qid_map);
593 ha->req_q_map[que_id] = req;
594 req->rid = rid;
595 req->vp_idx = vp_idx;
596 req->qos = qos;
597
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700598 if (rsp_que < 0)
599 req->rsp = NULL;
600 else
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800601 req->rsp = ha->rsp_q_map[rsp_que];
602 /* Use alternate PCI bus number */
603 if (MSB(req->rid))
604 options |= BIT_4;
605 /* Use alternate PCI devfn */
606 if (LSB(req->rid))
607 options |= BIT_5;
608 req->options = options;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700609
610 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
611 req->outstanding_cmds[cnt] = NULL;
612 req->current_outstanding_cmd = 1;
613
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800614 req->ring_ptr = req->ring;
615 req->ring_index = 0;
616 req->cnt = req->length;
617 req->id = que_id;
Andrew Vasquez08029992009-03-24 09:07:55 -0700618 reg = ISP_QUE_REG(ha, que_id);
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -0800619 req->max_q_depth = ha->req_q_map[0]->max_q_depth;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800620 mutex_unlock(&ha->vport_lock);
621
Anirban Chakraborty618a7522009-02-08 20:50:11 -0800622 ret = qla25xx_init_req_que(base_vha, req);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800623 if (ret != QLA_SUCCESS) {
624 qla_printk(KERN_WARNING, ha, "%s failed\n", __func__);
625 mutex_lock(&ha->vport_lock);
626 clear_bit(que_id, ha->req_qid_map);
627 mutex_unlock(&ha->vport_lock);
628 goto que_failed;
629 }
630
631 return req->id;
632
633que_failed:
634 qla25xx_free_req_que(base_vha, req);
635 return 0;
636}
637
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700638static void qla_do_work(struct work_struct *work)
639{
640 struct rsp_que *rsp = container_of(work, struct rsp_que, q_work);
641 struct scsi_qla_host *vha;
642
643 vha = qla25xx_get_host(rsp);
644 qla24xx_process_response_queue(vha, rsp);
645}
646
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800647/* create response queue */
648int
649qla25xx_create_rsp_que(struct qla_hw_data *ha, uint16_t options,
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700650 uint8_t vp_idx, uint16_t rid, int req)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800651{
652 int ret = 0;
653 struct rsp_que *rsp = NULL;
654 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Andrew Vasquez08029992009-03-24 09:07:55 -0700655 uint16_t que_id = 0;
656 device_reg_t __iomem *reg;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800657
658 rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
659 if (rsp == NULL) {
660 qla_printk(KERN_WARNING, ha, "could not allocate memory for"
661 " response que\n");
662 goto que_failed;
663 }
664
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700665 rsp->length = RESPONSE_ENTRY_CNT_MQ;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800666 rsp->ring = dma_alloc_coherent(&ha->pdev->dev,
667 (rsp->length + 1) * sizeof(response_t),
668 &rsp->dma, GFP_KERNEL);
669 if (rsp->ring == NULL) {
670 qla_printk(KERN_WARNING, ha,
671 "Memory Allocation failed - response_ring\n");
672 goto que_failed;
673 }
674
675 mutex_lock(&ha->vport_lock);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700676 que_id = find_first_zero_bit(ha->rsp_qid_map, ha->max_rsp_queues);
677 if (que_id >= ha->max_rsp_queues) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800678 mutex_unlock(&ha->vport_lock);
679 qla_printk(KERN_INFO, ha, "No resources to create "
680 "additional response queue\n");
681 goto que_failed;
682 }
683 set_bit(que_id, ha->rsp_qid_map);
684
685 if (ha->flags.msix_enabled)
686 rsp->msix = &ha->msix_entries[que_id + 1];
687 else
688 qla_printk(KERN_WARNING, ha, "msix not enabled\n");
689
690 ha->rsp_q_map[que_id] = rsp;
691 rsp->rid = rid;
692 rsp->vp_idx = vp_idx;
693 rsp->hw = ha;
694 /* Use alternate PCI bus number */
695 if (MSB(rsp->rid))
696 options |= BIT_4;
697 /* Use alternate PCI devfn */
698 if (LSB(rsp->rid))
699 options |= BIT_5;
700 rsp->options = options;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800701 rsp->id = que_id;
Andrew Vasquez08029992009-03-24 09:07:55 -0700702 reg = ISP_QUE_REG(ha, que_id);
703 rsp->rsp_q_in = &reg->isp25mq.rsp_q_in;
704 rsp->rsp_q_out = &reg->isp25mq.rsp_q_out;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800705 mutex_unlock(&ha->vport_lock);
706
707 ret = qla25xx_request_irq(rsp);
708 if (ret)
709 goto que_failed;
710
Anirban Chakraborty618a7522009-02-08 20:50:11 -0800711 ret = qla25xx_init_rsp_que(base_vha, rsp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800712 if (ret != QLA_SUCCESS) {
713 qla_printk(KERN_WARNING, ha, "%s failed\n", __func__);
714 mutex_lock(&ha->vport_lock);
715 clear_bit(que_id, ha->rsp_qid_map);
716 mutex_unlock(&ha->vport_lock);
717 goto que_failed;
718 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700719 if (req >= 0)
720 rsp->req = ha->req_q_map[req];
721 else
722 rsp->req = NULL;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800723
724 qla2x00_init_response_q_entries(rsp);
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700725 if (rsp->hw->wq)
726 INIT_WORK(&rsp->q_work, qla_do_work);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800727 return rsp->id;
728
729que_failed:
730 qla25xx_free_rsp_que(base_vha, rsp);
731 return 0;
732}
733
734int
735qla25xx_create_queues(struct scsi_qla_host *vha, uint8_t qos)
736{
737 uint16_t options = 0;
738 uint8_t ret = 0;
739 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700740 struct rsp_que *rsp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800741
742 options |= BIT_1;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700743 ret = qla25xx_create_rsp_que(ha, options, vha->vp_idx, 0, -1);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800744 if (!ret) {
745 qla_printk(KERN_WARNING, ha, "Response Que create failed\n");
746 return ret;
747 } else
748 qla_printk(KERN_INFO, ha, "Response Que:%d created.\n", ret);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700749 rsp = ha->rsp_q_map[ret];
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800750
751 options = 0;
752 if (qos & BIT_7)
753 options |= BIT_8;
754 ret = qla25xx_create_req_que(ha, options, vha->vp_idx, 0, ret,
755 qos & ~BIT_7);
756 if (ret) {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700757 vha->req = ha->req_q_map[ret];
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800758 qla_printk(KERN_INFO, ha, "Request Que:%d created.\n", ret);
759 } else
760 qla_printk(KERN_WARNING, ha, "Request Que create failed\n");
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700761 rsp->req = ha->req_q_map[ret];
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800762
763 return ret;
764}