Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1 | /* |
Andrew Vasquez | 01e58d8 | 2008-04-03 13:13:13 -0700 | [diff] [blame] | 2 | * QLogic Fibre Channel HBA Driver |
| 3 | * Copyright (c) 2003-2008 QLogic Corporation |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 4 | * |
Andrew Vasquez | 01e58d8 | 2008-04-03 13:13:13 -0700 | [diff] [blame] | 5 | * See LICENSE.qla2xxx for copyright and licensing details. |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 6 | */ |
| 7 | #include "qla_def.h" |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame^] | 8 | #include "qla_gbl.h" |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 9 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 10 | #include <linux/moduleparam.h> |
| 11 | #include <linux/vmalloc.h> |
| 12 | #include <linux/smp_lock.h> |
| 13 | #include <linux/list.h> |
| 14 | |
| 15 | #include <scsi/scsi_tcq.h> |
| 16 | #include <scsi/scsicam.h> |
| 17 | #include <linux/delay.h> |
| 18 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 19 | void |
| 20 | qla2x00_vp_stop_timer(scsi_qla_host_t *vha) |
| 21 | { |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame^] | 22 | if (vha->vp_idx && vha->timer_active) { |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 23 | del_timer_sync(&vha->timer); |
| 24 | vha->timer_active = 0; |
| 25 | } |
| 26 | } |
| 27 | |
Adrian Bunk | a824ebb | 2008-01-17 09:02:15 -0800 | [diff] [blame] | 28 | static uint32_t |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 29 | qla24xx_allocate_vp_id(scsi_qla_host_t *vha) |
| 30 | { |
| 31 | uint32_t vp_id; |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame^] | 32 | struct qla_hw_data *ha = vha->hw; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 33 | |
| 34 | /* Find an empty slot and assign an vp_id */ |
matthias@kaehlcke.net | 6c2f527 | 2008-05-12 22:21:11 -0700 | [diff] [blame] | 35 | mutex_lock(&ha->vport_lock); |
Andrew Vasquez | eb66dc6 | 2007-11-12 10:30:58 -0800 | [diff] [blame] | 36 | vp_id = find_first_zero_bit(ha->vp_idx_map, ha->max_npiv_vports + 1); |
| 37 | if (vp_id > ha->max_npiv_vports) { |
| 38 | DEBUG15(printk ("vp_id %d is bigger than max-supported %d.\n", |
| 39 | vp_id, ha->max_npiv_vports)); |
matthias@kaehlcke.net | 6c2f527 | 2008-05-12 22:21:11 -0700 | [diff] [blame] | 40 | mutex_unlock(&ha->vport_lock); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 41 | return vp_id; |
| 42 | } |
| 43 | |
Andrew Vasquez | eb66dc6 | 2007-11-12 10:30:58 -0800 | [diff] [blame] | 44 | set_bit(vp_id, ha->vp_idx_map); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 45 | ha->num_vhosts++; |
Seokmann Ju | 711c1d9 | 2008-07-10 16:55:51 -0700 | [diff] [blame] | 46 | ha->cur_vport_count++; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 47 | vha->vp_idx = vp_id; |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame^] | 48 | list_add_tail(&vha->list, &ha->vp_list); |
matthias@kaehlcke.net | 6c2f527 | 2008-05-12 22:21:11 -0700 | [diff] [blame] | 49 | mutex_unlock(&ha->vport_lock); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 50 | return vp_id; |
| 51 | } |
| 52 | |
| 53 | void |
| 54 | qla24xx_deallocate_vp_id(scsi_qla_host_t *vha) |
| 55 | { |
| 56 | uint16_t vp_id; |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame^] | 57 | struct qla_hw_data *ha = vha->hw; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 58 | |
matthias@kaehlcke.net | 6c2f527 | 2008-05-12 22:21:11 -0700 | [diff] [blame] | 59 | mutex_lock(&ha->vport_lock); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 60 | vp_id = vha->vp_idx; |
| 61 | ha->num_vhosts--; |
Seokmann Ju | 711c1d9 | 2008-07-10 16:55:51 -0700 | [diff] [blame] | 62 | ha->cur_vport_count--; |
Andrew Vasquez | eb66dc6 | 2007-11-12 10:30:58 -0800 | [diff] [blame] | 63 | clear_bit(vp_id, ha->vp_idx_map); |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame^] | 64 | list_del(&vha->list); |
matthias@kaehlcke.net | 6c2f527 | 2008-05-12 22:21:11 -0700 | [diff] [blame] | 65 | mutex_unlock(&ha->vport_lock); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 66 | } |
| 67 | |
Adrian Bunk | a824ebb | 2008-01-17 09:02:15 -0800 | [diff] [blame] | 68 | static scsi_qla_host_t * |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame^] | 69 | qla24xx_find_vhost_by_name(struct qla_hw_data *ha, uint8_t *port_name) |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 70 | { |
| 71 | scsi_qla_host_t *vha; |
| 72 | |
| 73 | /* Locate matching device in database. */ |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame^] | 74 | list_for_each_entry(vha, &ha->vp_list, list) { |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 75 | 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 Vasquez | 26ff776 | 2007-09-20 14:07:47 -0700 | [diff] [blame] | 94 | static void |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 95 | qla2x00_mark_vp_devices_dead(scsi_qla_host_t *vha) |
| 96 | { |
| 97 | fc_port_t *fcport; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 98 | |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame^] | 99 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 100 | 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 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 104 | qla2x00_mark_device_lost(vha, fcport, 0, 0); |
Andrew Vasquez | c9c5ced | 2008-07-24 08:31:49 -0700 | [diff] [blame] | 105 | atomic_set(&fcport->state, FCS_UNCONFIGURED); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 106 | } |
| 107 | } |
| 108 | |
| 109 | int |
| 110 | qla24xx_disable_vp(scsi_qla_host_t *vha) |
| 111 | { |
| 112 | int ret; |
| 113 | |
| 114 | ret = qla24xx_control_vp(vha, VCE_COMMAND_DISABLE_VPS_LOGO_ALL); |
| 115 | atomic_set(&vha->loop_state, LOOP_DOWN); |
| 116 | atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME); |
| 117 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 118 | qla2x00_mark_vp_devices_dead(vha); |
| 119 | atomic_set(&vha->vp_state, VP_FAILED); |
| 120 | vha->flags.management_server_logged_in = 0; |
| 121 | if (ret == QLA_SUCCESS) { |
| 122 | fc_vport_set_state(vha->fc_vport, FC_VPORT_DISABLED); |
| 123 | } else { |
| 124 | fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED); |
| 125 | return -1; |
| 126 | } |
| 127 | return 0; |
| 128 | } |
| 129 | |
| 130 | int |
| 131 | qla24xx_enable_vp(scsi_qla_host_t *vha) |
| 132 | { |
| 133 | int ret; |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame^] | 134 | struct qla_hw_data *ha = vha->hw; |
| 135 | scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 136 | |
| 137 | /* Check if physical ha port is Up */ |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame^] | 138 | if (atomic_read(&base_vha->loop_state) == LOOP_DOWN || |
| 139 | atomic_read(&base_vha->loop_state) == LOOP_DEAD) { |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 140 | vha->vp_err_state = VP_ERR_PORTDWN; |
| 141 | fc_vport_set_state(vha->fc_vport, FC_VPORT_LINKDOWN); |
| 142 | goto enable_failed; |
| 143 | } |
| 144 | |
| 145 | /* Initialize the new vport unless it is a persistent port */ |
matthias@kaehlcke.net | 6c2f527 | 2008-05-12 22:21:11 -0700 | [diff] [blame] | 146 | mutex_lock(&ha->vport_lock); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 147 | ret = qla24xx_modify_vp_config(vha); |
matthias@kaehlcke.net | 6c2f527 | 2008-05-12 22:21:11 -0700 | [diff] [blame] | 148 | mutex_unlock(&ha->vport_lock); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 149 | |
| 150 | if (ret != QLA_SUCCESS) { |
| 151 | fc_vport_set_state(vha->fc_vport, FC_VPORT_FAILED); |
| 152 | goto enable_failed; |
| 153 | } |
| 154 | |
| 155 | DEBUG15(qla_printk(KERN_INFO, ha, |
| 156 | "Virtual port with id: %d - Enabled\n", vha->vp_idx)); |
| 157 | return 0; |
| 158 | |
| 159 | enable_failed: |
| 160 | DEBUG15(qla_printk(KERN_INFO, ha, |
| 161 | "Virtual port with id: %d - Disabled\n", vha->vp_idx)); |
| 162 | return 1; |
| 163 | } |
| 164 | |
Andrew Vasquez | 26ff776 | 2007-09-20 14:07:47 -0700 | [diff] [blame] | 165 | static void |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 166 | qla24xx_configure_vp(scsi_qla_host_t *vha) |
| 167 | { |
| 168 | struct fc_vport *fc_vport; |
| 169 | int ret; |
| 170 | |
| 171 | fc_vport = vha->fc_vport; |
| 172 | |
| 173 | DEBUG15(printk("scsi(%ld): %s: change request #3 for this host.\n", |
| 174 | vha->host_no, __func__)); |
| 175 | ret = qla2x00_send_change_request(vha, 0x3, vha->vp_idx); |
| 176 | if (ret != QLA_SUCCESS) { |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame^] | 177 | DEBUG15(qla_printk(KERN_ERR, vha->hw, "Failed to enable " |
| 178 | "receiving of RSCN requests: 0x%x\n", ret)); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 179 | return; |
| 180 | } else { |
| 181 | /* Corresponds to SCR enabled */ |
| 182 | clear_bit(VP_SCR_NEEDED, &vha->vp_flags); |
| 183 | } |
| 184 | |
| 185 | vha->flags.online = 1; |
| 186 | if (qla24xx_configure_vhba(vha)) |
| 187 | return; |
| 188 | |
| 189 | atomic_set(&vha->vp_state, VP_ACTIVE); |
| 190 | fc_vport_set_state(fc_vport, FC_VPORT_ACTIVE); |
| 191 | } |
| 192 | |
| 193 | void |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame^] | 194 | qla2x00_alert_all_vps(struct qla_hw_data *ha, uint16_t *mb) |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 195 | { |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 196 | scsi_qla_host_t *vha; |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame^] | 197 | int i = 0; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 198 | |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame^] | 199 | list_for_each_entry(vha, &ha->vp_list, list) { |
| 200 | if (vha->vp_idx) { |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 201 | switch (mb[0]) { |
| 202 | case MBA_LIP_OCCURRED: |
| 203 | case MBA_LOOP_UP: |
| 204 | case MBA_LOOP_DOWN: |
| 205 | case MBA_LIP_RESET: |
| 206 | case MBA_POINT_TO_POINT: |
| 207 | case MBA_CHG_IN_CONNECTION: |
| 208 | case MBA_PORT_UPDATE: |
| 209 | case MBA_RSCN_UPDATE: |
| 210 | DEBUG15(printk("scsi(%ld)%s: Async_event for" |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame^] | 211 | " VP[%d], mb = 0x%x, vha=%p\n", |
| 212 | vha->host_no, __func__, i, *mb, vha)); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 213 | qla2x00_async_event(vha, mb); |
| 214 | break; |
| 215 | } |
| 216 | } |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame^] | 217 | i++; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 218 | } |
| 219 | } |
| 220 | |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame^] | 221 | int |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 222 | qla2x00_vp_abort_isp(scsi_qla_host_t *vha) |
| 223 | { |
| 224 | /* |
| 225 | * Physical port will do most of the abort and recovery work. We can |
| 226 | * just treat it as a loop down |
| 227 | */ |
| 228 | if (atomic_read(&vha->loop_state) != LOOP_DOWN) { |
| 229 | atomic_set(&vha->loop_state, LOOP_DOWN); |
| 230 | qla2x00_mark_all_devices_lost(vha, 0); |
| 231 | } else { |
| 232 | if (!atomic_read(&vha->loop_down_timer)) |
| 233 | atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME); |
| 234 | } |
| 235 | |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame^] | 236 | /* To exclusively reset vport, we need to log it out first.*/ |
| 237 | if (!test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) |
| 238 | qla24xx_control_vp(vha, VCE_COMMAND_DISABLE_VPS_LOGO_ALL); |
| 239 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 240 | DEBUG15(printk("scsi(%ld): Scheduling enable of Vport %d...\n", |
| 241 | vha->host_no, vha->vp_idx)); |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame^] | 242 | return qla24xx_enable_vp(vha); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 243 | } |
| 244 | |
Adrian Bunk | a824ebb | 2008-01-17 09:02:15 -0800 | [diff] [blame] | 245 | static int |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 246 | qla2x00_do_dpc_vp(scsi_qla_host_t *vha) |
| 247 | { |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame^] | 248 | struct qla_hw_data *ha = vha->hw; |
| 249 | scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev); |
Seokmann Ju | 221726d | 2008-04-03 13:13:31 -0700 | [diff] [blame] | 250 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 251 | if (test_and_clear_bit(VP_IDX_ACQUIRED, &vha->vp_flags)) { |
| 252 | /* VP acquired. complete port configuration */ |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame^] | 253 | if (atomic_read(&base_vha->loop_state) == LOOP_READY) { |
Seokmann Ju | 221726d | 2008-04-03 13:13:31 -0700 | [diff] [blame] | 254 | qla24xx_configure_vp(vha); |
| 255 | } else { |
| 256 | set_bit(VP_IDX_ACQUIRED, &vha->vp_flags); |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame^] | 257 | set_bit(VP_DPC_NEEDED, &base_vha->dpc_flags); |
Seokmann Ju | 221726d | 2008-04-03 13:13:31 -0700 | [diff] [blame] | 258 | } |
| 259 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 260 | return 0; |
| 261 | } |
| 262 | |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame^] | 263 | if (test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags)) { |
| 264 | qla2x00_update_fcports(vha); |
| 265 | clear_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags); |
| 266 | } |
| 267 | |
| 268 | if ((test_and_clear_bit(RELOGIN_NEEDED, &vha->dpc_flags)) && |
| 269 | !test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) && |
| 270 | atomic_read(&vha->loop_state) != LOOP_DOWN) { |
| 271 | |
| 272 | DEBUG(printk("scsi(%ld): qla2x00_port_login()\n", |
| 273 | vha->host_no)); |
| 274 | qla2x00_relogin(vha); |
| 275 | |
| 276 | DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n", |
| 277 | vha->host_no)); |
| 278 | } |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 279 | |
| 280 | if (test_and_clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) && |
| 281 | (!(test_and_set_bit(RESET_ACTIVE, &vha->dpc_flags)))) { |
| 282 | clear_bit(RESET_ACTIVE, &vha->dpc_flags); |
| 283 | } |
| 284 | |
Seokmann Ju | 5de1f70 | 2008-07-10 16:55:58 -0700 | [diff] [blame] | 285 | if (atomic_read(&vha->vp_state) == VP_ACTIVE && |
| 286 | test_and_clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) { |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 287 | if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags))) { |
| 288 | qla2x00_loop_resync(vha); |
| 289 | clear_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags); |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | return 0; |
| 294 | } |
| 295 | |
| 296 | void |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame^] | 297 | qla2x00_do_dpc_all_vps(scsi_qla_host_t *vha) |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 298 | { |
| 299 | int ret; |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame^] | 300 | struct qla_hw_data *ha = vha->hw; |
| 301 | scsi_qla_host_t *vp; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 302 | |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame^] | 303 | if (vha->vp_idx) |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 304 | return; |
| 305 | if (list_empty(&ha->vp_list)) |
| 306 | return; |
| 307 | |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame^] | 308 | clear_bit(VP_DPC_NEEDED, &vha->dpc_flags); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 309 | |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame^] | 310 | list_for_each_entry(vp, &ha->vp_list, list) { |
| 311 | if (vp->vp_idx) |
| 312 | ret = qla2x00_do_dpc_vp(vp); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 313 | } |
| 314 | } |
| 315 | |
| 316 | int |
| 317 | qla24xx_vport_create_req_sanity_check(struct fc_vport *fc_vport) |
| 318 | { |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame^] | 319 | scsi_qla_host_t *base_vha = shost_priv(fc_vport->shost); |
| 320 | struct qla_hw_data *ha = base_vha->hw; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 321 | scsi_qla_host_t *vha; |
| 322 | uint8_t port_name[WWN_SIZE]; |
| 323 | |
| 324 | if (fc_vport->roles != FC_PORT_ROLE_FCP_INITIATOR) |
| 325 | return VPCERR_UNSUPPORTED; |
| 326 | |
| 327 | /* Check up the F/W and H/W support NPIV */ |
| 328 | if (!ha->flags.npiv_supported) |
| 329 | return VPCERR_UNSUPPORTED; |
| 330 | |
| 331 | /* Check up whether npiv supported switch presented */ |
| 332 | if (!(ha->switch_cap & FLOGI_MID_SUPPORT)) |
| 333 | return VPCERR_NO_FABRIC_SUPP; |
| 334 | |
| 335 | /* Check up unique WWPN */ |
| 336 | u64_to_wwn(fc_vport->port_name, port_name); |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame^] | 337 | if (!memcmp(port_name, base_vha->port_name, WWN_SIZE)) |
Seokmann Ju | 50db6b1 | 2008-01-17 09:02:14 -0800 | [diff] [blame] | 338 | return VPCERR_BAD_WWN; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 339 | vha = qla24xx_find_vhost_by_name(ha, port_name); |
| 340 | if (vha) |
| 341 | return VPCERR_BAD_WWN; |
| 342 | |
| 343 | /* Check up max-npiv-supports */ |
| 344 | if (ha->num_vhosts > ha->max_npiv_vports) { |
Andrew Vasquez | eb66dc6 | 2007-11-12 10:30:58 -0800 | [diff] [blame] | 345 | DEBUG15(printk("scsi(%ld): num_vhosts %ud is bigger than " |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame^] | 346 | "max_npv_vports %ud.\n", base_vha->host_no, |
Andrew Vasquez | eb66dc6 | 2007-11-12 10:30:58 -0800 | [diff] [blame] | 347 | ha->num_vhosts, ha->max_npiv_vports)); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 348 | return VPCERR_UNSUPPORTED; |
| 349 | } |
| 350 | return 0; |
| 351 | } |
| 352 | |
| 353 | scsi_qla_host_t * |
| 354 | qla24xx_create_vhost(struct fc_vport *fc_vport) |
| 355 | { |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame^] | 356 | scsi_qla_host_t *base_vha = shost_priv(fc_vport->shost); |
| 357 | struct qla_hw_data *ha = base_vha->hw; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 358 | scsi_qla_host_t *vha; |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame^] | 359 | struct scsi_host_template *sht = &qla24xx_driver_template; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 360 | struct Scsi_Host *host; |
| 361 | |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame^] | 362 | vha = qla2x00_create_host(sht, ha); |
| 363 | if (!vha) { |
| 364 | DEBUG(printk("qla2xxx: scsi_host_alloc() failed for vport\n")); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 365 | return(NULL); |
| 366 | } |
| 367 | |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame^] | 368 | host = vha->host; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 369 | fc_vport->dd_data = vha; |
| 370 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 371 | /* New host info */ |
| 372 | u64_to_wwn(fc_vport->node_name, vha->node_name); |
| 373 | u64_to_wwn(fc_vport->port_name, vha->port_name); |
| 374 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 375 | vha->fc_vport = fc_vport; |
| 376 | vha->device_flags = 0; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 377 | vha->vp_idx = qla24xx_allocate_vp_id(vha); |
| 378 | if (vha->vp_idx > ha->max_npiv_vports) { |
| 379 | DEBUG15(printk("scsi(%ld): Couldn't allocate vp_id.\n", |
| 380 | vha->host_no)); |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame^] | 381 | goto create_vhost_failed; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 382 | } |
| 383 | vha->mgmt_svr_loop_id = 10 + vha->vp_idx; |
| 384 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 385 | vha->dpc_flags = 0L; |
| 386 | set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags); |
| 387 | set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags); |
| 388 | |
| 389 | /* |
| 390 | * To fix the issue of processing a parent's RSCN for the vport before |
| 391 | * its SCR is complete. |
| 392 | */ |
| 393 | set_bit(VP_SCR_NEEDED, &vha->vp_flags); |
| 394 | atomic_set(&vha->loop_state, LOOP_DOWN); |
| 395 | atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME); |
| 396 | |
| 397 | qla2x00_start_timer(vha, qla2x00_timer, WATCH_INTERVAL); |
| 398 | |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame^] | 399 | host->can_queue = ha->req->length + 128; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 400 | host->this_id = 255; |
| 401 | host->cmd_per_lun = 3; |
| 402 | host->max_cmd_len = MAX_CMDSZ; |
| 403 | host->max_channel = MAX_BUSES - 1; |
| 404 | host->max_lun = MAX_LUNS; |
Seokmann Ju | 711c1d9 | 2008-07-10 16:55:51 -0700 | [diff] [blame] | 405 | host->unique_id = host->host_no; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 406 | host->max_id = MAX_TARGETS_2200; |
| 407 | host->transportt = qla2xxx_transport_vport_template; |
| 408 | |
| 409 | DEBUG15(printk("DEBUG: detect vport hba %ld at address = %p\n", |
| 410 | vha->host_no, vha)); |
| 411 | |
| 412 | vha->flags.init_done = 1; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 413 | |
| 414 | return vha; |
| 415 | |
Anirban Chakraborty | 7b867cf | 2008-11-06 10:40:19 -0800 | [diff] [blame^] | 416 | create_vhost_failed: |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 417 | return NULL; |
| 418 | } |