| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1 | /******************************************************************* |
| 2 | * This file is part of the Emulex Linux Device Driver for * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 3 | * Fibre Channel Host Bus Adapters. * |
James Smart | 92c13f2 | 2013-05-31 17:05:45 -0400 | [diff] [blame] | 4 | * Copyright (C) 2004-2013 Emulex. All rights reserved. * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 5 | * EMULEX and SLI are trademarks of Emulex. * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 6 | * www.emulex.com * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 7 | * Portions Copyright (C) 2004-2005 Christoph Hellwig * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 8 | * * |
| 9 | * This program is free software; you can redistribute it and/or * |
James.Smart@Emulex.Com | c44ce17 | 2005-06-25 10:34:39 -0400 | [diff] [blame] | 10 | * 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. * |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 20 | *******************************************************************/ |
| 21 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 22 | #include <linux/blkdev.h> |
| 23 | #include <linux/pci.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 24 | #include <linux/slab.h> |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 25 | #include <linux/interrupt.h> |
| 26 | |
James.Smart@Emulex.Com | f888ba3 | 2005-08-10 15:03:01 -0400 | [diff] [blame] | 27 | #include <scsi/scsi_device.h> |
| 28 | #include <scsi/scsi_transport_fc.h> |
James.Smart@Emulex.Com | 9188652 | 2005-08-10 15:03:09 -0400 | [diff] [blame] | 29 | #include <scsi/scsi.h> |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 30 | #include <scsi/fc/fc_fs.h> |
James.Smart@Emulex.Com | 9188652 | 2005-08-10 15:03:09 -0400 | [diff] [blame] | 31 | |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 32 | #include "lpfc_hw4.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 33 | #include "lpfc_hw.h" |
| 34 | #include "lpfc_sli.h" |
James Smart | da0436e | 2009-05-22 14:51:39 -0400 | [diff] [blame] | 35 | #include "lpfc_sli4.h" |
James Smart | ea2151b | 2008-09-07 11:52:10 -0400 | [diff] [blame] | 36 | #include "lpfc_nl.h" |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 37 | #include "lpfc_disc.h" |
| 38 | #include "lpfc_scsi.h" |
| 39 | #include "lpfc.h" |
| 40 | #include "lpfc_logmsg.h" |
| 41 | #include "lpfc_crtn.h" |
| 42 | #include "lpfc_compat.h" |
| 43 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 44 | /** |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 45 | * lpfc_dump_static_vport - Dump HBA's static vport information. |
| 46 | * @phba: pointer to lpfc hba data structure. |
| 47 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 48 | * @offset: offset for dumping vport info. |
| 49 | * |
| 50 | * The dump mailbox command provides a method for the device driver to obtain |
| 51 | * various types of information from the HBA device. |
| 52 | * |
| 53 | * This routine prepares the mailbox command for dumping list of static |
| 54 | * vports to be created. |
| 55 | **/ |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 56 | int |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 57 | lpfc_dump_static_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb, |
| 58 | uint16_t offset) |
| 59 | { |
| 60 | MAILBOX_t *mb; |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 61 | struct lpfc_dmabuf *mp; |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 62 | |
| 63 | mb = &pmb->u.mb; |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 64 | |
| 65 | /* Setup to dump vport info region */ |
| 66 | memset(pmb, 0, sizeof(LPFC_MBOXQ_t)); |
| 67 | mb->mbxCommand = MBX_DUMP_MEMORY; |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 68 | mb->un.varDmp.type = DMP_NV_PARAMS; |
| 69 | mb->un.varDmp.entry_index = offset; |
| 70 | mb->un.varDmp.region_id = DMP_REGION_VPORT; |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 71 | mb->mbxOwner = OWN_HOST; |
| 72 | |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 73 | /* For SLI3 HBAs data is embedded in mailbox */ |
| 74 | if (phba->sli_rev != LPFC_SLI_REV4) { |
| 75 | mb->un.varDmp.cv = 1; |
| 76 | mb->un.varDmp.word_cnt = DMP_RSP_SIZE/sizeof(uint32_t); |
| 77 | return 0; |
| 78 | } |
| 79 | |
| 80 | /* For SLI4 HBAs driver need to allocate memory */ |
| 81 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 82 | if (mp) |
| 83 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); |
| 84 | |
| 85 | if (!mp || !mp->virt) { |
| 86 | kfree(mp); |
| 87 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
| 88 | "2605 lpfc_dump_static_vport: memory" |
| 89 | " allocation failed\n"); |
| 90 | return 1; |
| 91 | } |
| 92 | memset(mp->virt, 0, LPFC_BPL_SIZE); |
| 93 | INIT_LIST_HEAD(&mp->list); |
| 94 | /* save address for completion */ |
James Smart | cdcc234 | 2012-08-14 14:26:35 -0400 | [diff] [blame] | 95 | pmb->context1 = (uint8_t *)mp; |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 96 | mb->un.varWords[3] = putPaddrLow(mp->phys); |
| 97 | mb->un.varWords[4] = putPaddrHigh(mp->phys); |
| 98 | mb->un.varDmp.sli4_length = sizeof(struct static_vport_info); |
| 99 | |
| 100 | return 0; |
James Smart | 21e9a0a | 2009-05-22 14:53:21 -0400 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | /** |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 104 | * lpfc_down_link - Bring down HBAs link. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 105 | * @phba: pointer to lpfc hba data structure. |
| 106 | * @pmb: pointer to the driver internal queue element for mailbox command. |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 107 | * |
| 108 | * This routine prepares a mailbox command to bring down HBA link. |
| 109 | **/ |
| 110 | void |
| 111 | lpfc_down_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 112 | { |
| 113 | MAILBOX_t *mb; |
| 114 | memset(pmb, 0, sizeof(LPFC_MBOXQ_t)); |
| 115 | mb = &pmb->u.mb; |
| 116 | mb->mbxCommand = MBX_DOWN_LINK; |
| 117 | mb->mbxOwner = OWN_HOST; |
| 118 | } |
| 119 | |
| 120 | /** |
| 121 | * lpfc_dump_mem - Prepare a mailbox command for reading a region. |
| 122 | * @phba: pointer to lpfc hba data structure. |
| 123 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 124 | * @offset: offset into the region. |
| 125 | * @region_id: config region id. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 126 | * |
| 127 | * The dump mailbox command provides a method for the device driver to obtain |
| 128 | * various types of information from the HBA device. |
| 129 | * |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 130 | * This routine prepares the mailbox command for dumping HBA's config region. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 131 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 132 | void |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 133 | lpfc_dump_mem(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb, uint16_t offset, |
| 134 | uint16_t region_id) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 135 | { |
| 136 | MAILBOX_t *mb; |
| 137 | void *ctx; |
| 138 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 139 | mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 140 | ctx = pmb->context2; |
| 141 | |
| 142 | /* Setup to dump VPD region */ |
| 143 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 144 | mb->mbxCommand = MBX_DUMP_MEMORY; |
| 145 | mb->un.varDmp.cv = 1; |
| 146 | mb->un.varDmp.type = DMP_NV_PARAMS; |
| 147 | mb->un.varDmp.entry_index = offset; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 148 | mb->un.varDmp.region_id = region_id; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 149 | mb->un.varDmp.word_cnt = (DMP_RSP_SIZE / sizeof (uint32_t)); |
| 150 | mb->un.varDmp.co = 0; |
| 151 | mb->un.varDmp.resp_offset = 0; |
| 152 | pmb->context2 = ctx; |
| 153 | mb->mbxOwner = OWN_HOST; |
| 154 | return; |
| 155 | } |
| 156 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 157 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 158 | * lpfc_dump_wakeup_param - Prepare mailbox command for retrieving wakeup params |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 159 | * @phba: pointer to lpfc hba data structure. |
| 160 | * @pmb: pointer to the driver internal queue element for mailbox command. |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 161 | * |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 162 | * This function create a dump memory mailbox command to dump wake up |
| 163 | * parameters. |
| 164 | */ |
| 165 | void |
| 166 | lpfc_dump_wakeup_param(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 167 | { |
| 168 | MAILBOX_t *mb; |
| 169 | void *ctx; |
| 170 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 171 | mb = &pmb->u.mb; |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 172 | /* Save context so that we can restore after memset */ |
| 173 | ctx = pmb->context2; |
| 174 | |
| 175 | /* Setup to dump VPD region */ |
| 176 | memset(pmb, 0, sizeof(LPFC_MBOXQ_t)); |
| 177 | mb->mbxCommand = MBX_DUMP_MEMORY; |
| 178 | mb->mbxOwner = OWN_HOST; |
| 179 | mb->un.varDmp.cv = 1; |
| 180 | mb->un.varDmp.type = DMP_NV_PARAMS; |
James Smart | 1d1c296 | 2013-07-15 18:33:04 -0400 | [diff] [blame] | 181 | if (phba->sli_rev < LPFC_SLI_REV4) |
| 182 | mb->un.varDmp.entry_index = 0; |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 183 | mb->un.varDmp.region_id = WAKE_UP_PARMS_REGION_ID; |
| 184 | mb->un.varDmp.word_cnt = WAKE_UP_PARMS_WORD_SIZE; |
| 185 | mb->un.varDmp.co = 0; |
| 186 | mb->un.varDmp.resp_offset = 0; |
| 187 | pmb->context2 = ctx; |
| 188 | return; |
| 189 | } |
| 190 | |
| 191 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 192 | * lpfc_read_nv - Prepare a mailbox command for reading HBA's NVRAM param |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 193 | * @phba: pointer to lpfc hba data structure. |
| 194 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 195 | * |
| 196 | * The read NVRAM mailbox command returns the HBA's non-volatile parameters |
| 197 | * that are used as defaults when the Fibre Channel link is brought on-line. |
| 198 | * |
| 199 | * This routine prepares the mailbox command for reading information stored |
| 200 | * in the HBA's NVRAM. Specifically, the HBA's WWNN and WWPN. |
| 201 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 202 | void |
| 203 | lpfc_read_nv(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) |
| 204 | { |
| 205 | MAILBOX_t *mb; |
| 206 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 207 | mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 208 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 209 | mb->mbxCommand = MBX_READ_NV; |
| 210 | mb->mbxOwner = OWN_HOST; |
| 211 | return; |
| 212 | } |
| 213 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 214 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 215 | * lpfc_config_async - Prepare a mailbox command for enabling HBA async event |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 216 | * @phba: pointer to lpfc hba data structure. |
| 217 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 218 | * @ring: ring number for the asynchronous event to be configured. |
| 219 | * |
| 220 | * The asynchronous event enable mailbox command is used to enable the |
| 221 | * asynchronous event posting via the ASYNC_STATUS_CN IOCB response and |
| 222 | * specifies the default ring to which events are posted. |
| 223 | * |
| 224 | * This routine prepares the mailbox command for enabling HBA asynchronous |
| 225 | * event support on a IOCB ring. |
| 226 | **/ |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 227 | void |
| 228 | lpfc_config_async(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb, |
| 229 | uint32_t ring) |
| 230 | { |
| 231 | MAILBOX_t *mb; |
| 232 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 233 | mb = &pmb->u.mb; |
James Smart | 57127f1 | 2007-10-27 13:37:05 -0400 | [diff] [blame] | 234 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 235 | mb->mbxCommand = MBX_ASYNCEVT_ENABLE; |
| 236 | mb->un.varCfgAsyncEvent.ring = ring; |
| 237 | mb->mbxOwner = OWN_HOST; |
| 238 | return; |
| 239 | } |
| 240 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 241 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 242 | * lpfc_heart_beat - Prepare a mailbox command for heart beat |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 243 | * @phba: pointer to lpfc hba data structure. |
| 244 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 245 | * |
| 246 | * The heart beat mailbox command is used to detect an unresponsive HBA, which |
| 247 | * is defined as any device where no error attention is sent and both mailbox |
| 248 | * and rings are not processed. |
| 249 | * |
| 250 | * This routine prepares the mailbox command for issuing a heart beat in the |
| 251 | * form of mailbox command to the HBA. The timely completion of the heart |
| 252 | * beat mailbox command indicates the health of the HBA. |
| 253 | **/ |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 254 | void |
| 255 | lpfc_heart_beat(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) |
| 256 | { |
| 257 | MAILBOX_t *mb; |
| 258 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 259 | mb = &pmb->u.mb; |
James Smart | 858c9f6 | 2007-06-17 19:56:39 -0500 | [diff] [blame] | 260 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 261 | mb->mbxCommand = MBX_HEARTBEAT; |
| 262 | mb->mbxOwner = OWN_HOST; |
| 263 | return; |
| 264 | } |
| 265 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 266 | /** |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 267 | * lpfc_read_topology - Prepare a mailbox command for reading HBA topology |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 268 | * @phba: pointer to lpfc hba data structure. |
| 269 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 270 | * @mp: DMA buffer memory for reading the link attention information into. |
| 271 | * |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 272 | * The read topology mailbox command is issued to read the link topology |
| 273 | * information indicated by the HBA port when the Link Event bit of the Host |
| 274 | * Attention (HSTATT) register is set to 1 (For SLI-3) or when an FC Link |
| 275 | * Attention ACQE is received from the port (For SLI-4). A Link Event |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 276 | * Attention occurs based on an exception detected at the Fibre Channel link |
| 277 | * interface. |
| 278 | * |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 279 | * This routine prepares the mailbox command for reading HBA link topology |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 280 | * information. A DMA memory has been set aside and address passed to the |
| 281 | * HBA through @mp for the HBA to DMA link attention information into the |
| 282 | * memory as part of the execution of the mailbox command. |
| 283 | * |
| 284 | * Return codes |
| 285 | * 0 - Success (currently always return 0) |
| 286 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 287 | int |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 288 | lpfc_read_topology(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb, |
| 289 | struct lpfc_dmabuf *mp) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 290 | { |
| 291 | MAILBOX_t *mb; |
| 292 | struct lpfc_sli *psli; |
| 293 | |
| 294 | psli = &phba->sli; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 295 | mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 296 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 297 | |
| 298 | INIT_LIST_HEAD(&mp->list); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 299 | mb->mbxCommand = MBX_READ_TOPOLOGY; |
| 300 | mb->un.varReadTop.lilpBde64.tus.f.bdeSize = LPFC_ALPA_MAP_SIZE; |
| 301 | mb->un.varReadTop.lilpBde64.addrHigh = putPaddrHigh(mp->phys); |
| 302 | mb->un.varReadTop.lilpBde64.addrLow = putPaddrLow(mp->phys); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 303 | |
| 304 | /* Save address for later completion and set the owner to host so that |
| 305 | * the FW knows this mailbox is available for processing. |
| 306 | */ |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 307 | pmb->context1 = (uint8_t *)mp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 308 | mb->mbxOwner = OWN_HOST; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 309 | return (0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 310 | } |
| 311 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 312 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 313 | * lpfc_clear_la - Prepare a mailbox command for clearing HBA link attention |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 314 | * @phba: pointer to lpfc hba data structure. |
| 315 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 316 | * |
| 317 | * The clear link attention mailbox command is issued to clear the link event |
| 318 | * attention condition indicated by the Link Event bit of the Host Attention |
| 319 | * (HSTATT) register. The link event attention condition is cleared only if |
| 320 | * the event tag specified matches that of the current link event counter. |
| 321 | * The current event tag is read using the read link attention event mailbox |
| 322 | * command. |
| 323 | * |
| 324 | * This routine prepares the mailbox command for clearing HBA link attention |
| 325 | * information. |
| 326 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 327 | void |
| 328 | lpfc_clear_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) |
| 329 | { |
| 330 | MAILBOX_t *mb; |
| 331 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 332 | mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 333 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 334 | |
| 335 | mb->un.varClearLA.eventTag = phba->fc_eventTag; |
| 336 | mb->mbxCommand = MBX_CLEAR_LA; |
| 337 | mb->mbxOwner = OWN_HOST; |
| 338 | return; |
| 339 | } |
| 340 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 341 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 342 | * lpfc_config_link - Prepare a mailbox command for configuring link on a HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 343 | * @phba: pointer to lpfc hba data structure. |
| 344 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 345 | * |
| 346 | * The configure link mailbox command is used before the initialize link |
| 347 | * mailbox command to override default value and to configure link-oriented |
| 348 | * parameters such as DID address and various timers. Typically, this |
| 349 | * command would be used after an F_Port login to set the returned DID address |
| 350 | * and the fabric timeout values. This command is not valid before a configure |
| 351 | * port command has configured the HBA port. |
| 352 | * |
| 353 | * This routine prepares the mailbox command for configuring link on a HBA. |
| 354 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 355 | void |
| 356 | lpfc_config_link(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) |
| 357 | { |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 358 | struct lpfc_vport *vport = phba->pport; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 359 | MAILBOX_t *mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 360 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 361 | |
| 362 | /* NEW_FEATURE |
| 363 | * SLI-2, Coalescing Response Feature. |
| 364 | */ |
James Smart | 1d1c296 | 2013-07-15 18:33:04 -0400 | [diff] [blame] | 365 | if (phba->cfg_cr_delay && (phba->sli_rev < LPFC_SLI_REV4)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 366 | mb->un.varCfgLnk.cr = 1; |
| 367 | mb->un.varCfgLnk.ci = 1; |
| 368 | mb->un.varCfgLnk.cr_delay = phba->cfg_cr_delay; |
| 369 | mb->un.varCfgLnk.cr_count = phba->cfg_cr_count; |
| 370 | } |
| 371 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 372 | mb->un.varCfgLnk.myId = vport->fc_myDID; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 373 | mb->un.varCfgLnk.edtov = phba->fc_edtov; |
| 374 | mb->un.varCfgLnk.arbtov = phba->fc_arbtov; |
| 375 | mb->un.varCfgLnk.ratov = phba->fc_ratov; |
| 376 | mb->un.varCfgLnk.rttov = phba->fc_rttov; |
| 377 | mb->un.varCfgLnk.altov = phba->fc_altov; |
| 378 | mb->un.varCfgLnk.crtov = phba->fc_crtov; |
| 379 | mb->un.varCfgLnk.citov = phba->fc_citov; |
| 380 | |
James Smart | 1d1c296 | 2013-07-15 18:33:04 -0400 | [diff] [blame] | 381 | if (phba->cfg_ack0 && (phba->sli_rev < LPFC_SLI_REV4)) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 382 | mb->un.varCfgLnk.ack0_enable = 1; |
| 383 | |
| 384 | mb->mbxCommand = MBX_CONFIG_LINK; |
| 385 | mb->mbxOwner = OWN_HOST; |
| 386 | return; |
| 387 | } |
| 388 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 389 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 390 | * lpfc_config_msi - Prepare a mailbox command for configuring msi-x |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 391 | * @phba: pointer to lpfc hba data structure. |
| 392 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 393 | * |
| 394 | * The configure MSI-X mailbox command is used to configure the HBA's SLI-3 |
| 395 | * MSI-X multi-message interrupt vector association to interrupt attention |
| 396 | * conditions. |
| 397 | * |
| 398 | * Return codes |
| 399 | * 0 - Success |
| 400 | * -EINVAL - Failure |
| 401 | **/ |
| 402 | int |
| 403 | lpfc_config_msi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 404 | { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 405 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 9399627 | 2008-08-24 21:50:30 -0400 | [diff] [blame] | 406 | uint32_t attentionConditions[2]; |
| 407 | |
| 408 | /* Sanity check */ |
| 409 | if (phba->cfg_use_msi != 2) { |
| 410 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 411 | "0475 Not configured for supporting MSI-X " |
| 412 | "cfg_use_msi: 0x%x\n", phba->cfg_use_msi); |
| 413 | return -EINVAL; |
| 414 | } |
| 415 | |
| 416 | if (phba->sli_rev < 3) { |
| 417 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
| 418 | "0476 HBA not supporting SLI-3 or later " |
| 419 | "SLI Revision: 0x%x\n", phba->sli_rev); |
| 420 | return -EINVAL; |
| 421 | } |
| 422 | |
| 423 | /* Clear mailbox command fields */ |
| 424 | memset(pmb, 0, sizeof(LPFC_MBOXQ_t)); |
| 425 | |
| 426 | /* |
| 427 | * SLI-3, Message Signaled Interrupt Fearure. |
| 428 | */ |
| 429 | |
| 430 | /* Multi-message attention configuration */ |
| 431 | attentionConditions[0] = (HA_R0ATT | HA_R1ATT | HA_R2ATT | HA_ERATT | |
| 432 | HA_LATT | HA_MBATT); |
| 433 | attentionConditions[1] = 0; |
| 434 | |
| 435 | mb->un.varCfgMSI.attentionConditions[0] = attentionConditions[0]; |
| 436 | mb->un.varCfgMSI.attentionConditions[1] = attentionConditions[1]; |
| 437 | |
| 438 | /* |
| 439 | * Set up message number to HA bit association |
| 440 | */ |
| 441 | #ifdef __BIG_ENDIAN_BITFIELD |
| 442 | /* RA0 (FCP Ring) */ |
| 443 | mb->un.varCfgMSI.messageNumberByHA[HA_R0_POS] = 1; |
| 444 | /* RA1 (Other Protocol Extra Ring) */ |
| 445 | mb->un.varCfgMSI.messageNumberByHA[HA_R1_POS] = 1; |
| 446 | #else /* __LITTLE_ENDIAN_BITFIELD */ |
| 447 | /* RA0 (FCP Ring) */ |
| 448 | mb->un.varCfgMSI.messageNumberByHA[HA_R0_POS^3] = 1; |
| 449 | /* RA1 (Other Protocol Extra Ring) */ |
| 450 | mb->un.varCfgMSI.messageNumberByHA[HA_R1_POS^3] = 1; |
| 451 | #endif |
| 452 | /* Multi-message interrupt autoclear configuration*/ |
| 453 | mb->un.varCfgMSI.autoClearHA[0] = attentionConditions[0]; |
| 454 | mb->un.varCfgMSI.autoClearHA[1] = attentionConditions[1]; |
| 455 | |
| 456 | /* For now, HBA autoclear does not work reliably, disable it */ |
| 457 | mb->un.varCfgMSI.autoClearHA[0] = 0; |
| 458 | mb->un.varCfgMSI.autoClearHA[1] = 0; |
| 459 | |
| 460 | /* Set command and owner bit */ |
| 461 | mb->mbxCommand = MBX_CONFIG_MSI; |
| 462 | mb->mbxOwner = OWN_HOST; |
| 463 | |
| 464 | return 0; |
| 465 | } |
| 466 | |
| 467 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 468 | * lpfc_init_link - Prepare a mailbox command for initialize link on a HBA |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 469 | * @phba: pointer to lpfc hba data structure. |
| 470 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 471 | * @topology: the link topology for the link to be initialized to. |
| 472 | * @linkspeed: the link speed for the link to be initialized to. |
| 473 | * |
| 474 | * The initialize link mailbox command is used to initialize the Fibre |
| 475 | * Channel link. This command must follow a configure port command that |
| 476 | * establishes the mode of operation. |
| 477 | * |
| 478 | * This routine prepares the mailbox command for initializing link on a HBA |
| 479 | * with the specified link topology and speed. |
| 480 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 481 | void |
| 482 | lpfc_init_link(struct lpfc_hba * phba, |
| 483 | LPFC_MBOXQ_t * pmb, uint32_t topology, uint32_t linkspeed) |
| 484 | { |
| 485 | lpfc_vpd_t *vpd; |
| 486 | struct lpfc_sli *psli; |
| 487 | MAILBOX_t *mb; |
| 488 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 489 | mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 490 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 491 | |
| 492 | psli = &phba->sli; |
| 493 | switch (topology) { |
| 494 | case FLAGS_TOPOLOGY_MODE_LOOP_PT: |
| 495 | mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_LOOP; |
| 496 | mb->un.varInitLnk.link_flags |= FLAGS_TOPOLOGY_FAILOVER; |
| 497 | break; |
| 498 | case FLAGS_TOPOLOGY_MODE_PT_PT: |
| 499 | mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_PT_PT; |
| 500 | break; |
| 501 | case FLAGS_TOPOLOGY_MODE_LOOP: |
| 502 | mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_LOOP; |
| 503 | break; |
| 504 | case FLAGS_TOPOLOGY_MODE_PT_LOOP: |
| 505 | mb->un.varInitLnk.link_flags = FLAGS_TOPOLOGY_MODE_PT_PT; |
| 506 | mb->un.varInitLnk.link_flags |= FLAGS_TOPOLOGY_FAILOVER; |
| 507 | break; |
Jamie Wellnitz | 367c271 | 2006-02-28 19:25:32 -0500 | [diff] [blame] | 508 | case FLAGS_LOCAL_LB: |
| 509 | mb->un.varInitLnk.link_flags = FLAGS_LOCAL_LB; |
| 510 | break; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 511 | } |
| 512 | |
James Smart | 4b0b91d | 2006-04-15 11:53:00 -0400 | [diff] [blame] | 513 | /* Enable asynchronous ABTS responses from firmware */ |
| 514 | mb->un.varInitLnk.link_flags |= FLAGS_IMED_ABORT; |
| 515 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 516 | /* NEW_FEATURE |
| 517 | * Setting up the link speed |
| 518 | */ |
| 519 | vpd = &phba->vpd; |
| 520 | if (vpd->rev.feaLevelHigh >= 0x02){ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 521 | switch(linkspeed){ |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 522 | case LPFC_USER_LINK_SPEED_1G: |
| 523 | mb->un.varInitLnk.link_flags |= FLAGS_LINK_SPEED; |
| 524 | mb->un.varInitLnk.link_speed = LINK_SPEED_1G; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 525 | break; |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 526 | case LPFC_USER_LINK_SPEED_2G: |
| 527 | mb->un.varInitLnk.link_flags |= FLAGS_LINK_SPEED; |
| 528 | mb->un.varInitLnk.link_speed = LINK_SPEED_2G; |
| 529 | break; |
| 530 | case LPFC_USER_LINK_SPEED_4G: |
| 531 | mb->un.varInitLnk.link_flags |= FLAGS_LINK_SPEED; |
| 532 | mb->un.varInitLnk.link_speed = LINK_SPEED_4G; |
| 533 | break; |
| 534 | case LPFC_USER_LINK_SPEED_8G: |
| 535 | mb->un.varInitLnk.link_flags |= FLAGS_LINK_SPEED; |
| 536 | mb->un.varInitLnk.link_speed = LINK_SPEED_8G; |
| 537 | break; |
| 538 | case LPFC_USER_LINK_SPEED_10G: |
| 539 | mb->un.varInitLnk.link_flags |= FLAGS_LINK_SPEED; |
| 540 | mb->un.varInitLnk.link_speed = LINK_SPEED_10G; |
| 541 | break; |
| 542 | case LPFC_USER_LINK_SPEED_16G: |
| 543 | mb->un.varInitLnk.link_flags |= FLAGS_LINK_SPEED; |
| 544 | mb->un.varInitLnk.link_speed = LINK_SPEED_16G; |
| 545 | break; |
| 546 | case LPFC_USER_LINK_SPEED_AUTO: |
| 547 | default: |
| 548 | mb->un.varInitLnk.link_speed = LINK_SPEED_AUTO; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 549 | break; |
| 550 | } |
| 551 | |
| 552 | } |
| 553 | else |
| 554 | mb->un.varInitLnk.link_speed = LINK_SPEED_AUTO; |
| 555 | |
| 556 | mb->mbxCommand = (volatile uint8_t)MBX_INIT_LINK; |
| 557 | mb->mbxOwner = OWN_HOST; |
| 558 | mb->un.varInitLnk.fabric_AL_PA = phba->fc_pref_ALPA; |
| 559 | return; |
| 560 | } |
| 561 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 562 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 563 | * lpfc_read_sparam - Prepare a mailbox command for reading HBA parameters |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 564 | * @phba: pointer to lpfc hba data structure. |
| 565 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 566 | * @vpi: virtual N_Port identifier. |
| 567 | * |
| 568 | * The read service parameter mailbox command is used to read the HBA port |
| 569 | * service parameters. The service parameters are read into the buffer |
| 570 | * specified directly by a BDE in the mailbox command. These service |
| 571 | * parameters may then be used to build the payload of an N_Port/F_POrt |
| 572 | * login request and reply (LOGI/ACC). |
| 573 | * |
| 574 | * This routine prepares the mailbox command for reading HBA port service |
| 575 | * parameters. The DMA memory is allocated in this function and the addresses |
| 576 | * are populated into the mailbox command for the HBA to DMA the service |
| 577 | * parameters into. |
| 578 | * |
| 579 | * Return codes |
| 580 | * 0 - Success |
| 581 | * 1 - DMA memory allocation failed |
| 582 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 583 | int |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 584 | lpfc_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb, int vpi) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 585 | { |
| 586 | struct lpfc_dmabuf *mp; |
| 587 | MAILBOX_t *mb; |
| 588 | struct lpfc_sli *psli; |
| 589 | |
| 590 | psli = &phba->sli; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 591 | mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 592 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 593 | |
| 594 | mb->mbxOwner = OWN_HOST; |
| 595 | |
| 596 | /* Get a buffer to hold the HBAs Service Parameters */ |
| 597 | |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 598 | mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); |
| 599 | if (mp) |
| 600 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); |
| 601 | if (!mp || !mp->virt) { |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 602 | kfree(mp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 603 | mb->mbxCommand = MBX_READ_SPARM64; |
| 604 | /* READ_SPARAM: no buffers */ |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 605 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX, |
| 606 | "0301 READ_SPARAM: no buffers\n"); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 607 | return (1); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 608 | } |
| 609 | INIT_LIST_HEAD(&mp->list); |
| 610 | mb->mbxCommand = MBX_READ_SPARM64; |
| 611 | mb->un.varRdSparm.un.sp64.tus.f.bdeSize = sizeof (struct serv_parm); |
| 612 | mb->un.varRdSparm.un.sp64.addrHigh = putPaddrHigh(mp->phys); |
| 613 | mb->un.varRdSparm.un.sp64.addrLow = putPaddrLow(mp->phys); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 614 | if (phba->sli_rev >= LPFC_SLI_REV3) |
| 615 | mb->un.varRdSparm.vpi = phba->vpi_ids[vpi]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 616 | |
| 617 | /* save address for completion */ |
| 618 | pmb->context1 = mp; |
| 619 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 620 | return (0); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 621 | } |
| 622 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 623 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 624 | * lpfc_unreg_did - Prepare a mailbox command for unregistering DID |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 625 | * @phba: pointer to lpfc hba data structure. |
| 626 | * @vpi: virtual N_Port identifier. |
| 627 | * @did: remote port identifier. |
| 628 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 629 | * |
| 630 | * The unregister DID mailbox command is used to unregister an N_Port/F_Port |
| 631 | * login for an unknown RPI by specifying the DID of a remote port. This |
| 632 | * command frees an RPI context in the HBA port. This has the effect of |
| 633 | * performing an implicit N_Port/F_Port logout. |
| 634 | * |
| 635 | * This routine prepares the mailbox command for unregistering a remote |
| 636 | * N_Port/F_Port (DID) login. |
| 637 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 638 | void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 639 | lpfc_unreg_did(struct lpfc_hba * phba, uint16_t vpi, uint32_t did, |
| 640 | LPFC_MBOXQ_t * pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 641 | { |
| 642 | MAILBOX_t *mb; |
| 643 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 644 | mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 645 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 646 | |
| 647 | mb->un.varUnregDID.did = did; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 648 | mb->un.varUnregDID.vpi = vpi; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 649 | if ((vpi != 0xffff) && |
| 650 | (phba->sli_rev == LPFC_SLI_REV4)) |
| 651 | mb->un.varUnregDID.vpi = phba->vpi_ids[vpi]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 652 | |
| 653 | mb->mbxCommand = MBX_UNREG_D_ID; |
| 654 | mb->mbxOwner = OWN_HOST; |
| 655 | return; |
| 656 | } |
| 657 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 658 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 659 | * lpfc_read_config - Prepare a mailbox command for reading HBA configuration |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 660 | * @phba: pointer to lpfc hba data structure. |
| 661 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 662 | * |
| 663 | * The read configuration mailbox command is used to read the HBA port |
| 664 | * configuration parameters. This mailbox command provides a method for |
| 665 | * seeing any parameters that may have changed via various configuration |
| 666 | * mailbox commands. |
| 667 | * |
| 668 | * This routine prepares the mailbox command for reading out HBA configuration |
| 669 | * parameters. |
| 670 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 671 | void |
| 672 | lpfc_read_config(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) |
| 673 | { |
| 674 | MAILBOX_t *mb; |
| 675 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 676 | mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 677 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 678 | |
| 679 | mb->mbxCommand = MBX_READ_CONFIG; |
| 680 | mb->mbxOwner = OWN_HOST; |
| 681 | return; |
| 682 | } |
| 683 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 684 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 685 | * lpfc_read_lnk_stat - Prepare a mailbox command for reading HBA link stats |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 686 | * @phba: pointer to lpfc hba data structure. |
| 687 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 688 | * |
| 689 | * The read link status mailbox command is used to read the link status from |
| 690 | * the HBA. Link status includes all link-related error counters. These |
| 691 | * counters are maintained by the HBA and originated in the link hardware |
| 692 | * unit. Note that all of these counters wrap. |
| 693 | * |
| 694 | * This routine prepares the mailbox command for reading out HBA link status. |
| 695 | **/ |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 696 | void |
| 697 | lpfc_read_lnk_stat(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) |
| 698 | { |
| 699 | MAILBOX_t *mb; |
| 700 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 701 | mb = &pmb->u.mb; |
Jamie Wellnitz | 7bb3b13 | 2006-02-28 19:25:15 -0500 | [diff] [blame] | 702 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 703 | |
| 704 | mb->mbxCommand = MBX_READ_LNK_STAT; |
| 705 | mb->mbxOwner = OWN_HOST; |
| 706 | return; |
| 707 | } |
| 708 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 709 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 710 | * lpfc_reg_rpi - Prepare a mailbox command for registering remote login |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 711 | * @phba: pointer to lpfc hba data structure. |
| 712 | * @vpi: virtual N_Port identifier. |
| 713 | * @did: remote port identifier. |
| 714 | * @param: pointer to memory holding the server parameters. |
| 715 | * @pmb: pointer to the driver internal queue element for mailbox command. |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 716 | * @rpi: the rpi to use in the registration (usually only used for SLI4. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 717 | * |
| 718 | * The registration login mailbox command is used to register an N_Port or |
| 719 | * F_Port login. This registration allows the HBA to cache the remote N_Port |
| 720 | * service parameters internally and thereby make the appropriate FC-2 |
| 721 | * decisions. The remote port service parameters are handed off by the driver |
| 722 | * to the HBA using a descriptor entry that directly identifies a buffer in |
| 723 | * host memory. In exchange, the HBA returns an RPI identifier. |
| 724 | * |
| 725 | * This routine prepares the mailbox command for registering remote port login. |
| 726 | * The function allocates DMA buffer for passing the service parameters to the |
| 727 | * HBA with the mailbox command. |
| 728 | * |
| 729 | * Return codes |
| 730 | * 0 - Success |
| 731 | * 1 - DMA memory allocation failed |
| 732 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 733 | int |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 734 | lpfc_reg_rpi(struct lpfc_hba *phba, uint16_t vpi, uint32_t did, |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 735 | uint8_t *param, LPFC_MBOXQ_t *pmb, uint16_t rpi) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 736 | { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 737 | MAILBOX_t *mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 738 | uint8_t *sparam; |
| 739 | struct lpfc_dmabuf *mp; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 740 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 741 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 742 | |
| 743 | mb->un.varRegLogin.rpi = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 744 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 745 | mb->un.varRegLogin.rpi = phba->sli4_hba.rpi_ids[rpi]; |
| 746 | if (phba->sli_rev >= LPFC_SLI_REV3) |
| 747 | mb->un.varRegLogin.vpi = phba->vpi_ids[vpi]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 748 | mb->un.varRegLogin.did = did; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 749 | mb->mbxOwner = OWN_HOST; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 750 | /* Get a buffer to hold NPorts Service Parameters */ |
James Smart | 98c9ea5 | 2007-10-27 13:37:33 -0400 | [diff] [blame] | 751 | mp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL); |
| 752 | if (mp) |
| 753 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); |
| 754 | if (!mp || !mp->virt) { |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 755 | kfree(mp); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 756 | mb->mbxCommand = MBX_REG_LOGIN64; |
| 757 | /* REG_LOGIN: no buffers */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 758 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX, |
James Smart | e8b6201 | 2007-08-02 11:10:09 -0400 | [diff] [blame] | 759 | "0302 REG_LOGIN: no buffers, VPI:%d DID:x%x, " |
James Smart | 4042629 | 2010-12-15 17:58:10 -0500 | [diff] [blame] | 760 | "rpi x%x\n", vpi, did, rpi); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 761 | return 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 762 | } |
| 763 | INIT_LIST_HEAD(&mp->list); |
| 764 | sparam = mp->virt; |
| 765 | |
| 766 | /* Copy param's into a new buffer */ |
| 767 | memcpy(sparam, param, sizeof (struct serv_parm)); |
| 768 | |
| 769 | /* save address for completion */ |
| 770 | pmb->context1 = (uint8_t *) mp; |
| 771 | |
| 772 | mb->mbxCommand = MBX_REG_LOGIN64; |
| 773 | mb->un.varRegLogin.un.sp64.tus.f.bdeSize = sizeof (struct serv_parm); |
| 774 | mb->un.varRegLogin.un.sp64.addrHigh = putPaddrHigh(mp->phys); |
| 775 | mb->un.varRegLogin.un.sp64.addrLow = putPaddrLow(mp->phys); |
| 776 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 777 | return 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 778 | } |
| 779 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 780 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 781 | * lpfc_unreg_login - Prepare a mailbox command for unregistering remote login |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 782 | * @phba: pointer to lpfc hba data structure. |
| 783 | * @vpi: virtual N_Port identifier. |
| 784 | * @rpi: remote port identifier |
| 785 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 786 | * |
| 787 | * The unregistration login mailbox command is used to unregister an N_Port |
| 788 | * or F_Port login. This command frees an RPI context in the HBA. It has the |
| 789 | * effect of performing an implicit N_Port/F_Port logout. |
| 790 | * |
| 791 | * This routine prepares the mailbox command for unregistering remote port |
| 792 | * login. |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 793 | * |
| 794 | * For SLI4 ports, the rpi passed to this function must be the physical |
| 795 | * rpi value, not the logical index. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 796 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 797 | void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 798 | lpfc_unreg_login(struct lpfc_hba *phba, uint16_t vpi, uint32_t rpi, |
| 799 | LPFC_MBOXQ_t * pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 800 | { |
| 801 | MAILBOX_t *mb; |
| 802 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 803 | mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 804 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 805 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 806 | mb->un.varUnregLogin.rpi = rpi; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 807 | mb->un.varUnregLogin.rsvd1 = 0; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 808 | if (phba->sli_rev >= LPFC_SLI_REV3) |
| 809 | mb->un.varUnregLogin.vpi = phba->vpi_ids[vpi]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 810 | |
| 811 | mb->mbxCommand = MBX_UNREG_LOGIN; |
| 812 | mb->mbxOwner = OWN_HOST; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 813 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 814 | return; |
| 815 | } |
| 816 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 817 | /** |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 818 | * lpfc_sli4_unreg_all_rpis - unregister all RPIs for a vport on SLI4 HBA. |
| 819 | * @vport: pointer to a vport object. |
| 820 | * |
| 821 | * This routine sends mailbox command to unregister all active RPIs for |
| 822 | * a vport. |
| 823 | **/ |
| 824 | void |
| 825 | lpfc_sli4_unreg_all_rpis(struct lpfc_vport *vport) |
| 826 | { |
| 827 | struct lpfc_hba *phba = vport->phba; |
| 828 | LPFC_MBOXQ_t *mbox; |
| 829 | int rc; |
| 830 | |
| 831 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
| 832 | if (mbox) { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 833 | /* |
| 834 | * For SLI4 functions, the rpi field is overloaded for |
| 835 | * the vport context unreg all. This routine passes |
| 836 | * 0 for the rpi field in lpfc_unreg_login for compatibility |
| 837 | * with SLI3 and then overrides the rpi field with the |
| 838 | * expected value for SLI4. |
| 839 | */ |
| 840 | lpfc_unreg_login(phba, vport->vpi, phba->vpi_ids[vport->vpi], |
| 841 | mbox); |
| 842 | mbox->u.mb.un.varUnregLogin.rsvd1 = 0x4000; |
James Smart | 5af5eee | 2010-10-22 11:06:38 -0400 | [diff] [blame] | 843 | mbox->vport = vport; |
| 844 | mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; |
| 845 | mbox->context1 = NULL; |
| 846 | rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT); |
| 847 | if (rc == MBX_NOT_FINISHED) |
| 848 | mempool_free(mbox, phba->mbox_mem_pool); |
| 849 | } |
| 850 | } |
| 851 | |
| 852 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 853 | * lpfc_reg_vpi - Prepare a mailbox command for registering vport identifier |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 854 | * @phba: pointer to lpfc hba data structure. |
| 855 | * @vpi: virtual N_Port identifier. |
| 856 | * @sid: Fibre Channel S_ID (N_Port_ID assigned to a virtual N_Port). |
| 857 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 858 | * |
| 859 | * The registration vport identifier mailbox command is used to activate a |
| 860 | * virtual N_Port after it has acquired an N_Port_ID. The HBA validates the |
| 861 | * N_Port_ID against the information in the selected virtual N_Port context |
| 862 | * block and marks it active to allow normal processing of IOCB commands and |
| 863 | * received unsolicited exchanges. |
| 864 | * |
| 865 | * This routine prepares the mailbox command for registering a virtual N_Port. |
| 866 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 867 | void |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 868 | lpfc_reg_vpi(struct lpfc_vport *vport, LPFC_MBOXQ_t *pmb) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 869 | { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 870 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 871 | struct lpfc_hba *phba = vport->phba; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 872 | |
| 873 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
James Smart | 38b92ef | 2010-08-04 16:11:39 -0400 | [diff] [blame] | 874 | /* |
| 875 | * Set the re-reg VPI bit for f/w to update the MAC address. |
| 876 | */ |
| 877 | if ((phba->sli_rev == LPFC_SLI_REV4) && |
| 878 | !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) |
| 879 | mb->un.varRegVpi.upd = 1; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 880 | |
| 881 | mb->un.varRegVpi.vpi = phba->vpi_ids[vport->vpi]; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 882 | mb->un.varRegVpi.sid = vport->fc_myDID; |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 883 | if (phba->sli_rev == LPFC_SLI_REV4) |
| 884 | mb->un.varRegVpi.vfi = phba->sli4_hba.vfi_ids[vport->vfi]; |
| 885 | else |
| 886 | mb->un.varRegVpi.vfi = vport->vfi + vport->phba->vfi_base; |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 887 | memcpy(mb->un.varRegVpi.wwn, &vport->fc_portname, |
| 888 | sizeof(struct lpfc_name)); |
| 889 | mb->un.varRegVpi.wwn[0] = cpu_to_le32(mb->un.varRegVpi.wwn[0]); |
| 890 | mb->un.varRegVpi.wwn[1] = cpu_to_le32(mb->un.varRegVpi.wwn[1]); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 891 | |
| 892 | mb->mbxCommand = MBX_REG_VPI; |
| 893 | mb->mbxOwner = OWN_HOST; |
| 894 | return; |
| 895 | |
| 896 | } |
| 897 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 898 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 899 | * lpfc_unreg_vpi - Prepare a mailbox command for unregistering vport id |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 900 | * @phba: pointer to lpfc hba data structure. |
| 901 | * @vpi: virtual N_Port identifier. |
| 902 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 903 | * |
| 904 | * The unregistration vport identifier mailbox command is used to inactivate |
| 905 | * a virtual N_Port. The driver must have logged out and unregistered all |
| 906 | * remote N_Ports to abort any activity on the virtual N_Port. The HBA will |
| 907 | * unregisters any default RPIs associated with the specified vpi, aborting |
| 908 | * any active exchanges. The HBA will post the mailbox response after making |
| 909 | * the virtual N_Port inactive. |
| 910 | * |
| 911 | * This routine prepares the mailbox command for unregistering a virtual |
| 912 | * N_Port. |
| 913 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 914 | void |
| 915 | lpfc_unreg_vpi(struct lpfc_hba *phba, uint16_t vpi, LPFC_MBOXQ_t *pmb) |
| 916 | { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 917 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 918 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 919 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 920 | if (phba->sli_rev == LPFC_SLI_REV3) |
| 921 | mb->un.varUnregVpi.vpi = phba->vpi_ids[vpi]; |
| 922 | else if (phba->sli_rev >= LPFC_SLI_REV4) |
| 923 | mb->un.varUnregVpi.sli4_vpi = phba->vpi_ids[vpi]; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 924 | |
| 925 | mb->mbxCommand = MBX_UNREG_VPI; |
| 926 | mb->mbxOwner = OWN_HOST; |
| 927 | return; |
| 928 | |
| 929 | } |
| 930 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 931 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 932 | * lpfc_config_pcb_setup - Set up IOCB rings in the Port Control Block (PCB) |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 933 | * @phba: pointer to lpfc hba data structure. |
| 934 | * |
| 935 | * This routine sets up and initializes the IOCB rings in the Port Control |
| 936 | * Block (PCB). |
| 937 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 938 | static void |
| 939 | lpfc_config_pcb_setup(struct lpfc_hba * phba) |
| 940 | { |
| 941 | struct lpfc_sli *psli = &phba->sli; |
| 942 | struct lpfc_sli_ring *pring; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 943 | PCB_t *pcbp = phba->pcb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 944 | dma_addr_t pdma_addr; |
| 945 | uint32_t offset; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 946 | uint32_t iocbCnt = 0; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 947 | int i; |
| 948 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 949 | pcbp->maxRing = (psli->num_rings - 1); |
| 950 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 951 | for (i = 0; i < psli->num_rings; i++) { |
| 952 | pring = &psli->ring[i]; |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 953 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 954 | pring->sli.sli3.sizeCiocb = |
| 955 | phba->sli_rev == 3 ? SLI3_IOCB_CMD_SIZE : |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 956 | SLI2_IOCB_CMD_SIZE; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 957 | pring->sli.sli3.sizeRiocb = |
| 958 | phba->sli_rev == 3 ? SLI3_IOCB_RSP_SIZE : |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 959 | SLI2_IOCB_RSP_SIZE; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 960 | /* A ring MUST have both cmd and rsp entries defined to be |
| 961 | valid */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 962 | if ((pring->sli.sli3.numCiocb == 0) || |
| 963 | (pring->sli.sli3.numRiocb == 0)) { |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 964 | pcbp->rdsc[i].cmdEntries = 0; |
| 965 | pcbp->rdsc[i].rspEntries = 0; |
| 966 | pcbp->rdsc[i].cmdAddrHigh = 0; |
| 967 | pcbp->rdsc[i].rspAddrHigh = 0; |
| 968 | pcbp->rdsc[i].cmdAddrLow = 0; |
| 969 | pcbp->rdsc[i].rspAddrLow = 0; |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 970 | pring->sli.sli3.cmdringaddr = NULL; |
| 971 | pring->sli.sli3.rspringaddr = NULL; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 972 | continue; |
| 973 | } |
| 974 | /* Command ring setup for ring */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 975 | pring->sli.sli3.cmdringaddr = (void *)&phba->IOCBs[iocbCnt]; |
| 976 | pcbp->rdsc[i].cmdEntries = pring->sli.sli3.numCiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 977 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 978 | offset = (uint8_t *) &phba->IOCBs[iocbCnt] - |
| 979 | (uint8_t *) phba->slim2p.virt; |
| 980 | pdma_addr = phba->slim2p.phys + offset; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 981 | pcbp->rdsc[i].cmdAddrHigh = putPaddrHigh(pdma_addr); |
| 982 | pcbp->rdsc[i].cmdAddrLow = putPaddrLow(pdma_addr); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 983 | iocbCnt += pring->sli.sli3.numCiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 984 | |
| 985 | /* Response ring setup for ring */ |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 986 | pring->sli.sli3.rspringaddr = (void *) &phba->IOCBs[iocbCnt]; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 987 | |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 988 | pcbp->rdsc[i].rspEntries = pring->sli.sli3.numRiocb; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 989 | offset = (uint8_t *)&phba->IOCBs[iocbCnt] - |
| 990 | (uint8_t *)phba->slim2p.virt; |
| 991 | pdma_addr = phba->slim2p.phys + offset; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 992 | pcbp->rdsc[i].rspAddrHigh = putPaddrHigh(pdma_addr); |
| 993 | pcbp->rdsc[i].rspAddrLow = putPaddrLow(pdma_addr); |
James Smart | 7e56aa2 | 2012-08-03 12:35:34 -0400 | [diff] [blame] | 994 | iocbCnt += pring->sli.sli3.numRiocb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 995 | } |
| 996 | } |
| 997 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 998 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 999 | * lpfc_read_rev - Prepare a mailbox command for reading HBA revision |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1000 | * @phba: pointer to lpfc hba data structure. |
| 1001 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 1002 | * |
| 1003 | * The read revision mailbox command is used to read the revision levels of |
| 1004 | * the HBA components. These components include hardware units, resident |
| 1005 | * firmware, and available firmware. HBAs that supports SLI-3 mode of |
| 1006 | * operation provide different response information depending on the version |
| 1007 | * requested by the driver. |
| 1008 | * |
| 1009 | * This routine prepares the mailbox command for reading HBA revision |
| 1010 | * information. |
| 1011 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1012 | void |
| 1013 | lpfc_read_rev(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) |
| 1014 | { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1015 | MAILBOX_t *mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1016 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 1017 | mb->un.varRdRev.cv = 1; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1018 | mb->un.varRdRev.v3req = 1; /* Request SLI3 info */ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1019 | mb->mbxCommand = MBX_READ_REV; |
| 1020 | mb->mbxOwner = OWN_HOST; |
| 1021 | return; |
| 1022 | } |
| 1023 | |
James Smart | d7c4799 | 2010-06-08 18:31:54 -0400 | [diff] [blame] | 1024 | void |
| 1025 | lpfc_sli4_swap_str(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| 1026 | { |
| 1027 | MAILBOX_t *mb = &pmb->u.mb; |
| 1028 | struct lpfc_mqe *mqe; |
| 1029 | |
| 1030 | switch (mb->mbxCommand) { |
| 1031 | case MBX_READ_REV: |
| 1032 | mqe = &pmb->u.mqe; |
| 1033 | lpfc_sli_pcimem_bcopy(mqe->un.read_rev.fw_name, |
| 1034 | mqe->un.read_rev.fw_name, 16); |
| 1035 | lpfc_sli_pcimem_bcopy(mqe->un.read_rev.ulp_fw_name, |
| 1036 | mqe->un.read_rev.ulp_fw_name, 16); |
| 1037 | break; |
| 1038 | default: |
| 1039 | break; |
| 1040 | } |
| 1041 | return; |
| 1042 | } |
| 1043 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1044 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1045 | * lpfc_build_hbq_profile2 - Set up the HBQ Selection Profile 2 |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1046 | * @hbqmb: pointer to the HBQ configuration data structure in mailbox command. |
| 1047 | * @hbq_desc: pointer to the HBQ selection profile descriptor. |
| 1048 | * |
| 1049 | * The Host Buffer Queue (HBQ) Selection Profile 2 specifies that the HBA |
| 1050 | * tests the incoming frames' R_CTL/TYPE fields with works 10:15 and performs |
| 1051 | * the Sequence Length Test using the fields in the Selection Profile 2 |
| 1052 | * extension in words 20:31. |
| 1053 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1054 | static void |
| 1055 | lpfc_build_hbq_profile2(struct config_hbq_var *hbqmb, |
| 1056 | struct lpfc_hbq_init *hbq_desc) |
| 1057 | { |
| 1058 | hbqmb->profiles.profile2.seqlenbcnt = hbq_desc->seqlenbcnt; |
| 1059 | hbqmb->profiles.profile2.maxlen = hbq_desc->maxlen; |
| 1060 | hbqmb->profiles.profile2.seqlenoff = hbq_desc->seqlenoff; |
| 1061 | } |
| 1062 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1063 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1064 | * lpfc_build_hbq_profile3 - Set up the HBQ Selection Profile 3 |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1065 | * @hbqmb: pointer to the HBQ configuration data structure in mailbox command. |
| 1066 | * @hbq_desc: pointer to the HBQ selection profile descriptor. |
| 1067 | * |
| 1068 | * The Host Buffer Queue (HBQ) Selection Profile 3 specifies that the HBA |
| 1069 | * tests the incoming frame's R_CTL/TYPE fields with words 10:15 and performs |
| 1070 | * the Sequence Length Test and Byte Field Test using the fields in the |
| 1071 | * Selection Profile 3 extension in words 20:31. |
| 1072 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1073 | static void |
| 1074 | lpfc_build_hbq_profile3(struct config_hbq_var *hbqmb, |
| 1075 | struct lpfc_hbq_init *hbq_desc) |
| 1076 | { |
| 1077 | hbqmb->profiles.profile3.seqlenbcnt = hbq_desc->seqlenbcnt; |
| 1078 | hbqmb->profiles.profile3.maxlen = hbq_desc->maxlen; |
| 1079 | hbqmb->profiles.profile3.cmdcodeoff = hbq_desc->cmdcodeoff; |
| 1080 | hbqmb->profiles.profile3.seqlenoff = hbq_desc->seqlenoff; |
| 1081 | memcpy(&hbqmb->profiles.profile3.cmdmatch, hbq_desc->cmdmatch, |
| 1082 | sizeof(hbqmb->profiles.profile3.cmdmatch)); |
| 1083 | } |
| 1084 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1085 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1086 | * lpfc_build_hbq_profile5 - Set up the HBQ Selection Profile 5 |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1087 | * @hbqmb: pointer to the HBQ configuration data structure in mailbox command. |
| 1088 | * @hbq_desc: pointer to the HBQ selection profile descriptor. |
| 1089 | * |
| 1090 | * The Host Buffer Queue (HBQ) Selection Profile 5 specifies a header HBQ. The |
| 1091 | * HBA tests the initial frame of an incoming sequence using the frame's |
| 1092 | * R_CTL/TYPE fields with words 10:15 and performs the Sequence Length Test |
| 1093 | * and Byte Field Test using the fields in the Selection Profile 5 extension |
| 1094 | * words 20:31. |
| 1095 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1096 | static void |
| 1097 | lpfc_build_hbq_profile5(struct config_hbq_var *hbqmb, |
| 1098 | struct lpfc_hbq_init *hbq_desc) |
| 1099 | { |
| 1100 | hbqmb->profiles.profile5.seqlenbcnt = hbq_desc->seqlenbcnt; |
| 1101 | hbqmb->profiles.profile5.maxlen = hbq_desc->maxlen; |
| 1102 | hbqmb->profiles.profile5.cmdcodeoff = hbq_desc->cmdcodeoff; |
| 1103 | hbqmb->profiles.profile5.seqlenoff = hbq_desc->seqlenoff; |
| 1104 | memcpy(&hbqmb->profiles.profile5.cmdmatch, hbq_desc->cmdmatch, |
| 1105 | sizeof(hbqmb->profiles.profile5.cmdmatch)); |
| 1106 | } |
| 1107 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1108 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1109 | * lpfc_config_hbq - Prepare a mailbox command for configuring an HBQ |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1110 | * @phba: pointer to lpfc hba data structure. |
| 1111 | * @id: HBQ identifier. |
| 1112 | * @hbq_desc: pointer to the HBA descriptor data structure. |
| 1113 | * @hbq_entry_index: index of the HBQ entry data structures. |
| 1114 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 1115 | * |
| 1116 | * The configure HBQ (Host Buffer Queue) mailbox command is used to configure |
| 1117 | * an HBQ. The configuration binds events that require buffers to a particular |
| 1118 | * ring and HBQ based on a selection profile. |
| 1119 | * |
| 1120 | * This routine prepares the mailbox command for configuring an HBQ. |
| 1121 | **/ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1122 | void |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1123 | lpfc_config_hbq(struct lpfc_hba *phba, uint32_t id, |
| 1124 | struct lpfc_hbq_init *hbq_desc, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1125 | uint32_t hbq_entry_index, LPFC_MBOXQ_t *pmb) |
| 1126 | { |
| 1127 | int i; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1128 | MAILBOX_t *mb = &pmb->u.mb; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1129 | struct config_hbq_var *hbqmb = &mb->un.varCfgHbq; |
| 1130 | |
| 1131 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1132 | hbqmb->hbqId = id; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1133 | hbqmb->entry_count = hbq_desc->entry_count; /* # entries in HBQ */ |
| 1134 | hbqmb->recvNotify = hbq_desc->rn; /* Receive |
| 1135 | * Notification */ |
| 1136 | hbqmb->numMask = hbq_desc->mask_count; /* # R_CTL/TYPE masks |
| 1137 | * # in words 0-19 */ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1138 | hbqmb->profile = hbq_desc->profile; /* Selection profile: |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1139 | * 0 = all, |
| 1140 | * 7 = logentry */ |
| 1141 | hbqmb->ringMask = hbq_desc->ring_mask; /* Binds HBQ to a ring |
| 1142 | * e.g. Ring0=b0001, |
| 1143 | * ring2=b0100 */ |
| 1144 | hbqmb->headerLen = hbq_desc->headerLen; /* 0 if not profile 4 |
| 1145 | * or 5 */ |
| 1146 | hbqmb->logEntry = hbq_desc->logEntry; /* Set to 1 if this |
| 1147 | * HBQ will be used |
| 1148 | * for LogEntry |
| 1149 | * buffers */ |
| 1150 | hbqmb->hbqaddrLow = putPaddrLow(phba->hbqslimp.phys) + |
| 1151 | hbq_entry_index * sizeof(struct lpfc_hbq_entry); |
| 1152 | hbqmb->hbqaddrHigh = putPaddrHigh(phba->hbqslimp.phys); |
| 1153 | |
| 1154 | mb->mbxCommand = MBX_CONFIG_HBQ; |
| 1155 | mb->mbxOwner = OWN_HOST; |
| 1156 | |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1157 | /* Copy info for profiles 2,3,5. Other |
| 1158 | * profiles this area is reserved |
| 1159 | */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1160 | if (hbq_desc->profile == 2) |
| 1161 | lpfc_build_hbq_profile2(hbqmb, hbq_desc); |
| 1162 | else if (hbq_desc->profile == 3) |
| 1163 | lpfc_build_hbq_profile3(hbqmb, hbq_desc); |
| 1164 | else if (hbq_desc->profile == 5) |
| 1165 | lpfc_build_hbq_profile5(hbqmb, hbq_desc); |
| 1166 | |
| 1167 | /* Return if no rctl / type masks for this HBQ */ |
| 1168 | if (!hbq_desc->mask_count) |
| 1169 | return; |
| 1170 | |
| 1171 | /* Otherwise we setup specific rctl / type masks for this HBQ */ |
| 1172 | for (i = 0; i < hbq_desc->mask_count; i++) { |
| 1173 | hbqmb->hbqMasks[i].tmatch = hbq_desc->hbqMasks[i].tmatch; |
| 1174 | hbqmb->hbqMasks[i].tmask = hbq_desc->hbqMasks[i].tmask; |
| 1175 | hbqmb->hbqMasks[i].rctlmatch = hbq_desc->hbqMasks[i].rctlmatch; |
| 1176 | hbqmb->hbqMasks[i].rctlmask = hbq_desc->hbqMasks[i].rctlmask; |
| 1177 | } |
| 1178 | |
| 1179 | return; |
| 1180 | } |
| 1181 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1182 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1183 | * lpfc_config_ring - Prepare a mailbox command for configuring an IOCB ring |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1184 | * @phba: pointer to lpfc hba data structure. |
| 1185 | * @ring: |
| 1186 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 1187 | * |
| 1188 | * The configure ring mailbox command is used to configure an IOCB ring. This |
| 1189 | * configuration binds from one to six of HBA RC_CTL/TYPE mask entries to the |
| 1190 | * ring. This is used to map incoming sequences to a particular ring whose |
| 1191 | * RC_CTL/TYPE mask entry matches that of the sequence. The driver should not |
| 1192 | * attempt to configure a ring whose number is greater than the number |
| 1193 | * specified in the Port Control Block (PCB). It is an error to issue the |
| 1194 | * configure ring command more than once with the same ring number. The HBA |
| 1195 | * returns an error if the driver attempts this. |
| 1196 | * |
| 1197 | * This routine prepares the mailbox command for configuring IOCB ring. |
| 1198 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1199 | void |
| 1200 | lpfc_config_ring(struct lpfc_hba * phba, int ring, LPFC_MBOXQ_t * pmb) |
| 1201 | { |
| 1202 | int i; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1203 | MAILBOX_t *mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1204 | struct lpfc_sli *psli; |
| 1205 | struct lpfc_sli_ring *pring; |
| 1206 | |
| 1207 | memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); |
| 1208 | |
| 1209 | mb->un.varCfgRing.ring = ring; |
| 1210 | mb->un.varCfgRing.maxOrigXchg = 0; |
| 1211 | mb->un.varCfgRing.maxRespXchg = 0; |
| 1212 | mb->un.varCfgRing.recvNotify = 1; |
| 1213 | |
| 1214 | psli = &phba->sli; |
| 1215 | pring = &psli->ring[ring]; |
| 1216 | mb->un.varCfgRing.numMask = pring->num_mask; |
| 1217 | mb->mbxCommand = MBX_CONFIG_RING; |
| 1218 | mb->mbxOwner = OWN_HOST; |
| 1219 | |
| 1220 | /* Is this ring configured for a specific profile */ |
| 1221 | if (pring->prt[0].profile) { |
| 1222 | mb->un.varCfgRing.profile = pring->prt[0].profile; |
| 1223 | return; |
| 1224 | } |
| 1225 | |
| 1226 | /* Otherwise we setup specific rctl / type masks for this ring */ |
| 1227 | for (i = 0; i < pring->num_mask; i++) { |
| 1228 | mb->un.varCfgRing.rrRegs[i].rval = pring->prt[i].rctl; |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 1229 | if (mb->un.varCfgRing.rrRegs[i].rval != FC_RCTL_ELS_REQ) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1230 | mb->un.varCfgRing.rrRegs[i].rmask = 0xff; |
| 1231 | else |
| 1232 | mb->un.varCfgRing.rrRegs[i].rmask = 0xfe; |
| 1233 | mb->un.varCfgRing.rrRegs[i].tval = pring->prt[i].type; |
| 1234 | mb->un.varCfgRing.rrRegs[i].tmask = 0xff; |
| 1235 | } |
| 1236 | |
| 1237 | return; |
| 1238 | } |
| 1239 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1240 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1241 | * lpfc_config_port - Prepare a mailbox command for configuring port |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1242 | * @phba: pointer to lpfc hba data structure. |
| 1243 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 1244 | * |
| 1245 | * The configure port mailbox command is used to identify the Port Control |
| 1246 | * Block (PCB) in the driver memory. After this command is issued, the |
| 1247 | * driver must not access the mailbox in the HBA without first resetting |
| 1248 | * the HBA. The HBA may copy the PCB information to internal storage for |
| 1249 | * subsequent use; the driver can not change the PCB information unless it |
| 1250 | * resets the HBA. |
| 1251 | * |
| 1252 | * This routine prepares the mailbox command for configuring port. |
| 1253 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1254 | void |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1255 | lpfc_config_port(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1256 | { |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1257 | MAILBOX_t __iomem *mb_slim = (MAILBOX_t __iomem *) phba->MBslimaddr; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1258 | MAILBOX_t *mb = &pmb->u.mb; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1259 | dma_addr_t pdma_addr; |
| 1260 | uint32_t bar_low, bar_high; |
| 1261 | size_t offset; |
James.Smart@Emulex.Com | 4cc2da1 | 2005-06-25 10:34:00 -0400 | [diff] [blame] | 1262 | struct lpfc_hgp hgp; |
James.Smart@Emulex.Com | f91b392 | 2005-10-28 20:29:28 -0400 | [diff] [blame] | 1263 | int i; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1264 | uint32_t pgp_offset; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1265 | |
| 1266 | memset(pmb, 0, sizeof(LPFC_MBOXQ_t)); |
| 1267 | mb->mbxCommand = MBX_CONFIG_PORT; |
| 1268 | mb->mbxOwner = OWN_HOST; |
| 1269 | |
| 1270 | mb->un.varCfgPort.pcbLen = sizeof(PCB_t); |
| 1271 | |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1272 | offset = (uint8_t *)phba->pcb - (uint8_t *)phba->slim2p.virt; |
| 1273 | pdma_addr = phba->slim2p.phys + offset; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1274 | mb->un.varCfgPort.pcbLow = putPaddrLow(pdma_addr); |
| 1275 | mb->un.varCfgPort.pcbHigh = putPaddrHigh(pdma_addr); |
| 1276 | |
James Smart | 9720748 | 2008-12-04 22:39:19 -0500 | [diff] [blame] | 1277 | /* Always Host Group Pointer is in SLIM */ |
| 1278 | mb->un.varCfgPort.hps = 1; |
| 1279 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1280 | /* If HBA supports SLI=3 ask for it */ |
| 1281 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1282 | if (phba->sli_rev == LPFC_SLI_REV3 && phba->vpd.sli3Feat.cerbm) { |
James Smart | e2a0a9d | 2008-12-04 22:40:02 -0500 | [diff] [blame] | 1283 | if (phba->cfg_enable_bg) |
| 1284 | mb->un.varCfgPort.cbg = 1; /* configure BlockGuard */ |
James Smart | ab56dc2 | 2011-02-16 12:39:57 -0500 | [diff] [blame] | 1285 | if (phba->cfg_enable_dss) |
| 1286 | mb->un.varCfgPort.cdss = 1; /* Configure Security */ |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1287 | mb->un.varCfgPort.cerbm = 1; /* Request HBQs */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1288 | mb->un.varCfgPort.ccrp = 1; /* Command Ring Polling */ |
James Smart | 51ef4c2 | 2007-08-02 11:10:31 -0400 | [diff] [blame] | 1289 | mb->un.varCfgPort.max_hbq = lpfc_sli_hbq_count(); |
James Smart | 78b2d85 | 2007-08-02 11:10:21 -0400 | [diff] [blame] | 1290 | if (phba->max_vpi && phba->cfg_enable_npiv && |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1291 | phba->vpd.sli3Feat.cmv) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1292 | mb->un.varCfgPort.max_vpi = LPFC_MAX_VPI; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1293 | mb->un.varCfgPort.cmv = 1; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1294 | } else |
| 1295 | mb->un.varCfgPort.max_vpi = phba->max_vpi = 0; |
| 1296 | } else |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1297 | phba->sli_rev = LPFC_SLI_REV2; |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1298 | mb->un.varCfgPort.sli_mode = phba->sli_rev; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1299 | |
James Smart | cb69f7d | 2011-12-13 13:21:57 -0500 | [diff] [blame] | 1300 | /* If this is an SLI3 port, configure async status notification. */ |
| 1301 | if (phba->sli_rev == LPFC_SLI_REV3) |
| 1302 | mb->un.varCfgPort.casabt = 1; |
| 1303 | |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1304 | /* Now setup pcb */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1305 | phba->pcb->type = TYPE_NATIVE_SLI2; |
| 1306 | phba->pcb->feature = FEATURE_INITIAL_SLI2; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1307 | |
| 1308 | /* Setup Mailbox pointers */ |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 1309 | phba->pcb->mailBoxSize = sizeof(MAILBOX_t) + MAILBOX_EXT_SIZE; |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1310 | offset = (uint8_t *)phba->mbox - (uint8_t *)phba->slim2p.virt; |
| 1311 | pdma_addr = phba->slim2p.phys + offset; |
| 1312 | phba->pcb->mbAddrHigh = putPaddrHigh(pdma_addr); |
| 1313 | phba->pcb->mbAddrLow = putPaddrLow(pdma_addr); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1314 | |
| 1315 | /* |
| 1316 | * Setup Host Group ring pointer. |
| 1317 | * |
| 1318 | * For efficiency reasons, the ring get/put pointers can be |
| 1319 | * placed in adapter memory (SLIM) rather than in host memory. |
| 1320 | * This allows firmware to avoid PCI reads/writes when updating |
| 1321 | * and checking pointers. |
| 1322 | * |
| 1323 | * The firmware recognizes the use of SLIM memory by comparing |
| 1324 | * the address of the get/put pointers structure with that of |
| 1325 | * the SLIM BAR (BAR0). |
| 1326 | * |
| 1327 | * Caution: be sure to use the PCI config space value of BAR0/BAR1 |
| 1328 | * (the hardware's view of the base address), not the OS's |
| 1329 | * value of pci_resource_start() as the OS value may be a cookie |
| 1330 | * for ioremap/iomap. |
| 1331 | */ |
| 1332 | |
| 1333 | |
| 1334 | pci_read_config_dword(phba->pcidev, PCI_BASE_ADDRESS_0, &bar_low); |
| 1335 | pci_read_config_dword(phba->pcidev, PCI_BASE_ADDRESS_1, &bar_high); |
| 1336 | |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1337 | /* |
| 1338 | * Set up HGP - Port Memory |
| 1339 | * |
| 1340 | * The port expects the host get/put pointers to reside in memory |
| 1341 | * following the "non-diagnostic" mode mailbox (32 words, 0x80 bytes) |
| 1342 | * area of SLIM. In SLI-2 mode, there's an additional 16 reserved |
| 1343 | * words (0x40 bytes). This area is not reserved if HBQs are |
| 1344 | * configured in SLI-3. |
| 1345 | * |
| 1346 | * CR0Put - SLI2(no HBQs) = 0xc0, With HBQs = 0x80 |
| 1347 | * RR0Get 0xc4 0x84 |
| 1348 | * CR1Put 0xc8 0x88 |
| 1349 | * RR1Get 0xcc 0x8c |
| 1350 | * CR2Put 0xd0 0x90 |
| 1351 | * RR2Get 0xd4 0x94 |
| 1352 | * CR3Put 0xd8 0x98 |
| 1353 | * RR3Get 0xdc 0x9c |
| 1354 | * |
| 1355 | * Reserved 0xa0-0xbf |
| 1356 | * If HBQs configured: |
| 1357 | * HBQ 0 Put ptr 0xc0 |
| 1358 | * HBQ 1 Put ptr 0xc4 |
| 1359 | * HBQ 2 Put ptr 0xc8 |
| 1360 | * ...... |
| 1361 | * HBQ(M-1)Put Pointer 0xc0+(M-1)*4 |
| 1362 | * |
| 1363 | */ |
| 1364 | |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 1365 | if (phba->cfg_hostmem_hgp && phba->sli_rev != 3) { |
| 1366 | phba->host_gp = &phba->mbox->us.s2.host[0]; |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1367 | phba->hbq_put = NULL; |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 1368 | offset = (uint8_t *)&phba->mbox->us.s2.host - |
| 1369 | (uint8_t *)phba->slim2p.virt; |
| 1370 | pdma_addr = phba->slim2p.phys + offset; |
| 1371 | phba->pcb->hgpAddrHigh = putPaddrHigh(pdma_addr); |
| 1372 | phba->pcb->hgpAddrLow = putPaddrLow(pdma_addr); |
| 1373 | } else { |
| 1374 | /* Always Host Group Pointer is in SLIM */ |
| 1375 | mb->un.varCfgPort.hps = 1; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1376 | |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 1377 | if (phba->sli_rev == 3) { |
| 1378 | phba->host_gp = &mb_slim->us.s3.host[0]; |
| 1379 | phba->hbq_put = &mb_slim->us.s3.hbq_put[0]; |
| 1380 | } else { |
| 1381 | phba->host_gp = &mb_slim->us.s2.host[0]; |
| 1382 | phba->hbq_put = NULL; |
| 1383 | } |
James.Smart@Emulex.Com | f91b392 | 2005-10-28 20:29:28 -0400 | [diff] [blame] | 1384 | |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 1385 | /* mask off BAR0's flag bits 0 - 3 */ |
| 1386 | phba->pcb->hgpAddrLow = (bar_low & PCI_BASE_ADDRESS_MEM_MASK) + |
| 1387 | (void __iomem *)phba->host_gp - |
| 1388 | (void __iomem *)phba->MBslimaddr; |
| 1389 | if (bar_low & PCI_BASE_ADDRESS_MEM_TYPE_64) |
| 1390 | phba->pcb->hgpAddrHigh = bar_high; |
| 1391 | else |
| 1392 | phba->pcb->hgpAddrHigh = 0; |
| 1393 | /* write HGP data to SLIM at the required longword offset */ |
| 1394 | memset(&hgp, 0, sizeof(struct lpfc_hgp)); |
| 1395 | |
| 1396 | for (i = 0; i < phba->sli.num_rings; i++) { |
| 1397 | lpfc_memcpy_to_slim(phba->host_gp + i, &hgp, |
James Smart | ed95768 | 2007-06-17 19:56:37 -0500 | [diff] [blame] | 1398 | sizeof(*phba->host_gp)); |
James Smart | 7a47027 | 2010-03-15 11:25:20 -0400 | [diff] [blame] | 1399 | } |
James.Smart@Emulex.Com | f91b392 | 2005-10-28 20:29:28 -0400 | [diff] [blame] | 1400 | } |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1401 | |
James Smart | 8f34f4c | 2008-12-04 22:39:23 -0500 | [diff] [blame] | 1402 | /* Setup Port Group offset */ |
| 1403 | if (phba->sli_rev == 3) |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1404 | pgp_offset = offsetof(struct lpfc_sli2_slim, |
| 1405 | mbx.us.s3_pgp.port); |
James Smart | 8f34f4c | 2008-12-04 22:39:23 -0500 | [diff] [blame] | 1406 | else |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1407 | pgp_offset = offsetof(struct lpfc_sli2_slim, mbx.us.s2.port); |
| 1408 | pdma_addr = phba->slim2p.phys + pgp_offset; |
| 1409 | phba->pcb->pgpAddrHigh = putPaddrHigh(pdma_addr); |
| 1410 | phba->pcb->pgpAddrLow = putPaddrLow(pdma_addr); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1411 | |
| 1412 | /* Use callback routine to setp rings in the pcb */ |
| 1413 | lpfc_config_pcb_setup(phba); |
| 1414 | |
| 1415 | /* special handling for LC HBAs */ |
| 1416 | if (lpfc_is_LC_HBA(phba->pcidev->device)) { |
| 1417 | uint32_t hbainit[5]; |
| 1418 | |
| 1419 | lpfc_hba_init(phba, hbainit); |
| 1420 | |
| 1421 | memcpy(&mb->un.varCfgPort.hbainit, hbainit, 20); |
| 1422 | } |
| 1423 | |
| 1424 | /* Swap PCB if needed */ |
James Smart | 34b02dc | 2008-08-24 21:49:55 -0400 | [diff] [blame] | 1425 | lpfc_sli_pcimem_bcopy(phba->pcb, phba->pcb, sizeof(PCB_t)); |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1426 | } |
| 1427 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1428 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1429 | * lpfc_kill_board - Prepare a mailbox command for killing board |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1430 | * @phba: pointer to lpfc hba data structure. |
| 1431 | * @pmb: pointer to the driver internal queue element for mailbox command. |
| 1432 | * |
| 1433 | * The kill board mailbox command is used to tell firmware to perform a |
| 1434 | * graceful shutdown of a channel on a specified board to prepare for reset. |
| 1435 | * When the kill board mailbox command is received, the ER3 bit is set to 1 |
| 1436 | * in the Host Status register and the ER Attention bit is set to 1 in the |
| 1437 | * Host Attention register of the HBA function that received the kill board |
| 1438 | * command. |
| 1439 | * |
| 1440 | * This routine prepares the mailbox command for killing the board in |
| 1441 | * preparation for a graceful shutdown. |
| 1442 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1443 | void |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1444 | lpfc_kill_board(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) |
| 1445 | { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1446 | MAILBOX_t *mb = &pmb->u.mb; |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1447 | |
| 1448 | memset(pmb, 0, sizeof(LPFC_MBOXQ_t)); |
| 1449 | mb->mbxCommand = MBX_KILL_BOARD; |
| 1450 | mb->mbxOwner = OWN_HOST; |
| 1451 | return; |
| 1452 | } |
| 1453 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1454 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1455 | * lpfc_mbox_put - Put a mailbox cmd into the tail of driver's mailbox queue |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1456 | * @phba: pointer to lpfc hba data structure. |
| 1457 | * @mbq: pointer to the driver internal queue element for mailbox command. |
| 1458 | * |
| 1459 | * Driver maintains a internal mailbox command queue implemented as a linked |
| 1460 | * list. When a mailbox command is issued, it shall be put into the mailbox |
| 1461 | * command queue such that they shall be processed orderly as HBA can process |
| 1462 | * one mailbox command at a time. |
| 1463 | **/ |
Jamie Wellnitz | 4141586 | 2006-02-28 19:25:27 -0500 | [diff] [blame] | 1464 | void |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1465 | lpfc_mbox_put(struct lpfc_hba * phba, LPFC_MBOXQ_t * mbq) |
| 1466 | { |
| 1467 | struct lpfc_sli *psli; |
| 1468 | |
| 1469 | psli = &phba->sli; |
| 1470 | |
| 1471 | list_add_tail(&mbq->list, &psli->mboxq); |
| 1472 | |
| 1473 | psli->mboxq_cnt++; |
| 1474 | |
| 1475 | return; |
| 1476 | } |
| 1477 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1478 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1479 | * lpfc_mbox_get - Remove a mailbox cmd from the head of driver's mailbox queue |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1480 | * @phba: pointer to lpfc hba data structure. |
| 1481 | * |
| 1482 | * Driver maintains a internal mailbox command queue implemented as a linked |
| 1483 | * list. When a mailbox command is issued, it shall be put into the mailbox |
| 1484 | * command queue such that they shall be processed orderly as HBA can process |
| 1485 | * one mailbox command at a time. After HBA finished processing a mailbox |
| 1486 | * command, the driver will remove a pending mailbox command from the head of |
| 1487 | * the mailbox command queue and send to the HBA for processing. |
| 1488 | * |
| 1489 | * Return codes |
| 1490 | * pointer to the driver internal queue element for mailbox command. |
| 1491 | **/ |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1492 | LPFC_MBOXQ_t * |
| 1493 | lpfc_mbox_get(struct lpfc_hba * phba) |
| 1494 | { |
| 1495 | LPFC_MBOXQ_t *mbq = NULL; |
| 1496 | struct lpfc_sli *psli = &phba->sli; |
| 1497 | |
James Smart | 2e0fef8 | 2007-06-17 19:56:36 -0500 | [diff] [blame] | 1498 | list_remove_head((&psli->mboxq), mbq, LPFC_MBOXQ_t, list); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1499 | if (mbq) |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1500 | psli->mboxq_cnt--; |
| dea3101 | 2005-04-17 16:05:31 -0500 | [diff] [blame] | 1501 | |
| 1502 | return mbq; |
| 1503 | } |
James Smart | a309a6b | 2006-08-01 07:33:43 -0400 | [diff] [blame] | 1504 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1505 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1506 | * __lpfc_mbox_cmpl_put - Put mailbox cmd into mailbox cmd complete list |
| 1507 | * @phba: pointer to lpfc hba data structure. |
| 1508 | * @mbq: pointer to the driver internal queue element for mailbox command. |
| 1509 | * |
| 1510 | * This routine put the completed mailbox command into the mailbox command |
| 1511 | * complete list. This is the unlocked version of the routine. The mailbox |
| 1512 | * complete list is used by the driver worker thread to process mailbox |
| 1513 | * complete callback functions outside the driver interrupt handler. |
| 1514 | **/ |
| 1515 | void |
| 1516 | __lpfc_mbox_cmpl_put(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbq) |
| 1517 | { |
| 1518 | list_add_tail(&mbq->list, &phba->sli.mboxq_cmpl); |
| 1519 | } |
| 1520 | |
| 1521 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1522 | * lpfc_mbox_cmpl_put - Put mailbox command into mailbox command complete list |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1523 | * @phba: pointer to lpfc hba data structure. |
| 1524 | * @mbq: pointer to the driver internal queue element for mailbox command. |
| 1525 | * |
| 1526 | * This routine put the completed mailbox command into the mailbox command |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1527 | * complete list. This is the locked version of the routine. The mailbox |
| 1528 | * complete list is used by the driver worker thread to process mailbox |
| 1529 | * complete callback functions outside the driver interrupt handler. |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1530 | **/ |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1531 | void |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1532 | lpfc_mbox_cmpl_put(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbq) |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1533 | { |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 1534 | unsigned long iflag; |
| 1535 | |
Joe Perches | b1c1181 | 2008-02-03 17:28:22 +0200 | [diff] [blame] | 1536 | /* This function expects to be called from interrupt context */ |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 1537 | spin_lock_irqsave(&phba->hbalock, iflag); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1538 | __lpfc_mbox_cmpl_put(phba, mbq); |
James Smart | 5b75da2 | 2008-12-04 22:39:35 -0500 | [diff] [blame] | 1539 | spin_unlock_irqrestore(&phba->hbalock, iflag); |
James Smart | 92d7f7b | 2007-06-17 19:56:38 -0500 | [diff] [blame] | 1540 | return; |
| 1541 | } |
| 1542 | |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1543 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1544 | * lpfc_mbox_cmd_check - Check the validality of a mailbox command |
| 1545 | * @phba: pointer to lpfc hba data structure. |
| 1546 | * @mboxq: pointer to the driver internal queue element for mailbox command. |
| 1547 | * |
| 1548 | * This routine is to check whether a mailbox command is valid to be issued. |
| 1549 | * This check will be performed by both the mailbox issue API when a client |
| 1550 | * is to issue a mailbox command to the mailbox transport. |
| 1551 | * |
| 1552 | * Return 0 - pass the check, -ENODEV - fail the check |
| 1553 | **/ |
| 1554 | int |
| 1555 | lpfc_mbox_cmd_check(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
| 1556 | { |
| 1557 | /* Mailbox command that have a completion handler must also have a |
| 1558 | * vport specified. |
| 1559 | */ |
| 1560 | if (mboxq->mbox_cmpl && mboxq->mbox_cmpl != lpfc_sli_def_mbox_cmpl && |
| 1561 | mboxq->mbox_cmpl != lpfc_sli_wake_mbox_wait) { |
| 1562 | if (!mboxq->vport) { |
| 1563 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_VPORT, |
| 1564 | "1814 Mbox x%x failed, no vport\n", |
| 1565 | mboxq->u.mb.mbxCommand); |
| 1566 | dump_stack(); |
| 1567 | return -ENODEV; |
| 1568 | } |
| 1569 | } |
| 1570 | return 0; |
| 1571 | } |
| 1572 | |
| 1573 | /** |
| 1574 | * lpfc_mbox_dev_check - Check the device state for issuing a mailbox command |
| 1575 | * @phba: pointer to lpfc hba data structure. |
| 1576 | * |
| 1577 | * This routine is to check whether the HBA device is ready for posting a |
| 1578 | * mailbox command. It is used by the mailbox transport API at the time the |
| 1579 | * to post a mailbox command to the device. |
| 1580 | * |
| 1581 | * Return 0 - pass the check, -ENODEV - fail the check |
| 1582 | **/ |
| 1583 | int |
| 1584 | lpfc_mbox_dev_check(struct lpfc_hba *phba) |
| 1585 | { |
| 1586 | /* If the PCI channel is in offline state, do not issue mbox */ |
| 1587 | if (unlikely(pci_channel_offline(phba->pcidev))) |
| 1588 | return -ENODEV; |
| 1589 | |
| 1590 | /* If the HBA is in error state, do not issue mbox */ |
| 1591 | if (phba->link_state == LPFC_HBA_ERROR) |
| 1592 | return -ENODEV; |
| 1593 | |
| 1594 | return 0; |
| 1595 | } |
| 1596 | |
| 1597 | /** |
James Smart | 3621a71 | 2009-04-06 18:47:14 -0400 | [diff] [blame] | 1598 | * lpfc_mbox_tmo_val - Retrieve mailbox command timeout value |
James Smart | e59058c | 2008-08-24 21:49:00 -0400 | [diff] [blame] | 1599 | * @phba: pointer to lpfc hba data structure. |
| 1600 | * @cmd: mailbox command code. |
| 1601 | * |
| 1602 | * This routine retrieves the proper timeout value according to the mailbox |
| 1603 | * command code. |
| 1604 | * |
| 1605 | * Return codes |
| 1606 | * Timeout value to be used for the given mailbox command |
| 1607 | **/ |
James Smart | a309a6b | 2006-08-01 07:33:43 -0400 | [diff] [blame] | 1608 | int |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 1609 | lpfc_mbox_tmo_val(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq) |
James Smart | a309a6b | 2006-08-01 07:33:43 -0400 | [diff] [blame] | 1610 | { |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 1611 | MAILBOX_t *mbox = &mboxq->u.mb; |
| 1612 | uint8_t subsys, opcode; |
| 1613 | |
| 1614 | switch (mbox->mbxCommand) { |
James Smart | a309a6b | 2006-08-01 07:33:43 -0400 | [diff] [blame] | 1615 | case MBX_WRITE_NV: /* 0x03 */ |
James Smart | 940eb68 | 2012-08-03 12:37:08 -0400 | [diff] [blame] | 1616 | case MBX_DUMP_MEMORY: /* 0x17 */ |
James Smart | a309a6b | 2006-08-01 07:33:43 -0400 | [diff] [blame] | 1617 | case MBX_UPDATE_CFG: /* 0x1B */ |
| 1618 | case MBX_DOWN_LOAD: /* 0x1C */ |
| 1619 | case MBX_DEL_LD_ENTRY: /* 0x1D */ |
James Smart | 940eb68 | 2012-08-03 12:37:08 -0400 | [diff] [blame] | 1620 | case MBX_WRITE_VPARMS: /* 0x32 */ |
James Smart | a309a6b | 2006-08-01 07:33:43 -0400 | [diff] [blame] | 1621 | case MBX_LOAD_AREA: /* 0x81 */ |
James Smart | 0937282 | 2008-01-11 01:52:54 -0500 | [diff] [blame] | 1622 | case MBX_WRITE_WWN: /* 0x98 */ |
James Smart | a309a6b | 2006-08-01 07:33:43 -0400 | [diff] [blame] | 1623 | case MBX_LOAD_EXP_ROM: /* 0x9C */ |
James Smart | 940eb68 | 2012-08-03 12:37:08 -0400 | [diff] [blame] | 1624 | case MBX_ACCESS_VDATA: /* 0xA5 */ |
James Smart | a309a6b | 2006-08-01 07:33:43 -0400 | [diff] [blame] | 1625 | return LPFC_MBOX_TMO_FLASH_CMD; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1626 | case MBX_SLI4_CONFIG: /* 0x9b */ |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 1627 | subsys = lpfc_sli_config_mbox_subsys_get(phba, mboxq); |
| 1628 | opcode = lpfc_sli_config_mbox_opcode_get(phba, mboxq); |
| 1629 | if (subsys == LPFC_MBOX_SUBSYSTEM_COMMON) { |
| 1630 | switch (opcode) { |
| 1631 | case LPFC_MBOX_OPCODE_READ_OBJECT: |
| 1632 | case LPFC_MBOX_OPCODE_WRITE_OBJECT: |
| 1633 | case LPFC_MBOX_OPCODE_READ_OBJECT_LIST: |
| 1634 | case LPFC_MBOX_OPCODE_DELETE_OBJECT: |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 1635 | case LPFC_MBOX_OPCODE_GET_PROFILE_LIST: |
| 1636 | case LPFC_MBOX_OPCODE_SET_ACT_PROFILE: |
James Smart | 940eb68 | 2012-08-03 12:37:08 -0400 | [diff] [blame] | 1637 | case LPFC_MBOX_OPCODE_GET_PROFILE_CONFIG: |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 1638 | case LPFC_MBOX_OPCODE_SET_PROFILE_CONFIG: |
| 1639 | case LPFC_MBOX_OPCODE_GET_FACTORY_PROFILE_CONFIG: |
James Smart | 940eb68 | 2012-08-03 12:37:08 -0400 | [diff] [blame] | 1640 | case LPFC_MBOX_OPCODE_GET_PROFILE_CAPACITIES: |
| 1641 | case LPFC_MBOX_OPCODE_SEND_ACTIVATION: |
| 1642 | case LPFC_MBOX_OPCODE_RESET_LICENSES: |
| 1643 | case LPFC_MBOX_OPCODE_SET_BOOT_CONFIG: |
| 1644 | case LPFC_MBOX_OPCODE_GET_VPD_DATA: |
| 1645 | case LPFC_MBOX_OPCODE_SET_PHYSICAL_LINK_CONFIG: |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 1646 | return LPFC_MBOX_SLI4_CONFIG_EXTENDED_TMO; |
| 1647 | } |
| 1648 | } |
| 1649 | if (subsys == LPFC_MBOX_SUBSYSTEM_FCOE) { |
| 1650 | switch (opcode) { |
| 1651 | case LPFC_MBOX_OPCODE_FCOE_SET_FCLINK_SETTINGS: |
| 1652 | return LPFC_MBOX_SLI4_CONFIG_EXTENDED_TMO; |
| 1653 | } |
| 1654 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1655 | return LPFC_MBOX_SLI4_CONFIG_TMO; |
James Smart | a309a6b | 2006-08-01 07:33:43 -0400 | [diff] [blame] | 1656 | } |
| 1657 | return LPFC_MBOX_TMO; |
| 1658 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1659 | |
| 1660 | /** |
| 1661 | * lpfc_sli4_mbx_sge_set - Set a sge entry in non-embedded mailbox command |
| 1662 | * @mbox: pointer to lpfc mbox command. |
| 1663 | * @sgentry: sge entry index. |
| 1664 | * @phyaddr: physical address for the sge |
| 1665 | * @length: Length of the sge. |
| 1666 | * |
| 1667 | * This routine sets up an entry in the non-embedded mailbox command at the sge |
| 1668 | * index location. |
| 1669 | **/ |
| 1670 | void |
| 1671 | lpfc_sli4_mbx_sge_set(struct lpfcMboxq *mbox, uint32_t sgentry, |
| 1672 | dma_addr_t phyaddr, uint32_t length) |
| 1673 | { |
| 1674 | struct lpfc_mbx_nembed_cmd *nembed_sge; |
| 1675 | |
| 1676 | nembed_sge = (struct lpfc_mbx_nembed_cmd *) |
| 1677 | &mbox->u.mqe.un.nembed_cmd; |
| 1678 | nembed_sge->sge[sgentry].pa_lo = putPaddrLow(phyaddr); |
| 1679 | nembed_sge->sge[sgentry].pa_hi = putPaddrHigh(phyaddr); |
| 1680 | nembed_sge->sge[sgentry].length = length; |
| 1681 | } |
| 1682 | |
| 1683 | /** |
| 1684 | * lpfc_sli4_mbx_sge_get - Get a sge entry from non-embedded mailbox command |
| 1685 | * @mbox: pointer to lpfc mbox command. |
| 1686 | * @sgentry: sge entry index. |
| 1687 | * |
| 1688 | * This routine gets an entry from the non-embedded mailbox command at the sge |
| 1689 | * index location. |
| 1690 | **/ |
| 1691 | void |
| 1692 | lpfc_sli4_mbx_sge_get(struct lpfcMboxq *mbox, uint32_t sgentry, |
| 1693 | struct lpfc_mbx_sge *sge) |
| 1694 | { |
| 1695 | struct lpfc_mbx_nembed_cmd *nembed_sge; |
| 1696 | |
| 1697 | nembed_sge = (struct lpfc_mbx_nembed_cmd *) |
| 1698 | &mbox->u.mqe.un.nembed_cmd; |
| 1699 | sge->pa_lo = nembed_sge->sge[sgentry].pa_lo; |
| 1700 | sge->pa_hi = nembed_sge->sge[sgentry].pa_hi; |
| 1701 | sge->length = nembed_sge->sge[sgentry].length; |
| 1702 | } |
| 1703 | |
| 1704 | /** |
| 1705 | * lpfc_sli4_mbox_cmd_free - Free a sli4 mailbox command |
| 1706 | * @phba: pointer to lpfc hba data structure. |
| 1707 | * @mbox: pointer to lpfc mbox command. |
| 1708 | * |
| 1709 | * This routine frees SLI4 specific mailbox command for sending IOCTL command. |
| 1710 | **/ |
| 1711 | void |
| 1712 | lpfc_sli4_mbox_cmd_free(struct lpfc_hba *phba, struct lpfcMboxq *mbox) |
| 1713 | { |
| 1714 | struct lpfc_mbx_sli4_config *sli4_cfg; |
| 1715 | struct lpfc_mbx_sge sge; |
| 1716 | dma_addr_t phyaddr; |
| 1717 | uint32_t sgecount, sgentry; |
| 1718 | |
| 1719 | sli4_cfg = &mbox->u.mqe.un.sli4_config; |
| 1720 | |
| 1721 | /* For embedded mbox command, just free the mbox command */ |
| 1722 | if (bf_get(lpfc_mbox_hdr_emb, &sli4_cfg->header.cfg_mhdr)) { |
| 1723 | mempool_free(mbox, phba->mbox_mem_pool); |
| 1724 | return; |
| 1725 | } |
| 1726 | |
| 1727 | /* For non-embedded mbox command, we need to free the pages first */ |
| 1728 | sgecount = bf_get(lpfc_mbox_hdr_sge_cnt, &sli4_cfg->header.cfg_mhdr); |
| 1729 | /* There is nothing we can do if there is no sge address array */ |
| 1730 | if (unlikely(!mbox->sge_array)) { |
| 1731 | mempool_free(mbox, phba->mbox_mem_pool); |
| 1732 | return; |
| 1733 | } |
| 1734 | /* Each non-embedded DMA memory was allocated in the length of a page */ |
| 1735 | for (sgentry = 0; sgentry < sgecount; sgentry++) { |
| 1736 | lpfc_sli4_mbx_sge_get(mbox, sgentry, &sge); |
| 1737 | phyaddr = getPaddr(sge.pa_hi, sge.pa_lo); |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 1738 | dma_free_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE, |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1739 | mbox->sge_array->addr[sgentry], phyaddr); |
| 1740 | } |
| 1741 | /* Free the sge address array memory */ |
| 1742 | kfree(mbox->sge_array); |
| 1743 | /* Finally, free the mailbox command itself */ |
| 1744 | mempool_free(mbox, phba->mbox_mem_pool); |
| 1745 | } |
| 1746 | |
| 1747 | /** |
| 1748 | * lpfc_sli4_config - Initialize the SLI4 Config Mailbox command |
| 1749 | * @phba: pointer to lpfc hba data structure. |
| 1750 | * @mbox: pointer to lpfc mbox command. |
| 1751 | * @subsystem: The sli4 config sub mailbox subsystem. |
| 1752 | * @opcode: The sli4 config sub mailbox command opcode. |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 1753 | * @length: Length of the sli4 config mailbox command (including sub-header). |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1754 | * |
| 1755 | * This routine sets up the header fields of SLI4 specific mailbox command |
| 1756 | * for sending IOCTL command. |
| 1757 | * |
| 1758 | * Return: the actual length of the mbox command allocated (mostly useful |
| 1759 | * for none embedded mailbox command). |
| 1760 | **/ |
| 1761 | int |
| 1762 | lpfc_sli4_config(struct lpfc_hba *phba, struct lpfcMboxq *mbox, |
| 1763 | uint8_t subsystem, uint8_t opcode, uint32_t length, bool emb) |
| 1764 | { |
| 1765 | struct lpfc_mbx_sli4_config *sli4_config; |
| 1766 | union lpfc_sli4_cfg_shdr *cfg_shdr = NULL; |
| 1767 | uint32_t alloc_len; |
| 1768 | uint32_t resid_len; |
| 1769 | uint32_t pagen, pcount; |
| 1770 | void *viraddr; |
| 1771 | dma_addr_t phyaddr; |
| 1772 | |
| 1773 | /* Set up SLI4 mailbox command header fields */ |
| 1774 | memset(mbox, 0, sizeof(*mbox)); |
| 1775 | bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_SLI4_CONFIG); |
| 1776 | |
| 1777 | /* Set up SLI4 ioctl command header fields */ |
| 1778 | sli4_config = &mbox->u.mqe.un.sli4_config; |
| 1779 | |
| 1780 | /* Setup for the embedded mbox command */ |
| 1781 | if (emb) { |
| 1782 | /* Set up main header fields */ |
| 1783 | bf_set(lpfc_mbox_hdr_emb, &sli4_config->header.cfg_mhdr, 1); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 1784 | sli4_config->header.cfg_mhdr.payload_length = length; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1785 | /* Set up sub-header fields following main header */ |
| 1786 | bf_set(lpfc_mbox_hdr_opcode, |
| 1787 | &sli4_config->header.cfg_shdr.request, opcode); |
| 1788 | bf_set(lpfc_mbox_hdr_subsystem, |
| 1789 | &sli4_config->header.cfg_shdr.request, subsystem); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 1790 | sli4_config->header.cfg_shdr.request.request_length = |
| 1791 | length - LPFC_MBX_CMD_HDR_LENGTH; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1792 | return length; |
| 1793 | } |
| 1794 | |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 1795 | /* Setup for the non-embedded mbox command */ |
James Smart | 9589b062 | 2011-04-16 11:03:17 -0400 | [diff] [blame] | 1796 | pcount = (SLI4_PAGE_ALIGN(length))/SLI4_PAGE_SIZE; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1797 | pcount = (pcount > LPFC_SLI4_MBX_SGE_MAX_PAGES) ? |
| 1798 | LPFC_SLI4_MBX_SGE_MAX_PAGES : pcount; |
| 1799 | /* Allocate record for keeping SGE virtual addresses */ |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 1800 | mbox->sge_array = kzalloc(sizeof(struct lpfc_mbx_nembed_sge_virt), |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1801 | GFP_KERNEL); |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 1802 | if (!mbox->sge_array) { |
| 1803 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
| 1804 | "2527 Failed to allocate non-embedded SGE " |
| 1805 | "array.\n"); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1806 | return 0; |
James Smart | 6a9c52c | 2009-10-02 15:16:51 -0400 | [diff] [blame] | 1807 | } |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1808 | for (pagen = 0, alloc_len = 0; pagen < pcount; pagen++) { |
| 1809 | /* The DMA memory is always allocated in the length of a |
| 1810 | * page even though the last SGE might not fill up to a |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 1811 | * page, this is used as a priori size of SLI4_PAGE_SIZE for |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1812 | * the later DMA memory free. |
| 1813 | */ |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 1814 | viraddr = dma_alloc_coherent(&phba->pcidev->dev, SLI4_PAGE_SIZE, |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1815 | &phyaddr, GFP_KERNEL); |
| 1816 | /* In case of malloc fails, proceed with whatever we have */ |
| 1817 | if (!viraddr) |
| 1818 | break; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 1819 | memset(viraddr, 0, SLI4_PAGE_SIZE); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1820 | mbox->sge_array->addr[pagen] = viraddr; |
| 1821 | /* Keep the first page for later sub-header construction */ |
| 1822 | if (pagen == 0) |
| 1823 | cfg_shdr = (union lpfc_sli4_cfg_shdr *)viraddr; |
| 1824 | resid_len = length - alloc_len; |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 1825 | if (resid_len > SLI4_PAGE_SIZE) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1826 | lpfc_sli4_mbx_sge_set(mbox, pagen, phyaddr, |
James Smart | 49198b3 | 2010-04-06 15:04:33 -0400 | [diff] [blame] | 1827 | SLI4_PAGE_SIZE); |
| 1828 | alloc_len += SLI4_PAGE_SIZE; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1829 | } else { |
| 1830 | lpfc_sli4_mbx_sge_set(mbox, pagen, phyaddr, |
| 1831 | resid_len); |
| 1832 | alloc_len = length; |
| 1833 | } |
| 1834 | } |
| 1835 | |
| 1836 | /* Set up main header fields in mailbox command */ |
| 1837 | sli4_config->header.cfg_mhdr.payload_length = alloc_len; |
| 1838 | bf_set(lpfc_mbox_hdr_sge_cnt, &sli4_config->header.cfg_mhdr, pagen); |
| 1839 | |
| 1840 | /* Set up sub-header fields into the first page */ |
| 1841 | if (pagen > 0) { |
| 1842 | bf_set(lpfc_mbox_hdr_opcode, &cfg_shdr->request, opcode); |
| 1843 | bf_set(lpfc_mbox_hdr_subsystem, &cfg_shdr->request, subsystem); |
| 1844 | cfg_shdr->request.request_length = |
| 1845 | alloc_len - sizeof(union lpfc_sli4_cfg_shdr); |
| 1846 | } |
| 1847 | /* The sub-header is in DMA memory, which needs endian converstion */ |
James Smart | 72100cc | 2010-02-12 14:43:01 -0500 | [diff] [blame] | 1848 | if (cfg_shdr) |
| 1849 | lpfc_sli_pcimem_bcopy(cfg_shdr, cfg_shdr, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 1850 | sizeof(union lpfc_sli4_cfg_shdr)); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1851 | return alloc_len; |
| 1852 | } |
| 1853 | |
| 1854 | /** |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 1855 | * lpfc_sli4_mbox_rsrc_extent - Initialize the opcode resource extent. |
| 1856 | * @phba: pointer to lpfc hba data structure. |
| 1857 | * @mbox: pointer to an allocated lpfc mbox resource. |
| 1858 | * @exts_count: the number of extents, if required, to allocate. |
| 1859 | * @rsrc_type: the resource extent type. |
| 1860 | * @emb: true if LPFC_SLI4_MBX_EMBED. false if LPFC_SLI4_MBX_NEMBED. |
| 1861 | * |
| 1862 | * This routine completes the subcommand header for SLI4 resource extent |
| 1863 | * mailbox commands. It is called after lpfc_sli4_config. The caller must |
| 1864 | * pass an allocated mailbox and the attributes required to initialize the |
| 1865 | * mailbox correctly. |
| 1866 | * |
| 1867 | * Return: the actual length of the mbox command allocated. |
| 1868 | **/ |
| 1869 | int |
| 1870 | lpfc_sli4_mbox_rsrc_extent(struct lpfc_hba *phba, struct lpfcMboxq *mbox, |
| 1871 | uint16_t exts_count, uint16_t rsrc_type, bool emb) |
| 1872 | { |
| 1873 | uint8_t opcode = 0; |
| 1874 | struct lpfc_mbx_nembed_rsrc_extent *n_rsrc_extnt = NULL; |
| 1875 | void *virtaddr = NULL; |
| 1876 | |
| 1877 | /* Set up SLI4 ioctl command header fields */ |
| 1878 | if (emb == LPFC_SLI4_MBX_NEMBED) { |
| 1879 | /* Get the first SGE entry from the non-embedded DMA memory */ |
| 1880 | virtaddr = mbox->sge_array->addr[0]; |
| 1881 | if (virtaddr == NULL) |
| 1882 | return 1; |
| 1883 | n_rsrc_extnt = (struct lpfc_mbx_nembed_rsrc_extent *) virtaddr; |
| 1884 | } |
| 1885 | |
| 1886 | /* |
| 1887 | * The resource type is common to all extent Opcodes and resides in the |
| 1888 | * same position. |
| 1889 | */ |
| 1890 | if (emb == LPFC_SLI4_MBX_EMBED) |
| 1891 | bf_set(lpfc_mbx_alloc_rsrc_extents_type, |
| 1892 | &mbox->u.mqe.un.alloc_rsrc_extents.u.req, |
| 1893 | rsrc_type); |
| 1894 | else { |
| 1895 | /* This is DMA data. Byteswap is required. */ |
| 1896 | bf_set(lpfc_mbx_alloc_rsrc_extents_type, |
| 1897 | n_rsrc_extnt, rsrc_type); |
| 1898 | lpfc_sli_pcimem_bcopy(&n_rsrc_extnt->word4, |
| 1899 | &n_rsrc_extnt->word4, |
| 1900 | sizeof(uint32_t)); |
| 1901 | } |
| 1902 | |
| 1903 | /* Complete the initialization for the particular Opcode. */ |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 1904 | opcode = lpfc_sli_config_mbox_opcode_get(phba, mbox); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 1905 | switch (opcode) { |
| 1906 | case LPFC_MBOX_OPCODE_ALLOC_RSRC_EXTENT: |
| 1907 | if (emb == LPFC_SLI4_MBX_EMBED) |
| 1908 | bf_set(lpfc_mbx_alloc_rsrc_extents_cnt, |
| 1909 | &mbox->u.mqe.un.alloc_rsrc_extents.u.req, |
| 1910 | exts_count); |
| 1911 | else |
| 1912 | bf_set(lpfc_mbx_alloc_rsrc_extents_cnt, |
| 1913 | n_rsrc_extnt, exts_count); |
| 1914 | break; |
| 1915 | case LPFC_MBOX_OPCODE_GET_ALLOC_RSRC_EXTENT: |
| 1916 | case LPFC_MBOX_OPCODE_GET_RSRC_EXTENT_INFO: |
| 1917 | case LPFC_MBOX_OPCODE_DEALLOC_RSRC_EXTENT: |
| 1918 | /* Initialization is complete.*/ |
| 1919 | break; |
| 1920 | default: |
| 1921 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
| 1922 | "2929 Resource Extent Opcode x%x is " |
| 1923 | "unsupported\n", opcode); |
| 1924 | return 1; |
| 1925 | } |
| 1926 | |
| 1927 | return 0; |
| 1928 | } |
| 1929 | |
| 1930 | /** |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 1931 | * lpfc_sli_config_mbox_subsys_get - Get subsystem from a sli_config mbox cmd |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1932 | * @phba: pointer to lpfc hba data structure. |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 1933 | * @mbox: pointer to lpfc mbox command queue entry. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1934 | * |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 1935 | * This routine gets the subsystem from a SLI4 specific SLI_CONFIG mailbox |
| 1936 | * command. If the mailbox command is not MBX_SLI4_CONFIG (0x9B) or if the |
| 1937 | * sub-header is not present, subsystem LPFC_MBOX_SUBSYSTEM_NA (0x0) shall |
| 1938 | * be returned. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1939 | **/ |
| 1940 | uint8_t |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 1941 | lpfc_sli_config_mbox_subsys_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox) |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1942 | { |
| 1943 | struct lpfc_mbx_sli4_config *sli4_cfg; |
| 1944 | union lpfc_sli4_cfg_shdr *cfg_shdr; |
| 1945 | |
| 1946 | if (mbox->u.mb.mbxCommand != MBX_SLI4_CONFIG) |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 1947 | return LPFC_MBOX_SUBSYSTEM_NA; |
| 1948 | sli4_cfg = &mbox->u.mqe.un.sli4_config; |
| 1949 | |
| 1950 | /* For embedded mbox command, get opcode from embedded sub-header*/ |
| 1951 | if (bf_get(lpfc_mbox_hdr_emb, &sli4_cfg->header.cfg_mhdr)) { |
| 1952 | cfg_shdr = &mbox->u.mqe.un.sli4_config.header.cfg_shdr; |
| 1953 | return bf_get(lpfc_mbox_hdr_subsystem, &cfg_shdr->request); |
| 1954 | } |
| 1955 | |
| 1956 | /* For non-embedded mbox command, get opcode from first dma page */ |
| 1957 | if (unlikely(!mbox->sge_array)) |
| 1958 | return LPFC_MBOX_SUBSYSTEM_NA; |
| 1959 | cfg_shdr = (union lpfc_sli4_cfg_shdr *)mbox->sge_array->addr[0]; |
| 1960 | return bf_get(lpfc_mbox_hdr_subsystem, &cfg_shdr->request); |
| 1961 | } |
| 1962 | |
| 1963 | /** |
| 1964 | * lpfc_sli_config_mbox_opcode_get - Get opcode from a sli_config mbox cmd |
| 1965 | * @phba: pointer to lpfc hba data structure. |
| 1966 | * @mbox: pointer to lpfc mbox command queue entry. |
| 1967 | * |
| 1968 | * This routine gets the opcode from a SLI4 specific SLI_CONFIG mailbox |
| 1969 | * command. If the mailbox command is not MBX_SLI4_CONFIG (0x9B) or if |
| 1970 | * the sub-header is not present, opcode LPFC_MBOX_OPCODE_NA (0x0) be |
| 1971 | * returned. |
| 1972 | **/ |
| 1973 | uint8_t |
| 1974 | lpfc_sli_config_mbox_opcode_get(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbox) |
| 1975 | { |
| 1976 | struct lpfc_mbx_sli4_config *sli4_cfg; |
| 1977 | union lpfc_sli4_cfg_shdr *cfg_shdr; |
| 1978 | |
| 1979 | if (mbox->u.mb.mbxCommand != MBX_SLI4_CONFIG) |
| 1980 | return LPFC_MBOX_OPCODE_NA; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1981 | sli4_cfg = &mbox->u.mqe.un.sli4_config; |
| 1982 | |
| 1983 | /* For embedded mbox command, get opcode from embedded sub-header*/ |
| 1984 | if (bf_get(lpfc_mbox_hdr_emb, &sli4_cfg->header.cfg_mhdr)) { |
| 1985 | cfg_shdr = &mbox->u.mqe.un.sli4_config.header.cfg_shdr; |
| 1986 | return bf_get(lpfc_mbox_hdr_opcode, &cfg_shdr->request); |
| 1987 | } |
| 1988 | |
| 1989 | /* For non-embedded mbox command, get opcode from first dma page */ |
| 1990 | if (unlikely(!mbox->sge_array)) |
James Smart | a183a15 | 2011-10-10 21:32:43 -0400 | [diff] [blame] | 1991 | return LPFC_MBOX_OPCODE_NA; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 1992 | cfg_shdr = (union lpfc_sli4_cfg_shdr *)mbox->sge_array->addr[0]; |
| 1993 | return bf_get(lpfc_mbox_hdr_opcode, &cfg_shdr->request); |
| 1994 | } |
| 1995 | |
| 1996 | /** |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 1997 | * lpfc_sli4_mbx_read_fcf_rec - Allocate and construct read fcf mbox cmd |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 1998 | * @phba: pointer to lpfc hba data structure. |
| 1999 | * @fcf_index: index to fcf table. |
| 2000 | * |
| 2001 | * This routine routine allocates and constructs non-embedded mailbox command |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 2002 | * for reading a FCF table entry referred by @fcf_index. |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2003 | * |
| 2004 | * Return: pointer to the mailbox command constructed if successful, otherwise |
| 2005 | * NULL. |
| 2006 | **/ |
| 2007 | int |
James Smart | 0c9ab6f | 2010-02-26 14:15:57 -0500 | [diff] [blame] | 2008 | lpfc_sli4_mbx_read_fcf_rec(struct lpfc_hba *phba, |
| 2009 | struct lpfcMboxq *mboxq, |
| 2010 | uint16_t fcf_index) |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2011 | { |
| 2012 | void *virt_addr; |
| 2013 | dma_addr_t phys_addr; |
| 2014 | uint8_t *bytep; |
| 2015 | struct lpfc_mbx_sge sge; |
| 2016 | uint32_t alloc_len, req_len; |
| 2017 | struct lpfc_mbx_read_fcf_tbl *read_fcf; |
| 2018 | |
| 2019 | if (!mboxq) |
| 2020 | return -ENOMEM; |
| 2021 | |
| 2022 | req_len = sizeof(struct fcf_record) + |
| 2023 | sizeof(union lpfc_sli4_cfg_shdr) + 2 * sizeof(uint32_t); |
| 2024 | |
| 2025 | /* Set up READ_FCF SLI4_CONFIG mailbox-ioctl command */ |
| 2026 | alloc_len = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE, |
| 2027 | LPFC_MBOX_OPCODE_FCOE_READ_FCF_TABLE, req_len, |
| 2028 | LPFC_SLI4_MBX_NEMBED); |
| 2029 | |
| 2030 | if (alloc_len < req_len) { |
| 2031 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX, |
| 2032 | "0291 Allocated DMA memory size (x%x) is " |
| 2033 | "less than the requested DMA memory " |
| 2034 | "size (x%x)\n", alloc_len, req_len); |
| 2035 | return -ENOMEM; |
| 2036 | } |
| 2037 | |
| 2038 | /* Get the first SGE entry from the non-embedded DMA memory. This |
| 2039 | * routine only uses a single SGE. |
| 2040 | */ |
| 2041 | lpfc_sli4_mbx_sge_get(mboxq, 0, &sge); |
| 2042 | phys_addr = getPaddr(sge.pa_hi, sge.pa_lo); |
| 2043 | virt_addr = mboxq->sge_array->addr[0]; |
| 2044 | read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr; |
| 2045 | |
| 2046 | /* Set up command fields */ |
| 2047 | bf_set(lpfc_mbx_read_fcf_tbl_indx, &read_fcf->u.request, fcf_index); |
| 2048 | /* Perform necessary endian conversion */ |
| 2049 | bytep = virt_addr + sizeof(union lpfc_sli4_cfg_shdr); |
| 2050 | lpfc_sli_pcimem_bcopy(bytep, bytep, sizeof(uint32_t)); |
| 2051 | |
| 2052 | return 0; |
| 2053 | } |
| 2054 | |
| 2055 | /** |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2056 | * lpfc_request_features: Configure SLI4 REQUEST_FEATURES mailbox |
| 2057 | * @mboxq: pointer to lpfc mbox command. |
| 2058 | * |
| 2059 | * This routine sets up the mailbox for an SLI4 REQUEST_FEATURES |
| 2060 | * mailbox command. |
| 2061 | **/ |
| 2062 | void |
| 2063 | lpfc_request_features(struct lpfc_hba *phba, struct lpfcMboxq *mboxq) |
| 2064 | { |
| 2065 | /* Set up SLI4 mailbox command header fields */ |
| 2066 | memset(mboxq, 0, sizeof(LPFC_MBOXQ_t)); |
| 2067 | bf_set(lpfc_mqe_command, &mboxq->u.mqe, MBX_SLI4_REQ_FTRS); |
| 2068 | |
| 2069 | /* Set up host requested features. */ |
| 2070 | bf_set(lpfc_mbx_rq_ftr_rq_fcpi, &mboxq->u.mqe.un.req_ftrs, 1); |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 2071 | bf_set(lpfc_mbx_rq_ftr_rq_perfh, &mboxq->u.mqe.un.req_ftrs, 1); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2072 | |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2073 | /* Enable DIF (block guard) only if configured to do so. */ |
| 2074 | if (phba->cfg_enable_bg) |
| 2075 | bf_set(lpfc_mbx_rq_ftr_rq_dif, &mboxq->u.mqe.un.req_ftrs, 1); |
| 2076 | |
| 2077 | /* Enable NPIV only if configured to do so. */ |
| 2078 | if (phba->max_vpi && phba->cfg_enable_npiv) |
| 2079 | bf_set(lpfc_mbx_rq_ftr_rq_npiv, &mboxq->u.mqe.un.req_ftrs, 1); |
| 2080 | |
| 2081 | return; |
| 2082 | } |
| 2083 | |
| 2084 | /** |
| 2085 | * lpfc_init_vfi - Initialize the INIT_VFI mailbox command |
| 2086 | * @mbox: pointer to lpfc mbox command to initialize. |
| 2087 | * @vport: Vport associated with the VF. |
| 2088 | * |
| 2089 | * This routine initializes @mbox to all zeros and then fills in the mailbox |
| 2090 | * fields from @vport. INIT_VFI configures virtual fabrics identified by VFI |
| 2091 | * in the context of an FCF. The driver issues this command to setup a VFI |
| 2092 | * before issuing a FLOGI to login to the VSAN. The driver should also issue a |
| 2093 | * REG_VFI after a successful VSAN login. |
| 2094 | **/ |
| 2095 | void |
| 2096 | lpfc_init_vfi(struct lpfcMboxq *mbox, struct lpfc_vport *vport) |
| 2097 | { |
| 2098 | struct lpfc_mbx_init_vfi *init_vfi; |
| 2099 | |
| 2100 | memset(mbox, 0, sizeof(*mbox)); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2101 | mbox->vport = vport; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2102 | init_vfi = &mbox->u.mqe.un.init_vfi; |
| 2103 | bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_INIT_VFI); |
| 2104 | bf_set(lpfc_init_vfi_vr, init_vfi, 1); |
| 2105 | bf_set(lpfc_init_vfi_vt, init_vfi, 1); |
James Smart | 76a95d7 | 2010-11-20 23:11:48 -0500 | [diff] [blame] | 2106 | bf_set(lpfc_init_vfi_vp, init_vfi, 1); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 2107 | bf_set(lpfc_init_vfi_vfi, init_vfi, |
| 2108 | vport->phba->sli4_hba.vfi_ids[vport->vfi]); |
James Smart | 7851fe2 | 2011-07-22 18:36:52 -0400 | [diff] [blame] | 2109 | bf_set(lpfc_init_vfi_vpi, init_vfi, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 2110 | vport->phba->vpi_ids[vport->vpi]); |
| 2111 | bf_set(lpfc_init_vfi_fcfi, init_vfi, |
| 2112 | vport->phba->fcf.fcfi); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2113 | } |
| 2114 | |
| 2115 | /** |
| 2116 | * lpfc_reg_vfi - Initialize the REG_VFI mailbox command |
| 2117 | * @mbox: pointer to lpfc mbox command to initialize. |
| 2118 | * @vport: vport associated with the VF. |
| 2119 | * @phys: BDE DMA bus address used to send the service parameters to the HBA. |
| 2120 | * |
| 2121 | * This routine initializes @mbox to all zeros and then fills in the mailbox |
| 2122 | * fields from @vport, and uses @buf as a DMAable buffer to send the vport's |
| 2123 | * fc service parameters to the HBA for this VFI. REG_VFI configures virtual |
| 2124 | * fabrics identified by VFI in the context of an FCF. |
| 2125 | **/ |
| 2126 | void |
| 2127 | lpfc_reg_vfi(struct lpfcMboxq *mbox, struct lpfc_vport *vport, dma_addr_t phys) |
| 2128 | { |
| 2129 | struct lpfc_mbx_reg_vfi *reg_vfi; |
James Smart | ae05ebe | 2013-03-01 16:35:38 -0500 | [diff] [blame] | 2130 | struct lpfc_hba *phba = vport->phba; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2131 | |
| 2132 | memset(mbox, 0, sizeof(*mbox)); |
| 2133 | reg_vfi = &mbox->u.mqe.un.reg_vfi; |
| 2134 | bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_REG_VFI); |
| 2135 | bf_set(lpfc_reg_vfi_vp, reg_vfi, 1); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 2136 | bf_set(lpfc_reg_vfi_vfi, reg_vfi, |
James Smart | ae05ebe | 2013-03-01 16:35:38 -0500 | [diff] [blame] | 2137 | phba->sli4_hba.vfi_ids[vport->vfi]); |
| 2138 | bf_set(lpfc_reg_vfi_fcfi, reg_vfi, phba->fcf.fcfi); |
| 2139 | bf_set(lpfc_reg_vfi_vpi, reg_vfi, phba->vpi_ids[vport->vpi]); |
James Smart | c868595 | 2009-11-18 15:39:16 -0500 | [diff] [blame] | 2140 | memcpy(reg_vfi->wwn, &vport->fc_portname, sizeof(struct lpfc_name)); |
| 2141 | reg_vfi->wwn[0] = cpu_to_le32(reg_vfi->wwn[0]); |
| 2142 | reg_vfi->wwn[1] = cpu_to_le32(reg_vfi->wwn[1]); |
James Smart | ae05ebe | 2013-03-01 16:35:38 -0500 | [diff] [blame] | 2143 | reg_vfi->e_d_tov = phba->fc_edtov; |
| 2144 | reg_vfi->r_a_tov = phba->fc_ratov; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2145 | reg_vfi->bde.addrHigh = putPaddrHigh(phys); |
| 2146 | reg_vfi->bde.addrLow = putPaddrLow(phys); |
| 2147 | reg_vfi->bde.tus.f.bdeSize = sizeof(vport->fc_sparam); |
| 2148 | reg_vfi->bde.tus.f.bdeFlags = BUFF_TYPE_BDE_64; |
| 2149 | bf_set(lpfc_reg_vfi_nport_id, reg_vfi, vport->fc_myDID); |
James Smart | ae05ebe | 2013-03-01 16:35:38 -0500 | [diff] [blame] | 2150 | |
| 2151 | /* Only FC supports upd bit */ |
| 2152 | if ((phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC) && |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 2153 | (vport->fc_flag & FC_VFI_REGISTERED) && |
| 2154 | (!phba->fc_topology_changed)) { |
James Smart | ae05ebe | 2013-03-01 16:35:38 -0500 | [diff] [blame] | 2155 | bf_set(lpfc_reg_vfi_vp, reg_vfi, 0); |
| 2156 | bf_set(lpfc_reg_vfi_upd, reg_vfi, 1); |
| 2157 | } |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 2158 | lpfc_printf_vlog(vport, KERN_INFO, LOG_MBOX, |
| 2159 | "3134 Register VFI, mydid:x%x, fcfi:%d, " |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 2160 | " vfi:%d, vpi:%d, fc_pname:%x%x fc_flag:x%x" |
| 2161 | " port_state:x%x topology chg:%d\n", |
James Smart | 1b51197 | 2011-12-13 13:23:09 -0500 | [diff] [blame] | 2162 | vport->fc_myDID, |
James Smart | ae05ebe | 2013-03-01 16:35:38 -0500 | [diff] [blame] | 2163 | phba->fcf.fcfi, |
| 2164 | phba->sli4_hba.vfi_ids[vport->vfi], |
| 2165 | phba->vpi_ids[vport->vpi], |
James Smart | e74c03c | 2013-04-17 20:15:19 -0400 | [diff] [blame] | 2166 | reg_vfi->wwn[0], reg_vfi->wwn[1], vport->fc_flag, |
| 2167 | vport->port_state, phba->fc_topology_changed); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2168 | } |
| 2169 | |
| 2170 | /** |
| 2171 | * lpfc_init_vpi - Initialize the INIT_VPI mailbox command |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2172 | * @phba: pointer to the hba structure to init the VPI for. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2173 | * @mbox: pointer to lpfc mbox command to initialize. |
| 2174 | * @vpi: VPI to be initialized. |
| 2175 | * |
| 2176 | * The INIT_VPI mailbox command supports virtual N_Ports. The driver uses the |
| 2177 | * command to activate a virtual N_Port. The HBA assigns a MAC address to use |
| 2178 | * with the virtual N Port. The SLI Host issues this command before issuing a |
| 2179 | * FDISC to connect to the Fabric. The SLI Host should issue a REG_VPI after a |
| 2180 | * successful virtual NPort login. |
| 2181 | **/ |
| 2182 | void |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2183 | lpfc_init_vpi(struct lpfc_hba *phba, struct lpfcMboxq *mbox, uint16_t vpi) |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2184 | { |
| 2185 | memset(mbox, 0, sizeof(*mbox)); |
| 2186 | bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_INIT_VPI); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2187 | bf_set(lpfc_init_vpi_vpi, &mbox->u.mqe.un.init_vpi, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 2188 | phba->vpi_ids[vpi]); |
James Smart | 1c6834a | 2009-07-19 10:01:26 -0400 | [diff] [blame] | 2189 | bf_set(lpfc_init_vpi_vfi, &mbox->u.mqe.un.init_vpi, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 2190 | phba->sli4_hba.vfi_ids[phba->pport->vfi]); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2191 | } |
| 2192 | |
| 2193 | /** |
| 2194 | * lpfc_unreg_vfi - Initialize the UNREG_VFI mailbox command |
| 2195 | * @mbox: pointer to lpfc mbox command to initialize. |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 2196 | * @vport: vport associated with the VF. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2197 | * |
| 2198 | * The UNREG_VFI mailbox command causes the SLI Host to put a virtual fabric |
| 2199 | * (logical NPort) into the inactive state. The SLI Host must have logged out |
| 2200 | * and unregistered all remote N_Ports to abort any activity on the virtual |
| 2201 | * fabric. The SLI Port posts the mailbox response after marking the virtual |
| 2202 | * fabric inactive. |
| 2203 | **/ |
| 2204 | void |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 2205 | lpfc_unreg_vfi(struct lpfcMboxq *mbox, struct lpfc_vport *vport) |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2206 | { |
| 2207 | memset(mbox, 0, sizeof(*mbox)); |
| 2208 | bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_UNREG_VFI); |
James Smart | 6669f9b | 2009-10-02 15:16:45 -0400 | [diff] [blame] | 2209 | bf_set(lpfc_unreg_vfi_vfi, &mbox->u.mqe.un.unreg_vfi, |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 2210 | vport->phba->sli4_hba.vfi_ids[vport->vfi]); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2211 | } |
| 2212 | |
| 2213 | /** |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 2214 | * lpfc_sli4_dump_cfg_rg23 - Dump sli4 port config region 23 |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2215 | * @phba: pointer to the hba structure containing. |
| 2216 | * @mbox: pointer to lpfc mbox command to initialize. |
| 2217 | * |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 2218 | * This function create a SLI4 dump mailbox command to dump configure |
| 2219 | * region 23. |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2220 | **/ |
| 2221 | int |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 2222 | lpfc_sli4_dump_cfg_rg23(struct lpfc_hba *phba, struct lpfcMboxq *mbox) |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2223 | { |
| 2224 | struct lpfc_dmabuf *mp = NULL; |
| 2225 | MAILBOX_t *mb; |
| 2226 | |
| 2227 | memset(mbox, 0, sizeof(*mbox)); |
| 2228 | mb = &mbox->u.mb; |
| 2229 | |
| 2230 | mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); |
| 2231 | if (mp) |
| 2232 | mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys); |
| 2233 | |
| 2234 | if (!mp || !mp->virt) { |
| 2235 | kfree(mp); |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 2236 | /* dump config region 23 failed to allocate memory */ |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2237 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX, |
James Smart | 026abb8 | 2011-12-13 13:20:45 -0500 | [diff] [blame] | 2238 | "2569 lpfc dump config region 23: memory" |
James Smart | e4e7427 | 2009-07-19 10:01:38 -0400 | [diff] [blame] | 2239 | " allocation failed\n"); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2240 | return 1; |
| 2241 | } |
| 2242 | |
| 2243 | memset(mp->virt, 0, LPFC_BPL_SIZE); |
| 2244 | INIT_LIST_HEAD(&mp->list); |
| 2245 | |
| 2246 | /* save address for completion */ |
| 2247 | mbox->context1 = (uint8_t *) mp; |
| 2248 | |
| 2249 | mb->mbxCommand = MBX_DUMP_MEMORY; |
| 2250 | mb->un.varDmp.type = DMP_NV_PARAMS; |
James Smart | a0c87cb | 2009-07-19 10:01:10 -0400 | [diff] [blame] | 2251 | mb->un.varDmp.region_id = DMP_REGION_23; |
| 2252 | mb->un.varDmp.sli4_length = DMP_RGN23_SIZE; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2253 | mb->un.varWords[3] = putPaddrLow(mp->phys); |
| 2254 | mb->un.varWords[4] = putPaddrHigh(mp->phys); |
| 2255 | return 0; |
| 2256 | } |
| 2257 | |
| 2258 | /** |
| 2259 | * lpfc_reg_fcfi - Initialize the REG_FCFI mailbox command |
| 2260 | * @phba: pointer to the hba structure containing the FCF index and RQ ID. |
| 2261 | * @mbox: pointer to lpfc mbox command to initialize. |
| 2262 | * |
| 2263 | * The REG_FCFI mailbox command supports Fibre Channel Forwarders (FCFs). The |
| 2264 | * SLI Host uses the command to activate an FCF after it has acquired FCF |
| 2265 | * information via a READ_FCF mailbox command. This mailbox command also is used |
| 2266 | * to indicate where received unsolicited frames from this FCF will be sent. By |
| 2267 | * default this routine will set up the FCF to forward all unsolicited frames |
| 2268 | * the the RQ ID passed in the @phba. This can be overridden by the caller for |
| 2269 | * more complicated setups. |
| 2270 | **/ |
| 2271 | void |
| 2272 | lpfc_reg_fcfi(struct lpfc_hba *phba, struct lpfcMboxq *mbox) |
| 2273 | { |
| 2274 | struct lpfc_mbx_reg_fcfi *reg_fcfi; |
| 2275 | |
| 2276 | memset(mbox, 0, sizeof(*mbox)); |
| 2277 | reg_fcfi = &mbox->u.mqe.un.reg_fcfi; |
| 2278 | bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_REG_FCFI); |
| 2279 | bf_set(lpfc_reg_fcfi_rq_id0, reg_fcfi, phba->sli4_hba.hdr_rq->queue_id); |
| 2280 | bf_set(lpfc_reg_fcfi_rq_id1, reg_fcfi, REG_FCF_INVALID_QID); |
| 2281 | bf_set(lpfc_reg_fcfi_rq_id2, reg_fcfi, REG_FCF_INVALID_QID); |
| 2282 | bf_set(lpfc_reg_fcfi_rq_id3, reg_fcfi, REG_FCF_INVALID_QID); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2283 | bf_set(lpfc_reg_fcfi_info_index, reg_fcfi, |
| 2284 | phba->fcf.current_rec.fcf_indx); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2285 | /* reg_fcf addr mode is bit wise inverted value of fcf addr_mode */ |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2286 | bf_set(lpfc_reg_fcfi_mam, reg_fcfi, (~phba->fcf.addr_mode) & 0x3); |
James Smart | 3804dc8 | 2010-07-14 15:31:37 -0400 | [diff] [blame] | 2287 | if (phba->fcf.current_rec.vlan_id != LPFC_FCOE_NULL_VID) { |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2288 | bf_set(lpfc_reg_fcfi_vv, reg_fcfi, 1); |
James Smart | ecfd03c | 2010-02-12 14:41:27 -0500 | [diff] [blame] | 2289 | bf_set(lpfc_reg_fcfi_vlan_tag, reg_fcfi, |
| 2290 | phba->fcf.current_rec.vlan_id); |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2291 | } |
| 2292 | } |
| 2293 | |
| 2294 | /** |
| 2295 | * lpfc_unreg_fcfi - Initialize the UNREG_FCFI mailbox command |
| 2296 | * @mbox: pointer to lpfc mbox command to initialize. |
| 2297 | * @fcfi: FCFI to be unregistered. |
| 2298 | * |
| 2299 | * The UNREG_FCFI mailbox command supports Fibre Channel Forwarders (FCFs). |
| 2300 | * The SLI Host uses the command to inactivate an FCFI. |
| 2301 | **/ |
| 2302 | void |
| 2303 | lpfc_unreg_fcfi(struct lpfcMboxq *mbox, uint16_t fcfi) |
| 2304 | { |
| 2305 | memset(mbox, 0, sizeof(*mbox)); |
| 2306 | bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_UNREG_FCFI); |
| 2307 | bf_set(lpfc_unreg_fcfi, &mbox->u.mqe.un.unreg_fcfi, fcfi); |
| 2308 | } |
| 2309 | |
| 2310 | /** |
| 2311 | * lpfc_resume_rpi - Initialize the RESUME_RPI mailbox command |
| 2312 | * @mbox: pointer to lpfc mbox command to initialize. |
| 2313 | * @ndlp: The nodelist structure that describes the RPI to resume. |
| 2314 | * |
| 2315 | * The RESUME_RPI mailbox command is used to restart I/O to an RPI after a |
| 2316 | * link event. |
| 2317 | **/ |
| 2318 | void |
| 2319 | lpfc_resume_rpi(struct lpfcMboxq *mbox, struct lpfc_nodelist *ndlp) |
| 2320 | { |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 2321 | struct lpfc_hba *phba = ndlp->phba; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2322 | struct lpfc_mbx_resume_rpi *resume_rpi; |
| 2323 | |
| 2324 | memset(mbox, 0, sizeof(*mbox)); |
| 2325 | resume_rpi = &mbox->u.mqe.un.resume_rpi; |
| 2326 | bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_RESUME_RPI); |
James Smart | 6d368e5 | 2011-05-24 11:44:12 -0400 | [diff] [blame] | 2327 | bf_set(lpfc_resume_rpi_index, resume_rpi, |
| 2328 | phba->sli4_hba.rpi_ids[ndlp->nlp_rpi]); |
James Smart | 8fa3851 | 2009-07-19 10:01:03 -0400 | [diff] [blame] | 2329 | bf_set(lpfc_resume_rpi_ii, resume_rpi, RESUME_INDEX_RPI); |
| 2330 | resume_rpi->event_tag = ndlp->phba->fc_eventTag; |
James Smart | 04c6849 | 2009-05-22 14:52:52 -0400 | [diff] [blame] | 2331 | } |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 2332 | |
| 2333 | /** |
| 2334 | * lpfc_supported_pages - Initialize the PORT_CAPABILITIES supported pages |
| 2335 | * mailbox command. |
| 2336 | * @mbox: pointer to lpfc mbox command to initialize. |
| 2337 | * |
| 2338 | * The PORT_CAPABILITIES supported pages mailbox command is issued to |
| 2339 | * retrieve the particular feature pages supported by the port. |
| 2340 | **/ |
| 2341 | void |
| 2342 | lpfc_supported_pages(struct lpfcMboxq *mbox) |
| 2343 | { |
| 2344 | struct lpfc_mbx_supp_pages *supp_pages; |
| 2345 | |
| 2346 | memset(mbox, 0, sizeof(*mbox)); |
| 2347 | supp_pages = &mbox->u.mqe.un.supp_pages; |
| 2348 | bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_PORT_CAPABILITIES); |
| 2349 | bf_set(cpn, supp_pages, LPFC_SUPP_PAGES); |
| 2350 | } |
| 2351 | |
| 2352 | /** |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 2353 | * lpfc_pc_sli4_params - Initialize the PORT_CAPABILITIES SLI4 Params mbox cmd. |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 2354 | * @mbox: pointer to lpfc mbox command to initialize. |
| 2355 | * |
| 2356 | * The PORT_CAPABILITIES SLI4 parameters mailbox command is issued to |
| 2357 | * retrieve the particular SLI4 features supported by the port. |
| 2358 | **/ |
| 2359 | void |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 2360 | lpfc_pc_sli4_params(struct lpfcMboxq *mbox) |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 2361 | { |
James Smart | fedd3b7 | 2011-02-16 12:39:24 -0500 | [diff] [blame] | 2362 | struct lpfc_mbx_pc_sli4_params *sli4_params; |
James Smart | 28baac7 | 2010-02-12 14:42:03 -0500 | [diff] [blame] | 2363 | |
| 2364 | memset(mbox, 0, sizeof(*mbox)); |
| 2365 | sli4_params = &mbox->u.mqe.un.sli4_params; |
| 2366 | bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_PORT_CAPABILITIES); |
| 2367 | bf_set(cpn, sli4_params, LPFC_SLI4_PARAMETERS); |
| 2368 | } |