blob: 7256be3f4e2f2325528d5c62037e757c57a4b0dc [file] [log] [blame]
dea31012005-04-17 16:05:31 -05001/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04003 * Fibre Channel Host Bus Adapters. *
James Smart9413aff2007-04-25 09:53:35 -04004 * Copyright (C) 2004-2007 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04005 * EMULEX and SLI are trademarks of Emulex. *
dea31012005-04-17 16:05:31 -05006 * www.emulex.com *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea31012005-04-17 16:05:31 -05008 * *
9 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040010 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
dea31012005-04-17 16:05:31 -050020 *******************************************************************/
21
dea31012005-04-17 16:05:31 -050022#include <linux/blkdev.h>
23#include <linux/pci.h>
24#include <linux/interrupt.h>
25
James.Smart@Emulex.Comf888ba32005-08-10 15:03:01 -040026#include <scsi/scsi_device.h>
27#include <scsi/scsi_transport_fc.h>
28
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040029#include <scsi/scsi.h>
30
dea31012005-04-17 16:05:31 -050031#include "lpfc_hw.h"
32#include "lpfc_sli.h"
33#include "lpfc_disc.h"
34#include "lpfc_scsi.h"
35#include "lpfc.h"
36#include "lpfc_logmsg.h"
37#include "lpfc_crtn.h"
38#include "lpfc_compat.h"
39
40/**********************************************/
41
42/* mailbox command */
43/**********************************************/
44void
45lpfc_dump_mem(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb, uint16_t offset)
46{
47 MAILBOX_t *mb;
48 void *ctx;
49
50 mb = &pmb->mb;
51 ctx = pmb->context2;
52
53 /* Setup to dump VPD region */
54 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
55 mb->mbxCommand = MBX_DUMP_MEMORY;
56 mb->un.varDmp.cv = 1;
57 mb->un.varDmp.type = DMP_NV_PARAMS;
58 mb->un.varDmp.entry_index = offset;
59 mb->un.varDmp.region_id = DMP_REGION_VPD;
60 mb->un.varDmp.word_cnt = (DMP_RSP_SIZE / sizeof (uint32_t));
61 mb->un.varDmp.co = 0;
62 mb->un.varDmp.resp_offset = 0;
63 pmb->context2 = ctx;
64 mb->mbxOwner = OWN_HOST;
65 return;
66}
67
68/**********************************************/
69/* lpfc_read_nv Issue a READ NVPARAM */
70/* mailbox command */
71/**********************************************/
72void
73lpfc_read_nv(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
74{
75 MAILBOX_t *mb;
76
77 mb = &pmb->mb;
78 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
79 mb->mbxCommand = MBX_READ_NV;
80 mb->mbxOwner = OWN_HOST;
81 return;
82}
83
84/**********************************************/
James Smart57127f12007-10-27 13:37:05 -040085/* lpfc_config_async Issue a */
86/* MBX_ASYNC_EVT_ENABLE mailbox command */
87/**********************************************/
88void
89lpfc_config_async(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb,
90 uint32_t ring)
91{
92 MAILBOX_t *mb;
93
94 mb = &pmb->mb;
95 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
96 mb->mbxCommand = MBX_ASYNCEVT_ENABLE;
97 mb->un.varCfgAsyncEvent.ring = ring;
98 mb->mbxOwner = OWN_HOST;
99 return;
100}
101
102/**********************************************/
James Smart858c9f62007-06-17 19:56:39 -0500103/* lpfc_heart_beat Issue a HEART_BEAT */
104/* mailbox command */
105/**********************************************/
106void
107lpfc_heart_beat(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
108{
109 MAILBOX_t *mb;
110
111 mb = &pmb->mb;
112 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
113 mb->mbxCommand = MBX_HEARTBEAT;
114 mb->mbxOwner = OWN_HOST;
115 return;
116}
117
118/**********************************************/
dea31012005-04-17 16:05:31 -0500119/* lpfc_read_la Issue a READ LA */
120/* mailbox command */
121/**********************************************/
122int
123lpfc_read_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb, struct lpfc_dmabuf *mp)
124{
125 MAILBOX_t *mb;
126 struct lpfc_sli *psli;
127
128 psli = &phba->sli;
129 mb = &pmb->mb;
130 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
131
132 INIT_LIST_HEAD(&mp->list);
133 mb->mbxCommand = MBX_READ_LA64;
134 mb->un.varReadLA.un.lilpBde64.tus.f.bdeSize = 128;
135 mb->un.varReadLA.un.lilpBde64.addrHigh = putPaddrHigh(mp->phys);
136 mb->un.varReadLA.un.lilpBde64.addrLow = putPaddrLow(mp->phys);
137
138 /* Save address for later completion and set the owner to host so that
139 * the FW knows this mailbox is available for processing.
140 */
141 pmb->context1 = (uint8_t *) mp;
142 mb->mbxOwner = OWN_HOST;
James Smart92d7f7b2007-06-17 19:56:38 -0500143 return (0);
dea31012005-04-17 16:05:31 -0500144}
145
146/**********************************************/
147/* lpfc_clear_la Issue a CLEAR LA */
148/* mailbox command */
149/**********************************************/
150void
151lpfc_clear_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
152{
153 MAILBOX_t *mb;
154
155 mb = &pmb->mb;
156 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
157
158 mb->un.varClearLA.eventTag = phba->fc_eventTag;
159 mb->mbxCommand = MBX_CLEAR_LA;
160 mb->mbxOwner = OWN_HOST;
161 return;
162}
163
164/**************************************************/
165/* lpfc_config_link Issue a CONFIG LINK */
166/* mailbox command */
167/**************************************************/
168void
169lpfc_config_link(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
170{
James Smart2e0fef82007-06-17 19:56:36 -0500171 struct lpfc_vport *vport = phba->pport;
dea31012005-04-17 16:05:31 -0500172 MAILBOX_t *mb = &pmb->mb;
173 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
174
175 /* NEW_FEATURE
176 * SLI-2, Coalescing Response Feature.
177 */
178 if (phba->cfg_cr_delay) {
179 mb->un.varCfgLnk.cr = 1;
180 mb->un.varCfgLnk.ci = 1;
181 mb->un.varCfgLnk.cr_delay = phba->cfg_cr_delay;
182 mb->un.varCfgLnk.cr_count = phba->cfg_cr_count;
183 }
184
James Smart2e0fef82007-06-17 19:56:36 -0500185 mb->un.varCfgLnk.myId = vport->fc_myDID;
dea31012005-04-17 16:05:31 -0500186 mb->un.varCfgLnk.edtov = phba->fc_edtov;
187 mb->un.varCfgLnk.arbtov = phba->fc_arbtov;
188 mb->un.varCfgLnk.ratov = phba->fc_ratov;
189 mb->un.varCfgLnk.rttov = phba->fc_rttov;
190 mb->un.varCfgLnk.altov = phba->fc_altov;
191 mb->un.varCfgLnk.crtov = phba->fc_crtov;
192 mb->un.varCfgLnk.citov = phba->fc_citov;
193
194 if (phba->cfg_ack0)
195 mb->un.varCfgLnk.ack0_enable = 1;
196
197 mb->mbxCommand = MBX_CONFIG_LINK;
198 mb->mbxOwner = OWN_HOST;
199 return;
200}
201
202/**********************************************/
203/* lpfc_init_link Issue an INIT LINK */
204/* mailbox command */
205/**********************************************/
206void
207lpfc_init_link(struct lpfc_hba * phba,
208 LPFC_MBOXQ_t * pmb, uint32_t topology, uint32_t linkspeed)
209{
210 lpfc_vpd_t *vpd;
211 struct lpfc_sli *psli;
212 MAILBOX_t *mb;
213
214 mb = &pmb->mb;
215 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
216
217 psli = &phba->sli;
218 switch (topology) {
219 case FLAGS_TOPOLOGY_MODE_LOOP_PT:
220 mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_LOOP;
221 mb->un.varInitLnk.link_flags |= FLAGS_TOPOLOGY_FAILOVER;
222 break;
223 case FLAGS_TOPOLOGY_MODE_PT_PT:
224 mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_PT_PT;
225 break;
226 case FLAGS_TOPOLOGY_MODE_LOOP:
227 mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_LOOP;
228 break;
229 case FLAGS_TOPOLOGY_MODE_PT_LOOP:
230 mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_PT_PT;
231 mb->un.varInitLnk.link_flags |= FLAGS_TOPOLOGY_FAILOVER;
232 break;
Jamie Wellnitz367c2712006-02-28 19:25:32 -0500233 case FLAGS_LOCAL_LB:
234 mb->un.varInitLnk.link_flags = FLAGS_LOCAL_LB;
235 break;
dea31012005-04-17 16:05:31 -0500236 }
237
James Smart4b0b91d2006-04-15 11:53:00 -0400238 /* Enable asynchronous ABTS responses from firmware */
239 mb->un.varInitLnk.link_flags |= FLAGS_IMED_ABORT;
240
dea31012005-04-17 16:05:31 -0500241 /* NEW_FEATURE
242 * Setting up the link speed
243 */
244 vpd = &phba->vpd;
245 if (vpd->rev.feaLevelHigh >= 0x02){
James Smart92d7f7b2007-06-17 19:56:38 -0500246 switch(linkspeed){
dea31012005-04-17 16:05:31 -0500247 case LINK_SPEED_1G:
248 case LINK_SPEED_2G:
249 case LINK_SPEED_4G:
James Smartb87eab32007-04-25 09:53:28 -0400250 case LINK_SPEED_8G:
dea31012005-04-17 16:05:31 -0500251 mb->un.varInitLnk.link_flags |=
252 FLAGS_LINK_SPEED;
253 mb->un.varInitLnk.link_speed = linkspeed;
254 break;
255 case LINK_SPEED_AUTO:
256 default:
257 mb->un.varInitLnk.link_speed =
258 LINK_SPEED_AUTO;
259 break;
260 }
261
262 }
263 else
264 mb->un.varInitLnk.link_speed = LINK_SPEED_AUTO;
265
266 mb->mbxCommand = (volatile uint8_t)MBX_INIT_LINK;
267 mb->mbxOwner = OWN_HOST;
268 mb->un.varInitLnk.fabric_AL_PA = phba->fc_pref_ALPA;
269 return;
270}
271
272/**********************************************/
273/* lpfc_read_sparam Issue a READ SPARAM */
274/* mailbox command */
275/**********************************************/
276int
James Smart92d7f7b2007-06-17 19:56:38 -0500277lpfc_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb, int vpi)
dea31012005-04-17 16:05:31 -0500278{
279 struct lpfc_dmabuf *mp;
280 MAILBOX_t *mb;
281 struct lpfc_sli *psli;
282
283 psli = &phba->sli;
284 mb = &pmb->mb;
285 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
286
287 mb->mbxOwner = OWN_HOST;
288
289 /* Get a buffer to hold the HBAs Service Parameters */
290
291 if (((mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL)) == 0) ||
292 ((mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys))) == 0)) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -0800293 kfree(mp);
dea31012005-04-17 16:05:31 -0500294 mb->mbxCommand = MBX_READ_SPARM64;
295 /* READ_SPARAM: no buffers */
James Smarte8b62012007-08-02 11:10:09 -0400296 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
297 "0301 READ_SPARAM: no buffers\n");
James Smart92d7f7b2007-06-17 19:56:38 -0500298 return (1);
dea31012005-04-17 16:05:31 -0500299 }
300 INIT_LIST_HEAD(&mp->list);
301 mb->mbxCommand = MBX_READ_SPARM64;
302 mb->un.varRdSparm.un.sp64.tus.f.bdeSize = sizeof (struct serv_parm);
303 mb->un.varRdSparm.un.sp64.addrHigh = putPaddrHigh(mp->phys);
304 mb->un.varRdSparm.un.sp64.addrLow = putPaddrLow(mp->phys);
James Smart92d7f7b2007-06-17 19:56:38 -0500305 mb->un.varRdSparm.vpi = vpi;
dea31012005-04-17 16:05:31 -0500306
307 /* save address for completion */
308 pmb->context1 = mp;
309
James Smart92d7f7b2007-06-17 19:56:38 -0500310 return (0);
dea31012005-04-17 16:05:31 -0500311}
312
313/********************************************/
314/* lpfc_unreg_did Issue a UNREG_DID */
315/* mailbox command */
316/********************************************/
317void
James Smart92d7f7b2007-06-17 19:56:38 -0500318lpfc_unreg_did(struct lpfc_hba * phba, uint16_t vpi, uint32_t did,
319 LPFC_MBOXQ_t * pmb)
dea31012005-04-17 16:05:31 -0500320{
321 MAILBOX_t *mb;
322
323 mb = &pmb->mb;
324 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
325
326 mb->un.varUnregDID.did = did;
James Smart92d7f7b2007-06-17 19:56:38 -0500327 mb->un.varUnregDID.vpi = vpi;
dea31012005-04-17 16:05:31 -0500328
329 mb->mbxCommand = MBX_UNREG_D_ID;
330 mb->mbxOwner = OWN_HOST;
331 return;
332}
333
dea31012005-04-17 16:05:31 -0500334/**********************************************/
335/* lpfc_read_nv Issue a READ CONFIG */
336/* mailbox command */
337/**********************************************/
338void
339lpfc_read_config(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
340{
341 MAILBOX_t *mb;
342
343 mb = &pmb->mb;
344 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
345
346 mb->mbxCommand = MBX_READ_CONFIG;
347 mb->mbxOwner = OWN_HOST;
348 return;
349}
350
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -0500351/*************************************************/
352/* lpfc_read_lnk_stat Issue a READ LINK STATUS */
353/* mailbox command */
354/*************************************************/
355void
356lpfc_read_lnk_stat(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
357{
358 MAILBOX_t *mb;
359
360 mb = &pmb->mb;
361 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
362
363 mb->mbxCommand = MBX_READ_LNK_STAT;
364 mb->mbxOwner = OWN_HOST;
365 return;
366}
367
dea31012005-04-17 16:05:31 -0500368/********************************************/
369/* lpfc_reg_login Issue a REG_LOGIN */
370/* mailbox command */
371/********************************************/
372int
James Smart92d7f7b2007-06-17 19:56:38 -0500373lpfc_reg_login(struct lpfc_hba *phba, uint16_t vpi, uint32_t did,
374 uint8_t *param, LPFC_MBOXQ_t *pmb, uint32_t flag)
dea31012005-04-17 16:05:31 -0500375{
James Smart2e0fef82007-06-17 19:56:36 -0500376 MAILBOX_t *mb = &pmb->mb;
dea31012005-04-17 16:05:31 -0500377 uint8_t *sparam;
378 struct lpfc_dmabuf *mp;
dea31012005-04-17 16:05:31 -0500379
dea31012005-04-17 16:05:31 -0500380 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
381
382 mb->un.varRegLogin.rpi = 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500383 mb->un.varRegLogin.vpi = vpi;
dea31012005-04-17 16:05:31 -0500384 mb->un.varRegLogin.did = did;
385 mb->un.varWords[30] = flag; /* Set flag to issue action on cmpl */
386
387 mb->mbxOwner = OWN_HOST;
388
389 /* Get a buffer to hold NPorts Service Parameters */
390 if (((mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL)) == NULL) ||
391 ((mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys))) == 0)) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -0800392 kfree(mp);
dea31012005-04-17 16:05:31 -0500393 mb->mbxCommand = MBX_REG_LOGIN64;
394 /* REG_LOGIN: no buffers */
James Smart92d7f7b2007-06-17 19:56:38 -0500395 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
James Smarte8b62012007-08-02 11:10:09 -0400396 "0302 REG_LOGIN: no buffers, VPI:%d DID:x%x, "
397 "flag x%x\n", vpi, did, flag);
James Smart92d7f7b2007-06-17 19:56:38 -0500398 return (1);
dea31012005-04-17 16:05:31 -0500399 }
400 INIT_LIST_HEAD(&mp->list);
401 sparam = mp->virt;
402
403 /* Copy param's into a new buffer */
404 memcpy(sparam, param, sizeof (struct serv_parm));
405
406 /* save address for completion */
407 pmb->context1 = (uint8_t *) mp;
408
409 mb->mbxCommand = MBX_REG_LOGIN64;
410 mb->un.varRegLogin.un.sp64.tus.f.bdeSize = sizeof (struct serv_parm);
411 mb->un.varRegLogin.un.sp64.addrHigh = putPaddrHigh(mp->phys);
412 mb->un.varRegLogin.un.sp64.addrLow = putPaddrLow(mp->phys);
413
James Smart92d7f7b2007-06-17 19:56:38 -0500414 return (0);
dea31012005-04-17 16:05:31 -0500415}
416
417/**********************************************/
418/* lpfc_unreg_login Issue a UNREG_LOGIN */
419/* mailbox command */
420/**********************************************/
421void
James Smart92d7f7b2007-06-17 19:56:38 -0500422lpfc_unreg_login(struct lpfc_hba *phba, uint16_t vpi, uint32_t rpi,
423 LPFC_MBOXQ_t * pmb)
dea31012005-04-17 16:05:31 -0500424{
425 MAILBOX_t *mb;
426
427 mb = &pmb->mb;
428 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
429
430 mb->un.varUnregLogin.rpi = (uint16_t) rpi;
431 mb->un.varUnregLogin.rsvd1 = 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500432 mb->un.varUnregLogin.vpi = vpi;
dea31012005-04-17 16:05:31 -0500433
434 mb->mbxCommand = MBX_UNREG_LOGIN;
435 mb->mbxOwner = OWN_HOST;
436 return;
437}
438
James Smart92d7f7b2007-06-17 19:56:38 -0500439/**************************************************/
440/* lpfc_reg_vpi Issue a REG_VPI */
441/* mailbox command */
442/**************************************************/
443void
444lpfc_reg_vpi(struct lpfc_hba *phba, uint16_t vpi, uint32_t sid,
445 LPFC_MBOXQ_t *pmb)
446{
447 MAILBOX_t *mb = &pmb->mb;
448
449 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
450
451 mb->un.varRegVpi.vpi = vpi;
452 mb->un.varRegVpi.sid = sid;
453
454 mb->mbxCommand = MBX_REG_VPI;
455 mb->mbxOwner = OWN_HOST;
456 return;
457
458}
459
460/**************************************************/
461/* lpfc_unreg_vpi Issue a UNREG_VNPI */
462/* mailbox command */
463/**************************************************/
464void
465lpfc_unreg_vpi(struct lpfc_hba *phba, uint16_t vpi, LPFC_MBOXQ_t *pmb)
466{
467 MAILBOX_t *mb = &pmb->mb;
468 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
469
470 mb->un.varUnregVpi.vpi = vpi;
471
472 mb->mbxCommand = MBX_UNREG_VPI;
473 mb->mbxOwner = OWN_HOST;
474 return;
475
476}
477
dea31012005-04-17 16:05:31 -0500478static void
479lpfc_config_pcb_setup(struct lpfc_hba * phba)
480{
481 struct lpfc_sli *psli = &phba->sli;
482 struct lpfc_sli_ring *pring;
483 PCB_t *pcbp = &phba->slim2p->pcb;
484 dma_addr_t pdma_addr;
485 uint32_t offset;
James Smart2e0fef82007-06-17 19:56:36 -0500486 uint32_t iocbCnt = 0;
dea31012005-04-17 16:05:31 -0500487 int i;
488
dea31012005-04-17 16:05:31 -0500489 pcbp->maxRing = (psli->num_rings - 1);
490
dea31012005-04-17 16:05:31 -0500491 for (i = 0; i < psli->num_rings; i++) {
492 pring = &psli->ring[i];
James Smart2e0fef82007-06-17 19:56:36 -0500493
James Smarted957682007-06-17 19:56:37 -0500494 pring->sizeCiocb = phba->sli_rev == 3 ? SLI3_IOCB_CMD_SIZE:
James Smart92d7f7b2007-06-17 19:56:38 -0500495 SLI2_IOCB_CMD_SIZE;
James Smarted957682007-06-17 19:56:37 -0500496 pring->sizeRiocb = phba->sli_rev == 3 ? SLI3_IOCB_RSP_SIZE:
James Smart92d7f7b2007-06-17 19:56:38 -0500497 SLI2_IOCB_RSP_SIZE;
dea31012005-04-17 16:05:31 -0500498 /* A ring MUST have both cmd and rsp entries defined to be
499 valid */
500 if ((pring->numCiocb == 0) || (pring->numRiocb == 0)) {
501 pcbp->rdsc[i].cmdEntries = 0;
502 pcbp->rdsc[i].rspEntries = 0;
503 pcbp->rdsc[i].cmdAddrHigh = 0;
504 pcbp->rdsc[i].rspAddrHigh = 0;
505 pcbp->rdsc[i].cmdAddrLow = 0;
506 pcbp->rdsc[i].rspAddrLow = 0;
507 pring->cmdringaddr = NULL;
508 pring->rspringaddr = NULL;
509 continue;
510 }
511 /* Command ring setup for ring */
James Smart92d7f7b2007-06-17 19:56:38 -0500512 pring->cmdringaddr = (void *) &phba->slim2p->IOCBs[iocbCnt];
dea31012005-04-17 16:05:31 -0500513 pcbp->rdsc[i].cmdEntries = pring->numCiocb;
514
James Smart92d7f7b2007-06-17 19:56:38 -0500515 offset = (uint8_t *) &phba->slim2p->IOCBs[iocbCnt] -
516 (uint8_t *) phba->slim2p;
dea31012005-04-17 16:05:31 -0500517 pdma_addr = phba->slim2p_mapping + offset;
518 pcbp->rdsc[i].cmdAddrHigh = putPaddrHigh(pdma_addr);
519 pcbp->rdsc[i].cmdAddrLow = putPaddrLow(pdma_addr);
520 iocbCnt += pring->numCiocb;
521
522 /* Response ring setup for ring */
James Smart92d7f7b2007-06-17 19:56:38 -0500523 pring->rspringaddr = (void *) &phba->slim2p->IOCBs[iocbCnt];
dea31012005-04-17 16:05:31 -0500524
525 pcbp->rdsc[i].rspEntries = pring->numRiocb;
526 offset = (uint8_t *)&phba->slim2p->IOCBs[iocbCnt] -
527 (uint8_t *)phba->slim2p;
528 pdma_addr = phba->slim2p_mapping + offset;
529 pcbp->rdsc[i].rspAddrHigh = putPaddrHigh(pdma_addr);
530 pcbp->rdsc[i].rspAddrLow = putPaddrLow(pdma_addr);
531 iocbCnt += pring->numRiocb;
532 }
533}
534
535void
536lpfc_read_rev(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
537{
James Smart2e0fef82007-06-17 19:56:36 -0500538 MAILBOX_t *mb = &pmb->mb;
dea31012005-04-17 16:05:31 -0500539 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
540 mb->un.varRdRev.cv = 1;
James Smarted957682007-06-17 19:56:37 -0500541 mb->un.varRdRev.v3req = 1; /* Request SLI3 info */
dea31012005-04-17 16:05:31 -0500542 mb->mbxCommand = MBX_READ_REV;
543 mb->mbxOwner = OWN_HOST;
544 return;
545}
546
James Smarted957682007-06-17 19:56:37 -0500547static void
548lpfc_build_hbq_profile2(struct config_hbq_var *hbqmb,
549 struct lpfc_hbq_init *hbq_desc)
550{
551 hbqmb->profiles.profile2.seqlenbcnt = hbq_desc->seqlenbcnt;
552 hbqmb->profiles.profile2.maxlen = hbq_desc->maxlen;
553 hbqmb->profiles.profile2.seqlenoff = hbq_desc->seqlenoff;
554}
555
556static void
557lpfc_build_hbq_profile3(struct config_hbq_var *hbqmb,
558 struct lpfc_hbq_init *hbq_desc)
559{
560 hbqmb->profiles.profile3.seqlenbcnt = hbq_desc->seqlenbcnt;
561 hbqmb->profiles.profile3.maxlen = hbq_desc->maxlen;
562 hbqmb->profiles.profile3.cmdcodeoff = hbq_desc->cmdcodeoff;
563 hbqmb->profiles.profile3.seqlenoff = hbq_desc->seqlenoff;
564 memcpy(&hbqmb->profiles.profile3.cmdmatch, hbq_desc->cmdmatch,
565 sizeof(hbqmb->profiles.profile3.cmdmatch));
566}
567
568static void
569lpfc_build_hbq_profile5(struct config_hbq_var *hbqmb,
570 struct lpfc_hbq_init *hbq_desc)
571{
572 hbqmb->profiles.profile5.seqlenbcnt = hbq_desc->seqlenbcnt;
573 hbqmb->profiles.profile5.maxlen = hbq_desc->maxlen;
574 hbqmb->profiles.profile5.cmdcodeoff = hbq_desc->cmdcodeoff;
575 hbqmb->profiles.profile5.seqlenoff = hbq_desc->seqlenoff;
576 memcpy(&hbqmb->profiles.profile5.cmdmatch, hbq_desc->cmdmatch,
577 sizeof(hbqmb->profiles.profile5.cmdmatch));
578}
579
580void
James Smart51ef4c22007-08-02 11:10:31 -0400581lpfc_config_hbq(struct lpfc_hba *phba, uint32_t id,
582 struct lpfc_hbq_init *hbq_desc,
James Smarted957682007-06-17 19:56:37 -0500583 uint32_t hbq_entry_index, LPFC_MBOXQ_t *pmb)
584{
585 int i;
586 MAILBOX_t *mb = &pmb->mb;
587 struct config_hbq_var *hbqmb = &mb->un.varCfgHbq;
588
589 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
James Smart51ef4c22007-08-02 11:10:31 -0400590 hbqmb->hbqId = id;
James Smarted957682007-06-17 19:56:37 -0500591 hbqmb->entry_count = hbq_desc->entry_count; /* # entries in HBQ */
592 hbqmb->recvNotify = hbq_desc->rn; /* Receive
593 * Notification */
594 hbqmb->numMask = hbq_desc->mask_count; /* # R_CTL/TYPE masks
595 * # in words 0-19 */
James Smart92d7f7b2007-06-17 19:56:38 -0500596 hbqmb->profile = hbq_desc->profile; /* Selection profile:
James Smarted957682007-06-17 19:56:37 -0500597 * 0 = all,
598 * 7 = logentry */
599 hbqmb->ringMask = hbq_desc->ring_mask; /* Binds HBQ to a ring
600 * e.g. Ring0=b0001,
601 * ring2=b0100 */
602 hbqmb->headerLen = hbq_desc->headerLen; /* 0 if not profile 4
603 * or 5 */
604 hbqmb->logEntry = hbq_desc->logEntry; /* Set to 1 if this
605 * HBQ will be used
606 * for LogEntry
607 * buffers */
608 hbqmb->hbqaddrLow = putPaddrLow(phba->hbqslimp.phys) +
609 hbq_entry_index * sizeof(struct lpfc_hbq_entry);
610 hbqmb->hbqaddrHigh = putPaddrHigh(phba->hbqslimp.phys);
611
612 mb->mbxCommand = MBX_CONFIG_HBQ;
613 mb->mbxOwner = OWN_HOST;
614
James Smart92d7f7b2007-06-17 19:56:38 -0500615 /* Copy info for profiles 2,3,5. Other
616 * profiles this area is reserved
617 */
James Smarted957682007-06-17 19:56:37 -0500618 if (hbq_desc->profile == 2)
619 lpfc_build_hbq_profile2(hbqmb, hbq_desc);
620 else if (hbq_desc->profile == 3)
621 lpfc_build_hbq_profile3(hbqmb, hbq_desc);
622 else if (hbq_desc->profile == 5)
623 lpfc_build_hbq_profile5(hbqmb, hbq_desc);
624
625 /* Return if no rctl / type masks for this HBQ */
626 if (!hbq_desc->mask_count)
627 return;
628
629 /* Otherwise we setup specific rctl / type masks for this HBQ */
630 for (i = 0; i < hbq_desc->mask_count; i++) {
631 hbqmb->hbqMasks[i].tmatch = hbq_desc->hbqMasks[i].tmatch;
632 hbqmb->hbqMasks[i].tmask = hbq_desc->hbqMasks[i].tmask;
633 hbqmb->hbqMasks[i].rctlmatch = hbq_desc->hbqMasks[i].rctlmatch;
634 hbqmb->hbqMasks[i].rctlmask = hbq_desc->hbqMasks[i].rctlmask;
635 }
636
637 return;
638}
639
James Smart92d7f7b2007-06-17 19:56:38 -0500640
641
dea31012005-04-17 16:05:31 -0500642void
643lpfc_config_ring(struct lpfc_hba * phba, int ring, LPFC_MBOXQ_t * pmb)
644{
645 int i;
646 MAILBOX_t *mb = &pmb->mb;
647 struct lpfc_sli *psli;
648 struct lpfc_sli_ring *pring;
649
650 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
651
652 mb->un.varCfgRing.ring = ring;
653 mb->un.varCfgRing.maxOrigXchg = 0;
654 mb->un.varCfgRing.maxRespXchg = 0;
655 mb->un.varCfgRing.recvNotify = 1;
656
657 psli = &phba->sli;
658 pring = &psli->ring[ring];
659 mb->un.varCfgRing.numMask = pring->num_mask;
660 mb->mbxCommand = MBX_CONFIG_RING;
661 mb->mbxOwner = OWN_HOST;
662
663 /* Is this ring configured for a specific profile */
664 if (pring->prt[0].profile) {
665 mb->un.varCfgRing.profile = pring->prt[0].profile;
666 return;
667 }
668
669 /* Otherwise we setup specific rctl / type masks for this ring */
670 for (i = 0; i < pring->num_mask; i++) {
671 mb->un.varCfgRing.rrRegs[i].rval = pring->prt[i].rctl;
672 if (mb->un.varCfgRing.rrRegs[i].rval != FC_ELS_REQ)
673 mb->un.varCfgRing.rrRegs[i].rmask = 0xff;
674 else
675 mb->un.varCfgRing.rrRegs[i].rmask = 0xfe;
676 mb->un.varCfgRing.rrRegs[i].tval = pring->prt[i].type;
677 mb->un.varCfgRing.rrRegs[i].tmask = 0xff;
678 }
679
680 return;
681}
682
683void
James Smart92d7f7b2007-06-17 19:56:38 -0500684lpfc_config_port(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -0500685{
James Smarted957682007-06-17 19:56:37 -0500686 MAILBOX_t __iomem *mb_slim = (MAILBOX_t __iomem *) phba->MBslimaddr;
dea31012005-04-17 16:05:31 -0500687 MAILBOX_t *mb = &pmb->mb;
688 dma_addr_t pdma_addr;
689 uint32_t bar_low, bar_high;
690 size_t offset;
James.Smart@Emulex.Com4cc2da12005-06-25 10:34:00 -0400691 struct lpfc_hgp hgp;
James.Smart@Emulex.Comf91b3922005-10-28 20:29:28 -0400692 int i;
James Smarted957682007-06-17 19:56:37 -0500693 uint32_t pgp_offset;
dea31012005-04-17 16:05:31 -0500694
695 memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
696 mb->mbxCommand = MBX_CONFIG_PORT;
697 mb->mbxOwner = OWN_HOST;
698
699 mb->un.varCfgPort.pcbLen = sizeof(PCB_t);
700
701 offset = (uint8_t *)&phba->slim2p->pcb - (uint8_t *)phba->slim2p;
702 pdma_addr = phba->slim2p_mapping + offset;
703 mb->un.varCfgPort.pcbLow = putPaddrLow(pdma_addr);
704 mb->un.varCfgPort.pcbHigh = putPaddrHigh(pdma_addr);
705
James Smarted957682007-06-17 19:56:37 -0500706 /* If HBA supports SLI=3 ask for it */
707
James Smart92d7f7b2007-06-17 19:56:38 -0500708 if (phba->sli_rev == 3 && phba->vpd.sli3Feat.cerbm) {
James Smarted957682007-06-17 19:56:37 -0500709 mb->un.varCfgPort.cerbm = 1; /* Request HBQs */
James Smart51ef4c22007-08-02 11:10:31 -0400710 mb->un.varCfgPort.max_hbq = lpfc_sli_hbq_count();
James Smart78b2d852007-08-02 11:10:21 -0400711 if (phba->max_vpi && phba->cfg_enable_npiv &&
James Smart92d7f7b2007-06-17 19:56:38 -0500712 phba->vpd.sli3Feat.cmv) {
713 mb->un.varCfgPort.max_vpi = phba->max_vpi;
714 mb->un.varCfgPort.cmv = 1;
715 phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
716 } else
717 mb->un.varCfgPort.max_vpi = phba->max_vpi = 0;
718 } else
719 phba->sli_rev = 2;
720 mb->un.varCfgPort.sli_mode = phba->sli_rev;
James Smarted957682007-06-17 19:56:37 -0500721
dea31012005-04-17 16:05:31 -0500722 /* Now setup pcb */
723 phba->slim2p->pcb.type = TYPE_NATIVE_SLI2;
724 phba->slim2p->pcb.feature = FEATURE_INITIAL_SLI2;
725
726 /* Setup Mailbox pointers */
James Smarted957682007-06-17 19:56:37 -0500727 phba->slim2p->pcb.mailBoxSize = offsetof(MAILBOX_t, us) +
728 sizeof(struct sli2_desc);
dea31012005-04-17 16:05:31 -0500729 offset = (uint8_t *)&phba->slim2p->mbx - (uint8_t *)phba->slim2p;
730 pdma_addr = phba->slim2p_mapping + offset;
731 phba->slim2p->pcb.mbAddrHigh = putPaddrHigh(pdma_addr);
732 phba->slim2p->pcb.mbAddrLow = putPaddrLow(pdma_addr);
733
734 /*
735 * Setup Host Group ring pointer.
736 *
737 * For efficiency reasons, the ring get/put pointers can be
738 * placed in adapter memory (SLIM) rather than in host memory.
739 * This allows firmware to avoid PCI reads/writes when updating
740 * and checking pointers.
741 *
742 * The firmware recognizes the use of SLIM memory by comparing
743 * the address of the get/put pointers structure with that of
744 * the SLIM BAR (BAR0).
745 *
746 * Caution: be sure to use the PCI config space value of BAR0/BAR1
747 * (the hardware's view of the base address), not the OS's
748 * value of pci_resource_start() as the OS value may be a cookie
749 * for ioremap/iomap.
750 */
751
752
753 pci_read_config_dword(phba->pcidev, PCI_BASE_ADDRESS_0, &bar_low);
754 pci_read_config_dword(phba->pcidev, PCI_BASE_ADDRESS_1, &bar_high);
755
James Smarted957682007-06-17 19:56:37 -0500756 /*
757 * Set up HGP - Port Memory
758 *
759 * The port expects the host get/put pointers to reside in memory
760 * following the "non-diagnostic" mode mailbox (32 words, 0x80 bytes)
761 * area of SLIM. In SLI-2 mode, there's an additional 16 reserved
762 * words (0x40 bytes). This area is not reserved if HBQs are
763 * configured in SLI-3.
764 *
765 * CR0Put - SLI2(no HBQs) = 0xc0, With HBQs = 0x80
766 * RR0Get 0xc4 0x84
767 * CR1Put 0xc8 0x88
768 * RR1Get 0xcc 0x8c
769 * CR2Put 0xd0 0x90
770 * RR2Get 0xd4 0x94
771 * CR3Put 0xd8 0x98
772 * RR3Get 0xdc 0x9c
773 *
774 * Reserved 0xa0-0xbf
775 * If HBQs configured:
776 * HBQ 0 Put ptr 0xc0
777 * HBQ 1 Put ptr 0xc4
778 * HBQ 2 Put ptr 0xc8
779 * ......
780 * HBQ(M-1)Put Pointer 0xc0+(M-1)*4
781 *
782 */
783
784 if (phba->sli_rev == 3) {
785 phba->host_gp = &mb_slim->us.s3.host[0];
786 phba->hbq_put = &mb_slim->us.s3.hbq_put[0];
787 } else {
788 phba->host_gp = &mb_slim->us.s2.host[0];
789 phba->hbq_put = NULL;
790 }
dea31012005-04-17 16:05:31 -0500791
792 /* mask off BAR0's flag bits 0 - 3 */
793 phba->slim2p->pcb.hgpAddrLow = (bar_low & PCI_BASE_ADDRESS_MEM_MASK) +
James Smarted957682007-06-17 19:56:37 -0500794 (void __iomem *) phba->host_gp -
795 (void __iomem *)phba->MBslimaddr;
dea31012005-04-17 16:05:31 -0500796 if (bar_low & PCI_BASE_ADDRESS_MEM_TYPE_64)
797 phba->slim2p->pcb.hgpAddrHigh = bar_high;
798 else
799 phba->slim2p->pcb.hgpAddrHigh = 0;
800 /* write HGP data to SLIM at the required longword offset */
James.Smart@Emulex.Com4cc2da12005-06-25 10:34:00 -0400801 memset(&hgp, 0, sizeof(struct lpfc_hgp));
James.Smart@Emulex.Comf91b3922005-10-28 20:29:28 -0400802
803 for (i=0; i < phba->sli.num_rings; i++) {
James Smarted957682007-06-17 19:56:37 -0500804 lpfc_memcpy_to_slim(phba->host_gp + i, &hgp,
805 sizeof(*phba->host_gp));
James.Smart@Emulex.Comf91b3922005-10-28 20:29:28 -0400806 }
dea31012005-04-17 16:05:31 -0500807
808 /* Setup Port Group ring pointer */
James Smarted957682007-06-17 19:56:37 -0500809 if (phba->sli_rev == 3)
810 pgp_offset = (uint8_t *)&phba->slim2p->mbx.us.s3_pgp.port -
811 (uint8_t *)phba->slim2p;
812 else
813 pgp_offset = (uint8_t *)&phba->slim2p->mbx.us.s2.port -
814 (uint8_t *)phba->slim2p;
815
816 pdma_addr = phba->slim2p_mapping + pgp_offset;
dea31012005-04-17 16:05:31 -0500817 phba->slim2p->pcb.pgpAddrHigh = putPaddrHigh(pdma_addr);
818 phba->slim2p->pcb.pgpAddrLow = putPaddrLow(pdma_addr);
James Smarted957682007-06-17 19:56:37 -0500819 phba->hbq_get = &phba->slim2p->mbx.us.s3_pgp.hbq_get[0];
dea31012005-04-17 16:05:31 -0500820
821 /* Use callback routine to setp rings in the pcb */
822 lpfc_config_pcb_setup(phba);
823
824 /* special handling for LC HBAs */
825 if (lpfc_is_LC_HBA(phba->pcidev->device)) {
826 uint32_t hbainit[5];
827
828 lpfc_hba_init(phba, hbainit);
829
830 memcpy(&mb->un.varCfgPort.hbainit, hbainit, 20);
831 }
832
833 /* Swap PCB if needed */
834 lpfc_sli_pcimem_bcopy(&phba->slim2p->pcb, &phba->slim2p->pcb,
James Smart92d7f7b2007-06-17 19:56:38 -0500835 sizeof(PCB_t));
dea31012005-04-17 16:05:31 -0500836}
837
838void
Jamie Wellnitz41415862006-02-28 19:25:27 -0500839lpfc_kill_board(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
840{
841 MAILBOX_t *mb = &pmb->mb;
842
843 memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
844 mb->mbxCommand = MBX_KILL_BOARD;
845 mb->mbxOwner = OWN_HOST;
846 return;
847}
848
849void
dea31012005-04-17 16:05:31 -0500850lpfc_mbox_put(struct lpfc_hba * phba, LPFC_MBOXQ_t * mbq)
851{
852 struct lpfc_sli *psli;
853
854 psli = &phba->sli;
855
856 list_add_tail(&mbq->list, &psli->mboxq);
857
858 psli->mboxq_cnt++;
859
860 return;
861}
862
863LPFC_MBOXQ_t *
864lpfc_mbox_get(struct lpfc_hba * phba)
865{
866 LPFC_MBOXQ_t *mbq = NULL;
867 struct lpfc_sli *psli = &phba->sli;
868
James Smart2e0fef82007-06-17 19:56:36 -0500869 list_remove_head((&psli->mboxq), mbq, LPFC_MBOXQ_t, list);
James Smart92d7f7b2007-06-17 19:56:38 -0500870 if (mbq)
dea31012005-04-17 16:05:31 -0500871 psli->mboxq_cnt--;
dea31012005-04-17 16:05:31 -0500872
873 return mbq;
874}
James Smarta309a6b2006-08-01 07:33:43 -0400875
James Smart92d7f7b2007-06-17 19:56:38 -0500876void
877lpfc_mbox_cmpl_put(struct lpfc_hba * phba, LPFC_MBOXQ_t * mbq)
878{
879 /* This function expects to be called from interupt context */
880 spin_lock(&phba->hbalock);
881 list_add_tail(&mbq->list, &phba->sli.mboxq_cmpl);
882 spin_unlock(&phba->hbalock);
883 return;
884}
885
James Smarta309a6b2006-08-01 07:33:43 -0400886int
887lpfc_mbox_tmo_val(struct lpfc_hba *phba, int cmd)
888{
889 switch (cmd) {
890 case MBX_WRITE_NV: /* 0x03 */
891 case MBX_UPDATE_CFG: /* 0x1B */
892 case MBX_DOWN_LOAD: /* 0x1C */
893 case MBX_DEL_LD_ENTRY: /* 0x1D */
894 case MBX_LOAD_AREA: /* 0x81 */
895 case MBX_FLASH_WR_ULA: /* 0x98 */
896 case MBX_LOAD_EXP_ROM: /* 0x9C */
897 return LPFC_MBOX_TMO_FLASH_CMD;
898 }
899 return LPFC_MBOX_TMO;
900}