aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/lpfc/lpfc_init.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/scsi/lpfc/lpfc_init.c')
-rw-r--r--drivers/scsi/lpfc/lpfc_init.c948
1 files changed, 622 insertions, 326 deletions
diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
index 955b2e48d041..f81f85ee190f 100644
--- a/drivers/scsi/lpfc/lpfc_init.c
+++ b/drivers/scsi/lpfc/lpfc_init.c
@@ -27,6 +27,7 @@
27#include <linux/kthread.h> 27#include <linux/kthread.h>
28#include <linux/pci.h> 28#include <linux/pci.h>
29#include <linux/spinlock.h> 29#include <linux/spinlock.h>
30#include <linux/ctype.h>
30 31
31#include <scsi/scsi.h> 32#include <scsi/scsi.h>
32#include <scsi/scsi_device.h> 33#include <scsi/scsi_device.h>
@@ -40,15 +41,20 @@
40#include "lpfc.h" 41#include "lpfc.h"
41#include "lpfc_logmsg.h" 42#include "lpfc_logmsg.h"
42#include "lpfc_crtn.h" 43#include "lpfc_crtn.h"
44#include "lpfc_vport.h"
43#include "lpfc_version.h" 45#include "lpfc_version.h"
46#include "lpfc_vport.h"
44 47
45static int lpfc_parse_vpd(struct lpfc_hba *, uint8_t *, int); 48static int lpfc_parse_vpd(struct lpfc_hba *, uint8_t *, int);
46static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *); 49static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *);
47static int lpfc_post_rcv_buf(struct lpfc_hba *); 50static int lpfc_post_rcv_buf(struct lpfc_hba *);
48 51
49static struct scsi_transport_template *lpfc_transport_template = NULL; 52static struct scsi_transport_template *lpfc_transport_template = NULL;
53static struct scsi_transport_template *lpfc_vport_transport_template = NULL;
50static DEFINE_IDR(lpfc_hba_index); 54static DEFINE_IDR(lpfc_hba_index);
51 55
56
57
52/************************************************************************/ 58/************************************************************************/
53/* */ 59/* */
54/* lpfc_config_port_prep */ 60/* lpfc_config_port_prep */
@@ -61,7 +67,7 @@ static DEFINE_IDR(lpfc_hba_index);
61/* */ 67/* */
62/************************************************************************/ 68/************************************************************************/
63int 69int
64lpfc_config_port_prep(struct lpfc_hba * phba) 70lpfc_config_port_prep(struct lpfc_hba *phba)
65{ 71{
66 lpfc_vpd_t *vp = &phba->vpd; 72 lpfc_vpd_t *vp = &phba->vpd;
67 int i = 0, rc; 73 int i = 0, rc;
@@ -75,12 +81,12 @@ lpfc_config_port_prep(struct lpfc_hba * phba)
75 81
76 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); 82 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
77 if (!pmb) { 83 if (!pmb) {
78 phba->hba_state = LPFC_HBA_ERROR; 84 phba->link_state = LPFC_HBA_ERROR;
79 return -ENOMEM; 85 return -ENOMEM;
80 } 86 }
81 87
82 mb = &pmb->mb; 88 mb = &pmb->mb;
83 phba->hba_state = LPFC_INIT_MBX_CMDS; 89 phba->link_state = LPFC_INIT_MBX_CMDS;
84 90
85 if (lpfc_is_LC_HBA(phba->pcidev->device)) { 91 if (lpfc_is_LC_HBA(phba->pcidev->device)) {
86 if (init_key) { 92 if (init_key) {
@@ -100,9 +106,7 @@ lpfc_config_port_prep(struct lpfc_hba * phba)
100 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); 106 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
101 107
102 if (rc != MBX_SUCCESS) { 108 if (rc != MBX_SUCCESS) {
103 lpfc_printf_log(phba, 109 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
104 KERN_ERR,
105 LOG_MBOX,
106 "%d:0324 Config Port initialization " 110 "%d:0324 Config Port initialization "
107 "error, mbxCmd x%x READ_NVPARM, " 111 "error, mbxCmd x%x READ_NVPARM, "
108 "mbxStatus x%x\n", 112 "mbxStatus x%x\n",
@@ -112,16 +116,18 @@ lpfc_config_port_prep(struct lpfc_hba * phba)
112 return -ERESTART; 116 return -ERESTART;
113 } 117 }
114 memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename, 118 memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename,
115 sizeof (mb->un.varRDnvp.nodename)); 119 sizeof(phba->wwnn));
120 memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname,
121 sizeof(phba->wwpn));
116 } 122 }
117 123
124 phba->sli3_options = 0x0;
125
118 /* Setup and issue mailbox READ REV command */ 126 /* Setup and issue mailbox READ REV command */
119 lpfc_read_rev(phba, pmb); 127 lpfc_read_rev(phba, pmb);
120 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); 128 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
121 if (rc != MBX_SUCCESS) { 129 if (rc != MBX_SUCCESS) {
122 lpfc_printf_log(phba, 130 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
123 KERN_ERR,
124 LOG_INIT,
125 "%d:0439 Adapter failed to init, mbxCmd x%x " 131 "%d:0439 Adapter failed to init, mbxCmd x%x "
126 "READ_REV, mbxStatus x%x\n", 132 "READ_REV, mbxStatus x%x\n",
127 phba->brd_no, 133 phba->brd_no,
@@ -130,6 +136,7 @@ lpfc_config_port_prep(struct lpfc_hba * phba)
130 return -ERESTART; 136 return -ERESTART;
131 } 137 }
132 138
139
133 /* 140 /*
134 * The value of rr must be 1 since the driver set the cv field to 1. 141 * The value of rr must be 1 since the driver set the cv field to 1.
135 * This setting requires the FW to set all revision fields. 142 * This setting requires the FW to set all revision fields.
@@ -144,8 +151,12 @@ lpfc_config_port_prep(struct lpfc_hba * phba)
144 return -ERESTART; 151 return -ERESTART;
145 } 152 }
146 153
154 if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp)
155 return -EINVAL;
156
147 /* Save information as VPD data */ 157 /* Save information as VPD data */
148 vp->rev.rBit = 1; 158 vp->rev.rBit = 1;
159 memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t));
149 vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev; 160 vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev;
150 memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16); 161 memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16);
151 vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev; 162 vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev;
@@ -161,6 +172,13 @@ lpfc_config_port_prep(struct lpfc_hba * phba)
161 vp->rev.postKernRev = mb->un.varRdRev.postKernRev; 172 vp->rev.postKernRev = mb->un.varRdRev.postKernRev;
162 vp->rev.opFwRev = mb->un.varRdRev.opFwRev; 173 vp->rev.opFwRev = mb->un.varRdRev.opFwRev;
163 174
175 /* If the sli feature level is less then 9, we must
176 * tear down all RPIs and VPIs on link down if NPIV
177 * is enabled.
178 */
179 if (vp->rev.feaLevelHigh < 9)
180 phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN;
181
164 if (lpfc_is_LC_HBA(phba->pcidev->device)) 182 if (lpfc_is_LC_HBA(phba->pcidev->device))
165 memcpy(phba->RandomData, (char *)&mb->un.varWords[24], 183 memcpy(phba->RandomData, (char *)&mb->un.varWords[24],
166 sizeof (phba->RandomData)); 184 sizeof (phba->RandomData));
@@ -188,7 +206,7 @@ lpfc_config_port_prep(struct lpfc_hba * phba)
188 if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset) 206 if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset)
189 mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset; 207 mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset;
190 lpfc_sli_pcimem_bcopy(pmb->context2, lpfc_vpd_data + offset, 208 lpfc_sli_pcimem_bcopy(pmb->context2, lpfc_vpd_data + offset,
191 mb->un.varDmp.word_cnt); 209 mb->un.varDmp.word_cnt);
192 offset += mb->un.varDmp.word_cnt; 210 offset += mb->un.varDmp.word_cnt;
193 } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE); 211 } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE);
194 lpfc_parse_vpd(phba, lpfc_vpd_data, offset); 212 lpfc_parse_vpd(phba, lpfc_vpd_data, offset);
@@ -212,48 +230,34 @@ out_free_mbox:
212/* */ 230/* */
213/************************************************************************/ 231/************************************************************************/
214int 232int
215lpfc_config_port_post(struct lpfc_hba * phba) 233lpfc_config_port_post(struct lpfc_hba *phba)
216{ 234{
235 struct lpfc_vport *vport = phba->pport;
217 LPFC_MBOXQ_t *pmb; 236 LPFC_MBOXQ_t *pmb;
218 MAILBOX_t *mb; 237 MAILBOX_t *mb;
219 struct lpfc_dmabuf *mp; 238 struct lpfc_dmabuf *mp;
220 struct lpfc_sli *psli = &phba->sli; 239 struct lpfc_sli *psli = &phba->sli;
221 uint32_t status, timeout; 240 uint32_t status, timeout;
222 int i, j, rc; 241 int i, j;
242 int rc;
223 243
224 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); 244 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
225 if (!pmb) { 245 if (!pmb) {
226 phba->hba_state = LPFC_HBA_ERROR; 246 phba->link_state = LPFC_HBA_ERROR;
227 return -ENOMEM; 247 return -ENOMEM;
228 } 248 }
229 mb = &pmb->mb; 249 mb = &pmb->mb;
230 250
231 lpfc_config_link(phba, pmb);
232 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
233 if (rc != MBX_SUCCESS) {
234 lpfc_printf_log(phba,
235 KERN_ERR,
236 LOG_INIT,
237 "%d:0447 Adapter failed init, mbxCmd x%x "
238 "CONFIG_LINK mbxStatus x%x\n",
239 phba->brd_no,
240 mb->mbxCommand, mb->mbxStatus);
241 phba->hba_state = LPFC_HBA_ERROR;
242 mempool_free( pmb, phba->mbox_mem_pool);
243 return -EIO;
244 }
245
246 /* Get login parameters for NID. */ 251 /* Get login parameters for NID. */
247 lpfc_read_sparam(phba, pmb); 252 lpfc_read_sparam(phba, pmb, 0);
253 pmb->vport = vport;
248 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { 254 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
249 lpfc_printf_log(phba, 255 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
250 KERN_ERR,
251 LOG_INIT,
252 "%d:0448 Adapter failed init, mbxCmd x%x " 256 "%d:0448 Adapter failed init, mbxCmd x%x "
253 "READ_SPARM mbxStatus x%x\n", 257 "READ_SPARM mbxStatus x%x\n",
254 phba->brd_no, 258 phba->brd_no,
255 mb->mbxCommand, mb->mbxStatus); 259 mb->mbxCommand, mb->mbxStatus);
256 phba->hba_state = LPFC_HBA_ERROR; 260 phba->link_state = LPFC_HBA_ERROR;
257 mp = (struct lpfc_dmabuf *) pmb->context1; 261 mp = (struct lpfc_dmabuf *) pmb->context1;
258 mempool_free( pmb, phba->mbox_mem_pool); 262 mempool_free( pmb, phba->mbox_mem_pool);
259 lpfc_mbuf_free(phba, mp->virt, mp->phys); 263 lpfc_mbuf_free(phba, mp->virt, mp->phys);
@@ -263,25 +267,27 @@ lpfc_config_port_post(struct lpfc_hba * phba)
263 267
264 mp = (struct lpfc_dmabuf *) pmb->context1; 268 mp = (struct lpfc_dmabuf *) pmb->context1;
265 269
266 memcpy(&phba->fc_sparam, mp->virt, sizeof (struct serv_parm)); 270 memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm));
267 lpfc_mbuf_free(phba, mp->virt, mp->phys); 271 lpfc_mbuf_free(phba, mp->virt, mp->phys);
268 kfree(mp); 272 kfree(mp);
269 pmb->context1 = NULL; 273 pmb->context1 = NULL;
270 274
271 if (phba->cfg_soft_wwnn) 275 if (phba->cfg_soft_wwnn)
272 u64_to_wwn(phba->cfg_soft_wwnn, phba->fc_sparam.nodeName.u.wwn); 276 u64_to_wwn(phba->cfg_soft_wwnn,
277 vport->fc_sparam.nodeName.u.wwn);
273 if (phba->cfg_soft_wwpn) 278 if (phba->cfg_soft_wwpn)
274 u64_to_wwn(phba->cfg_soft_wwpn, phba->fc_sparam.portName.u.wwn); 279 u64_to_wwn(phba->cfg_soft_wwpn,
275 memcpy(&phba->fc_nodename, &phba->fc_sparam.nodeName, 280 vport->fc_sparam.portName.u.wwn);
281 memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
276 sizeof (struct lpfc_name)); 282 sizeof (struct lpfc_name));
277 memcpy(&phba->fc_portname, &phba->fc_sparam.portName, 283 memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
278 sizeof (struct lpfc_name)); 284 sizeof (struct lpfc_name));
279 /* If no serial number in VPD data, use low 6 bytes of WWNN */ 285 /* If no serial number in VPD data, use low 6 bytes of WWNN */
280 /* This should be consolidated into parse_vpd ? - mr */ 286 /* This should be consolidated into parse_vpd ? - mr */
281 if (phba->SerialNumber[0] == 0) { 287 if (phba->SerialNumber[0] == 0) {
282 uint8_t *outptr; 288 uint8_t *outptr;
283 289
284 outptr = &phba->fc_nodename.u.s.IEEE[0]; 290 outptr = &vport->fc_nodename.u.s.IEEE[0];
285 for (i = 0; i < 12; i++) { 291 for (i = 0; i < 12; i++) {
286 status = *outptr++; 292 status = *outptr++;
287 j = ((status & 0xf0) >> 4); 293 j = ((status & 0xf0) >> 4);
@@ -303,15 +309,14 @@ lpfc_config_port_post(struct lpfc_hba * phba)
303 } 309 }
304 310
305 lpfc_read_config(phba, pmb); 311 lpfc_read_config(phba, pmb);
312 pmb->vport = vport;
306 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) { 313 if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
307 lpfc_printf_log(phba, 314 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
308 KERN_ERR,
309 LOG_INIT,
310 "%d:0453 Adapter failed to init, mbxCmd x%x " 315 "%d:0453 Adapter failed to init, mbxCmd x%x "
311 "READ_CONFIG, mbxStatus x%x\n", 316 "READ_CONFIG, mbxStatus x%x\n",
312 phba->brd_no, 317 phba->brd_no,
313 mb->mbxCommand, mb->mbxStatus); 318 mb->mbxCommand, mb->mbxStatus);
314 phba->hba_state = LPFC_HBA_ERROR; 319 phba->link_state = LPFC_HBA_ERROR;
315 mempool_free( pmb, phba->mbox_mem_pool); 320 mempool_free( pmb, phba->mbox_mem_pool);
316 return -EIO; 321 return -EIO;
317 } 322 }
@@ -338,9 +343,7 @@ lpfc_config_port_post(struct lpfc_hba * phba)
338 || ((phba->cfg_link_speed == LINK_SPEED_10G) 343 || ((phba->cfg_link_speed == LINK_SPEED_10G)
339 && !(phba->lmt & LMT_10Gb))) { 344 && !(phba->lmt & LMT_10Gb))) {
340 /* Reset link speed to auto */ 345 /* Reset link speed to auto */
341 lpfc_printf_log(phba, 346 lpfc_printf_log(phba, KERN_WARNING, LOG_LINK_EVENT,
342 KERN_WARNING,
343 LOG_LINK_EVENT,
344 "%d:1302 Invalid speed for this board: " 347 "%d:1302 Invalid speed for this board: "
345 "Reset link speed to auto: x%x\n", 348 "Reset link speed to auto: x%x\n",
346 phba->brd_no, 349 phba->brd_no,
@@ -348,7 +351,7 @@ lpfc_config_port_post(struct lpfc_hba * phba)
348 phba->cfg_link_speed = LINK_SPEED_AUTO; 351 phba->cfg_link_speed = LINK_SPEED_AUTO;
349 } 352 }
350 353
351 phba->hba_state = LPFC_LINK_DOWN; 354 phba->link_state = LPFC_LINK_DOWN;
352 355
353 /* Only process IOCBs on ring 0 till hba_state is READY */ 356 /* Only process IOCBs on ring 0 till hba_state is READY */
354 if (psli->ring[psli->extra_ring].cmdringaddr) 357 if (psli->ring[psli->extra_ring].cmdringaddr)
@@ -359,10 +362,11 @@ lpfc_config_port_post(struct lpfc_hba * phba)
359 psli->ring[psli->next_ring].flag |= LPFC_STOP_IOCB_EVENT; 362 psli->ring[psli->next_ring].flag |= LPFC_STOP_IOCB_EVENT;
360 363
361 /* Post receive buffers for desired rings */ 364 /* Post receive buffers for desired rings */
362 lpfc_post_rcv_buf(phba); 365 if (phba->sli_rev != 3)
366 lpfc_post_rcv_buf(phba);
363 367
364 /* Enable appropriate host interrupts */ 368 /* Enable appropriate host interrupts */
365 spin_lock_irq(phba->host->host_lock); 369 spin_lock_irq(&phba->hbalock);
366 status = readl(phba->HCregaddr); 370 status = readl(phba->HCregaddr);
367 status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA; 371 status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA;
368 if (psli->num_rings > 0) 372 if (psli->num_rings > 0)
@@ -380,22 +384,24 @@ lpfc_config_port_post(struct lpfc_hba * phba)
380 384
381 writel(status, phba->HCregaddr); 385 writel(status, phba->HCregaddr);
382 readl(phba->HCregaddr); /* flush */ 386 readl(phba->HCregaddr); /* flush */
383 spin_unlock_irq(phba->host->host_lock); 387 spin_unlock_irq(&phba->hbalock);
384 388
385 /* 389 /*
386 * Setup the ring 0 (els) timeout handler 390 * Setup the ring 0 (els) timeout handler
387 */ 391 */
388 timeout = phba->fc_ratov << 1; 392 timeout = phba->fc_ratov << 1;
389 mod_timer(&phba->els_tmofunc, jiffies + HZ * timeout); 393 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
394 mod_timer(&phba->hb_tmofunc, jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
395 phba->hb_outstanding = 0;
396 phba->last_completion_time = jiffies;
390 397
391 lpfc_init_link(phba, pmb, phba->cfg_topology, phba->cfg_link_speed); 398 lpfc_init_link(phba, pmb, phba->cfg_topology, phba->cfg_link_speed);
392 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; 399 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
400 pmb->vport = vport;
393 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); 401 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
394 lpfc_set_loopback_flag(phba); 402 lpfc_set_loopback_flag(phba);
395 if (rc != MBX_SUCCESS) { 403 if (rc != MBX_SUCCESS) {
396 lpfc_printf_log(phba, 404 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
397 KERN_ERR,
398 LOG_INIT,
399 "%d:0454 Adapter failed to init, mbxCmd x%x " 405 "%d:0454 Adapter failed to init, mbxCmd x%x "
400 "INIT_LINK, mbxStatus x%x\n", 406 "INIT_LINK, mbxStatus x%x\n",
401 phba->brd_no, 407 phba->brd_no,
@@ -408,7 +414,7 @@ lpfc_config_port_post(struct lpfc_hba * phba)
408 writel(0xffffffff, phba->HAregaddr); 414 writel(0xffffffff, phba->HAregaddr);
409 readl(phba->HAregaddr); /* flush */ 415 readl(phba->HAregaddr); /* flush */
410 416
411 phba->hba_state = LPFC_HBA_ERROR; 417 phba->link_state = LPFC_HBA_ERROR;
412 if (rc != MBX_BUSY) 418 if (rc != MBX_BUSY)
413 mempool_free(pmb, phba->mbox_mem_pool); 419 mempool_free(pmb, phba->mbox_mem_pool);
414 return -EIO; 420 return -EIO;
@@ -429,18 +435,19 @@ lpfc_config_port_post(struct lpfc_hba * phba)
429/* */ 435/* */
430/************************************************************************/ 436/************************************************************************/
431int 437int
432lpfc_hba_down_prep(struct lpfc_hba * phba) 438lpfc_hba_down_prep(struct lpfc_hba *phba)
433{ 439{
440 struct lpfc_vport *vport = phba->pport;
441
434 /* Disable interrupts */ 442 /* Disable interrupts */
435 writel(0, phba->HCregaddr); 443 writel(0, phba->HCregaddr);
436 readl(phba->HCregaddr); /* flush */ 444 readl(phba->HCregaddr); /* flush */
437 445
438 /* Cleanup potential discovery resources */ 446 list_for_each_entry(vport, &phba->port_list, listentry) {
439 lpfc_els_flush_rscn(phba); 447 lpfc_cleanup_discovery_resources(vport);
440 lpfc_els_flush_cmd(phba); 448 }
441 lpfc_disc_flush_list(phba);
442 449
443 return (0); 450 return 0;
444} 451}
445 452
446/************************************************************************/ 453/************************************************************************/
@@ -453,20 +460,24 @@ lpfc_hba_down_prep(struct lpfc_hba * phba)
453/* */ 460/* */
454/************************************************************************/ 461/************************************************************************/
455int 462int
456lpfc_hba_down_post(struct lpfc_hba * phba) 463lpfc_hba_down_post(struct lpfc_hba *phba)
457{ 464{
458 struct lpfc_sli *psli = &phba->sli; 465 struct lpfc_sli *psli = &phba->sli;
459 struct lpfc_sli_ring *pring; 466 struct lpfc_sli_ring *pring;
460 struct lpfc_dmabuf *mp, *next_mp; 467 struct lpfc_dmabuf *mp, *next_mp;
461 int i; 468 int i;
462 469
463 /* Cleanup preposted buffers on the ELS ring */ 470 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)
464 pring = &psli->ring[LPFC_ELS_RING]; 471 lpfc_sli_hbqbuf_free_all(phba);
465 list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) { 472 else {
466 list_del(&mp->list); 473 /* Cleanup preposted buffers on the ELS ring */
467 pring->postbufq_cnt--; 474 pring = &psli->ring[LPFC_ELS_RING];
468 lpfc_mbuf_free(phba, mp->virt, mp->phys); 475 list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
469 kfree(mp); 476 list_del(&mp->list);
477 pring->postbufq_cnt--;
478 lpfc_mbuf_free(phba, mp->virt, mp->phys);
479 kfree(mp);
480 }
470 } 481 }
471 482
472 for (i = 0; i < psli->num_rings; i++) { 483 for (i = 0; i < psli->num_rings; i++) {
@@ -477,6 +488,119 @@ lpfc_hba_down_post(struct lpfc_hba * phba)
477 return 0; 488 return 0;
478} 489}
479 490
491/* HBA heart beat timeout handler */
492void
493lpfc_hb_timeout(unsigned long ptr)
494{
495 struct lpfc_hba *phba;
496 unsigned long iflag;
497
498 phba = (struct lpfc_hba *)ptr;
499 spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
500 if (!(phba->pport->work_port_events & WORKER_HB_TMO))
501 phba->pport->work_port_events |= WORKER_HB_TMO;
502 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
503
504 if (phba->work_wait)
505 wake_up(phba->work_wait);
506 return;
507}
508
509static void
510lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
511{
512 unsigned long drvr_flag;
513
514 spin_lock_irqsave(&phba->hbalock, drvr_flag);
515 phba->hb_outstanding = 0;
516 spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
517
518 mempool_free(pmboxq, phba->mbox_mem_pool);
519 if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) &&
520 !(phba->link_state == LPFC_HBA_ERROR) &&
521 !(phba->pport->fc_flag & FC_UNLOADING))
522 mod_timer(&phba->hb_tmofunc,
523 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
524 return;
525}
526
527void
528lpfc_hb_timeout_handler(struct lpfc_hba *phba)
529{
530 LPFC_MBOXQ_t *pmboxq;
531 int retval;
532 struct lpfc_sli *psli = &phba->sli;
533
534 if ((phba->link_state == LPFC_HBA_ERROR) ||
535 (phba->pport->fc_flag & FC_UNLOADING) ||
536 (phba->pport->fc_flag & FC_OFFLINE_MODE))
537 return;
538
539 spin_lock_irq(&phba->pport->work_port_lock);
540 /* If the timer is already canceled do nothing */
541 if (!(phba->pport->work_port_events & WORKER_HB_TMO)) {
542 spin_unlock_irq(&phba->pport->work_port_lock);
543 return;
544 }
545
546 if (time_after(phba->last_completion_time + LPFC_HB_MBOX_INTERVAL * HZ,
547 jiffies)) {
548 spin_unlock_irq(&phba->pport->work_port_lock);
549 if (!phba->hb_outstanding)
550 mod_timer(&phba->hb_tmofunc,
551 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
552 else
553 mod_timer(&phba->hb_tmofunc,
554 jiffies + HZ * LPFC_HB_MBOX_TIMEOUT);
555 return;
556 }
557 spin_unlock_irq(&phba->pport->work_port_lock);
558
559 /* If there is no heart beat outstanding, issue a heartbeat command */
560 if (!phba->hb_outstanding) {
561 pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
562 if (!pmboxq) {
563 mod_timer(&phba->hb_tmofunc,
564 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
565 return;
566 }
567
568 lpfc_heart_beat(phba, pmboxq);
569 pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl;
570 pmboxq->vport = phba->pport;
571 retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
572
573 if (retval != MBX_BUSY && retval != MBX_SUCCESS) {
574 mempool_free(pmboxq, phba->mbox_mem_pool);
575 mod_timer(&phba->hb_tmofunc,
576 jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
577 return;
578 }
579 mod_timer(&phba->hb_tmofunc,
580 jiffies + HZ * LPFC_HB_MBOX_TIMEOUT);
581 phba->hb_outstanding = 1;
582 return;
583 } else {
584 /*
585 * If heart beat timeout called with hb_outstanding set we
586 * need to take the HBA offline.
587 */
588 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
589 "%d:0459 Adapter heartbeat failure, taking "
590 "this port offline.\n", phba->brd_no);
591
592 spin_lock_irq(&phba->hbalock);
593 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
594 spin_unlock_irq(&phba->hbalock);
595
596 lpfc_offline_prep(phba);
597 lpfc_offline(phba);
598 lpfc_unblock_mgmt_io(phba);
599 phba->link_state = LPFC_HBA_ERROR;
600 lpfc_hba_down_post(phba);
601 }
602}
603
480/************************************************************************/ 604/************************************************************************/
481/* */ 605/* */
482/* lpfc_handle_eratt */ 606/* lpfc_handle_eratt */
@@ -486,11 +610,15 @@ lpfc_hba_down_post(struct lpfc_hba * phba)
486/* */ 610/* */
487/************************************************************************/ 611/************************************************************************/
488void 612void
489lpfc_handle_eratt(struct lpfc_hba * phba) 613lpfc_handle_eratt(struct lpfc_hba *phba)
490{ 614{
491 struct lpfc_sli *psli = &phba->sli; 615 struct lpfc_vport *vport = phba->pport;
616 struct lpfc_sli *psli = &phba->sli;
492 struct lpfc_sli_ring *pring; 617 struct lpfc_sli_ring *pring;
618 struct lpfc_vport *port_iterator;
493 uint32_t event_data; 619 uint32_t event_data;
620 struct Scsi_Host *shost;
621
494 /* If the pci channel is offline, ignore possible errors, 622 /* If the pci channel is offline, ignore possible errors,
495 * since we cannot communicate with the pci card anyway. */ 623 * since we cannot communicate with the pci card anyway. */
496 if (pci_channel_offline(phba->pcidev)) 624 if (pci_channel_offline(phba->pcidev))
@@ -504,10 +632,17 @@ lpfc_handle_eratt(struct lpfc_hba * phba)
504 "Data: x%x x%x x%x\n", 632 "Data: x%x x%x x%x\n",
505 phba->brd_no, phba->work_hs, 633 phba->brd_no, phba->work_hs,
506 phba->work_status[0], phba->work_status[1]); 634 phba->work_status[0], phba->work_status[1]);
507 spin_lock_irq(phba->host->host_lock); 635 list_for_each_entry(port_iterator, &phba->port_list,
508 phba->fc_flag |= FC_ESTABLISH_LINK; 636 listentry) {
637 shost = lpfc_shost_from_vport(port_iterator);
638
639 spin_lock_irq(shost->host_lock);
640 port_iterator->fc_flag |= FC_ESTABLISH_LINK;
641 spin_unlock_irq(shost->host_lock);
642 }
643 spin_lock_irq(&phba->hbalock);
509 psli->sli_flag &= ~LPFC_SLI2_ACTIVE; 644 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
510 spin_unlock_irq(phba->host->host_lock); 645 spin_unlock_irq(&phba->hbalock);
511 646
512 /* 647 /*
513 * Firmware stops when it triggled erratt with HS_FFER6. 648 * Firmware stops when it triggled erratt with HS_FFER6.
@@ -544,15 +679,18 @@ lpfc_handle_eratt(struct lpfc_hba * phba)
544 phba->work_status[0], phba->work_status[1]); 679 phba->work_status[0], phba->work_status[1]);
545 680
546 event_data = FC_REG_DUMP_EVENT; 681 event_data = FC_REG_DUMP_EVENT;
547 fc_host_post_vendor_event(phba->host, fc_get_event_number(), 682 shost = lpfc_shost_from_vport(vport);
683 fc_host_post_vendor_event(shost, fc_get_event_number(),
548 sizeof(event_data), (char *) &event_data, 684 sizeof(event_data), (char *) &event_data,
549 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX); 685 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
550 686
687 spin_lock_irq(&phba->hbalock);
551 psli->sli_flag &= ~LPFC_SLI2_ACTIVE; 688 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
689 spin_unlock_irq(&phba->hbalock);
552 lpfc_offline_prep(phba); 690 lpfc_offline_prep(phba);
553 lpfc_offline(phba); 691 lpfc_offline(phba);
554 lpfc_unblock_mgmt_io(phba); 692 lpfc_unblock_mgmt_io(phba);
555 phba->hba_state = LPFC_HBA_ERROR; 693 phba->link_state = LPFC_HBA_ERROR;
556 lpfc_hba_down_post(phba); 694 lpfc_hba_down_post(phba);
557 } 695 }
558} 696}
@@ -566,9 +704,11 @@ lpfc_handle_eratt(struct lpfc_hba * phba)
566/* */ 704/* */
567/************************************************************************/ 705/************************************************************************/
568void 706void
569lpfc_handle_latt(struct lpfc_hba * phba) 707lpfc_handle_latt(struct lpfc_hba *phba)
570{ 708{
571 struct lpfc_sli *psli = &phba->sli; 709 struct lpfc_vport *vport = phba->pport;
710 struct lpfc_sli *psli = &phba->sli;
711 struct lpfc_vport *port_iterator;
572 LPFC_MBOXQ_t *pmb; 712 LPFC_MBOXQ_t *pmb;
573 volatile uint32_t control; 713 volatile uint32_t control;
574 struct lpfc_dmabuf *mp; 714 struct lpfc_dmabuf *mp;
@@ -589,20 +729,22 @@ lpfc_handle_latt(struct lpfc_hba * phba)
589 rc = -EIO; 729 rc = -EIO;
590 730
591 /* Cleanup any outstanding ELS commands */ 731 /* Cleanup any outstanding ELS commands */
592 lpfc_els_flush_cmd(phba); 732 list_for_each_entry(port_iterator, &phba->port_list, listentry)
733 lpfc_els_flush_cmd(port_iterator);
593 734
594 psli->slistat.link_event++; 735 psli->slistat.link_event++;
595 lpfc_read_la(phba, pmb, mp); 736 lpfc_read_la(phba, pmb, mp);
596 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_la; 737 pmb->mbox_cmpl = lpfc_mbx_cmpl_read_la;
738 pmb->vport = vport;
597 rc = lpfc_sli_issue_mbox (phba, pmb, (MBX_NOWAIT | MBX_STOP_IOCB)); 739 rc = lpfc_sli_issue_mbox (phba, pmb, (MBX_NOWAIT | MBX_STOP_IOCB));
598 if (rc == MBX_NOT_FINISHED) 740 if (rc == MBX_NOT_FINISHED)
599 goto lpfc_handle_latt_free_mbuf; 741 goto lpfc_handle_latt_free_mbuf;
600 742
601 /* Clear Link Attention in HA REG */ 743 /* Clear Link Attention in HA REG */
602 spin_lock_irq(phba->host->host_lock); 744 spin_lock_irq(&phba->hbalock);
603 writel(HA_LATT, phba->HAregaddr); 745 writel(HA_LATT, phba->HAregaddr);
604 readl(phba->HAregaddr); /* flush */ 746 readl(phba->HAregaddr); /* flush */
605 spin_unlock_irq(phba->host->host_lock); 747 spin_unlock_irq(&phba->hbalock);
606 748
607 return; 749 return;
608 750
@@ -614,7 +756,7 @@ lpfc_handle_latt_free_pmb:
614 mempool_free(pmb, phba->mbox_mem_pool); 756 mempool_free(pmb, phba->mbox_mem_pool);
615lpfc_handle_latt_err_exit: 757lpfc_handle_latt_err_exit:
616 /* Enable Link attention interrupts */ 758 /* Enable Link attention interrupts */
617 spin_lock_irq(phba->host->host_lock); 759 spin_lock_irq(&phba->hbalock);
618 psli->sli_flag |= LPFC_PROCESS_LA; 760 psli->sli_flag |= LPFC_PROCESS_LA;
619 control = readl(phba->HCregaddr); 761 control = readl(phba->HCregaddr);
620 control |= HC_LAINT_ENA; 762 control |= HC_LAINT_ENA;
@@ -624,15 +766,13 @@ lpfc_handle_latt_err_exit:
624 /* Clear Link Attention in HA REG */ 766 /* Clear Link Attention in HA REG */
625 writel(HA_LATT, phba->HAregaddr); 767 writel(HA_LATT, phba->HAregaddr);
626 readl(phba->HAregaddr); /* flush */ 768 readl(phba->HAregaddr); /* flush */
627 spin_unlock_irq(phba->host->host_lock); 769 spin_unlock_irq(&phba->hbalock);
628 lpfc_linkdown(phba); 770 lpfc_linkdown(phba);
629 phba->hba_state = LPFC_HBA_ERROR; 771 phba->link_state = LPFC_HBA_ERROR;
630 772
631 /* The other case is an error from issue_mbox */ 773 /* The other case is an error from issue_mbox */
632 if (rc == -ENOMEM) 774 if (rc == -ENOMEM)
633 lpfc_printf_log(phba, 775 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
634 KERN_WARNING,
635 LOG_MBOX,
636 "%d:0300 READ_LA: no buffers\n", 776 "%d:0300 READ_LA: no buffers\n",
637 phba->brd_no); 777 phba->brd_no);
638 778
@@ -646,7 +786,7 @@ lpfc_handle_latt_err_exit:
646/* */ 786/* */
647/************************************************************************/ 787/************************************************************************/
648static int 788static int
649lpfc_parse_vpd(struct lpfc_hba * phba, uint8_t * vpd, int len) 789lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len)
650{ 790{
651 uint8_t lenlo, lenhi; 791 uint8_t lenlo, lenhi;
652 int Length; 792 int Length;
@@ -658,9 +798,7 @@ lpfc_parse_vpd(struct lpfc_hba * phba, uint8_t * vpd, int len)
658 return 0; 798 return 0;
659 799
660 /* Vital Product */ 800 /* Vital Product */
661 lpfc_printf_log(phba, 801 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
662 KERN_INFO,
663 LOG_INIT,
664 "%d:0455 Vital Product Data: x%x x%x x%x x%x\n", 802 "%d:0455 Vital Product Data: x%x x%x x%x x%x\n",
665 phba->brd_no, 803 phba->brd_no,
666 (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2], 804 (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
@@ -785,7 +923,7 @@ lpfc_parse_vpd(struct lpfc_hba * phba, uint8_t * vpd, int len)
785} 923}
786 924
787static void 925static void
788lpfc_get_hba_model_desc(struct lpfc_hba * phba, uint8_t * mdp, uint8_t * descp) 926lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
789{ 927{
790 lpfc_vpd_t *vp; 928 lpfc_vpd_t *vp;
791 uint16_t dev_id = phba->pcidev->device; 929 uint16_t dev_id = phba->pcidev->device;
@@ -943,7 +1081,7 @@ lpfc_get_hba_model_desc(struct lpfc_hba * phba, uint8_t * mdp, uint8_t * descp)
943/* Returns the number of buffers NOT posted. */ 1081/* Returns the number of buffers NOT posted. */
944/**************************************************/ 1082/**************************************************/
945int 1083int
946lpfc_post_buffer(struct lpfc_hba * phba, struct lpfc_sli_ring * pring, int cnt, 1084lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt,
947 int type) 1085 int type)
948{ 1086{
949 IOCB_t *icmd; 1087 IOCB_t *icmd;
@@ -955,9 +1093,7 @@ lpfc_post_buffer(struct lpfc_hba * phba, struct lpfc_sli_ring * pring, int cnt,
955 /* While there are buffers to post */ 1093 /* While there are buffers to post */
956 while (cnt > 0) { 1094 while (cnt > 0) {
957 /* Allocate buffer for command iocb */ 1095 /* Allocate buffer for command iocb */
958 spin_lock_irq(phba->host->host_lock);
959 iocb = lpfc_sli_get_iocbq(phba); 1096 iocb = lpfc_sli_get_iocbq(phba);
960 spin_unlock_irq(phba->host->host_lock);
961 if (iocb == NULL) { 1097 if (iocb == NULL) {
962 pring->missbufcnt = cnt; 1098 pring->missbufcnt = cnt;
963 return cnt; 1099 return cnt;
@@ -972,9 +1108,7 @@ lpfc_post_buffer(struct lpfc_hba * phba, struct lpfc_sli_ring * pring, int cnt,
972 &mp1->phys); 1108 &mp1->phys);
973 if (mp1 == 0 || mp1->virt == 0) { 1109 if (mp1 == 0 || mp1->virt == 0) {
974 kfree(mp1); 1110 kfree(mp1);
975 spin_lock_irq(phba->host->host_lock);
976 lpfc_sli_release_iocbq(phba, iocb); 1111 lpfc_sli_release_iocbq(phba, iocb);
977 spin_unlock_irq(phba->host->host_lock);
978 pring->missbufcnt = cnt; 1112 pring->missbufcnt = cnt;
979 return cnt; 1113 return cnt;
980 } 1114 }
@@ -990,9 +1124,7 @@ lpfc_post_buffer(struct lpfc_hba * phba, struct lpfc_sli_ring * pring, int cnt,
990 kfree(mp2); 1124 kfree(mp2);
991 lpfc_mbuf_free(phba, mp1->virt, mp1->phys); 1125 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
992 kfree(mp1); 1126 kfree(mp1);
993 spin_lock_irq(phba->host->host_lock);
994 lpfc_sli_release_iocbq(phba, iocb); 1127 lpfc_sli_release_iocbq(phba, iocb);
995 spin_unlock_irq(phba->host->host_lock);
996 pring->missbufcnt = cnt; 1128 pring->missbufcnt = cnt;
997 return cnt; 1129 return cnt;
998 } 1130 }
@@ -1018,7 +1150,6 @@ lpfc_post_buffer(struct lpfc_hba * phba, struct lpfc_sli_ring * pring, int cnt,
1018 icmd->ulpCommand = CMD_QUE_RING_BUF64_CN; 1150 icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
1019 icmd->ulpLe = 1; 1151 icmd->ulpLe = 1;
1020 1152
1021 spin_lock_irq(phba->host->host_lock);
1022 if (lpfc_sli_issue_iocb(phba, pring, iocb, 0) == IOCB_ERROR) { 1153 if (lpfc_sli_issue_iocb(phba, pring, iocb, 0) == IOCB_ERROR) {
1023 lpfc_mbuf_free(phba, mp1->virt, mp1->phys); 1154 lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
1024 kfree(mp1); 1155 kfree(mp1);
@@ -1030,14 +1161,11 @@ lpfc_post_buffer(struct lpfc_hba * phba, struct lpfc_sli_ring * pring, int cnt,
1030 } 1161 }
1031 lpfc_sli_release_iocbq(phba, iocb); 1162 lpfc_sli_release_iocbq(phba, iocb);
1032 pring->missbufcnt = cnt; 1163 pring->missbufcnt = cnt;
1033 spin_unlock_irq(phba->host->host_lock);
1034 return cnt; 1164 return cnt;
1035 } 1165 }
1036 spin_unlock_irq(phba->host->host_lock);
1037 lpfc_sli_ringpostbuf_put(phba, pring, mp1); 1166 lpfc_sli_ringpostbuf_put(phba, pring, mp1);
1038 if (mp2) { 1167 if (mp2)
1039 lpfc_sli_ringpostbuf_put(phba, pring, mp2); 1168 lpfc_sli_ringpostbuf_put(phba, pring, mp2);
1040 }
1041 } 1169 }
1042 pring->missbufcnt = 0; 1170 pring->missbufcnt = 0;
1043 return 0; 1171 return 0;
@@ -1050,7 +1178,7 @@ lpfc_post_buffer(struct lpfc_hba * phba, struct lpfc_sli_ring * pring, int cnt,
1050/* */ 1178/* */
1051/************************************************************************/ 1179/************************************************************************/
1052static int 1180static int
1053lpfc_post_rcv_buf(struct lpfc_hba * phba) 1181lpfc_post_rcv_buf(struct lpfc_hba *phba)
1054{ 1182{
1055 struct lpfc_sli *psli = &phba->sli; 1183 struct lpfc_sli *psli = &phba->sli;
1056 1184
@@ -1151,7 +1279,7 @@ lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
1151{ 1279{
1152 int t; 1280 int t;
1153 uint32_t *HashWorking; 1281 uint32_t *HashWorking;
1154 uint32_t *pwwnn = phba->wwnn; 1282 uint32_t *pwwnn = (uint32_t *) phba->wwnn;
1155 1283
1156 HashWorking = kmalloc(80 * sizeof(uint32_t), GFP_KERNEL); 1284 HashWorking = kmalloc(80 * sizeof(uint32_t), GFP_KERNEL);
1157 if (!HashWorking) 1285 if (!HashWorking)
@@ -1170,64 +1298,76 @@ lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
1170} 1298}
1171 1299
1172static void 1300static void
1173lpfc_cleanup(struct lpfc_hba * phba) 1301lpfc_cleanup(struct lpfc_vport *vport)
1174{ 1302{
1175 struct lpfc_nodelist *ndlp, *next_ndlp; 1303 struct lpfc_nodelist *ndlp, *next_ndlp;
1176 1304
1177 /* clean up phba - lpfc specific */ 1305 /* clean up phba - lpfc specific */
1178 lpfc_can_disctmo(phba); 1306 lpfc_can_disctmo(vport);
1179 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_nodes, nlp_listp) 1307 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp)
1180 lpfc_nlp_put(ndlp); 1308 lpfc_nlp_put(ndlp);
1181
1182 INIT_LIST_HEAD(&phba->fc_nodes);
1183
1184 return; 1309 return;
1185} 1310}
1186 1311
1187static void 1312static void
1188lpfc_establish_link_tmo(unsigned long ptr) 1313lpfc_establish_link_tmo(unsigned long ptr)
1189{ 1314{
1190 struct lpfc_hba *phba = (struct lpfc_hba *)ptr; 1315 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
1316 struct lpfc_vport *vport = phba->pport;
1191 unsigned long iflag; 1317 unsigned long iflag;
1192 1318
1193
1194 /* Re-establishing Link, timer expired */ 1319 /* Re-establishing Link, timer expired */
1195 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, 1320 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
1196 "%d:1300 Re-establishing Link, timer expired " 1321 "%d:1300 Re-establishing Link, timer expired "
1197 "Data: x%x x%x\n", 1322 "Data: x%x x%x\n",
1198 phba->brd_no, phba->fc_flag, phba->hba_state); 1323 phba->brd_no, vport->fc_flag,
1199 spin_lock_irqsave(phba->host->host_lock, iflag); 1324 vport->port_state);
1200 phba->fc_flag &= ~FC_ESTABLISH_LINK; 1325 list_for_each_entry(vport, &phba->port_list, listentry) {
1201 spin_unlock_irqrestore(phba->host->host_lock, iflag); 1326 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1327
1328 spin_lock_irqsave(shost->host_lock, iflag);
1329 vport->fc_flag &= ~FC_ESTABLISH_LINK;
1330 spin_unlock_irqrestore(shost->host_lock, iflag);
1331 }
1202} 1332}
1203 1333
1204static int 1334void
1205lpfc_stop_timer(struct lpfc_hba * phba) 1335lpfc_stop_vport_timers(struct lpfc_vport *vport)
1206{ 1336{
1207 struct lpfc_sli *psli = &phba->sli; 1337 del_timer_sync(&vport->els_tmofunc);
1338 del_timer_sync(&vport->fc_fdmitmo);
1339 lpfc_can_disctmo(vport);
1340 return;
1341}
1342
1343static void
1344lpfc_stop_phba_timers(struct lpfc_hba *phba)
1345{
1346 struct lpfc_vport *vport;
1208 1347
1209 del_timer_sync(&phba->fcp_poll_timer); 1348 del_timer_sync(&phba->fcp_poll_timer);
1210 del_timer_sync(&phba->fc_estabtmo); 1349 del_timer_sync(&phba->fc_estabtmo);
1211 del_timer_sync(&phba->fc_disctmo); 1350 list_for_each_entry(vport, &phba->port_list, listentry)
1212 del_timer_sync(&phba->fc_fdmitmo); 1351 lpfc_stop_vport_timers(vport);
1213 del_timer_sync(&phba->els_tmofunc); 1352 del_timer_sync(&phba->sli.mbox_tmo);
1214 psli = &phba->sli; 1353 del_timer_sync(&phba->fabric_block_timer);
1215 del_timer_sync(&psli->mbox_tmo); 1354 phba->hb_outstanding = 0;
1216 return(1); 1355 del_timer_sync(&phba->hb_tmofunc);
1356 return;
1217} 1357}
1218 1358
1219int 1359int
1220lpfc_online(struct lpfc_hba * phba) 1360lpfc_online(struct lpfc_hba *phba)
1221{ 1361{
1362 struct lpfc_vport *vport = phba->pport;
1363
1222 if (!phba) 1364 if (!phba)
1223 return 0; 1365 return 0;
1224 1366
1225 if (!(phba->fc_flag & FC_OFFLINE_MODE)) 1367 if (!(vport->fc_flag & FC_OFFLINE_MODE))
1226 return 0; 1368 return 0;
1227 1369
1228 lpfc_printf_log(phba, 1370 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1229 KERN_WARNING,
1230 LOG_INIT,
1231 "%d:0458 Bring Adapter online\n", 1371 "%d:0458 Bring Adapter online\n",
1232 phba->brd_no); 1372 phba->brd_no);
1233 1373
@@ -1243,9 +1383,14 @@ lpfc_online(struct lpfc_hba * phba)
1243 return 1; 1383 return 1;
1244 } 1384 }
1245 1385
1246 spin_lock_irq(phba->host->host_lock); 1386 list_for_each_entry(vport, &phba->port_list, listentry) {
1247 phba->fc_flag &= ~FC_OFFLINE_MODE; 1387 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1248 spin_unlock_irq(phba->host->host_lock); 1388 spin_lock_irq(shost->host_lock);
1389 vport->fc_flag &= ~FC_OFFLINE_MODE;
1390 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
1391 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
1392 spin_unlock_irq(shost->host_lock);
1393 }
1249 1394
1250 lpfc_unblock_mgmt_io(phba); 1395 lpfc_unblock_mgmt_io(phba);
1251 return 0; 1396 return 0;
@@ -1256,9 +1401,9 @@ lpfc_block_mgmt_io(struct lpfc_hba * phba)
1256{ 1401{
1257 unsigned long iflag; 1402 unsigned long iflag;
1258 1403
1259 spin_lock_irqsave(phba->host->host_lock, iflag); 1404 spin_lock_irqsave(&phba->hbalock, iflag);
1260 phba->fc_flag |= FC_BLOCK_MGMT_IO; 1405 phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO;
1261 spin_unlock_irqrestore(phba->host->host_lock, iflag); 1406 spin_unlock_irqrestore(&phba->hbalock, iflag);
1262} 1407}
1263 1408
1264void 1409void
@@ -1266,17 +1411,18 @@ lpfc_unblock_mgmt_io(struct lpfc_hba * phba)
1266{ 1411{
1267 unsigned long iflag; 1412 unsigned long iflag;
1268 1413
1269 spin_lock_irqsave(phba->host->host_lock, iflag); 1414 spin_lock_irqsave(&phba->hbalock, iflag);
1270 phba->fc_flag &= ~FC_BLOCK_MGMT_IO; 1415 phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO;
1271 spin_unlock_irqrestore(phba->host->host_lock, iflag); 1416 spin_unlock_irqrestore(&phba->hbalock, iflag);
1272} 1417}
1273 1418
1274void 1419void
1275lpfc_offline_prep(struct lpfc_hba * phba) 1420lpfc_offline_prep(struct lpfc_hba * phba)
1276{ 1421{
1422 struct lpfc_vport *vport = phba->pport;
1277 struct lpfc_nodelist *ndlp, *next_ndlp; 1423 struct lpfc_nodelist *ndlp, *next_ndlp;
1278 1424
1279 if (phba->fc_flag & FC_OFFLINE_MODE) 1425 if (vport->fc_flag & FC_OFFLINE_MODE)
1280 return; 1426 return;
1281 1427
1282 lpfc_block_mgmt_io(phba); 1428 lpfc_block_mgmt_io(phba);
@@ -1284,39 +1430,49 @@ lpfc_offline_prep(struct lpfc_hba * phba)
1284 lpfc_linkdown(phba); 1430 lpfc_linkdown(phba);
1285 1431
1286 /* Issue an unreg_login to all nodes */ 1432 /* Issue an unreg_login to all nodes */
1287 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_nodes, nlp_listp) 1433 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp)
1288 if (ndlp->nlp_state != NLP_STE_UNUSED_NODE) 1434 if (ndlp->nlp_state != NLP_STE_UNUSED_NODE)
1289 lpfc_unreg_rpi(phba, ndlp); 1435 lpfc_unreg_rpi(vport, ndlp);
1290 1436
1291 lpfc_sli_flush_mbox_queue(phba); 1437 lpfc_sli_flush_mbox_queue(phba);
1292} 1438}
1293 1439
1294void 1440void
1295lpfc_offline(struct lpfc_hba * phba) 1441lpfc_offline(struct lpfc_hba *phba)
1296{ 1442{
1297 unsigned long iflag; 1443 struct lpfc_vport *vport = phba->pport;
1444 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1445 struct lpfc_vport *port_iterator;
1298 1446
1299 if (phba->fc_flag & FC_OFFLINE_MODE) 1447 if (vport->fc_flag & FC_OFFLINE_MODE)
1300 return; 1448 return;
1301 1449
1302 /* stop all timers associated with this hba */ 1450 /* stop all timers associated with this hba */
1303 lpfc_stop_timer(phba); 1451 lpfc_stop_phba_timers(phba);
1452 list_for_each_entry(port_iterator, &phba->port_list, listentry) {
1453 port_iterator->work_port_events = 0;
1454 }
1304 1455
1305 lpfc_printf_log(phba, 1456 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
1306 KERN_WARNING,
1307 LOG_INIT,
1308 "%d:0460 Bring Adapter offline\n", 1457 "%d:0460 Bring Adapter offline\n",
1309 phba->brd_no); 1458 phba->brd_no);
1310 1459
1311 /* Bring down the SLI Layer and cleanup. The HBA is offline 1460 /* Bring down the SLI Layer and cleanup. The HBA is offline
1312 now. */ 1461 now. */
1313 lpfc_sli_hba_down(phba); 1462 lpfc_sli_hba_down(phba);
1314 lpfc_cleanup(phba); 1463 spin_lock_irq(&phba->hbalock);
1315 spin_lock_irqsave(phba->host->host_lock, iflag);
1316 phba->work_hba_events = 0;
1317 phba->work_ha = 0; 1464 phba->work_ha = 0;
1318 phba->fc_flag |= FC_OFFLINE_MODE; 1465 vport->fc_flag |= FC_OFFLINE_MODE;
1319 spin_unlock_irqrestore(phba->host->host_lock, iflag); 1466 spin_unlock_irq(&phba->hbalock);
1467 list_for_each_entry(port_iterator, &phba->port_list, listentry) {
1468 shost = lpfc_shost_from_vport(port_iterator);
1469
1470 lpfc_cleanup(port_iterator);
1471 spin_lock_irq(shost->host_lock);
1472 vport->work_port_events = 0;
1473 vport->fc_flag |= FC_OFFLINE_MODE;
1474 spin_unlock_irq(shost->host_lock);
1475 }
1320} 1476}
1321 1477
1322/****************************************************************************** 1478/******************************************************************************
@@ -1326,17 +1482,17 @@ lpfc_offline(struct lpfc_hba * phba)
1326* 1482*
1327******************************************************************************/ 1483******************************************************************************/
1328static int 1484static int
1329lpfc_scsi_free(struct lpfc_hba * phba) 1485lpfc_scsi_free(struct lpfc_hba *phba)
1330{ 1486{
1331 struct lpfc_scsi_buf *sb, *sb_next; 1487 struct lpfc_scsi_buf *sb, *sb_next;
1332 struct lpfc_iocbq *io, *io_next; 1488 struct lpfc_iocbq *io, *io_next;
1333 1489
1334 spin_lock_irq(phba->host->host_lock); 1490 spin_lock_irq(&phba->hbalock);
1335 /* Release all the lpfc_scsi_bufs maintained by this host. */ 1491 /* Release all the lpfc_scsi_bufs maintained by this host. */
1336 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list, list) { 1492 list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list, list) {
1337 list_del(&sb->list); 1493 list_del(&sb->list);
1338 pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data, 1494 pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data,
1339 sb->dma_handle); 1495 sb->dma_handle);
1340 kfree(sb); 1496 kfree(sb);
1341 phba->total_scsi_bufs--; 1497 phba->total_scsi_bufs--;
1342 } 1498 }
@@ -1348,134 +1504,183 @@ lpfc_scsi_free(struct lpfc_hba * phba)
1348 phba->total_iocbq_bufs--; 1504 phba->total_iocbq_bufs--;
1349 } 1505 }
1350 1506
1351 spin_unlock_irq(phba->host->host_lock); 1507 spin_unlock_irq(&phba->hbalock);
1352 1508
1353 return 0; 1509 return 0;
1354} 1510}
1355 1511
1356void lpfc_remove_device(struct lpfc_hba *phba)
1357{
1358 unsigned long iflag;
1359 1512
1360 lpfc_free_sysfs_attr(phba); 1513struct lpfc_vport *
1361 1514lpfc_create_port(struct lpfc_hba *phba, int instance, struct fc_vport *fc_vport)
1362 spin_lock_irqsave(phba->host->host_lock, iflag); 1515{
1363 phba->fc_flag |= FC_UNLOADING; 1516 struct lpfc_vport *vport;
1517 struct Scsi_Host *shost;
1518 int error = 0;
1364 1519
1365 spin_unlock_irqrestore(phba->host->host_lock, iflag); 1520 shost = scsi_host_alloc(&lpfc_template, sizeof(struct lpfc_vport));
1521 if (!shost)
1522 goto out;
1366 1523
1367 fc_remove_host(phba->host); 1524 vport = (struct lpfc_vport *) shost->hostdata;
1368 scsi_remove_host(phba->host); 1525 vport->phba = phba;
1369 1526
1370 kthread_stop(phba->worker_thread); 1527 vport->load_flag |= FC_LOADING;
1528 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
1371 1529
1530 shost->unique_id = instance;
1531 shost->max_id = LPFC_MAX_TARGET;
1532 shost->max_lun = phba->cfg_max_luns;
1533 shost->this_id = -1;
1534 shost->max_cmd_len = 16;
1372 /* 1535 /*
1373 * Bring down the SLI Layer. This step disable all interrupts, 1536 * Set initial can_queue value since 0 is no longer supported and
1374 * clears the rings, discards all mailbox commands, and resets 1537 * scsi_add_host will fail. This will be adjusted later based on the
1375 * the HBA. 1538 * max xri value determined in hba setup.
1376 */ 1539 */
1377 lpfc_sli_hba_down(phba); 1540 shost->can_queue = phba->cfg_hba_queue_depth - 10;
1378 lpfc_sli_brdrestart(phba); 1541 if (fc_vport != NULL) {
1542 shost->transportt = lpfc_vport_transport_template;
1543 vport->port_type = LPFC_NPIV_PORT;
1544 } else {
1545 shost->transportt = lpfc_transport_template;
1546 vport->port_type = LPFC_PHYSICAL_PORT;
1547 }
1379 1548
1380 /* Release the irq reservation */ 1549 /* Initialize all internally managed lists. */
1381 free_irq(phba->pcidev->irq, phba); 1550 INIT_LIST_HEAD(&vport->fc_nodes);
1382 pci_disable_msi(phba->pcidev); 1551 spin_lock_init(&vport->work_port_lock);
1383 1552
1384 lpfc_cleanup(phba); 1553 init_timer(&vport->fc_disctmo);
1385 lpfc_stop_timer(phba); 1554 vport->fc_disctmo.function = lpfc_disc_timeout;
1386 phba->work_hba_events = 0; 1555 vport->fc_disctmo.data = (unsigned long)vport;
1387 1556
1388 /* 1557 init_timer(&vport->fc_fdmitmo);
1389 * Call scsi_free before mem_free since scsi bufs are released to their 1558 vport->fc_fdmitmo.function = lpfc_fdmi_tmo;
1390 * corresponding pools here. 1559 vport->fc_fdmitmo.data = (unsigned long)vport;
1391 */
1392 lpfc_scsi_free(phba);
1393 lpfc_mem_free(phba);
1394 1560
1395 /* Free resources associated with SLI2 interface */ 1561 init_timer(&vport->els_tmofunc);
1396 dma_free_coherent(&phba->pcidev->dev, SLI2_SLIM_SIZE, 1562 vport->els_tmofunc.function = lpfc_els_timeout;
1397 phba->slim2p, phba->slim2p_mapping); 1563 vport->els_tmofunc.data = (unsigned long)vport;
1398 1564
1399 /* unmap adapter SLIM and Control Registers */ 1565 if (fc_vport != NULL) {
1400 iounmap(phba->ctrl_regs_memmap_p); 1566 error = scsi_add_host(shost, &fc_vport->dev);
1401 iounmap(phba->slim_memmap_p); 1567 } else {
1568 error = scsi_add_host(shost, &phba->pcidev->dev);
1569 }
1570 if (error)
1571 goto out_put_shost;
1402 1572
1403 pci_release_regions(phba->pcidev); 1573 list_add_tail(&vport->listentry, &phba->port_list);
1404 pci_disable_device(phba->pcidev); 1574 return vport;
1405 1575
1406 idr_remove(&lpfc_hba_index, phba->brd_no); 1576out_put_shost:
1407 scsi_host_put(phba->host); 1577 scsi_host_put(shost);
1578out:
1579 return NULL;
1408} 1580}
1409 1581
1410void lpfc_scan_start(struct Scsi_Host *host) 1582void
1583destroy_port(struct lpfc_vport *vport)
1411{ 1584{
1412 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata; 1585 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1586 struct lpfc_hba *phba = vport->phba;
1413 1587
1414 if (lpfc_alloc_sysfs_attr(phba)) 1588 kfree(vport->vname);
1415 goto error;
1416 1589
1417 phba->MBslimaddr = phba->slim_memmap_p; 1590 lpfc_debugfs_terminate(vport);
1418 phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET; 1591 fc_remove_host(shost);
1419 phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET; 1592 scsi_remove_host(shost);
1420 phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
1421 phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
1422 1593
1423 if (lpfc_sli_hba_setup(phba)) 1594 spin_lock_irq(&phba->hbalock);
1424 goto error; 1595 list_del_init(&vport->listentry);
1596 spin_unlock_irq(&phba->hbalock);
1425 1597
1426 /* 1598 lpfc_cleanup(vport);
1427 * hba setup may have changed the hba_queue_depth so we need to adjust
1428 * the value of can_queue.
1429 */
1430 host->can_queue = phba->cfg_hba_queue_depth - 10;
1431 return; 1599 return;
1600}
1601
1602int
1603lpfc_get_instance(void)
1604{
1605 int instance = 0;
1432 1606
1433error: 1607 /* Assign an unused number */
1434 lpfc_remove_device(phba); 1608 if (!idr_pre_get(&lpfc_hba_index, GFP_KERNEL))
1609 return -1;
1610 if (idr_get_new(&lpfc_hba_index, NULL, &instance))
1611 return -1;
1612 return instance;
1435} 1613}
1436 1614
1615/*
1616 * Note: there is no scan_start function as adapter initialization
1617 * will have asynchronously kicked off the link initialization.
1618 */
1619
1437int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time) 1620int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
1438{ 1621{
1439 struct lpfc_hba *phba = (struct lpfc_hba *)shost->hostdata; 1622 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1623 struct lpfc_hba *phba = vport->phba;
1624 int stat = 0;
1440 1625
1441 if (!phba->host) 1626 spin_lock_irq(shost->host_lock);
1442 return 1; 1627
1443 if (time >= 30 * HZ) 1628 if (vport->fc_flag & FC_UNLOADING) {
1629 stat = 1;
1630 goto finished;
1631 }
1632 if (time >= 30 * HZ) {
1633 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
1634 "%d:0461 Scanning longer than 30 "
1635 "seconds. Continuing initialization\n",
1636 phba->brd_no);
1637 stat = 1;
1638 goto finished;
1639 }
1640 if (time >= 15 * HZ && phba->link_state <= LPFC_LINK_DOWN) {
1641 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
1642 "%d:0465 Link down longer than 15 "
1643 "seconds. Continuing initialization\n",
1644 phba->brd_no);
1645 stat = 1;
1444 goto finished; 1646 goto finished;
1647 }
1445 1648
1446 if (phba->hba_state != LPFC_HBA_READY) 1649 if (vport->port_state != LPFC_VPORT_READY)
1447 return 0; 1650 goto finished;
1448 if (phba->num_disc_nodes || phba->fc_prli_sent) 1651 if (vport->num_disc_nodes || vport->fc_prli_sent)
1449 return 0; 1652 goto finished;
1450 if ((phba->fc_map_cnt == 0) && (time < 2 * HZ)) 1653 if (vport->fc_map_cnt == 0 && time < 2 * HZ)
1451 return 0; 1654 goto finished;
1452 if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) 1655 if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
1453 return 0; 1656 goto finished;
1454 if ((phba->hba_state > LPFC_LINK_DOWN) || (time < 15 * HZ)) 1657
1455 return 0; 1658 stat = 1;
1456 1659
1457finished: 1660finished:
1458 if (phba->cfg_poll & DISABLE_FCP_RING_INT) { 1661 spin_unlock_irq(shost->host_lock);
1459 spin_lock_irq(shost->host_lock); 1662 return stat;
1460 lpfc_poll_start_timer(phba); 1663}
1461 spin_unlock_irq(shost->host_lock);
1462 }
1463 1664
1665void lpfc_host_attrib_init(struct Scsi_Host *shost)
1666{
1667 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1668 struct lpfc_hba *phba = vport->phba;
1464 /* 1669 /*
1465 * set fixed host attributes 1670 * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
1466 * Must done after lpfc_sli_hba_setup()
1467 */ 1671 */
1468 1672
1469 fc_host_node_name(shost) = wwn_to_u64(phba->fc_nodename.u.wwn); 1673 fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
1470 fc_host_port_name(shost) = wwn_to_u64(phba->fc_portname.u.wwn); 1674 fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
1471 fc_host_supported_classes(shost) = FC_COS_CLASS3; 1675 fc_host_supported_classes(shost) = FC_COS_CLASS3;
1472 1676
1473 memset(fc_host_supported_fc4s(shost), 0, 1677 memset(fc_host_supported_fc4s(shost), 0,
1474 sizeof(fc_host_supported_fc4s(shost))); 1678 sizeof(fc_host_supported_fc4s(shost)));
1475 fc_host_supported_fc4s(shost)[2] = 1; 1679 fc_host_supported_fc4s(shost)[2] = 1;
1476 fc_host_supported_fc4s(shost)[7] = 1; 1680 fc_host_supported_fc4s(shost)[7] = 1;
1477 1681
1478 lpfc_get_hba_sym_node_name(phba, fc_host_symbolic_name(shost)); 1682 lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
1683 sizeof fc_host_symbolic_name(shost));
1479 1684
1480 fc_host_supported_speeds(shost) = 0; 1685 fc_host_supported_speeds(shost) = 0;
1481 if (phba->lmt & LMT_10Gb) 1686 if (phba->lmt & LMT_10Gb)
@@ -1488,31 +1693,31 @@ finished:
1488 fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT; 1693 fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT;
1489 1694
1490 fc_host_maxframe_size(shost) = 1695 fc_host_maxframe_size(shost) =
1491 ((((uint32_t) phba->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) | 1696 (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
1492 (uint32_t) phba->fc_sparam.cmn.bbRcvSizeLsb); 1697 (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb;
1493 1698
1494 /* This value is also unchanging */ 1699 /* This value is also unchanging */
1495 memset(fc_host_active_fc4s(shost), 0, 1700 memset(fc_host_active_fc4s(shost), 0,
1496 sizeof(fc_host_active_fc4s(shost))); 1701 sizeof(fc_host_active_fc4s(shost)));
1497 fc_host_active_fc4s(shost)[2] = 1; 1702 fc_host_active_fc4s(shost)[2] = 1;
1498 fc_host_active_fc4s(shost)[7] = 1; 1703 fc_host_active_fc4s(shost)[7] = 1;
1499 1704
1705 fc_host_max_npiv_vports(shost) = phba->max_vpi;
1500 spin_lock_irq(shost->host_lock); 1706 spin_lock_irq(shost->host_lock);
1501 phba->fc_flag &= ~FC_LOADING; 1707 vport->fc_flag &= ~FC_LOADING;
1502 spin_unlock_irq(shost->host_lock); 1708 spin_unlock_irq(shost->host_lock);
1503
1504 return 1;
1505} 1709}
1506 1710
1507static int __devinit 1711static int __devinit
1508lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid) 1712lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
1509{ 1713{
1510 struct Scsi_Host *host; 1714 struct lpfc_vport *vport = NULL;
1511 struct lpfc_hba *phba; 1715 struct lpfc_hba *phba;
1512 struct lpfc_sli *psli; 1716 struct lpfc_sli *psli;
1513 struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL; 1717 struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
1718 struct Scsi_Host *shost = NULL;
1514 unsigned long bar0map_len, bar2map_len; 1719 unsigned long bar0map_len, bar2map_len;
1515 int error = -ENODEV, retval; 1720 int error = -ENODEV;
1516 int i; 1721 int i;
1517 uint16_t iotag; 1722 uint16_t iotag;
1518 1723
@@ -1521,61 +1726,46 @@ lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
1521 if (pci_request_regions(pdev, LPFC_DRIVER_NAME)) 1726 if (pci_request_regions(pdev, LPFC_DRIVER_NAME))
1522 goto out_disable_device; 1727 goto out_disable_device;
1523 1728
1524 host = scsi_host_alloc(&lpfc_template, sizeof (struct lpfc_hba)); 1729 phba = kzalloc(sizeof (struct lpfc_hba), GFP_KERNEL);
1525 if (!host) 1730 if (!phba)
1526 goto out_release_regions; 1731 goto out_release_regions;
1527 1732
1528 phba = (struct lpfc_hba*)host->hostdata; 1733 spin_lock_init(&phba->hbalock);
1529 memset(phba, 0, sizeof (struct lpfc_hba));
1530 phba->host = host;
1531 1734
1532 phba->fc_flag |= FC_LOADING;
1533 phba->pcidev = pdev; 1735 phba->pcidev = pdev;
1534 1736
1535 /* Assign an unused board number */ 1737 /* Assign an unused board number */
1536 if (!idr_pre_get(&lpfc_hba_index, GFP_KERNEL)) 1738 if ((phba->brd_no = lpfc_get_instance()) < 0)
1537 goto out_put_host; 1739 goto out_free_phba;
1538 1740
1539 error = idr_get_new(&lpfc_hba_index, NULL, &phba->brd_no); 1741 INIT_LIST_HEAD(&phba->port_list);
1540 if (error) 1742 INIT_LIST_HEAD(&phba->hbq_buffer_list);
1541 goto out_put_host; 1743 /*
1542 1744 * Get all the module params for configuring this host and then
1543 host->unique_id = phba->brd_no; 1745 * establish the host.
1746 */
1747 lpfc_get_cfgparam(phba);
1748 phba->max_vpi = LPFC_MAX_VPI;
1544 1749
1545 /* Initialize timers used by driver */ 1750 /* Initialize timers used by driver */
1546 init_timer(&phba->fc_estabtmo); 1751 init_timer(&phba->fc_estabtmo);
1547 phba->fc_estabtmo.function = lpfc_establish_link_tmo; 1752 phba->fc_estabtmo.function = lpfc_establish_link_tmo;
1548 phba->fc_estabtmo.data = (unsigned long)phba; 1753 phba->fc_estabtmo.data = (unsigned long)phba;
1549 init_timer(&phba->fc_disctmo); 1754
1550 phba->fc_disctmo.function = lpfc_disc_timeout; 1755 init_timer(&phba->hb_tmofunc);
1551 phba->fc_disctmo.data = (unsigned long)phba; 1756 phba->hb_tmofunc.function = lpfc_hb_timeout;
1552 1757 phba->hb_tmofunc.data = (unsigned long)phba;
1553 init_timer(&phba->fc_fdmitmo); 1758
1554 phba->fc_fdmitmo.function = lpfc_fdmi_tmo;
1555 phba->fc_fdmitmo.data = (unsigned long)phba;
1556 init_timer(&phba->els_tmofunc);
1557 phba->els_tmofunc.function = lpfc_els_timeout;
1558 phba->els_tmofunc.data = (unsigned long)phba;
1559 psli = &phba->sli; 1759 psli = &phba->sli;
1560 init_timer(&psli->mbox_tmo); 1760 init_timer(&psli->mbox_tmo);
1561 psli->mbox_tmo.function = lpfc_mbox_timeout; 1761 psli->mbox_tmo.function = lpfc_mbox_timeout;
1562 psli->mbox_tmo.data = (unsigned long)phba; 1762 psli->mbox_tmo.data = (unsigned long) phba;
1563
1564 init_timer(&phba->fcp_poll_timer); 1763 init_timer(&phba->fcp_poll_timer);
1565 phba->fcp_poll_timer.function = lpfc_poll_timeout; 1764 phba->fcp_poll_timer.function = lpfc_poll_timeout;
1566 phba->fcp_poll_timer.data = (unsigned long)phba; 1765 phba->fcp_poll_timer.data = (unsigned long) phba;
1567 1766 init_timer(&phba->fabric_block_timer);
1568 /* 1767 phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
1569 * Get all the module params for configuring this host and then 1768 phba->fabric_block_timer.data = (unsigned long) phba;
1570 * establish the host parameters.
1571 */
1572 lpfc_get_cfgparam(phba);
1573
1574 host->max_id = LPFC_MAX_TARGET;
1575 host->max_lun = phba->cfg_max_luns;
1576 host->this_id = -1;
1577
1578 INIT_LIST_HEAD(&phba->fc_nodes);
1579 1769
1580 pci_set_master(pdev); 1770 pci_set_master(pdev);
1581 pci_try_set_mwi(pdev); 1771 pci_try_set_mwi(pdev);
@@ -1620,13 +1810,22 @@ lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
1620 1810
1621 memset(phba->slim2p, 0, SLI2_SLIM_SIZE); 1811 memset(phba->slim2p, 0, SLI2_SLIM_SIZE);
1622 1812
1813 phba->hbqslimp.virt = dma_alloc_coherent(&phba->pcidev->dev,
1814 lpfc_sli_hbq_size(),
1815 &phba->hbqslimp.phys,
1816 GFP_KERNEL);
1817 if (!phba->hbqslimp.virt)
1818 goto out_free_slim;
1819
1820 memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size());
1821
1623 /* Initialize the SLI Layer to run with lpfc HBAs. */ 1822 /* Initialize the SLI Layer to run with lpfc HBAs. */
1624 lpfc_sli_setup(phba); 1823 lpfc_sli_setup(phba);
1625 lpfc_sli_queue_setup(phba); 1824 lpfc_sli_queue_setup(phba);
1626 1825
1627 error = lpfc_mem_alloc(phba); 1826 error = lpfc_mem_alloc(phba);
1628 if (error) 1827 if (error)
1629 goto out_free_slim; 1828 goto out_free_hbqslimp;
1630 1829
1631 /* Initialize and populate the iocb list per host. */ 1830 /* Initialize and populate the iocb list per host. */
1632 INIT_LIST_HEAD(&phba->lpfc_iocb_list); 1831 INIT_LIST_HEAD(&phba->lpfc_iocb_list);
@@ -1650,10 +1849,11 @@ lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
1650 error = -ENOMEM; 1849 error = -ENOMEM;
1651 goto out_free_iocbq; 1850 goto out_free_iocbq;
1652 } 1851 }
1653 spin_lock_irq(phba->host->host_lock); 1852
1853 spin_lock_irq(&phba->hbalock);
1654 list_add(&iocbq_entry->list, &phba->lpfc_iocb_list); 1854 list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
1655 phba->total_iocbq_bufs++; 1855 phba->total_iocbq_bufs++;
1656 spin_unlock_irq(phba->host->host_lock); 1856 spin_unlock_irq(&phba->hbalock);
1657 } 1857 }
1658 1858
1659 /* Initialize HBA structure */ 1859 /* Initialize HBA structure */
@@ -1674,22 +1874,22 @@ lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
1674 goto out_free_iocbq; 1874 goto out_free_iocbq;
1675 } 1875 }
1676 1876
1677 /*
1678 * Set initial can_queue value since 0 is no longer supported and
1679 * scsi_add_host will fail. This will be adjusted later based on the
1680 * max xri value determined in hba setup.
1681 */
1682 host->can_queue = phba->cfg_hba_queue_depth - 10;
1683
1684 /* Tell the midlayer we support 16 byte commands */
1685 host->max_cmd_len = 16;
1686
1687 /* Initialize the list of scsi buffers used by driver for scsi IO. */ 1877 /* Initialize the list of scsi buffers used by driver for scsi IO. */
1688 spin_lock_init(&phba->scsi_buf_list_lock); 1878 spin_lock_init(&phba->scsi_buf_list_lock);
1689 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list); 1879 INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list);
1690 1880
1691 host->transportt = lpfc_transport_template; 1881 /* Initialize list of fabric iocbs */
1692 pci_set_drvdata(pdev, host); 1882 INIT_LIST_HEAD(&phba->fabric_iocb_list);
1883
1884 vport = lpfc_create_port(phba, phba->brd_no, NULL);
1885 if (!vport)
1886 goto out_kthread_stop;
1887
1888 shost = lpfc_shost_from_vport(vport);
1889 phba->pport = vport;
1890 lpfc_debugfs_initialize(vport);
1891
1892 pci_set_drvdata(pdev, shost);
1693 1893
1694 if (phba->cfg_use_msi) { 1894 if (phba->cfg_use_msi) {
1695 error = pci_enable_msi(phba->pcidev); 1895 error = pci_enable_msi(phba->pcidev);
@@ -1700,38 +1900,68 @@ lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
1700 } 1900 }
1701 1901
1702 error = request_irq(phba->pcidev->irq, lpfc_intr_handler, IRQF_SHARED, 1902 error = request_irq(phba->pcidev->irq, lpfc_intr_handler, IRQF_SHARED,
1703 LPFC_DRIVER_NAME, phba); 1903 LPFC_DRIVER_NAME, phba);
1704 if (error) { 1904 if (error) {
1705 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, 1905 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1706 "%d:0451 Enable interrupt handler failed\n", 1906 "%d:0451 Enable interrupt handler failed\n",
1707 phba->brd_no); 1907 phba->brd_no);
1708 goto out_kthread_stop; 1908 goto out_disable_msi;
1709 } 1909 }
1710 1910
1711 error = scsi_add_host(host, &pdev->dev); 1911 phba->MBslimaddr = phba->slim_memmap_p;
1712 if (error) 1912 phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
1913 phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
1914 phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
1915 phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
1916
1917 if (lpfc_alloc_sysfs_attr(vport))
1713 goto out_free_irq; 1918 goto out_free_irq;
1714 1919
1715 scsi_scan_host(host); 1920 if (lpfc_sli_hba_setup(phba))
1921 goto out_remove_device;
1922
1923 /*
1924 * hba setup may have changed the hba_queue_depth so we need to adjust
1925 * the value of can_queue.
1926 */
1927 shost->can_queue = phba->cfg_hba_queue_depth - 10;
1928
1929 lpfc_host_attrib_init(shost);
1930
1931 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
1932 spin_lock_irq(shost->host_lock);
1933 lpfc_poll_start_timer(phba);
1934 spin_unlock_irq(shost->host_lock);
1935 }
1936
1937 scsi_scan_host(shost);
1716 1938
1717 return 0; 1939 return 0;
1718 1940
1941out_remove_device:
1942 lpfc_free_sysfs_attr(vport);
1943 spin_lock_irq(shost->host_lock);
1944 vport->fc_flag |= FC_UNLOADING;
1945 spin_unlock_irq(shost->host_lock);
1719out_free_irq: 1946out_free_irq:
1720 lpfc_stop_timer(phba); 1947 lpfc_stop_phba_timers(phba);
1721 phba->work_hba_events = 0; 1948 phba->pport->work_port_events = 0;
1722 free_irq(phba->pcidev->irq, phba); 1949 free_irq(phba->pcidev->irq, phba);
1950out_disable_msi:
1723 pci_disable_msi(phba->pcidev); 1951 pci_disable_msi(phba->pcidev);
1952 destroy_port(vport);
1724out_kthread_stop: 1953out_kthread_stop:
1725 kthread_stop(phba->worker_thread); 1954 kthread_stop(phba->worker_thread);
1726out_free_iocbq: 1955out_free_iocbq:
1727 list_for_each_entry_safe(iocbq_entry, iocbq_next, 1956 list_for_each_entry_safe(iocbq_entry, iocbq_next,
1728 &phba->lpfc_iocb_list, list) { 1957 &phba->lpfc_iocb_list, list) {
1729 spin_lock_irq(phba->host->host_lock);
1730 kfree(iocbq_entry); 1958 kfree(iocbq_entry);
1731 phba->total_iocbq_bufs--; 1959 phba->total_iocbq_bufs--;
1732 spin_unlock_irq(phba->host->host_lock);
1733 } 1960 }
1734 lpfc_mem_free(phba); 1961 lpfc_mem_free(phba);
1962out_free_hbqslimp:
1963 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), phba->hbqslimp.virt,
1964 phba->hbqslimp.phys);
1735out_free_slim: 1965out_free_slim:
1736 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, phba->slim2p, 1966 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, phba->slim2p,
1737 phba->slim2p_mapping); 1967 phba->slim2p_mapping);
@@ -1741,27 +1971,85 @@ out_iounmap_slim:
1741 iounmap(phba->slim_memmap_p); 1971 iounmap(phba->slim_memmap_p);
1742out_idr_remove: 1972out_idr_remove:
1743 idr_remove(&lpfc_hba_index, phba->brd_no); 1973 idr_remove(&lpfc_hba_index, phba->brd_no);
1744out_put_host: 1974out_free_phba:
1745 phba->host = NULL; 1975 kfree(phba);
1746 scsi_host_put(host);
1747out_release_regions: 1976out_release_regions:
1748 pci_release_regions(pdev); 1977 pci_release_regions(pdev);
1749out_disable_device: 1978out_disable_device:
1750 pci_disable_device(pdev); 1979 pci_disable_device(pdev);
1751out: 1980out:
1752 pci_set_drvdata(pdev, NULL); 1981 pci_set_drvdata(pdev, NULL);
1982 if (shost)
1983 scsi_host_put(shost);
1753 return error; 1984 return error;
1754} 1985}
1755 1986
1756static void __devexit 1987static void __devexit
1757lpfc_pci_remove_one(struct pci_dev *pdev) 1988lpfc_pci_remove_one(struct pci_dev *pdev)
1758{ 1989{
1759 struct Scsi_Host *host = pci_get_drvdata(pdev); 1990 struct Scsi_Host *shost = pci_get_drvdata(pdev);
1760 struct lpfc_hba *phba = (struct lpfc_hba *)host->hostdata; 1991 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
1992 struct lpfc_hba *phba = vport->phba;
1993 struct lpfc_vport *port_iterator;
1994 list_for_each_entry(port_iterator, &phba->port_list, listentry)
1995 port_iterator->load_flag |= FC_UNLOADING;
1996
1997 kfree(vport->vname);
1998 lpfc_free_sysfs_attr(vport);
1999
2000 fc_remove_host(shost);
2001 scsi_remove_host(shost);
2002
2003 /*
2004 * Bring down the SLI Layer. This step disable all interrupts,
2005 * clears the rings, discards all mailbox commands, and resets
2006 * the HBA.
2007 */
2008 lpfc_sli_hba_down(phba);
2009 lpfc_sli_brdrestart(phba);
2010
2011 lpfc_stop_phba_timers(phba);
2012 spin_lock_irq(&phba->hbalock);
2013 list_del_init(&vport->listentry);
2014 spin_unlock_irq(&phba->hbalock);
2015
1761 2016
1762 lpfc_remove_device(phba); 2017 lpfc_debugfs_terminate(vport);
2018 lpfc_cleanup(vport);
2019
2020 kthread_stop(phba->worker_thread);
2021
2022 /* Release the irq reservation */
2023 free_irq(phba->pcidev->irq, phba);
2024 pci_disable_msi(phba->pcidev);
1763 2025
1764 pci_set_drvdata(pdev, NULL); 2026 pci_set_drvdata(pdev, NULL);
2027 scsi_host_put(shost);
2028
2029 /*
2030 * Call scsi_free before mem_free since scsi bufs are released to their
2031 * corresponding pools here.
2032 */
2033 lpfc_scsi_free(phba);
2034 lpfc_mem_free(phba);
2035
2036 dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), phba->hbqslimp.virt,
2037 phba->hbqslimp.phys);
2038
2039 /* Free resources associated with SLI2 interface */
2040 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
2041 phba->slim2p, phba->slim2p_mapping);
2042
2043 /* unmap adapter SLIM and Control Registers */
2044 iounmap(phba->ctrl_regs_memmap_p);
2045 iounmap(phba->slim_memmap_p);
2046
2047 idr_remove(&lpfc_hba_index, phba->brd_no);
2048
2049 kfree(phba);
2050
2051 pci_release_regions(pdev);
2052 pci_disable_device(pdev);
1765} 2053}
1766 2054
1767/** 2055/**
@@ -1819,10 +2107,13 @@ static pci_ers_result_t lpfc_io_slot_reset(struct pci_dev *pdev)
1819 pci_set_master(pdev); 2107 pci_set_master(pdev);
1820 2108
1821 /* Re-establishing Link */ 2109 /* Re-establishing Link */
1822 spin_lock_irq(phba->host->host_lock); 2110 spin_lock_irq(host->host_lock);
1823 phba->fc_flag |= FC_ESTABLISH_LINK; 2111 phba->pport->fc_flag |= FC_ESTABLISH_LINK;
2112 spin_unlock_irq(host->host_lock);
2113
2114 spin_lock_irq(&phba->hbalock);
1824 psli->sli_flag &= ~LPFC_SLI2_ACTIVE; 2115 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
1825 spin_unlock_irq(phba->host->host_lock); 2116 spin_unlock_irq(&phba->hbalock);
1826 2117
1827 2118
1828 /* Take device offline; this will perform cleanup */ 2119 /* Take device offline; this will perform cleanup */
@@ -1932,7 +2223,7 @@ static struct pci_driver lpfc_driver = {
1932 .id_table = lpfc_id_table, 2223 .id_table = lpfc_id_table,
1933 .probe = lpfc_pci_probe_one, 2224 .probe = lpfc_pci_probe_one,
1934 .remove = __devexit_p(lpfc_pci_remove_one), 2225 .remove = __devexit_p(lpfc_pci_remove_one),
1935 .err_handler = &lpfc_err_handler, 2226 .err_handler = &lpfc_err_handler,
1936}; 2227};
1937 2228
1938static int __init 2229static int __init
@@ -1945,11 +2236,15 @@ lpfc_init(void)
1945 2236
1946 lpfc_transport_template = 2237 lpfc_transport_template =
1947 fc_attach_transport(&lpfc_transport_functions); 2238 fc_attach_transport(&lpfc_transport_functions);
1948 if (!lpfc_transport_template) 2239 lpfc_vport_transport_template =
2240 fc_attach_transport(&lpfc_vport_transport_functions);
2241 if (!lpfc_transport_template || !lpfc_vport_transport_template)
1949 return -ENOMEM; 2242 return -ENOMEM;
1950 error = pci_register_driver(&lpfc_driver); 2243 error = pci_register_driver(&lpfc_driver);
1951 if (error) 2244 if (error) {
1952 fc_release_transport(lpfc_transport_template); 2245 fc_release_transport(lpfc_transport_template);
2246 fc_release_transport(lpfc_vport_transport_template);
2247 }
1953 2248
1954 return error; 2249 return error;
1955} 2250}
@@ -1959,6 +2254,7 @@ lpfc_exit(void)
1959{ 2254{
1960 pci_unregister_driver(&lpfc_driver); 2255 pci_unregister_driver(&lpfc_driver);
1961 fc_release_transport(lpfc_transport_template); 2256 fc_release_transport(lpfc_transport_template);
2257 fc_release_transport(lpfc_vport_transport_template);
1962} 2258}
1963 2259
1964module_init(lpfc_init); 2260module_init(lpfc_init);