]>
Commit | Line | Data |
---|---|---|
dea3101e JB |
1 | /******************************************************************* |
2 | * This file is part of the Emulex Linux Device Driver for * | |
c44ce173 | 3 | * Fibre Channel Host Bus Adapters. * |
d080abe0 JS |
4 | * Copyright (C) 2017 Broadcom. All Rights Reserved. The term * |
5 | * “Broadcom” refers to Broadcom Limited and/or its subsidiaries. * | |
50611577 | 6 | * Copyright (C) 2004-2016 Emulex. All rights reserved. * |
c44ce173 | 7 | * EMULEX and SLI are trademarks of Emulex. * |
d080abe0 | 8 | * www.broadcom.com * |
c44ce173 | 9 | * Portions Copyright (C) 2004-2005 Christoph Hellwig * |
dea3101e JB |
10 | * * |
11 | * This program is free software; you can redistribute it and/or * | |
c44ce173 JSEC |
12 | * modify it under the terms of version 2 of the GNU General * |
13 | * Public License as published by the Free Software Foundation. * | |
14 | * This program is distributed in the hope that it will be useful. * | |
15 | * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * | |
16 | * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * | |
17 | * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE * | |
18 | * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD * | |
19 | * TO BE LEGALLY INVALID. See the GNU General Public License for * | |
20 | * more details, a copy of which can be found in the file COPYING * | |
21 | * included with this package. * | |
dea3101e JB |
22 | *******************************************************************/ |
23 | ||
dea3101e | 24 | #include <linux/ctype.h> |
46fa311e | 25 | #include <linux/delay.h> |
dea3101e JB |
26 | #include <linux/pci.h> |
27 | #include <linux/interrupt.h> | |
acf3368f | 28 | #include <linux/module.h> |
0d878419 | 29 | #include <linux/aer.h> |
5a0e3ad6 | 30 | #include <linux/gfp.h> |
ecc30990 | 31 | #include <linux/kernel.h> |
dea3101e | 32 | |
91886523 | 33 | #include <scsi/scsi.h> |
dea3101e JB |
34 | #include <scsi/scsi_device.h> |
35 | #include <scsi/scsi_host.h> | |
36 | #include <scsi/scsi_tcq.h> | |
37 | #include <scsi/scsi_transport_fc.h> | |
6a9c52cf | 38 | #include <scsi/fc/fc_fs.h> |
dea3101e | 39 | |
895427bd JS |
40 | #include <linux/nvme-fc-driver.h> |
41 | ||
da0436e9 | 42 | #include "lpfc_hw4.h" |
dea3101e JB |
43 | #include "lpfc_hw.h" |
44 | #include "lpfc_sli.h" | |
da0436e9 | 45 | #include "lpfc_sli4.h" |
ea2151b4 | 46 | #include "lpfc_nl.h" |
dea3101e | 47 | #include "lpfc_disc.h" |
dea3101e | 48 | #include "lpfc.h" |
895427bd JS |
49 | #include "lpfc_scsi.h" |
50 | #include "lpfc_nvme.h" | |
f358dd0c | 51 | #include "lpfc_nvmet.h" |
dea3101e JB |
52 | #include "lpfc_logmsg.h" |
53 | #include "lpfc_version.h" | |
54 | #include "lpfc_compat.h" | |
55 | #include "lpfc_crtn.h" | |
92d7f7b0 | 56 | #include "lpfc_vport.h" |
93dd1911 | 57 | #include "lpfc_attr.h" |
dea3101e | 58 | |
2ea259ee JS |
59 | #define LPFC_DEF_DEVLOSS_TMO 30 |
60 | #define LPFC_MIN_DEVLOSS_TMO 1 | |
61 | #define LPFC_MAX_DEVLOSS_TMO 255 | |
dea3101e | 62 | |
2d7dbc4c JS |
63 | #define LPFC_DEF_MRQ_POST 256 |
64 | #define LPFC_MIN_MRQ_POST 32 | |
65 | #define LPFC_MAX_MRQ_POST 512 | |
dea3101e | 66 | |
f7a919b4 JS |
67 | /* |
68 | * Write key size should be multiple of 4. If write key is changed | |
69 | * make sure that library write key is also changed. | |
70 | */ | |
71 | #define LPFC_REG_WRITE_KEY_SIZE 4 | |
72 | #define LPFC_REG_WRITE_KEY "EMLX" | |
73 | ||
e59058c4 | 74 | /** |
3621a710 | 75 | * lpfc_jedec_to_ascii - Hex to ascii convertor according to JEDEC rules |
e59058c4 JS |
76 | * @incr: integer to convert. |
77 | * @hdw: ascii string holding converted integer plus a string terminator. | |
78 | * | |
79 | * Description: | |
80 | * JEDEC Joint Electron Device Engineering Council. | |
81 | * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii | |
82 | * character string. The string is then terminated with a NULL in byte 9. | |
83 | * Hex 0-9 becomes ascii '0' to '9'. | |
84 | * Hex a-f becomes ascii '=' to 'B' capital B. | |
85 | * | |
86 | * Notes: | |
87 | * Coded for 32 bit integers only. | |
88 | **/ | |
dea3101e JB |
89 | static void |
90 | lpfc_jedec_to_ascii(int incr, char hdw[]) | |
91 | { | |
92 | int i, j; | |
93 | for (i = 0; i < 8; i++) { | |
94 | j = (incr & 0xf); | |
95 | if (j <= 9) | |
96 | hdw[7 - i] = 0x30 + j; | |
97 | else | |
98 | hdw[7 - i] = 0x61 + j - 10; | |
99 | incr = (incr >> 4); | |
100 | } | |
101 | hdw[8] = 0; | |
102 | return; | |
103 | } | |
104 | ||
e59058c4 | 105 | /** |
3621a710 | 106 | * lpfc_drvr_version_show - Return the Emulex driver string with version number |
e59058c4 JS |
107 | * @dev: class unused variable. |
108 | * @attr: device attribute, not used. | |
109 | * @buf: on return contains the module description text. | |
110 | * | |
111 | * Returns: size of formatted string. | |
112 | **/ | |
dea3101e | 113 | static ssize_t |
ee959b00 TJ |
114 | lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr, |
115 | char *buf) | |
dea3101e JB |
116 | { |
117 | return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n"); | |
118 | } | |
119 | ||
45ed1190 JS |
120 | /** |
121 | * lpfc_enable_fip_show - Return the fip mode of the HBA | |
122 | * @dev: class unused variable. | |
123 | * @attr: device attribute, not used. | |
124 | * @buf: on return contains the module description text. | |
125 | * | |
126 | * Returns: size of formatted string. | |
127 | **/ | |
128 | static ssize_t | |
129 | lpfc_enable_fip_show(struct device *dev, struct device_attribute *attr, | |
130 | char *buf) | |
131 | { | |
132 | struct Scsi_Host *shost = class_to_shost(dev); | |
133 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
134 | struct lpfc_hba *phba = vport->phba; | |
135 | ||
136 | if (phba->hba_flag & HBA_FIP_SUPPORT) | |
137 | return snprintf(buf, PAGE_SIZE, "1\n"); | |
138 | else | |
139 | return snprintf(buf, PAGE_SIZE, "0\n"); | |
140 | } | |
141 | ||
895427bd JS |
142 | static ssize_t |
143 | lpfc_nvme_info_show(struct device *dev, struct device_attribute *attr, | |
144 | char *buf) | |
145 | { | |
146 | struct Scsi_Host *shost = class_to_shost(dev); | |
147 | struct lpfc_vport *vport = shost_priv(shost); | |
148 | struct lpfc_hba *phba = vport->phba; | |
f358dd0c | 149 | struct lpfc_nvmet_tgtport *tgtp; |
895427bd JS |
150 | struct nvme_fc_local_port *localport; |
151 | struct lpfc_nvme_lport *lport; | |
152 | struct lpfc_nvme_rport *rport; | |
153 | struct nvme_fc_remote_port *nrport; | |
154 | char *statep; | |
155 | int len = 0; | |
156 | ||
157 | if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME)) { | |
158 | len += snprintf(buf, PAGE_SIZE, "NVME Disabled\n"); | |
159 | return len; | |
160 | } | |
f358dd0c JS |
161 | if (phba->nvmet_support) { |
162 | if (!phba->targetport) { | |
163 | len = snprintf(buf, PAGE_SIZE, | |
164 | "NVME Target: x%llx is not allocated\n", | |
165 | wwn_to_u64(vport->fc_portname.u.wwn)); | |
166 | return len; | |
167 | } | |
168 | /* Port state is only one of two values for now. */ | |
169 | if (phba->targetport->port_id) | |
170 | statep = "REGISTERED"; | |
171 | else | |
172 | statep = "INIT"; | |
173 | len += snprintf(buf + len, PAGE_SIZE - len, | |
174 | "NVME Target: Enabled State %s\n", | |
175 | statep); | |
176 | len += snprintf(buf + len, PAGE_SIZE - len, | |
177 | "%s%d WWPN x%llx WWNN x%llx DID x%06x\n", | |
178 | "NVME Target: lpfc", | |
179 | phba->brd_no, | |
180 | wwn_to_u64(vport->fc_portname.u.wwn), | |
181 | wwn_to_u64(vport->fc_nodename.u.wwn), | |
182 | phba->targetport->port_id); | |
183 | ||
ea98ab34 | 184 | len += snprintf(buf + len, PAGE_SIZE - len, |
f358dd0c JS |
185 | "\nNVME Target: Statistics\n"); |
186 | tgtp = (struct lpfc_nvmet_tgtport *)phba->targetport->private; | |
187 | len += snprintf(buf+len, PAGE_SIZE-len, | |
188 | "LS: Rcv %08x Drop %08x Abort %08x\n", | |
189 | atomic_read(&tgtp->rcv_ls_req_in), | |
190 | atomic_read(&tgtp->rcv_ls_req_drop), | |
191 | atomic_read(&tgtp->xmt_ls_abort)); | |
192 | if (atomic_read(&tgtp->rcv_ls_req_in) != | |
193 | atomic_read(&tgtp->rcv_ls_req_out)) { | |
194 | len += snprintf(buf+len, PAGE_SIZE-len, | |
195 | "Rcv LS: in %08x != out %08x\n", | |
196 | atomic_read(&tgtp->rcv_ls_req_in), | |
197 | atomic_read(&tgtp->rcv_ls_req_out)); | |
198 | } | |
199 | ||
200 | len += snprintf(buf+len, PAGE_SIZE-len, | |
201 | "LS: Xmt %08x Drop %08x Cmpl %08x Err %08x\n", | |
202 | atomic_read(&tgtp->xmt_ls_rsp), | |
203 | atomic_read(&tgtp->xmt_ls_drop), | |
204 | atomic_read(&tgtp->xmt_ls_rsp_cmpl), | |
205 | atomic_read(&tgtp->xmt_ls_rsp_error)); | |
206 | ||
207 | len += snprintf(buf+len, PAGE_SIZE-len, | |
547077a4 | 208 | "FCP: Rcv %08x Release %08x Drop %08x\n", |
f358dd0c | 209 | atomic_read(&tgtp->rcv_fcp_cmd_in), |
547077a4 | 210 | atomic_read(&tgtp->xmt_fcp_release), |
f358dd0c JS |
211 | atomic_read(&tgtp->rcv_fcp_cmd_drop)); |
212 | ||
213 | if (atomic_read(&tgtp->rcv_fcp_cmd_in) != | |
214 | atomic_read(&tgtp->rcv_fcp_cmd_out)) { | |
215 | len += snprintf(buf+len, PAGE_SIZE-len, | |
216 | "Rcv FCP: in %08x != out %08x\n", | |
217 | atomic_read(&tgtp->rcv_fcp_cmd_in), | |
218 | atomic_read(&tgtp->rcv_fcp_cmd_out)); | |
219 | } | |
220 | ||
221 | len += snprintf(buf+len, PAGE_SIZE-len, | |
547077a4 JS |
222 | "FCP Rsp: RD %08x rsp %08x WR %08x rsp %08x " |
223 | "drop %08x\n", | |
f358dd0c JS |
224 | atomic_read(&tgtp->xmt_fcp_read), |
225 | atomic_read(&tgtp->xmt_fcp_read_rsp), | |
226 | atomic_read(&tgtp->xmt_fcp_write), | |
547077a4 | 227 | atomic_read(&tgtp->xmt_fcp_rsp), |
f358dd0c JS |
228 | atomic_read(&tgtp->xmt_fcp_drop)); |
229 | ||
230 | len += snprintf(buf+len, PAGE_SIZE-len, | |
231 | "FCP Rsp Cmpl: %08x err %08x drop %08x\n", | |
232 | atomic_read(&tgtp->xmt_fcp_rsp_cmpl), | |
233 | atomic_read(&tgtp->xmt_fcp_rsp_error), | |
234 | atomic_read(&tgtp->xmt_fcp_rsp_drop)); | |
235 | ||
236 | len += snprintf(buf+len, PAGE_SIZE-len, | |
547077a4 JS |
237 | "ABORT: Xmt %08x Cmpl %08x\n", |
238 | atomic_read(&tgtp->xmt_fcp_abort), | |
239 | atomic_read(&tgtp->xmt_fcp_abort_cmpl)); | |
240 | ||
241 | len += snprintf(buf + len, PAGE_SIZE - len, | |
242 | "ABORT: Sol %08x Usol %08x Err %08x Cmpl %08x", | |
243 | atomic_read(&tgtp->xmt_abort_sol), | |
244 | atomic_read(&tgtp->xmt_abort_unsol), | |
f358dd0c | 245 | atomic_read(&tgtp->xmt_abort_rsp), |
547077a4 | 246 | atomic_read(&tgtp->xmt_abort_rsp_error)); |
f358dd0c JS |
247 | |
248 | len += snprintf(buf+len, PAGE_SIZE-len, "\n"); | |
249 | return len; | |
250 | } | |
895427bd JS |
251 | |
252 | localport = vport->localport; | |
253 | if (!localport) { | |
254 | len = snprintf(buf, PAGE_SIZE, | |
255 | "NVME Initiator x%llx is not allocated\n", | |
256 | wwn_to_u64(vport->fc_portname.u.wwn)); | |
257 | return len; | |
258 | } | |
259 | len = snprintf(buf, PAGE_SIZE, "NVME Initiator Enabled\n"); | |
260 | ||
261 | spin_lock_irq(shost->host_lock); | |
262 | lport = (struct lpfc_nvme_lport *)localport->private; | |
263 | ||
264 | /* Port state is only one of two values for now. */ | |
265 | if (localport->port_id) | |
266 | statep = "ONLINE"; | |
267 | else | |
268 | statep = "UNKNOWN "; | |
269 | ||
270 | len += snprintf(buf + len, PAGE_SIZE - len, | |
271 | "%s%d WWPN x%llx WWNN x%llx DID x%06x %s\n", | |
272 | "NVME LPORT lpfc", | |
273 | phba->brd_no, | |
274 | wwn_to_u64(vport->fc_portname.u.wwn), | |
275 | wwn_to_u64(vport->fc_nodename.u.wwn), | |
276 | localport->port_id, statep); | |
277 | ||
278 | list_for_each_entry(rport, &lport->rport_list, list) { | |
279 | /* local short-hand pointer. */ | |
280 | nrport = rport->remoteport; | |
281 | ||
282 | /* Port state is only one of two values for now. */ | |
283 | switch (nrport->port_state) { | |
284 | case FC_OBJSTATE_ONLINE: | |
285 | statep = "ONLINE"; | |
286 | break; | |
287 | case FC_OBJSTATE_UNKNOWN: | |
288 | statep = "UNKNOWN "; | |
289 | break; | |
290 | default: | |
291 | statep = "UNSUPPORTED"; | |
292 | break; | |
293 | } | |
294 | ||
295 | /* Tab in to show lport ownership. */ | |
296 | len += snprintf(buf + len, PAGE_SIZE - len, | |
297 | "NVME RPORT "); | |
298 | if (phba->brd_no >= 10) | |
299 | len += snprintf(buf + len, PAGE_SIZE - len, " "); | |
300 | ||
301 | len += snprintf(buf + len, PAGE_SIZE - len, "WWPN x%llx ", | |
302 | nrport->port_name); | |
303 | len += snprintf(buf + len, PAGE_SIZE - len, "WWNN x%llx ", | |
304 | nrport->node_name); | |
305 | len += snprintf(buf + len, PAGE_SIZE - len, "DID x%06x ", | |
306 | nrport->port_id); | |
307 | ||
308 | switch (nrport->port_role) { | |
309 | case FC_PORT_ROLE_NVME_INITIATOR: | |
310 | len += snprintf(buf + len, PAGE_SIZE - len, | |
311 | "INITIATOR "); | |
312 | break; | |
313 | case FC_PORT_ROLE_NVME_TARGET: | |
314 | len += snprintf(buf + len, PAGE_SIZE - len, | |
315 | "TARGET "); | |
316 | break; | |
317 | case FC_PORT_ROLE_NVME_DISCOVERY: | |
318 | len += snprintf(buf + len, PAGE_SIZE - len, | |
319 | "DISCOVERY "); | |
320 | break; | |
321 | default: | |
322 | len += snprintf(buf + len, PAGE_SIZE - len, | |
323 | "UNKNOWN_ROLE x%x", | |
324 | nrport->port_role); | |
325 | break; | |
326 | } | |
327 | len += snprintf(buf + len, PAGE_SIZE - len, "%s ", statep); | |
328 | /* Terminate the string. */ | |
329 | len += snprintf(buf + len, PAGE_SIZE - len, "\n"); | |
330 | } | |
331 | spin_unlock_irq(shost->host_lock); | |
332 | ||
ea98ab34 | 333 | len += snprintf(buf + len, PAGE_SIZE - len, "\nNVME Statistics\n"); |
895427bd JS |
334 | len += snprintf(buf+len, PAGE_SIZE-len, |
335 | "LS: Xmt %016llx Cmpl %016llx\n", | |
336 | phba->fc4NvmeLsRequests, | |
337 | phba->fc4NvmeLsCmpls); | |
338 | ||
339 | len += snprintf(buf+len, PAGE_SIZE-len, | |
340 | "FCP: Rd %016llx Wr %016llx IO %016llx\n", | |
341 | phba->fc4NvmeInputRequests, | |
342 | phba->fc4NvmeOutputRequests, | |
343 | phba->fc4NvmeControlRequests); | |
344 | ||
345 | len += snprintf(buf+len, PAGE_SIZE-len, | |
346 | " Cmpl %016llx\n", phba->fc4NvmeIoCmpls); | |
347 | ||
348 | return len; | |
349 | } | |
350 | ||
81301a9b JS |
351 | static ssize_t |
352 | lpfc_bg_info_show(struct device *dev, struct device_attribute *attr, | |
353 | char *buf) | |
354 | { | |
355 | struct Scsi_Host *shost = class_to_shost(dev); | |
356 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
357 | struct lpfc_hba *phba = vport->phba; | |
358 | ||
359 | if (phba->cfg_enable_bg) | |
360 | if (phba->sli3_options & LPFC_SLI3_BG_ENABLED) | |
361 | return snprintf(buf, PAGE_SIZE, "BlockGuard Enabled\n"); | |
362 | else | |
363 | return snprintf(buf, PAGE_SIZE, | |
364 | "BlockGuard Not Supported\n"); | |
365 | else | |
366 | return snprintf(buf, PAGE_SIZE, | |
367 | "BlockGuard Disabled\n"); | |
368 | } | |
369 | ||
370 | static ssize_t | |
371 | lpfc_bg_guard_err_show(struct device *dev, struct device_attribute *attr, | |
372 | char *buf) | |
373 | { | |
374 | struct Scsi_Host *shost = class_to_shost(dev); | |
375 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
376 | struct lpfc_hba *phba = vport->phba; | |
377 | ||
87b5c328 JS |
378 | return snprintf(buf, PAGE_SIZE, "%llu\n", |
379 | (unsigned long long)phba->bg_guard_err_cnt); | |
81301a9b JS |
380 | } |
381 | ||
382 | static ssize_t | |
383 | lpfc_bg_apptag_err_show(struct device *dev, struct device_attribute *attr, | |
384 | char *buf) | |
385 | { | |
386 | struct Scsi_Host *shost = class_to_shost(dev); | |
387 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
388 | struct lpfc_hba *phba = vport->phba; | |
389 | ||
87b5c328 JS |
390 | return snprintf(buf, PAGE_SIZE, "%llu\n", |
391 | (unsigned long long)phba->bg_apptag_err_cnt); | |
81301a9b JS |
392 | } |
393 | ||
394 | static ssize_t | |
395 | lpfc_bg_reftag_err_show(struct device *dev, struct device_attribute *attr, | |
396 | char *buf) | |
397 | { | |
398 | struct Scsi_Host *shost = class_to_shost(dev); | |
399 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
400 | struct lpfc_hba *phba = vport->phba; | |
401 | ||
87b5c328 JS |
402 | return snprintf(buf, PAGE_SIZE, "%llu\n", |
403 | (unsigned long long)phba->bg_reftag_err_cnt); | |
81301a9b JS |
404 | } |
405 | ||
e59058c4 | 406 | /** |
3621a710 | 407 | * lpfc_info_show - Return some pci info about the host in ascii |
e59058c4 JS |
408 | * @dev: class converted to a Scsi_host structure. |
409 | * @attr: device attribute, not used. | |
410 | * @buf: on return contains the formatted text from lpfc_info(). | |
411 | * | |
412 | * Returns: size of formatted string. | |
413 | **/ | |
dea3101e | 414 | static ssize_t |
ee959b00 TJ |
415 | lpfc_info_show(struct device *dev, struct device_attribute *attr, |
416 | char *buf) | |
dea3101e | 417 | { |
ee959b00 | 418 | struct Scsi_Host *host = class_to_shost(dev); |
2e0fef85 | 419 | |
dea3101e JB |
420 | return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host)); |
421 | } | |
422 | ||
e59058c4 | 423 | /** |
3621a710 | 424 | * lpfc_serialnum_show - Return the hba serial number in ascii |
e59058c4 JS |
425 | * @dev: class converted to a Scsi_host structure. |
426 | * @attr: device attribute, not used. | |
427 | * @buf: on return contains the formatted text serial number. | |
428 | * | |
429 | * Returns: size of formatted string. | |
430 | **/ | |
dea3101e | 431 | static ssize_t |
ee959b00 TJ |
432 | lpfc_serialnum_show(struct device *dev, struct device_attribute *attr, |
433 | char *buf) | |
dea3101e | 434 | { |
ee959b00 | 435 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 JS |
436 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
437 | struct lpfc_hba *phba = vport->phba; | |
438 | ||
dea3101e JB |
439 | return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber); |
440 | } | |
441 | ||
e59058c4 | 442 | /** |
3621a710 | 443 | * lpfc_temp_sensor_show - Return the temperature sensor level |
e59058c4 JS |
444 | * @dev: class converted to a Scsi_host structure. |
445 | * @attr: device attribute, not used. | |
446 | * @buf: on return contains the formatted support level. | |
447 | * | |
448 | * Description: | |
449 | * Returns a number indicating the temperature sensor level currently | |
450 | * supported, zero or one in ascii. | |
451 | * | |
452 | * Returns: size of formatted string. | |
453 | **/ | |
57127f15 | 454 | static ssize_t |
ee959b00 TJ |
455 | lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr, |
456 | char *buf) | |
57127f15 | 457 | { |
ee959b00 | 458 | struct Scsi_Host *shost = class_to_shost(dev); |
57127f15 JS |
459 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
460 | struct lpfc_hba *phba = vport->phba; | |
461 | return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support); | |
462 | } | |
463 | ||
e59058c4 | 464 | /** |
3621a710 | 465 | * lpfc_modeldesc_show - Return the model description of the hba |
e59058c4 JS |
466 | * @dev: class converted to a Scsi_host structure. |
467 | * @attr: device attribute, not used. | |
468 | * @buf: on return contains the scsi vpd model description. | |
469 | * | |
470 | * Returns: size of formatted string. | |
471 | **/ | |
dea3101e | 472 | static ssize_t |
ee959b00 TJ |
473 | lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr, |
474 | char *buf) | |
dea3101e | 475 | { |
ee959b00 | 476 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 JS |
477 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
478 | struct lpfc_hba *phba = vport->phba; | |
479 | ||
dea3101e JB |
480 | return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc); |
481 | } | |
482 | ||
e59058c4 | 483 | /** |
3621a710 | 484 | * lpfc_modelname_show - Return the model name of the hba |
e59058c4 JS |
485 | * @dev: class converted to a Scsi_host structure. |
486 | * @attr: device attribute, not used. | |
487 | * @buf: on return contains the scsi vpd model name. | |
488 | * | |
489 | * Returns: size of formatted string. | |
490 | **/ | |
dea3101e | 491 | static ssize_t |
ee959b00 TJ |
492 | lpfc_modelname_show(struct device *dev, struct device_attribute *attr, |
493 | char *buf) | |
dea3101e | 494 | { |
ee959b00 | 495 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 JS |
496 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
497 | struct lpfc_hba *phba = vport->phba; | |
498 | ||
dea3101e JB |
499 | return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName); |
500 | } | |
501 | ||
e59058c4 | 502 | /** |
3621a710 | 503 | * lpfc_programtype_show - Return the program type of the hba |
e59058c4 JS |
504 | * @dev: class converted to a Scsi_host structure. |
505 | * @attr: device attribute, not used. | |
506 | * @buf: on return contains the scsi vpd program type. | |
507 | * | |
508 | * Returns: size of formatted string. | |
509 | **/ | |
dea3101e | 510 | static ssize_t |
ee959b00 TJ |
511 | lpfc_programtype_show(struct device *dev, struct device_attribute *attr, |
512 | char *buf) | |
dea3101e | 513 | { |
ee959b00 | 514 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 JS |
515 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
516 | struct lpfc_hba *phba = vport->phba; | |
517 | ||
dea3101e JB |
518 | return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType); |
519 | } | |
520 | ||
84774a4d | 521 | /** |
3621a710 | 522 | * lpfc_mlomgmt_show - Return the Menlo Maintenance sli flag |
84774a4d JS |
523 | * @dev: class converted to a Scsi_host structure. |
524 | * @attr: device attribute, not used. | |
525 | * @buf: on return contains the Menlo Maintenance sli flag. | |
526 | * | |
527 | * Returns: size of formatted string. | |
528 | **/ | |
529 | static ssize_t | |
530 | lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf) | |
531 | { | |
532 | struct Scsi_Host *shost = class_to_shost(dev); | |
533 | struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata; | |
534 | struct lpfc_hba *phba = vport->phba; | |
535 | ||
536 | return snprintf(buf, PAGE_SIZE, "%d\n", | |
537 | (phba->sli.sli_flag & LPFC_MENLO_MAINT)); | |
538 | } | |
539 | ||
e59058c4 | 540 | /** |
3621a710 | 541 | * lpfc_vportnum_show - Return the port number in ascii of the hba |
e59058c4 JS |
542 | * @dev: class converted to a Scsi_host structure. |
543 | * @attr: device attribute, not used. | |
544 | * @buf: on return contains scsi vpd program type. | |
545 | * | |
546 | * Returns: size of formatted string. | |
547 | **/ | |
dea3101e | 548 | static ssize_t |
ee959b00 TJ |
549 | lpfc_vportnum_show(struct device *dev, struct device_attribute *attr, |
550 | char *buf) | |
dea3101e | 551 | { |
ee959b00 | 552 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 JS |
553 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
554 | struct lpfc_hba *phba = vport->phba; | |
555 | ||
dea3101e JB |
556 | return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port); |
557 | } | |
558 | ||
e59058c4 | 559 | /** |
3621a710 | 560 | * lpfc_fwrev_show - Return the firmware rev running in the hba |
e59058c4 JS |
561 | * @dev: class converted to a Scsi_host structure. |
562 | * @attr: device attribute, not used. | |
563 | * @buf: on return contains the scsi vpd program type. | |
564 | * | |
565 | * Returns: size of formatted string. | |
566 | **/ | |
dea3101e | 567 | static ssize_t |
ee959b00 TJ |
568 | lpfc_fwrev_show(struct device *dev, struct device_attribute *attr, |
569 | char *buf) | |
dea3101e | 570 | { |
ee959b00 | 571 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 JS |
572 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
573 | struct lpfc_hba *phba = vport->phba; | |
026abb87 JS |
574 | uint32_t if_type; |
575 | uint8_t sli_family; | |
6b5151fd | 576 | char fwrev[FW_REV_STR_SIZE]; |
026abb87 | 577 | int len; |
2e0fef85 | 578 | |
dea3101e | 579 | lpfc_decode_firmware_rev(phba, fwrev, 1); |
026abb87 JS |
580 | if_type = phba->sli4_hba.pc_sli4_params.if_type; |
581 | sli_family = phba->sli4_hba.pc_sli4_params.sli_family; | |
582 | ||
583 | if (phba->sli_rev < LPFC_SLI_REV4) | |
584 | len = snprintf(buf, PAGE_SIZE, "%s, sli-%d\n", | |
585 | fwrev, phba->sli_rev); | |
586 | else | |
587 | len = snprintf(buf, PAGE_SIZE, "%s, sli-%d:%d:%x\n", | |
588 | fwrev, phba->sli_rev, if_type, sli_family); | |
589 | ||
590 | return len; | |
dea3101e JB |
591 | } |
592 | ||
e59058c4 | 593 | /** |
3621a710 | 594 | * lpfc_hdw_show - Return the jedec information about the hba |
e59058c4 JS |
595 | * @dev: class converted to a Scsi_host structure. |
596 | * @attr: device attribute, not used. | |
597 | * @buf: on return contains the scsi vpd program type. | |
598 | * | |
599 | * Returns: size of formatted string. | |
600 | **/ | |
dea3101e | 601 | static ssize_t |
ee959b00 | 602 | lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf) |
dea3101e JB |
603 | { |
604 | char hdw[9]; | |
ee959b00 | 605 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 JS |
606 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
607 | struct lpfc_hba *phba = vport->phba; | |
dea3101e | 608 | lpfc_vpd_t *vp = &phba->vpd; |
2e0fef85 | 609 | |
dea3101e JB |
610 | lpfc_jedec_to_ascii(vp->rev.biuRev, hdw); |
611 | return snprintf(buf, PAGE_SIZE, "%s\n", hdw); | |
612 | } | |
e59058c4 JS |
613 | |
614 | /** | |
3621a710 | 615 | * lpfc_option_rom_version_show - Return the adapter ROM FCode version |
e59058c4 JS |
616 | * @dev: class converted to a Scsi_host structure. |
617 | * @attr: device attribute, not used. | |
618 | * @buf: on return contains the ROM and FCode ascii strings. | |
619 | * | |
620 | * Returns: size of formatted string. | |
621 | **/ | |
dea3101e | 622 | static ssize_t |
ee959b00 TJ |
623 | lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr, |
624 | char *buf) | |
dea3101e | 625 | { |
ee959b00 | 626 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 JS |
627 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
628 | struct lpfc_hba *phba = vport->phba; | |
a0683bf6 JS |
629 | char fwrev[FW_REV_STR_SIZE]; |
630 | ||
631 | if (phba->sli_rev < LPFC_SLI_REV4) | |
632 | return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion); | |
2e0fef85 | 633 | |
a0683bf6 JS |
634 | lpfc_decode_firmware_rev(phba, fwrev, 1); |
635 | return snprintf(buf, PAGE_SIZE, "%s\n", fwrev); | |
dea3101e | 636 | } |
e59058c4 JS |
637 | |
638 | /** | |
3621a710 | 639 | * lpfc_state_show - Return the link state of the port |
e59058c4 JS |
640 | * @dev: class converted to a Scsi_host structure. |
641 | * @attr: device attribute, not used. | |
642 | * @buf: on return contains text describing the state of the link. | |
643 | * | |
644 | * Notes: | |
645 | * The switch statement has no default so zero will be returned. | |
646 | * | |
647 | * Returns: size of formatted string. | |
648 | **/ | |
dea3101e | 649 | static ssize_t |
bbd1ae41 HR |
650 | lpfc_link_state_show(struct device *dev, struct device_attribute *attr, |
651 | char *buf) | |
dea3101e | 652 | { |
ee959b00 | 653 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 JS |
654 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
655 | struct lpfc_hba *phba = vport->phba; | |
656 | int len = 0; | |
657 | ||
658 | switch (phba->link_state) { | |
659 | case LPFC_LINK_UNKNOWN: | |
41415862 | 660 | case LPFC_WARM_START: |
dea3101e JB |
661 | case LPFC_INIT_START: |
662 | case LPFC_INIT_MBX_CMDS: | |
663 | case LPFC_LINK_DOWN: | |
2e0fef85 | 664 | case LPFC_HBA_ERROR: |
a0c87cbd JS |
665 | if (phba->hba_flag & LINK_DISABLED) |
666 | len += snprintf(buf + len, PAGE_SIZE-len, | |
667 | "Link Down - User disabled\n"); | |
668 | else | |
669 | len += snprintf(buf + len, PAGE_SIZE-len, | |
670 | "Link Down\n"); | |
dea3101e JB |
671 | break; |
672 | case LPFC_LINK_UP: | |
dea3101e | 673 | case LPFC_CLEAR_LA: |
dea3101e | 674 | case LPFC_HBA_READY: |
a8adb832 | 675 | len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - "); |
2e0fef85 JS |
676 | |
677 | switch (vport->port_state) { | |
2e0fef85 JS |
678 | case LPFC_LOCAL_CFG_LINK: |
679 | len += snprintf(buf + len, PAGE_SIZE-len, | |
92d7f7b0 | 680 | "Configuring Link\n"); |
2e0fef85 | 681 | break; |
92d7f7b0 | 682 | case LPFC_FDISC: |
2e0fef85 JS |
683 | case LPFC_FLOGI: |
684 | case LPFC_FABRIC_CFG_LINK: | |
685 | case LPFC_NS_REG: | |
686 | case LPFC_NS_QRY: | |
687 | case LPFC_BUILD_DISC_LIST: | |
688 | case LPFC_DISC_AUTH: | |
689 | len += snprintf(buf + len, PAGE_SIZE - len, | |
690 | "Discovery\n"); | |
691 | break; | |
692 | case LPFC_VPORT_READY: | |
693 | len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n"); | |
694 | break; | |
695 | ||
92d7f7b0 JS |
696 | case LPFC_VPORT_FAILED: |
697 | len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n"); | |
698 | break; | |
699 | ||
700 | case LPFC_VPORT_UNKNOWN: | |
2e0fef85 JS |
701 | len += snprintf(buf + len, PAGE_SIZE - len, |
702 | "Unknown\n"); | |
703 | break; | |
704 | } | |
84774a4d JS |
705 | if (phba->sli.sli_flag & LPFC_MENLO_MAINT) |
706 | len += snprintf(buf + len, PAGE_SIZE-len, | |
707 | " Menlo Maint Mode\n"); | |
76a95d75 | 708 | else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
2e0fef85 | 709 | if (vport->fc_flag & FC_PUBLIC_LOOP) |
dea3101e JB |
710 | len += snprintf(buf + len, PAGE_SIZE-len, |
711 | " Public Loop\n"); | |
712 | else | |
713 | len += snprintf(buf + len, PAGE_SIZE-len, | |
714 | " Private Loop\n"); | |
715 | } else { | |
2e0fef85 | 716 | if (vport->fc_flag & FC_FABRIC) |
dea3101e JB |
717 | len += snprintf(buf + len, PAGE_SIZE-len, |
718 | " Fabric\n"); | |
719 | else | |
720 | len += snprintf(buf + len, PAGE_SIZE-len, | |
721 | " Point-2-Point\n"); | |
722 | } | |
723 | } | |
2e0fef85 | 724 | |
dea3101e JB |
725 | return len; |
726 | } | |
727 | ||
026abb87 JS |
728 | /** |
729 | * lpfc_sli4_protocol_show - Return the fip mode of the HBA | |
730 | * @dev: class unused variable. | |
731 | * @attr: device attribute, not used. | |
732 | * @buf: on return contains the module description text. | |
733 | * | |
734 | * Returns: size of formatted string. | |
735 | **/ | |
736 | static ssize_t | |
737 | lpfc_sli4_protocol_show(struct device *dev, struct device_attribute *attr, | |
738 | char *buf) | |
739 | { | |
740 | struct Scsi_Host *shost = class_to_shost(dev); | |
741 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
742 | struct lpfc_hba *phba = vport->phba; | |
743 | ||
744 | if (phba->sli_rev < LPFC_SLI_REV4) | |
745 | return snprintf(buf, PAGE_SIZE, "fc\n"); | |
746 | ||
747 | if (phba->sli4_hba.lnk_info.lnk_dv == LPFC_LNK_DAT_VAL) { | |
748 | if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_GE) | |
749 | return snprintf(buf, PAGE_SIZE, "fcoe\n"); | |
750 | if (phba->sli4_hba.lnk_info.lnk_tp == LPFC_LNK_TYPE_FC) | |
751 | return snprintf(buf, PAGE_SIZE, "fc\n"); | |
752 | } | |
753 | return snprintf(buf, PAGE_SIZE, "unknown\n"); | |
754 | } | |
755 | ||
1ba981fd JS |
756 | /** |
757 | * lpfc_oas_supported_show - Return whether or not Optimized Access Storage | |
758 | * (OAS) is supported. | |
759 | * @dev: class unused variable. | |
760 | * @attr: device attribute, not used. | |
761 | * @buf: on return contains the module description text. | |
762 | * | |
763 | * Returns: size of formatted string. | |
764 | **/ | |
765 | static ssize_t | |
766 | lpfc_oas_supported_show(struct device *dev, struct device_attribute *attr, | |
767 | char *buf) | |
768 | { | |
769 | struct Scsi_Host *shost = class_to_shost(dev); | |
770 | struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata; | |
771 | struct lpfc_hba *phba = vport->phba; | |
772 | ||
773 | return snprintf(buf, PAGE_SIZE, "%d\n", | |
774 | phba->sli4_hba.pc_sli4_params.oas_supported); | |
775 | } | |
776 | ||
84d1b006 JS |
777 | /** |
778 | * lpfc_link_state_store - Transition the link_state on an HBA port | |
779 | * @dev: class device that is converted into a Scsi_host. | |
780 | * @attr: device attribute, not used. | |
781 | * @buf: one or more lpfc_polling_flags values. | |
782 | * @count: not used. | |
783 | * | |
784 | * Returns: | |
785 | * -EINVAL if the buffer is not "up" or "down" | |
786 | * return from link state change function if non-zero | |
787 | * length of the buf on success | |
788 | **/ | |
789 | static ssize_t | |
790 | lpfc_link_state_store(struct device *dev, struct device_attribute *attr, | |
791 | const char *buf, size_t count) | |
792 | { | |
793 | struct Scsi_Host *shost = class_to_shost(dev); | |
794 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
795 | struct lpfc_hba *phba = vport->phba; | |
796 | ||
797 | int status = -EINVAL; | |
798 | ||
799 | if ((strncmp(buf, "up", sizeof("up") - 1) == 0) && | |
800 | (phba->link_state == LPFC_LINK_DOWN)) | |
6e7288d9 | 801 | status = phba->lpfc_hba_init_link(phba, MBX_NOWAIT); |
84d1b006 JS |
802 | else if ((strncmp(buf, "down", sizeof("down") - 1) == 0) && |
803 | (phba->link_state >= LPFC_LINK_UP)) | |
6e7288d9 | 804 | status = phba->lpfc_hba_down_link(phba, MBX_NOWAIT); |
84d1b006 JS |
805 | |
806 | if (status == 0) | |
807 | return strlen(buf); | |
808 | else | |
809 | return status; | |
810 | } | |
811 | ||
e59058c4 | 812 | /** |
3621a710 | 813 | * lpfc_num_discovered_ports_show - Return sum of mapped and unmapped vports |
e59058c4 JS |
814 | * @dev: class device that is converted into a Scsi_host. |
815 | * @attr: device attribute, not used. | |
816 | * @buf: on return contains the sum of fc mapped and unmapped. | |
817 | * | |
818 | * Description: | |
819 | * Returns the ascii text number of the sum of the fc mapped and unmapped | |
820 | * vport counts. | |
821 | * | |
822 | * Returns: size of formatted string. | |
823 | **/ | |
dea3101e | 824 | static ssize_t |
ee959b00 TJ |
825 | lpfc_num_discovered_ports_show(struct device *dev, |
826 | struct device_attribute *attr, char *buf) | |
dea3101e | 827 | { |
ee959b00 | 828 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 JS |
829 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
830 | ||
831 | return snprintf(buf, PAGE_SIZE, "%d\n", | |
832 | vport->fc_map_cnt + vport->fc_unmap_cnt); | |
dea3101e JB |
833 | } |
834 | ||
e59058c4 | 835 | /** |
3621a710 | 836 | * lpfc_issue_lip - Misnomer, name carried over from long ago |
e59058c4 JS |
837 | * @shost: Scsi_Host pointer. |
838 | * | |
839 | * Description: | |
840 | * Bring the link down gracefully then re-init the link. The firmware will | |
841 | * re-init the fiber channel interface as required. Does not issue a LIP. | |
842 | * | |
843 | * Returns: | |
844 | * -EPERM port offline or management commands are being blocked | |
845 | * -ENOMEM cannot allocate memory for the mailbox command | |
846 | * -EIO error sending the mailbox command | |
847 | * zero for success | |
848 | **/ | |
91ca7b01 | 849 | static int |
2e0fef85 | 850 | lpfc_issue_lip(struct Scsi_Host *shost) |
dea3101e | 851 | { |
2e0fef85 JS |
852 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
853 | struct lpfc_hba *phba = vport->phba; | |
dea3101e JB |
854 | LPFC_MBOXQ_t *pmboxq; |
855 | int mbxstatus = MBXERR_ERROR; | |
856 | ||
2e0fef85 | 857 | if ((vport->fc_flag & FC_OFFLINE_MODE) || |
83108bd3 | 858 | (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)) |
dea3101e JB |
859 | return -EPERM; |
860 | ||
861 | pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL); | |
862 | ||
863 | if (!pmboxq) | |
864 | return -ENOMEM; | |
865 | ||
866 | memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t)); | |
04c68496 JS |
867 | pmboxq->u.mb.mbxCommand = MBX_DOWN_LINK; |
868 | pmboxq->u.mb.mbxOwner = OWN_HOST; | |
4db621e0 | 869 | |
33ccf8d1 | 870 | mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2); |
dea3101e | 871 | |
04c68496 JS |
872 | if ((mbxstatus == MBX_SUCCESS) && |
873 | (pmboxq->u.mb.mbxStatus == 0 || | |
874 | pmboxq->u.mb.mbxStatus == MBXERR_LINK_DOWN)) { | |
4db621e0 JS |
875 | memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t)); |
876 | lpfc_init_link(phba, pmboxq, phba->cfg_topology, | |
877 | phba->cfg_link_speed); | |
878 | mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, | |
879 | phba->fc_ratov * 2); | |
dcf2a4e0 JS |
880 | if ((mbxstatus == MBX_SUCCESS) && |
881 | (pmboxq->u.mb.mbxStatus == MBXERR_SEC_NO_PERMISSION)) | |
882 | lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI, | |
883 | "2859 SLI authentication is required " | |
884 | "for INIT_LINK but has not done yet\n"); | |
4db621e0 JS |
885 | } |
886 | ||
5b8bd0c9 | 887 | lpfc_set_loopback_flag(phba); |
858c9f6c | 888 | if (mbxstatus != MBX_TIMEOUT) |
433c3579 | 889 | mempool_free(pmboxq, phba->mbox_mem_pool); |
dea3101e JB |
890 | |
891 | if (mbxstatus == MBXERR_ERROR) | |
892 | return -EIO; | |
893 | ||
91ca7b01 | 894 | return 0; |
dea3101e JB |
895 | } |
896 | ||
895427bd JS |
897 | int |
898 | lpfc_emptyq_wait(struct lpfc_hba *phba, struct list_head *q, spinlock_t *lock) | |
899 | { | |
900 | int cnt = 0; | |
901 | ||
902 | spin_lock_irq(lock); | |
903 | while (!list_empty(q)) { | |
904 | spin_unlock_irq(lock); | |
905 | msleep(20); | |
906 | if (cnt++ > 250) { /* 5 secs */ | |
907 | lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, | |
908 | "0466 %s %s\n", | |
909 | "Outstanding IO when ", | |
910 | "bringing Adapter offline\n"); | |
911 | return 0; | |
912 | } | |
913 | spin_lock_irq(lock); | |
914 | } | |
915 | spin_unlock_irq(lock); | |
916 | return 1; | |
917 | } | |
918 | ||
e59058c4 | 919 | /** |
3621a710 | 920 | * lpfc_do_offline - Issues a mailbox command to bring the link down |
e59058c4 JS |
921 | * @phba: lpfc_hba pointer. |
922 | * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL. | |
923 | * | |
924 | * Notes: | |
925 | * Assumes any error from lpfc_do_offline() will be negative. | |
926 | * Can wait up to 5 seconds for the port ring buffers count | |
927 | * to reach zero, prints a warning if it is not zero and continues. | |
3621a710 | 928 | * lpfc_workq_post_event() returns a non-zero return code if call fails. |
e59058c4 JS |
929 | * |
930 | * Returns: | |
931 | * -EIO error posting the event | |
932 | * zero for success | |
933 | **/ | |
40496f07 | 934 | static int |
46fa311e | 935 | lpfc_do_offline(struct lpfc_hba *phba, uint32_t type) |
40496f07 JS |
936 | { |
937 | struct completion online_compl; | |
895427bd | 938 | struct lpfc_queue *qp = NULL; |
46fa311e JS |
939 | struct lpfc_sli_ring *pring; |
940 | struct lpfc_sli *psli; | |
40496f07 | 941 | int status = 0; |
46fa311e | 942 | int i; |
fedd3b7b | 943 | int rc; |
40496f07 JS |
944 | |
945 | init_completion(&online_compl); | |
fedd3b7b | 946 | rc = lpfc_workq_post_event(phba, &status, &online_compl, |
46fa311e | 947 | LPFC_EVT_OFFLINE_PREP); |
fedd3b7b JS |
948 | if (rc == 0) |
949 | return -ENOMEM; | |
950 | ||
46fa311e JS |
951 | wait_for_completion(&online_compl); |
952 | ||
953 | if (status != 0) | |
954 | return -EIO; | |
955 | ||
956 | psli = &phba->sli; | |
957 | ||
09372820 JS |
958 | /* Wait a little for things to settle down, but not |
959 | * long enough for dev loss timeout to expire. | |
960 | */ | |
895427bd JS |
961 | if (phba->sli_rev != LPFC_SLI_REV4) { |
962 | for (i = 0; i < psli->num_rings; i++) { | |
963 | pring = &psli->sli3_ring[i]; | |
964 | if (!lpfc_emptyq_wait(phba, &pring->txcmplq, | |
965 | &phba->hbalock)) | |
966 | goto out; | |
967 | } | |
968 | } else { | |
969 | list_for_each_entry(qp, &phba->sli4_hba.lpfc_wq_list, wq_list) { | |
970 | pring = qp->pring; | |
971 | if (!pring) | |
972 | continue; | |
973 | if (!lpfc_emptyq_wait(phba, &pring->txcmplq, | |
974 | &pring->ring_lock)) | |
975 | goto out; | |
46fa311e JS |
976 | } |
977 | } | |
895427bd | 978 | out: |
46fa311e | 979 | init_completion(&online_compl); |
fedd3b7b JS |
980 | rc = lpfc_workq_post_event(phba, &status, &online_compl, type); |
981 | if (rc == 0) | |
982 | return -ENOMEM; | |
983 | ||
40496f07 JS |
984 | wait_for_completion(&online_compl); |
985 | ||
986 | if (status != 0) | |
987 | return -EIO; | |
988 | ||
46fa311e JS |
989 | return 0; |
990 | } | |
991 | ||
e59058c4 | 992 | /** |
3621a710 | 993 | * lpfc_selective_reset - Offline then onlines the port |
e59058c4 JS |
994 | * @phba: lpfc_hba pointer. |
995 | * | |
996 | * Description: | |
997 | * If the port is configured to allow a reset then the hba is brought | |
998 | * offline then online. | |
999 | * | |
1000 | * Notes: | |
1001 | * Assumes any error from lpfc_do_offline() will be negative. | |
ab56dc2e | 1002 | * Do not make this function static. |
e59058c4 JS |
1003 | * |
1004 | * Returns: | |
1005 | * lpfc_do_offline() return code if not zero | |
1006 | * -EIO reset not configured or error posting the event | |
1007 | * zero for success | |
1008 | **/ | |
7f86059a | 1009 | int |
46fa311e JS |
1010 | lpfc_selective_reset(struct lpfc_hba *phba) |
1011 | { | |
1012 | struct completion online_compl; | |
1013 | int status = 0; | |
fedd3b7b | 1014 | int rc; |
46fa311e | 1015 | |
71157c9e | 1016 | if (!phba->cfg_enable_hba_reset) |
f7a919b4 | 1017 | return -EACCES; |
13815c83 | 1018 | |
71157c9e JS |
1019 | if (!(phba->pport->fc_flag & FC_OFFLINE_MODE)) { |
1020 | status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE); | |
46fa311e | 1021 | |
71157c9e JS |
1022 | if (status != 0) |
1023 | return status; | |
1024 | } | |
46fa311e | 1025 | |
40496f07 | 1026 | init_completion(&online_compl); |
fedd3b7b | 1027 | rc = lpfc_workq_post_event(phba, &status, &online_compl, |
40496f07 | 1028 | LPFC_EVT_ONLINE); |
fedd3b7b JS |
1029 | if (rc == 0) |
1030 | return -ENOMEM; | |
1031 | ||
40496f07 JS |
1032 | wait_for_completion(&online_compl); |
1033 | ||
1034 | if (status != 0) | |
1035 | return -EIO; | |
1036 | ||
1037 | return 0; | |
1038 | } | |
1039 | ||
e59058c4 | 1040 | /** |
3621a710 | 1041 | * lpfc_issue_reset - Selectively resets an adapter |
e59058c4 JS |
1042 | * @dev: class device that is converted into a Scsi_host. |
1043 | * @attr: device attribute, not used. | |
1044 | * @buf: containing the string "selective". | |
1045 | * @count: unused variable. | |
1046 | * | |
1047 | * Description: | |
1048 | * If the buf contains the string "selective" then lpfc_selective_reset() | |
1049 | * is called to perform the reset. | |
1050 | * | |
1051 | * Notes: | |
1052 | * Assumes any error from lpfc_selective_reset() will be negative. | |
1053 | * If lpfc_selective_reset() returns zero then the length of the buffer | |
af901ca1 | 1054 | * is returned which indicates success |
e59058c4 JS |
1055 | * |
1056 | * Returns: | |
1057 | * -EINVAL if the buffer does not contain the string "selective" | |
1058 | * length of buf if lpfc-selective_reset() if the call succeeds | |
1059 | * return value of lpfc_selective_reset() if the call fails | |
1060 | **/ | |
40496f07 | 1061 | static ssize_t |
ee959b00 TJ |
1062 | lpfc_issue_reset(struct device *dev, struct device_attribute *attr, |
1063 | const char *buf, size_t count) | |
40496f07 | 1064 | { |
ee959b00 | 1065 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 JS |
1066 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
1067 | struct lpfc_hba *phba = vport->phba; | |
40496f07 JS |
1068 | int status = -EINVAL; |
1069 | ||
73d91e50 JS |
1070 | if (!phba->cfg_enable_hba_reset) |
1071 | return -EACCES; | |
1072 | ||
40496f07 | 1073 | if (strncmp(buf, "selective", sizeof("selective") - 1) == 0) |
7f86059a | 1074 | status = phba->lpfc_selective_reset(phba); |
40496f07 JS |
1075 | |
1076 | if (status == 0) | |
1077 | return strlen(buf); | |
1078 | else | |
1079 | return status; | |
1080 | } | |
1081 | ||
88a2cfbb JS |
1082 | /** |
1083 | * lpfc_sli4_pdev_status_reg_wait - Wait for pdev status register for readyness | |
1084 | * @phba: lpfc_hba pointer. | |
1085 | * | |
1086 | * Description: | |
1087 | * SLI4 interface type-2 device to wait on the sliport status register for | |
1088 | * the readyness after performing a firmware reset. | |
1089 | * | |
1090 | * Returns: | |
0b1587b1 | 1091 | * zero for success, -EPERM when port does not have privilege to perform the |
026abb87 JS |
1092 | * reset, -EIO when port timeout from recovering from the reset. |
1093 | * | |
1094 | * Note: | |
1095 | * As the caller will interpret the return code by value, be careful in making | |
1096 | * change or addition to return codes. | |
88a2cfbb | 1097 | **/ |
73d91e50 | 1098 | int |
88a2cfbb JS |
1099 | lpfc_sli4_pdev_status_reg_wait(struct lpfc_hba *phba) |
1100 | { | |
f7a919b4 | 1101 | struct lpfc_register portstat_reg = {0}; |
88a2cfbb JS |
1102 | int i; |
1103 | ||
f7a919b4 | 1104 | msleep(100); |
88a2cfbb JS |
1105 | lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr, |
1106 | &portstat_reg.word0); | |
1107 | ||
0b1587b1 | 1108 | /* verify if privileged for the request operation */ |
f7a919b4 JS |
1109 | if (!bf_get(lpfc_sliport_status_rn, &portstat_reg) && |
1110 | !bf_get(lpfc_sliport_status_err, &portstat_reg)) | |
1111 | return -EPERM; | |
1112 | ||
88a2cfbb JS |
1113 | /* wait for the SLI port firmware ready after firmware reset */ |
1114 | for (i = 0; i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT; i++) { | |
1115 | msleep(10); | |
1116 | lpfc_readl(phba->sli4_hba.u.if_type2.STATUSregaddr, | |
1117 | &portstat_reg.word0); | |
1118 | if (!bf_get(lpfc_sliport_status_err, &portstat_reg)) | |
1119 | continue; | |
1120 | if (!bf_get(lpfc_sliport_status_rn, &portstat_reg)) | |
1121 | continue; | |
1122 | if (!bf_get(lpfc_sliport_status_rdy, &portstat_reg)) | |
1123 | continue; | |
1124 | break; | |
1125 | } | |
1126 | ||
1127 | if (i < LPFC_FW_RESET_MAXIMUM_WAIT_10MS_CNT) | |
1128 | return 0; | |
1129 | else | |
1130 | return -EIO; | |
1131 | } | |
1132 | ||
c0c11512 | 1133 | /** |
52d52440 | 1134 | * lpfc_sli4_pdev_reg_request - Request physical dev to perform a register acc |
c0c11512 JS |
1135 | * @phba: lpfc_hba pointer. |
1136 | * | |
1137 | * Description: | |
52d52440 JS |
1138 | * Request SLI4 interface type-2 device to perform a physical register set |
1139 | * access. | |
c0c11512 JS |
1140 | * |
1141 | * Returns: | |
1142 | * zero for success | |
1143 | **/ | |
1144 | static ssize_t | |
52d52440 | 1145 | lpfc_sli4_pdev_reg_request(struct lpfc_hba *phba, uint32_t opcode) |
c0c11512 JS |
1146 | { |
1147 | struct completion online_compl; | |
b76f2dc9 | 1148 | struct pci_dev *pdev = phba->pcidev; |
026abb87 JS |
1149 | uint32_t before_fc_flag; |
1150 | uint32_t sriov_nr_virtfn; | |
c0c11512 | 1151 | uint32_t reg_val; |
026abb87 JS |
1152 | int status = 0, rc = 0; |
1153 | int job_posted = 1, sriov_err; | |
c0c11512 JS |
1154 | |
1155 | if (!phba->cfg_enable_hba_reset) | |
f7a919b4 | 1156 | return -EACCES; |
c0c11512 | 1157 | |
52d52440 JS |
1158 | if ((phba->sli_rev < LPFC_SLI_REV4) || |
1159 | (bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf) != | |
1160 | LPFC_SLI_INTF_IF_TYPE_2)) | |
1161 | return -EPERM; | |
1162 | ||
026abb87 JS |
1163 | /* Keep state if we need to restore back */ |
1164 | before_fc_flag = phba->pport->fc_flag; | |
1165 | sriov_nr_virtfn = phba->cfg_sriov_nr_virtfn; | |
1166 | ||
b76f2dc9 JS |
1167 | /* Disable SR-IOV virtual functions if enabled */ |
1168 | if (phba->cfg_sriov_nr_virtfn) { | |
1169 | pci_disable_sriov(pdev); | |
1170 | phba->cfg_sriov_nr_virtfn = 0; | |
1171 | } | |
229adb0e | 1172 | |
0293635e JS |
1173 | if (opcode == LPFC_FW_DUMP) |
1174 | phba->hba_flag |= HBA_FW_DUMP_OP; | |
1175 | ||
c0c11512 JS |
1176 | status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE); |
1177 | ||
0293635e JS |
1178 | if (status != 0) { |
1179 | phba->hba_flag &= ~HBA_FW_DUMP_OP; | |
c0c11512 | 1180 | return status; |
0293635e | 1181 | } |
c0c11512 JS |
1182 | |
1183 | /* wait for the device to be quiesced before firmware reset */ | |
1184 | msleep(100); | |
1185 | ||
1186 | reg_val = readl(phba->sli4_hba.conf_regs_memmap_p + | |
1187 | LPFC_CTL_PDEV_CTL_OFFSET); | |
52d52440 JS |
1188 | |
1189 | if (opcode == LPFC_FW_DUMP) | |
1190 | reg_val |= LPFC_FW_DUMP_REQUEST; | |
1191 | else if (opcode == LPFC_FW_RESET) | |
1192 | reg_val |= LPFC_CTL_PDEV_CTL_FRST; | |
1193 | else if (opcode == LPFC_DV_RESET) | |
1194 | reg_val |= LPFC_CTL_PDEV_CTL_DRST; | |
1195 | ||
c0c11512 JS |
1196 | writel(reg_val, phba->sli4_hba.conf_regs_memmap_p + |
1197 | LPFC_CTL_PDEV_CTL_OFFSET); | |
1198 | /* flush */ | |
1199 | readl(phba->sli4_hba.conf_regs_memmap_p + LPFC_CTL_PDEV_CTL_OFFSET); | |
1200 | ||
1201 | /* delay driver action following IF_TYPE_2 reset */ | |
88a2cfbb JS |
1202 | rc = lpfc_sli4_pdev_status_reg_wait(phba); |
1203 | ||
026abb87 | 1204 | if (rc == -EPERM) { |
0b1587b1 | 1205 | /* no privilege for reset */ |
6b5151fd | 1206 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
0b1587b1 | 1207 | "3150 No privilege to perform the requested " |
6b5151fd | 1208 | "access: x%x\n", reg_val); |
026abb87 JS |
1209 | } else if (rc == -EIO) { |
1210 | /* reset failed, there is nothing more we can do */ | |
6b5151fd JS |
1211 | lpfc_printf_log(phba, KERN_ERR, LOG_SLI, |
1212 | "3153 Fail to perform the requested " | |
1213 | "access: x%x\n", reg_val); | |
f7a919b4 | 1214 | return rc; |
026abb87 JS |
1215 | } |
1216 | ||
1217 | /* keep the original port state */ | |
1218 | if (before_fc_flag & FC_OFFLINE_MODE) | |
1219 | goto out; | |
c0c11512 JS |
1220 | |
1221 | init_completion(&online_compl); | |
026abb87 JS |
1222 | job_posted = lpfc_workq_post_event(phba, &status, &online_compl, |
1223 | LPFC_EVT_ONLINE); | |
1224 | if (!job_posted) | |
1225 | goto out; | |
c0c11512 JS |
1226 | |
1227 | wait_for_completion(&online_compl); | |
1228 | ||
026abb87 JS |
1229 | out: |
1230 | /* in any case, restore the virtual functions enabled as before */ | |
1231 | if (sriov_nr_virtfn) { | |
1232 | sriov_err = | |
1233 | lpfc_sli_probe_sriov_nr_virtfn(phba, sriov_nr_virtfn); | |
1234 | if (!sriov_err) | |
1235 | phba->cfg_sriov_nr_virtfn = sriov_nr_virtfn; | |
1236 | } | |
c0c11512 | 1237 | |
026abb87 JS |
1238 | /* return proper error code */ |
1239 | if (!rc) { | |
1240 | if (!job_posted) | |
1241 | rc = -ENOMEM; | |
1242 | else if (status) | |
1243 | rc = -EIO; | |
1244 | } | |
1245 | return rc; | |
c0c11512 JS |
1246 | } |
1247 | ||
e59058c4 | 1248 | /** |
3621a710 | 1249 | * lpfc_nport_evt_cnt_show - Return the number of nport events |
e59058c4 JS |
1250 | * @dev: class device that is converted into a Scsi_host. |
1251 | * @attr: device attribute, not used. | |
1252 | * @buf: on return contains the ascii number of nport events. | |
1253 | * | |
1254 | * Returns: size of formatted string. | |
1255 | **/ | |
dea3101e | 1256 | static ssize_t |
ee959b00 TJ |
1257 | lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr, |
1258 | char *buf) | |
dea3101e | 1259 | { |
ee959b00 | 1260 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 JS |
1261 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
1262 | struct lpfc_hba *phba = vport->phba; | |
1263 | ||
dea3101e JB |
1264 | return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt); |
1265 | } | |
1266 | ||
e59058c4 | 1267 | /** |
3621a710 | 1268 | * lpfc_board_mode_show - Return the state of the board |
e59058c4 JS |
1269 | * @dev: class device that is converted into a Scsi_host. |
1270 | * @attr: device attribute, not used. | |
1271 | * @buf: on return contains the state of the adapter. | |
1272 | * | |
1273 | * Returns: size of formatted string. | |
1274 | **/ | |
41415862 | 1275 | static ssize_t |
ee959b00 TJ |
1276 | lpfc_board_mode_show(struct device *dev, struct device_attribute *attr, |
1277 | char *buf) | |
41415862 | 1278 | { |
ee959b00 | 1279 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 JS |
1280 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
1281 | struct lpfc_hba *phba = vport->phba; | |
41415862 JW |
1282 | char * state; |
1283 | ||
2e0fef85 | 1284 | if (phba->link_state == LPFC_HBA_ERROR) |
41415862 | 1285 | state = "error"; |
2e0fef85 | 1286 | else if (phba->link_state == LPFC_WARM_START) |
41415862 | 1287 | state = "warm start"; |
2e0fef85 | 1288 | else if (phba->link_state == LPFC_INIT_START) |
41415862 JW |
1289 | state = "offline"; |
1290 | else | |
1291 | state = "online"; | |
1292 | ||
1293 | return snprintf(buf, PAGE_SIZE, "%s\n", state); | |
1294 | } | |
1295 | ||
e59058c4 | 1296 | /** |
3621a710 | 1297 | * lpfc_board_mode_store - Puts the hba in online, offline, warm or error state |
e59058c4 JS |
1298 | * @dev: class device that is converted into a Scsi_host. |
1299 | * @attr: device attribute, not used. | |
1300 | * @buf: containing one of the strings "online", "offline", "warm" or "error". | |
1301 | * @count: unused variable. | |
1302 | * | |
1303 | * Returns: | |
1304 | * -EACCES if enable hba reset not enabled | |
1305 | * -EINVAL if the buffer does not contain a valid string (see above) | |
1306 | * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails | |
1307 | * buf length greater than zero indicates success | |
1308 | **/ | |
41415862 | 1309 | static ssize_t |
ee959b00 TJ |
1310 | lpfc_board_mode_store(struct device *dev, struct device_attribute *attr, |
1311 | const char *buf, size_t count) | |
41415862 | 1312 | { |
ee959b00 | 1313 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 JS |
1314 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
1315 | struct lpfc_hba *phba = vport->phba; | |
41415862 | 1316 | struct completion online_compl; |
026abb87 JS |
1317 | char *board_mode_str = NULL; |
1318 | int status = 0; | |
fedd3b7b | 1319 | int rc; |
41415862 | 1320 | |
026abb87 JS |
1321 | if (!phba->cfg_enable_hba_reset) { |
1322 | status = -EACCES; | |
1323 | goto board_mode_out; | |
1324 | } | |
88a2cfbb JS |
1325 | |
1326 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, | |
026abb87 | 1327 | "3050 lpfc_board_mode set to %s\n", buf); |
88a2cfbb | 1328 | |
41415862 JW |
1329 | init_completion(&online_compl); |
1330 | ||
46fa311e | 1331 | if(strncmp(buf, "online", sizeof("online") - 1) == 0) { |
fedd3b7b | 1332 | rc = lpfc_workq_post_event(phba, &status, &online_compl, |
41415862 | 1333 | LPFC_EVT_ONLINE); |
026abb87 JS |
1334 | if (rc == 0) { |
1335 | status = -ENOMEM; | |
1336 | goto board_mode_out; | |
1337 | } | |
46fa311e JS |
1338 | wait_for_completion(&online_compl); |
1339 | } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0) | |
1340 | status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE); | |
41415862 | 1341 | else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0) |
6a9c52cf | 1342 | if (phba->sli_rev == LPFC_SLI_REV4) |
026abb87 | 1343 | status = -EINVAL; |
6a9c52cf JS |
1344 | else |
1345 | status = lpfc_do_offline(phba, LPFC_EVT_WARM_START); | |
46fa311e | 1346 | else if (strncmp(buf, "error", sizeof("error") - 1) == 0) |
6a9c52cf | 1347 | if (phba->sli_rev == LPFC_SLI_REV4) |
026abb87 | 1348 | status = -EINVAL; |
6a9c52cf JS |
1349 | else |
1350 | status = lpfc_do_offline(phba, LPFC_EVT_KILL); | |
c0c11512 | 1351 | else if (strncmp(buf, "dump", sizeof("dump") - 1) == 0) |
52d52440 JS |
1352 | status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_DUMP); |
1353 | else if (strncmp(buf, "fw_reset", sizeof("fw_reset") - 1) == 0) | |
1354 | status = lpfc_sli4_pdev_reg_request(phba, LPFC_FW_RESET); | |
1355 | else if (strncmp(buf, "dv_reset", sizeof("dv_reset") - 1) == 0) | |
1356 | status = lpfc_sli4_pdev_reg_request(phba, LPFC_DV_RESET); | |
41415862 | 1357 | else |
026abb87 | 1358 | status = -EINVAL; |
41415862 | 1359 | |
026abb87 | 1360 | board_mode_out: |
41415862 JW |
1361 | if (!status) |
1362 | return strlen(buf); | |
026abb87 JS |
1363 | else { |
1364 | board_mode_str = strchr(buf, '\n'); | |
1365 | if (board_mode_str) | |
1366 | *board_mode_str = '\0'; | |
1367 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, | |
1368 | "3097 Failed \"%s\", status(%d), " | |
1369 | "fc_flag(x%x)\n", | |
1370 | buf, status, phba->pport->fc_flag); | |
f7a919b4 | 1371 | return status; |
026abb87 | 1372 | } |
41415862 JW |
1373 | } |
1374 | ||
e59058c4 | 1375 | /** |
3621a710 | 1376 | * lpfc_get_hba_info - Return various bits of informaton about the adapter |
e59058c4 | 1377 | * @phba: pointer to the adapter structure. |
3621a710 JS |
1378 | * @mxri: max xri count. |
1379 | * @axri: available xri count. | |
1380 | * @mrpi: max rpi count. | |
1381 | * @arpi: available rpi count. | |
1382 | * @mvpi: max vpi count. | |
1383 | * @avpi: available vpi count. | |
e59058c4 JS |
1384 | * |
1385 | * Description: | |
1386 | * If an integer pointer for an count is not null then the value for the | |
1387 | * count is returned. | |
1388 | * | |
1389 | * Returns: | |
1390 | * zero on error | |
1391 | * one for success | |
1392 | **/ | |
311464ec | 1393 | static int |
858c9f6c JS |
1394 | lpfc_get_hba_info(struct lpfc_hba *phba, |
1395 | uint32_t *mxri, uint32_t *axri, | |
1396 | uint32_t *mrpi, uint32_t *arpi, | |
1397 | uint32_t *mvpi, uint32_t *avpi) | |
92d7f7b0 | 1398 | { |
04c68496 | 1399 | struct lpfc_mbx_read_config *rd_config; |
92d7f7b0 JS |
1400 | LPFC_MBOXQ_t *pmboxq; |
1401 | MAILBOX_t *pmb; | |
1402 | int rc = 0; | |
15672319 | 1403 | uint32_t max_vpi; |
92d7f7b0 JS |
1404 | |
1405 | /* | |
1406 | * prevent udev from issuing mailbox commands until the port is | |
1407 | * configured. | |
1408 | */ | |
1409 | if (phba->link_state < LPFC_LINK_DOWN || | |
1410 | !phba->mbox_mem_pool || | |
f4b4c68f | 1411 | (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0) |
92d7f7b0 JS |
1412 | return 0; |
1413 | ||
1414 | if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) | |
1415 | return 0; | |
1416 | ||
1417 | pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
1418 | if (!pmboxq) | |
1419 | return 0; | |
1420 | memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t)); | |
1421 | ||
04c68496 | 1422 | pmb = &pmboxq->u.mb; |
92d7f7b0 JS |
1423 | pmb->mbxCommand = MBX_READ_CONFIG; |
1424 | pmb->mbxOwner = OWN_HOST; | |
1425 | pmboxq->context1 = NULL; | |
1426 | ||
75baf696 | 1427 | if (phba->pport->fc_flag & FC_OFFLINE_MODE) |
92d7f7b0 JS |
1428 | rc = MBX_NOT_FINISHED; |
1429 | else | |
1430 | rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2); | |
1431 | ||
1432 | if (rc != MBX_SUCCESS) { | |
858c9f6c | 1433 | if (rc != MBX_TIMEOUT) |
92d7f7b0 JS |
1434 | mempool_free(pmboxq, phba->mbox_mem_pool); |
1435 | return 0; | |
1436 | } | |
1437 | ||
da0436e9 JS |
1438 | if (phba->sli_rev == LPFC_SLI_REV4) { |
1439 | rd_config = &pmboxq->u.mqe.un.rd_config; | |
1440 | if (mrpi) | |
1441 | *mrpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config); | |
1442 | if (arpi) | |
1443 | *arpi = bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config) - | |
1444 | phba->sli4_hba.max_cfg_param.rpi_used; | |
1445 | if (mxri) | |
1446 | *mxri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config); | |
1447 | if (axri) | |
1448 | *axri = bf_get(lpfc_mbx_rd_conf_xri_count, rd_config) - | |
1449 | phba->sli4_hba.max_cfg_param.xri_used; | |
15672319 JS |
1450 | |
1451 | /* Account for differences with SLI-3. Get vpi count from | |
1452 | * mailbox data and subtract one for max vpi value. | |
1453 | */ | |
1454 | max_vpi = (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) > 0) ? | |
1455 | (bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config) - 1) : 0; | |
1456 | ||
da0436e9 | 1457 | if (mvpi) |
15672319 | 1458 | *mvpi = max_vpi; |
da0436e9 | 1459 | if (avpi) |
15672319 | 1460 | *avpi = max_vpi - phba->sli4_hba.max_cfg_param.vpi_used; |
da0436e9 JS |
1461 | } else { |
1462 | if (mrpi) | |
1463 | *mrpi = pmb->un.varRdConfig.max_rpi; | |
1464 | if (arpi) | |
1465 | *arpi = pmb->un.varRdConfig.avail_rpi; | |
1466 | if (mxri) | |
1467 | *mxri = pmb->un.varRdConfig.max_xri; | |
1468 | if (axri) | |
1469 | *axri = pmb->un.varRdConfig.avail_xri; | |
1470 | if (mvpi) | |
1471 | *mvpi = pmb->un.varRdConfig.max_vpi; | |
1472 | if (avpi) | |
1473 | *avpi = pmb->un.varRdConfig.avail_vpi; | |
1474 | } | |
92d7f7b0 JS |
1475 | |
1476 | mempool_free(pmboxq, phba->mbox_mem_pool); | |
1477 | return 1; | |
1478 | } | |
1479 | ||
e59058c4 | 1480 | /** |
3621a710 | 1481 | * lpfc_max_rpi_show - Return maximum rpi |
e59058c4 JS |
1482 | * @dev: class device that is converted into a Scsi_host. |
1483 | * @attr: device attribute, not used. | |
1484 | * @buf: on return contains the maximum rpi count in decimal or "Unknown". | |
1485 | * | |
1486 | * Description: | |
1487 | * Calls lpfc_get_hba_info() asking for just the mrpi count. | |
1488 | * If lpfc_get_hba_info() returns zero (failure) the buffer text is set | |
1489 | * to "Unknown" and the buffer length is returned, therefore the caller | |
1490 | * must check for "Unknown" in the buffer to detect a failure. | |
1491 | * | |
1492 | * Returns: size of formatted string. | |
1493 | **/ | |
92d7f7b0 | 1494 | static ssize_t |
ee959b00 TJ |
1495 | lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr, |
1496 | char *buf) | |
92d7f7b0 | 1497 | { |
ee959b00 | 1498 | struct Scsi_Host *shost = class_to_shost(dev); |
92d7f7b0 JS |
1499 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
1500 | struct lpfc_hba *phba = vport->phba; | |
1501 | uint32_t cnt; | |
1502 | ||
858c9f6c | 1503 | if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL)) |
92d7f7b0 JS |
1504 | return snprintf(buf, PAGE_SIZE, "%d\n", cnt); |
1505 | return snprintf(buf, PAGE_SIZE, "Unknown\n"); | |
1506 | } | |
1507 | ||
e59058c4 | 1508 | /** |
3621a710 | 1509 | * lpfc_used_rpi_show - Return maximum rpi minus available rpi |
e59058c4 JS |
1510 | * @dev: class device that is converted into a Scsi_host. |
1511 | * @attr: device attribute, not used. | |
1512 | * @buf: containing the used rpi count in decimal or "Unknown". | |
1513 | * | |
1514 | * Description: | |
1515 | * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts. | |
1516 | * If lpfc_get_hba_info() returns zero (failure) the buffer text is set | |
1517 | * to "Unknown" and the buffer length is returned, therefore the caller | |
1518 | * must check for "Unknown" in the buffer to detect a failure. | |
1519 | * | |
1520 | * Returns: size of formatted string. | |
1521 | **/ | |
92d7f7b0 | 1522 | static ssize_t |
ee959b00 TJ |
1523 | lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr, |
1524 | char *buf) | |
92d7f7b0 | 1525 | { |
ee959b00 | 1526 | struct Scsi_Host *shost = class_to_shost(dev); |
92d7f7b0 JS |
1527 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
1528 | struct lpfc_hba *phba = vport->phba; | |
1529 | uint32_t cnt, acnt; | |
1530 | ||
858c9f6c | 1531 | if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL)) |
92d7f7b0 JS |
1532 | return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt)); |
1533 | return snprintf(buf, PAGE_SIZE, "Unknown\n"); | |
1534 | } | |
1535 | ||
e59058c4 | 1536 | /** |
3621a710 | 1537 | * lpfc_max_xri_show - Return maximum xri |
e59058c4 JS |
1538 | * @dev: class device that is converted into a Scsi_host. |
1539 | * @attr: device attribute, not used. | |
1540 | * @buf: on return contains the maximum xri count in decimal or "Unknown". | |
1541 | * | |
1542 | * Description: | |
1543 | * Calls lpfc_get_hba_info() asking for just the mrpi count. | |
1544 | * If lpfc_get_hba_info() returns zero (failure) the buffer text is set | |
1545 | * to "Unknown" and the buffer length is returned, therefore the caller | |
1546 | * must check for "Unknown" in the buffer to detect a failure. | |
1547 | * | |
1548 | * Returns: size of formatted string. | |
1549 | **/ | |
92d7f7b0 | 1550 | static ssize_t |
ee959b00 TJ |
1551 | lpfc_max_xri_show(struct device *dev, struct device_attribute *attr, |
1552 | char *buf) | |
92d7f7b0 | 1553 | { |
ee959b00 | 1554 | struct Scsi_Host *shost = class_to_shost(dev); |
92d7f7b0 JS |
1555 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
1556 | struct lpfc_hba *phba = vport->phba; | |
1557 | uint32_t cnt; | |
1558 | ||
858c9f6c | 1559 | if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL)) |
92d7f7b0 JS |
1560 | return snprintf(buf, PAGE_SIZE, "%d\n", cnt); |
1561 | return snprintf(buf, PAGE_SIZE, "Unknown\n"); | |
1562 | } | |
1563 | ||
e59058c4 | 1564 | /** |
3621a710 | 1565 | * lpfc_used_xri_show - Return maximum xpi minus the available xpi |
e59058c4 JS |
1566 | * @dev: class device that is converted into a Scsi_host. |
1567 | * @attr: device attribute, not used. | |
1568 | * @buf: on return contains the used xri count in decimal or "Unknown". | |
1569 | * | |
1570 | * Description: | |
1571 | * Calls lpfc_get_hba_info() asking for just the mxri and axri counts. | |
1572 | * If lpfc_get_hba_info() returns zero (failure) the buffer text is set | |
1573 | * to "Unknown" and the buffer length is returned, therefore the caller | |
1574 | * must check for "Unknown" in the buffer to detect a failure. | |
1575 | * | |
1576 | * Returns: size of formatted string. | |
1577 | **/ | |
92d7f7b0 | 1578 | static ssize_t |
ee959b00 TJ |
1579 | lpfc_used_xri_show(struct device *dev, struct device_attribute *attr, |
1580 | char *buf) | |
92d7f7b0 | 1581 | { |
ee959b00 | 1582 | struct Scsi_Host *shost = class_to_shost(dev); |
92d7f7b0 JS |
1583 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
1584 | struct lpfc_hba *phba = vport->phba; | |
1585 | uint32_t cnt, acnt; | |
1586 | ||
858c9f6c JS |
1587 | if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL)) |
1588 | return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt)); | |
1589 | return snprintf(buf, PAGE_SIZE, "Unknown\n"); | |
1590 | } | |
1591 | ||
e59058c4 | 1592 | /** |
3621a710 | 1593 | * lpfc_max_vpi_show - Return maximum vpi |
e59058c4 JS |
1594 | * @dev: class device that is converted into a Scsi_host. |
1595 | * @attr: device attribute, not used. | |
1596 | * @buf: on return contains the maximum vpi count in decimal or "Unknown". | |
1597 | * | |
1598 | * Description: | |
1599 | * Calls lpfc_get_hba_info() asking for just the mvpi count. | |
1600 | * If lpfc_get_hba_info() returns zero (failure) the buffer text is set | |
1601 | * to "Unknown" and the buffer length is returned, therefore the caller | |
1602 | * must check for "Unknown" in the buffer to detect a failure. | |
1603 | * | |
1604 | * Returns: size of formatted string. | |
1605 | **/ | |
858c9f6c | 1606 | static ssize_t |
ee959b00 TJ |
1607 | lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr, |
1608 | char *buf) | |
858c9f6c | 1609 | { |
ee959b00 | 1610 | struct Scsi_Host *shost = class_to_shost(dev); |
858c9f6c JS |
1611 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
1612 | struct lpfc_hba *phba = vport->phba; | |
1613 | uint32_t cnt; | |
1614 | ||
1615 | if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL)) | |
1616 | return snprintf(buf, PAGE_SIZE, "%d\n", cnt); | |
1617 | return snprintf(buf, PAGE_SIZE, "Unknown\n"); | |
1618 | } | |
1619 | ||
e59058c4 | 1620 | /** |
3621a710 | 1621 | * lpfc_used_vpi_show - Return maximum vpi minus the available vpi |
e59058c4 JS |
1622 | * @dev: class device that is converted into a Scsi_host. |
1623 | * @attr: device attribute, not used. | |
1624 | * @buf: on return contains the used vpi count in decimal or "Unknown". | |
1625 | * | |
1626 | * Description: | |
1627 | * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts. | |
1628 | * If lpfc_get_hba_info() returns zero (failure) the buffer text is set | |
1629 | * to "Unknown" and the buffer length is returned, therefore the caller | |
1630 | * must check for "Unknown" in the buffer to detect a failure. | |
1631 | * | |
1632 | * Returns: size of formatted string. | |
1633 | **/ | |
858c9f6c | 1634 | static ssize_t |
ee959b00 TJ |
1635 | lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr, |
1636 | char *buf) | |
858c9f6c | 1637 | { |
ee959b00 | 1638 | struct Scsi_Host *shost = class_to_shost(dev); |
858c9f6c JS |
1639 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
1640 | struct lpfc_hba *phba = vport->phba; | |
1641 | uint32_t cnt, acnt; | |
1642 | ||
1643 | if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt)) | |
92d7f7b0 JS |
1644 | return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt)); |
1645 | return snprintf(buf, PAGE_SIZE, "Unknown\n"); | |
1646 | } | |
1647 | ||
e59058c4 | 1648 | /** |
3621a710 | 1649 | * lpfc_npiv_info_show - Return text about NPIV support for the adapter |
e59058c4 JS |
1650 | * @dev: class device that is converted into a Scsi_host. |
1651 | * @attr: device attribute, not used. | |
1652 | * @buf: text that must be interpreted to determine if npiv is supported. | |
1653 | * | |
1654 | * Description: | |
1655 | * Buffer will contain text indicating npiv is not suppoerted on the port, | |
1656 | * the port is an NPIV physical port, or it is an npiv virtual port with | |
1657 | * the id of the vport. | |
1658 | * | |
1659 | * Returns: size of formatted string. | |
1660 | **/ | |
92d7f7b0 | 1661 | static ssize_t |
ee959b00 TJ |
1662 | lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr, |
1663 | char *buf) | |
92d7f7b0 | 1664 | { |
ee959b00 | 1665 | struct Scsi_Host *shost = class_to_shost(dev); |
92d7f7b0 JS |
1666 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
1667 | struct lpfc_hba *phba = vport->phba; | |
1668 | ||
1669 | if (!(phba->max_vpi)) | |
1670 | return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n"); | |
1671 | if (vport->port_type == LPFC_PHYSICAL_PORT) | |
1672 | return snprintf(buf, PAGE_SIZE, "NPIV Physical\n"); | |
1673 | return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi); | |
1674 | } | |
1675 | ||
e59058c4 | 1676 | /** |
3621a710 | 1677 | * lpfc_poll_show - Return text about poll support for the adapter |
e59058c4 JS |
1678 | * @dev: class device that is converted into a Scsi_host. |
1679 | * @attr: device attribute, not used. | |
1680 | * @buf: on return contains the cfg_poll in hex. | |
1681 | * | |
1682 | * Notes: | |
1683 | * cfg_poll should be a lpfc_polling_flags type. | |
1684 | * | |
1685 | * Returns: size of formatted string. | |
1686 | **/ | |
875fbdfe | 1687 | static ssize_t |
ee959b00 TJ |
1688 | lpfc_poll_show(struct device *dev, struct device_attribute *attr, |
1689 | char *buf) | |
875fbdfe | 1690 | { |
ee959b00 | 1691 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 JS |
1692 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
1693 | struct lpfc_hba *phba = vport->phba; | |
875fbdfe JSEC |
1694 | |
1695 | return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll); | |
1696 | } | |
1697 | ||
e59058c4 | 1698 | /** |
3621a710 | 1699 | * lpfc_poll_store - Set the value of cfg_poll for the adapter |
e59058c4 JS |
1700 | * @dev: class device that is converted into a Scsi_host. |
1701 | * @attr: device attribute, not used. | |
1702 | * @buf: one or more lpfc_polling_flags values. | |
1703 | * @count: not used. | |
1704 | * | |
1705 | * Notes: | |
1706 | * buf contents converted to integer and checked for a valid value. | |
1707 | * | |
1708 | * Returns: | |
1709 | * -EINVAL if the buffer connot be converted or is out of range | |
1710 | * length of the buf on success | |
1711 | **/ | |
875fbdfe | 1712 | static ssize_t |
ee959b00 TJ |
1713 | lpfc_poll_store(struct device *dev, struct device_attribute *attr, |
1714 | const char *buf, size_t count) | |
875fbdfe | 1715 | { |
ee959b00 | 1716 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 JS |
1717 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
1718 | struct lpfc_hba *phba = vport->phba; | |
875fbdfe JSEC |
1719 | uint32_t creg_val; |
1720 | uint32_t old_val; | |
1721 | int val=0; | |
1722 | ||
1723 | if (!isdigit(buf[0])) | |
1724 | return -EINVAL; | |
1725 | ||
1726 | if (sscanf(buf, "%i", &val) != 1) | |
1727 | return -EINVAL; | |
1728 | ||
1729 | if ((val & 0x3) != val) | |
1730 | return -EINVAL; | |
1731 | ||
45ed1190 JS |
1732 | if (phba->sli_rev == LPFC_SLI_REV4) |
1733 | val = 0; | |
1734 | ||
88a2cfbb JS |
1735 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
1736 | "3051 lpfc_poll changed from %d to %d\n", | |
1737 | phba->cfg_poll, val); | |
1738 | ||
2e0fef85 | 1739 | spin_lock_irq(&phba->hbalock); |
875fbdfe JSEC |
1740 | |
1741 | old_val = phba->cfg_poll; | |
1742 | ||
1743 | if (val & ENABLE_FCP_RING_POLLING) { | |
1744 | if ((val & DISABLE_FCP_RING_INT) && | |
1745 | !(old_val & DISABLE_FCP_RING_INT)) { | |
9940b97b JS |
1746 | if (lpfc_readl(phba->HCregaddr, &creg_val)) { |
1747 | spin_unlock_irq(&phba->hbalock); | |
1748 | return -EINVAL; | |
1749 | } | |
875fbdfe JSEC |
1750 | creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING); |
1751 | writel(creg_val, phba->HCregaddr); | |
1752 | readl(phba->HCregaddr); /* flush */ | |
1753 | ||
1754 | lpfc_poll_start_timer(phba); | |
1755 | } | |
1756 | } else if (val != 0x0) { | |
2e0fef85 | 1757 | spin_unlock_irq(&phba->hbalock); |
875fbdfe JSEC |
1758 | return -EINVAL; |
1759 | } | |
1760 | ||
1761 | if (!(val & DISABLE_FCP_RING_INT) && | |
1762 | (old_val & DISABLE_FCP_RING_INT)) | |
1763 | { | |
2e0fef85 | 1764 | spin_unlock_irq(&phba->hbalock); |
875fbdfe | 1765 | del_timer(&phba->fcp_poll_timer); |
2e0fef85 | 1766 | spin_lock_irq(&phba->hbalock); |
9940b97b JS |
1767 | if (lpfc_readl(phba->HCregaddr, &creg_val)) { |
1768 | spin_unlock_irq(&phba->hbalock); | |
1769 | return -EINVAL; | |
1770 | } | |
875fbdfe JSEC |
1771 | creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING); |
1772 | writel(creg_val, phba->HCregaddr); | |
1773 | readl(phba->HCregaddr); /* flush */ | |
1774 | } | |
1775 | ||
1776 | phba->cfg_poll = val; | |
1777 | ||
2e0fef85 | 1778 | spin_unlock_irq(&phba->hbalock); |
875fbdfe JSEC |
1779 | |
1780 | return strlen(buf); | |
1781 | } | |
dea3101e | 1782 | |
bc73905a JS |
1783 | /** |
1784 | * lpfc_fips_level_show - Return the current FIPS level for the HBA | |
1785 | * @dev: class unused variable. | |
1786 | * @attr: device attribute, not used. | |
1787 | * @buf: on return contains the module description text. | |
1788 | * | |
1789 | * Returns: size of formatted string. | |
1790 | **/ | |
1791 | static ssize_t | |
1792 | lpfc_fips_level_show(struct device *dev, struct device_attribute *attr, | |
1793 | char *buf) | |
1794 | { | |
1795 | struct Scsi_Host *shost = class_to_shost(dev); | |
1796 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
1797 | struct lpfc_hba *phba = vport->phba; | |
1798 | ||
1799 | return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_level); | |
1800 | } | |
1801 | ||
1802 | /** | |
1803 | * lpfc_fips_rev_show - Return the FIPS Spec revision for the HBA | |
1804 | * @dev: class unused variable. | |
1805 | * @attr: device attribute, not used. | |
1806 | * @buf: on return contains the module description text. | |
1807 | * | |
1808 | * Returns: size of formatted string. | |
1809 | **/ | |
1810 | static ssize_t | |
1811 | lpfc_fips_rev_show(struct device *dev, struct device_attribute *attr, | |
1812 | char *buf) | |
1813 | { | |
1814 | struct Scsi_Host *shost = class_to_shost(dev); | |
1815 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
1816 | struct lpfc_hba *phba = vport->phba; | |
1817 | ||
1818 | return snprintf(buf, PAGE_SIZE, "%d\n", phba->fips_spec_rev); | |
1819 | } | |
1820 | ||
ab56dc2e JS |
1821 | /** |
1822 | * lpfc_dss_show - Return the current state of dss and the configured state | |
1823 | * @dev: class converted to a Scsi_host structure. | |
1824 | * @attr: device attribute, not used. | |
1825 | * @buf: on return contains the formatted text. | |
1826 | * | |
1827 | * Returns: size of formatted string. | |
1828 | **/ | |
1829 | static ssize_t | |
1830 | lpfc_dss_show(struct device *dev, struct device_attribute *attr, | |
1831 | char *buf) | |
1832 | { | |
1833 | struct Scsi_Host *shost = class_to_shost(dev); | |
1834 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
1835 | struct lpfc_hba *phba = vport->phba; | |
1836 | ||
1837 | return snprintf(buf, PAGE_SIZE, "%s - %sOperational\n", | |
1838 | (phba->cfg_enable_dss) ? "Enabled" : "Disabled", | |
1839 | (phba->sli3_options & LPFC_SLI3_DSS_ENABLED) ? | |
1840 | "" : "Not "); | |
1841 | } | |
1842 | ||
912e3acd JS |
1843 | /** |
1844 | * lpfc_sriov_hw_max_virtfn_show - Return maximum number of virtual functions | |
1845 | * @dev: class converted to a Scsi_host structure. | |
1846 | * @attr: device attribute, not used. | |
1847 | * @buf: on return contains the formatted support level. | |
1848 | * | |
1849 | * Description: | |
1850 | * Returns the maximum number of virtual functions a physical function can | |
1851 | * support, 0 will be returned if called on virtual function. | |
1852 | * | |
1853 | * Returns: size of formatted string. | |
1854 | **/ | |
1855 | static ssize_t | |
1856 | lpfc_sriov_hw_max_virtfn_show(struct device *dev, | |
1857 | struct device_attribute *attr, | |
1858 | char *buf) | |
1859 | { | |
1860 | struct Scsi_Host *shost = class_to_shost(dev); | |
1861 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
1862 | struct lpfc_hba *phba = vport->phba; | |
0a96e975 | 1863 | uint16_t max_nr_virtfn; |
912e3acd | 1864 | |
0a96e975 JS |
1865 | max_nr_virtfn = lpfc_sli_sriov_nr_virtfn_get(phba); |
1866 | return snprintf(buf, PAGE_SIZE, "%d\n", max_nr_virtfn); | |
912e3acd JS |
1867 | } |
1868 | ||
de8c36bb AB |
1869 | static inline bool lpfc_rangecheck(uint val, uint min, uint max) |
1870 | { | |
1871 | return val >= min && val <= max; | |
1872 | } | |
1873 | ||
e59058c4 | 1874 | /** |
3621a710 | 1875 | * lpfc_param_show - Return a cfg attribute value in decimal |
e59058c4 JS |
1876 | * |
1877 | * Description: | |
1878 | * Macro that given an attr e.g. hba_queue_depth expands | |
1879 | * into a function with the name lpfc_hba_queue_depth_show. | |
1880 | * | |
1881 | * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field. | |
1882 | * @dev: class device that is converted into a Scsi_host. | |
1883 | * @attr: device attribute, not used. | |
1884 | * @buf: on return contains the attribute value in decimal. | |
1885 | * | |
1886 | * Returns: size of formatted string. | |
1887 | **/ | |
dea3101e JB |
1888 | #define lpfc_param_show(attr) \ |
1889 | static ssize_t \ | |
ee959b00 TJ |
1890 | lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \ |
1891 | char *buf) \ | |
dea3101e | 1892 | { \ |
ee959b00 | 1893 | struct Scsi_Host *shost = class_to_shost(dev);\ |
2e0fef85 JS |
1894 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\ |
1895 | struct lpfc_hba *phba = vport->phba;\ | |
7bcbb752 JSEC |
1896 | return snprintf(buf, PAGE_SIZE, "%d\n",\ |
1897 | phba->cfg_##attr);\ | |
1898 | } | |
1899 | ||
e59058c4 | 1900 | /** |
3621a710 | 1901 | * lpfc_param_hex_show - Return a cfg attribute value in hex |
e59058c4 JS |
1902 | * |
1903 | * Description: | |
1904 | * Macro that given an attr e.g. hba_queue_depth expands | |
1905 | * into a function with the name lpfc_hba_queue_depth_show | |
1906 | * | |
1907 | * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field. | |
1908 | * @dev: class device that is converted into a Scsi_host. | |
1909 | * @attr: device attribute, not used. | |
3621a710 | 1910 | * @buf: on return contains the attribute value in hexadecimal. |
e59058c4 JS |
1911 | * |
1912 | * Returns: size of formatted string. | |
1913 | **/ | |
93a20f74 JSEC |
1914 | #define lpfc_param_hex_show(attr) \ |
1915 | static ssize_t \ | |
ee959b00 TJ |
1916 | lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \ |
1917 | char *buf) \ | |
93a20f74 | 1918 | { \ |
ee959b00 | 1919 | struct Scsi_Host *shost = class_to_shost(dev);\ |
2e0fef85 JS |
1920 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\ |
1921 | struct lpfc_hba *phba = vport->phba;\ | |
84d1b006 | 1922 | uint val = 0;\ |
93a20f74 JSEC |
1923 | val = phba->cfg_##attr;\ |
1924 | return snprintf(buf, PAGE_SIZE, "%#x\n",\ | |
1925 | phba->cfg_##attr);\ | |
1926 | } | |
1927 | ||
e59058c4 | 1928 | /** |
b595076a | 1929 | * lpfc_param_init - Initializes a cfg attribute |
e59058c4 JS |
1930 | * |
1931 | * Description: | |
1932 | * Macro that given an attr e.g. hba_queue_depth expands | |
1933 | * into a function with the name lpfc_hba_queue_depth_init. The macro also | |
1934 | * takes a default argument, a minimum and maximum argument. | |
1935 | * | |
1936 | * lpfc_##attr##_init: Initializes an attribute. | |
1937 | * @phba: pointer the the adapter structure. | |
1938 | * @val: integer attribute value. | |
1939 | * | |
1940 | * Validates the min and max values then sets the adapter config field | |
1941 | * accordingly, or uses the default if out of range and prints an error message. | |
1942 | * | |
1943 | * Returns: | |
1944 | * zero on success | |
1945 | * -EINVAL if default used | |
1946 | **/ | |
7bcbb752 JSEC |
1947 | #define lpfc_param_init(attr, default, minval, maxval) \ |
1948 | static int \ | |
84d1b006 | 1949 | lpfc_##attr##_init(struct lpfc_hba *phba, uint val) \ |
7bcbb752 | 1950 | { \ |
de8c36bb | 1951 | if (lpfc_rangecheck(val, minval, maxval)) {\ |
7bcbb752 JSEC |
1952 | phba->cfg_##attr = val;\ |
1953 | return 0;\ | |
dea3101e | 1954 | }\ |
7bcbb752 | 1955 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \ |
e8b62011 JS |
1956 | "0449 lpfc_"#attr" attribute cannot be set to %d, "\ |
1957 | "allowed range is ["#minval", "#maxval"]\n", val); \ | |
7bcbb752 JSEC |
1958 | phba->cfg_##attr = default;\ |
1959 | return -EINVAL;\ | |
dea3101e JB |
1960 | } |
1961 | ||
e59058c4 | 1962 | /** |
3621a710 | 1963 | * lpfc_param_set - Set a cfg attribute value |
e59058c4 JS |
1964 | * |
1965 | * Description: | |
1966 | * Macro that given an attr e.g. hba_queue_depth expands | |
1967 | * into a function with the name lpfc_hba_queue_depth_set | |
1968 | * | |
1969 | * lpfc_##attr##_set: Sets an attribute value. | |
1970 | * @phba: pointer the the adapter structure. | |
1971 | * @val: integer attribute value. | |
1972 | * | |
1973 | * Description: | |
1974 | * Validates the min and max values then sets the | |
1975 | * adapter config field if in the valid range. prints error message | |
1976 | * and does not set the parameter if invalid. | |
1977 | * | |
1978 | * Returns: | |
1979 | * zero on success | |
1980 | * -EINVAL if val is invalid | |
1981 | **/ | |
7bcbb752 JSEC |
1982 | #define lpfc_param_set(attr, default, minval, maxval) \ |
1983 | static int \ | |
84d1b006 | 1984 | lpfc_##attr##_set(struct lpfc_hba *phba, uint val) \ |
7bcbb752 | 1985 | { \ |
de8c36bb | 1986 | if (lpfc_rangecheck(val, minval, maxval)) {\ |
88a2cfbb JS |
1987 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \ |
1988 | "3052 lpfc_" #attr " changed from %d to %d\n", \ | |
1989 | phba->cfg_##attr, val); \ | |
7bcbb752 JSEC |
1990 | phba->cfg_##attr = val;\ |
1991 | return 0;\ | |
1992 | }\ | |
1993 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \ | |
e8b62011 JS |
1994 | "0450 lpfc_"#attr" attribute cannot be set to %d, "\ |
1995 | "allowed range is ["#minval", "#maxval"]\n", val); \ | |
7bcbb752 JSEC |
1996 | return -EINVAL;\ |
1997 | } | |
1998 | ||
e59058c4 | 1999 | /** |
3621a710 | 2000 | * lpfc_param_store - Set a vport attribute value |
e59058c4 JS |
2001 | * |
2002 | * Description: | |
2003 | * Macro that given an attr e.g. hba_queue_depth expands | |
2004 | * into a function with the name lpfc_hba_queue_depth_store. | |
2005 | * | |
2006 | * lpfc_##attr##_store: Set an sttribute value. | |
2007 | * @dev: class device that is converted into a Scsi_host. | |
2008 | * @attr: device attribute, not used. | |
2009 | * @buf: contains the attribute value in ascii. | |
2010 | * @count: not used. | |
2011 | * | |
2012 | * Description: | |
2013 | * Convert the ascii text number to an integer, then | |
2014 | * use the lpfc_##attr##_set function to set the value. | |
2015 | * | |
2016 | * Returns: | |
2017 | * -EINVAL if val is invalid or lpfc_##attr##_set() fails | |
2018 | * length of buffer upon success. | |
2019 | **/ | |
7bcbb752 | 2020 | #define lpfc_param_store(attr) \ |
dea3101e | 2021 | static ssize_t \ |
ee959b00 TJ |
2022 | lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \ |
2023 | const char *buf, size_t count) \ | |
dea3101e | 2024 | { \ |
ee959b00 | 2025 | struct Scsi_Host *shost = class_to_shost(dev);\ |
2e0fef85 JS |
2026 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\ |
2027 | struct lpfc_hba *phba = vport->phba;\ | |
84d1b006 | 2028 | uint val = 0;\ |
93a20f74 JSEC |
2029 | if (!isdigit(buf[0]))\ |
2030 | return -EINVAL;\ | |
2031 | if (sscanf(buf, "%i", &val) != 1)\ | |
2032 | return -EINVAL;\ | |
7bcbb752 | 2033 | if (lpfc_##attr##_set(phba, val) == 0) \ |
755c0d06 | 2034 | return strlen(buf);\ |
7bcbb752 JSEC |
2035 | else \ |
2036 | return -EINVAL;\ | |
dea3101e JB |
2037 | } |
2038 | ||
e59058c4 | 2039 | /** |
3621a710 | 2040 | * lpfc_vport_param_show - Return decimal formatted cfg attribute value |
e59058c4 JS |
2041 | * |
2042 | * Description: | |
2043 | * Macro that given an attr e.g. hba_queue_depth expands | |
2044 | * into a function with the name lpfc_hba_queue_depth_show | |
2045 | * | |
2046 | * lpfc_##attr##_show: prints the attribute value in decimal. | |
2047 | * @dev: class device that is converted into a Scsi_host. | |
2048 | * @attr: device attribute, not used. | |
2049 | * @buf: on return contains the attribute value in decimal. | |
2050 | * | |
2051 | * Returns: length of formatted string. | |
2052 | **/ | |
3de2a653 JS |
2053 | #define lpfc_vport_param_show(attr) \ |
2054 | static ssize_t \ | |
ee959b00 TJ |
2055 | lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \ |
2056 | char *buf) \ | |
3de2a653 | 2057 | { \ |
ee959b00 | 2058 | struct Scsi_Host *shost = class_to_shost(dev);\ |
3de2a653 | 2059 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\ |
3de2a653 JS |
2060 | return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\ |
2061 | } | |
2062 | ||
e59058c4 | 2063 | /** |
3621a710 | 2064 | * lpfc_vport_param_hex_show - Return hex formatted attribute value |
e59058c4 JS |
2065 | * |
2066 | * Description: | |
2067 | * Macro that given an attr e.g. | |
2068 | * hba_queue_depth expands into a function with the name | |
2069 | * lpfc_hba_queue_depth_show | |
2070 | * | |
3621a710 | 2071 | * lpfc_##attr##_show: prints the attribute value in hexadecimal. |
e59058c4 JS |
2072 | * @dev: class device that is converted into a Scsi_host. |
2073 | * @attr: device attribute, not used. | |
3621a710 | 2074 | * @buf: on return contains the attribute value in hexadecimal. |
e59058c4 JS |
2075 | * |
2076 | * Returns: length of formatted string. | |
2077 | **/ | |
3de2a653 JS |
2078 | #define lpfc_vport_param_hex_show(attr) \ |
2079 | static ssize_t \ | |
ee959b00 TJ |
2080 | lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \ |
2081 | char *buf) \ | |
3de2a653 | 2082 | { \ |
ee959b00 | 2083 | struct Scsi_Host *shost = class_to_shost(dev);\ |
3de2a653 | 2084 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\ |
3de2a653 JS |
2085 | return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\ |
2086 | } | |
2087 | ||
e59058c4 | 2088 | /** |
3621a710 | 2089 | * lpfc_vport_param_init - Initialize a vport cfg attribute |
e59058c4 JS |
2090 | * |
2091 | * Description: | |
2092 | * Macro that given an attr e.g. hba_queue_depth expands | |
2093 | * into a function with the name lpfc_hba_queue_depth_init. The macro also | |
2094 | * takes a default argument, a minimum and maximum argument. | |
2095 | * | |
2096 | * lpfc_##attr##_init: validates the min and max values then sets the | |
2097 | * adapter config field accordingly, or uses the default if out of range | |
2098 | * and prints an error message. | |
2099 | * @phba: pointer the the adapter structure. | |
2100 | * @val: integer attribute value. | |
2101 | * | |
2102 | * Returns: | |
2103 | * zero on success | |
2104 | * -EINVAL if default used | |
2105 | **/ | |
3de2a653 JS |
2106 | #define lpfc_vport_param_init(attr, default, minval, maxval) \ |
2107 | static int \ | |
84d1b006 | 2108 | lpfc_##attr##_init(struct lpfc_vport *vport, uint val) \ |
3de2a653 | 2109 | { \ |
de8c36bb | 2110 | if (lpfc_rangecheck(val, minval, maxval)) {\ |
3de2a653 JS |
2111 | vport->cfg_##attr = val;\ |
2112 | return 0;\ | |
2113 | }\ | |
e8b62011 | 2114 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \ |
d7c255b2 | 2115 | "0423 lpfc_"#attr" attribute cannot be set to %d, "\ |
e8b62011 | 2116 | "allowed range is ["#minval", "#maxval"]\n", val); \ |
3de2a653 JS |
2117 | vport->cfg_##attr = default;\ |
2118 | return -EINVAL;\ | |
2119 | } | |
2120 | ||
e59058c4 | 2121 | /** |
3621a710 | 2122 | * lpfc_vport_param_set - Set a vport cfg attribute |
e59058c4 JS |
2123 | * |
2124 | * Description: | |
2125 | * Macro that given an attr e.g. hba_queue_depth expands | |
2126 | * into a function with the name lpfc_hba_queue_depth_set | |
2127 | * | |
2128 | * lpfc_##attr##_set: validates the min and max values then sets the | |
2129 | * adapter config field if in the valid range. prints error message | |
2130 | * and does not set the parameter if invalid. | |
2131 | * @phba: pointer the the adapter structure. | |
2132 | * @val: integer attribute value. | |
2133 | * | |
2134 | * Returns: | |
2135 | * zero on success | |
2136 | * -EINVAL if val is invalid | |
2137 | **/ | |
3de2a653 JS |
2138 | #define lpfc_vport_param_set(attr, default, minval, maxval) \ |
2139 | static int \ | |
84d1b006 | 2140 | lpfc_##attr##_set(struct lpfc_vport *vport, uint val) \ |
3de2a653 | 2141 | { \ |
de8c36bb | 2142 | if (lpfc_rangecheck(val, minval, maxval)) {\ |
88a2cfbb | 2143 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \ |
14660f4f JS |
2144 | "3053 lpfc_" #attr \ |
2145 | " changed from %d (x%x) to %d (x%x)\n", \ | |
2146 | vport->cfg_##attr, vport->cfg_##attr, \ | |
2147 | val, val); \ | |
3de2a653 JS |
2148 | vport->cfg_##attr = val;\ |
2149 | return 0;\ | |
2150 | }\ | |
e8b62011 | 2151 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \ |
d7c255b2 | 2152 | "0424 lpfc_"#attr" attribute cannot be set to %d, "\ |
e8b62011 | 2153 | "allowed range is ["#minval", "#maxval"]\n", val); \ |
3de2a653 JS |
2154 | return -EINVAL;\ |
2155 | } | |
2156 | ||
e59058c4 | 2157 | /** |
3621a710 | 2158 | * lpfc_vport_param_store - Set a vport attribute |
e59058c4 JS |
2159 | * |
2160 | * Description: | |
2161 | * Macro that given an attr e.g. hba_queue_depth | |
2162 | * expands into a function with the name lpfc_hba_queue_depth_store | |
2163 | * | |
2164 | * lpfc_##attr##_store: convert the ascii text number to an integer, then | |
2165 | * use the lpfc_##attr##_set function to set the value. | |
2166 | * @cdev: class device that is converted into a Scsi_host. | |
2167 | * @buf: contains the attribute value in decimal. | |
2168 | * @count: not used. | |
2169 | * | |
2170 | * Returns: | |
2171 | * -EINVAL if val is invalid or lpfc_##attr##_set() fails | |
2172 | * length of buffer upon success. | |
2173 | **/ | |
3de2a653 JS |
2174 | #define lpfc_vport_param_store(attr) \ |
2175 | static ssize_t \ | |
ee959b00 TJ |
2176 | lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \ |
2177 | const char *buf, size_t count) \ | |
3de2a653 | 2178 | { \ |
ee959b00 | 2179 | struct Scsi_Host *shost = class_to_shost(dev);\ |
3de2a653 | 2180 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\ |
84d1b006 | 2181 | uint val = 0;\ |
3de2a653 JS |
2182 | if (!isdigit(buf[0]))\ |
2183 | return -EINVAL;\ | |
2184 | if (sscanf(buf, "%i", &val) != 1)\ | |
2185 | return -EINVAL;\ | |
2186 | if (lpfc_##attr##_set(vport, val) == 0) \ | |
2187 | return strlen(buf);\ | |
2188 | else \ | |
2189 | return -EINVAL;\ | |
2190 | } | |
2191 | ||
2192 | ||
895427bd | 2193 | static DEVICE_ATTR(nvme_info, 0444, lpfc_nvme_info_show, NULL); |
81301a9b JS |
2194 | static DEVICE_ATTR(bg_info, S_IRUGO, lpfc_bg_info_show, NULL); |
2195 | static DEVICE_ATTR(bg_guard_err, S_IRUGO, lpfc_bg_guard_err_show, NULL); | |
2196 | static DEVICE_ATTR(bg_apptag_err, S_IRUGO, lpfc_bg_apptag_err_show, NULL); | |
2197 | static DEVICE_ATTR(bg_reftag_err, S_IRUGO, lpfc_bg_reftag_err_show, NULL); | |
ee959b00 TJ |
2198 | static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL); |
2199 | static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL); | |
2200 | static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL); | |
2201 | static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL); | |
2202 | static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL); | |
2203 | static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL); | |
2204 | static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL); | |
2205 | static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL); | |
84d1b006 JS |
2206 | static DEVICE_ATTR(link_state, S_IRUGO | S_IWUSR, lpfc_link_state_show, |
2207 | lpfc_link_state_store); | |
ee959b00 TJ |
2208 | static DEVICE_ATTR(option_rom_version, S_IRUGO, |
2209 | lpfc_option_rom_version_show, NULL); | |
2210 | static DEVICE_ATTR(num_discovered_ports, S_IRUGO, | |
2211 | lpfc_num_discovered_ports_show, NULL); | |
84774a4d | 2212 | static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL); |
ee959b00 TJ |
2213 | static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL); |
2214 | static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL); | |
45ed1190 | 2215 | static DEVICE_ATTR(lpfc_enable_fip, S_IRUGO, lpfc_enable_fip_show, NULL); |
ee959b00 TJ |
2216 | static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR, |
2217 | lpfc_board_mode_show, lpfc_board_mode_store); | |
2218 | static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset); | |
2219 | static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL); | |
2220 | static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL); | |
2221 | static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL); | |
2222 | static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL); | |
2223 | static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL); | |
2224 | static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL); | |
2225 | static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL); | |
2226 | static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL); | |
bc73905a JS |
2227 | static DEVICE_ATTR(lpfc_fips_level, S_IRUGO, lpfc_fips_level_show, NULL); |
2228 | static DEVICE_ATTR(lpfc_fips_rev, S_IRUGO, lpfc_fips_rev_show, NULL); | |
ab56dc2e | 2229 | static DEVICE_ATTR(lpfc_dss, S_IRUGO, lpfc_dss_show, NULL); |
912e3acd JS |
2230 | static DEVICE_ATTR(lpfc_sriov_hw_max_virtfn, S_IRUGO, |
2231 | lpfc_sriov_hw_max_virtfn_show, NULL); | |
026abb87 | 2232 | static DEVICE_ATTR(protocol, S_IRUGO, lpfc_sli4_protocol_show, NULL); |
1ba981fd JS |
2233 | static DEVICE_ATTR(lpfc_xlane_supported, S_IRUGO, lpfc_oas_supported_show, |
2234 | NULL); | |
c3f28afa | 2235 | |
352e5fd1 | 2236 | static char *lpfc_soft_wwn_key = "C99G71SL8032A"; |
1ba981fd JS |
2237 | #define WWN_SZ 8 |
2238 | /** | |
2239 | * lpfc_wwn_set - Convert string to the 8 byte WWN value. | |
2240 | * @buf: WWN string. | |
2241 | * @cnt: Length of string. | |
2242 | * @wwn: Array to receive converted wwn value. | |
2243 | * | |
2244 | * Returns: | |
2245 | * -EINVAL if the buffer does not contain a valid wwn | |
2246 | * 0 success | |
2247 | **/ | |
2248 | static size_t | |
2249 | lpfc_wwn_set(const char *buf, size_t cnt, char wwn[]) | |
2250 | { | |
2251 | unsigned int i, j; | |
2252 | ||
2253 | /* Count may include a LF at end of string */ | |
2254 | if (buf[cnt-1] == '\n') | |
2255 | cnt--; | |
c3f28afa | 2256 | |
1ba981fd JS |
2257 | if ((cnt < 16) || (cnt > 18) || ((cnt == 17) && (*buf++ != 'x')) || |
2258 | ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x')))) | |
2259 | return -EINVAL; | |
2260 | ||
2261 | memset(wwn, 0, WWN_SZ); | |
2262 | ||
2263 | /* Validate and store the new name */ | |
2264 | for (i = 0, j = 0; i < 16; i++) { | |
2265 | if ((*buf >= 'a') && (*buf <= 'f')) | |
2266 | j = ((j << 4) | ((*buf++ - 'a') + 10)); | |
2267 | else if ((*buf >= 'A') && (*buf <= 'F')) | |
2268 | j = ((j << 4) | ((*buf++ - 'A') + 10)); | |
2269 | else if ((*buf >= '0') && (*buf <= '9')) | |
2270 | j = ((j << 4) | (*buf++ - '0')); | |
2271 | else | |
2272 | return -EINVAL; | |
2273 | if (i % 2) { | |
2274 | wwn[i/2] = j & 0xff; | |
2275 | j = 0; | |
2276 | } | |
2277 | } | |
2278 | return 0; | |
2279 | } | |
352e5fd1 JS |
2280 | /** |
2281 | * lpfc_soft_wwn_enable_store - Allows setting of the wwn if the key is valid | |
2282 | * @dev: class device that is converted into a Scsi_host. | |
2283 | * @attr: device attribute, not used. | |
2284 | * @buf: containing the string lpfc_soft_wwn_key. | |
2285 | * @count: must be size of lpfc_soft_wwn_key. | |
2286 | * | |
2287 | * Returns: | |
2288 | * -EINVAL if the buffer does not contain lpfc_soft_wwn_key | |
2289 | * length of buf indicates success | |
2290 | **/ | |
2291 | static ssize_t | |
2292 | lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr, | |
2293 | const char *buf, size_t count) | |
2294 | { | |
2295 | struct Scsi_Host *shost = class_to_shost(dev); | |
2296 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
2297 | struct lpfc_hba *phba = vport->phba; | |
2298 | unsigned int cnt = count; | |
aeb3c817 JS |
2299 | uint8_t vvvl = vport->fc_sparam.cmn.valid_vendor_ver_level; |
2300 | u32 *fawwpn_key = (uint32_t *)&vport->fc_sparam.un.vendorVersion[0]; | |
352e5fd1 JS |
2301 | |
2302 | /* | |
2303 | * We're doing a simple sanity check for soft_wwpn setting. | |
2304 | * We require that the user write a specific key to enable | |
2305 | * the soft_wwpn attribute to be settable. Once the attribute | |
2306 | * is written, the enable key resets. If further updates are | |
2307 | * desired, the key must be written again to re-enable the | |
2308 | * attribute. | |
2309 | * | |
2310 | * The "key" is not secret - it is a hardcoded string shown | |
2311 | * here. The intent is to protect against the random user or | |
2312 | * application that is just writing attributes. | |
2313 | */ | |
aeb3c817 JS |
2314 | if (vvvl == 1 && cpu_to_be32(*fawwpn_key) == FAPWWN_KEY_VENDOR) { |
2315 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
2316 | "0051 "LPFC_DRIVER_NAME" soft wwpn can not" | |
2317 | " be enabled: fawwpn is enabled\n"); | |
2318 | return -EINVAL; | |
2319 | } | |
352e5fd1 JS |
2320 | |
2321 | /* count may include a LF at end of string */ | |
2322 | if (buf[cnt-1] == '\n') | |
2323 | cnt--; | |
2324 | ||
2325 | if ((cnt != strlen(lpfc_soft_wwn_key)) || | |
2326 | (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0)) | |
2327 | return -EINVAL; | |
2328 | ||
2329 | phba->soft_wwn_enable = 1; | |
2330 | ||
2331 | dev_printk(KERN_WARNING, &phba->pcidev->dev, | |
2332 | "lpfc%d: soft_wwpn assignment has been enabled.\n", | |
2333 | phba->brd_no); | |
2334 | dev_printk(KERN_WARNING, &phba->pcidev->dev, | |
2335 | " The soft_wwpn feature is not supported by Broadcom."); | |
2336 | ||
2337 | return count; | |
2338 | } | |
2339 | static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL, | |
2340 | lpfc_soft_wwn_enable_store); | |
2341 | ||
2342 | /** | |
2343 | * lpfc_soft_wwpn_show - Return the cfg soft ww port name of the adapter | |
2344 | * @dev: class device that is converted into a Scsi_host. | |
2345 | * @attr: device attribute, not used. | |
2346 | * @buf: on return contains the wwpn in hexadecimal. | |
2347 | * | |
2348 | * Returns: size of formatted string. | |
2349 | **/ | |
2350 | static ssize_t | |
2351 | lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr, | |
2352 | char *buf) | |
2353 | { | |
2354 | struct Scsi_Host *shost = class_to_shost(dev); | |
2355 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
2356 | struct lpfc_hba *phba = vport->phba; | |
2357 | ||
2358 | return snprintf(buf, PAGE_SIZE, "0x%llx\n", | |
2359 | (unsigned long long)phba->cfg_soft_wwpn); | |
2360 | } | |
2361 | ||
2362 | /** | |
2363 | * lpfc_soft_wwpn_store - Set the ww port name of the adapter | |
2364 | * @dev class device that is converted into a Scsi_host. | |
2365 | * @attr: device attribute, not used. | |
2366 | * @buf: contains the wwpn in hexadecimal. | |
2367 | * @count: number of wwpn bytes in buf | |
2368 | * | |
2369 | * Returns: | |
2370 | * -EACCES hba reset not enabled, adapter over temp | |
2371 | * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid | |
2372 | * -EIO error taking adapter offline or online | |
2373 | * value of count on success | |
2374 | **/ | |
2375 | static ssize_t | |
2376 | lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr, | |
2377 | const char *buf, size_t count) | |
2378 | { | |
2379 | struct Scsi_Host *shost = class_to_shost(dev); | |
2380 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
2381 | struct lpfc_hba *phba = vport->phba; | |
2382 | struct completion online_compl; | |
2383 | int stat1 = 0, stat2 = 0; | |
2384 | unsigned int cnt = count; | |
2385 | u8 wwpn[WWN_SZ]; | |
2386 | int rc; | |
2387 | ||
2388 | if (!phba->cfg_enable_hba_reset) | |
2389 | return -EACCES; | |
2390 | spin_lock_irq(&phba->hbalock); | |
2391 | if (phba->over_temp_state == HBA_OVER_TEMP) { | |
2392 | spin_unlock_irq(&phba->hbalock); | |
2393 | return -EACCES; | |
2394 | } | |
2395 | spin_unlock_irq(&phba->hbalock); | |
2396 | /* count may include a LF at end of string */ | |
2397 | if (buf[cnt-1] == '\n') | |
2398 | cnt--; | |
2399 | ||
2400 | if (!phba->soft_wwn_enable) | |
2401 | return -EINVAL; | |
2402 | ||
2403 | /* lock setting wwpn, wwnn down */ | |
2404 | phba->soft_wwn_enable = 0; | |
2405 | ||
2406 | rc = lpfc_wwn_set(buf, cnt, wwpn); | |
e2934ed1 | 2407 | if (rc) { |
352e5fd1 JS |
2408 | /* not able to set wwpn, unlock it */ |
2409 | phba->soft_wwn_enable = 1; | |
2410 | return rc; | |
2411 | } | |
2412 | ||
2413 | phba->cfg_soft_wwpn = wwn_to_u64(wwpn); | |
2414 | fc_host_port_name(shost) = phba->cfg_soft_wwpn; | |
2415 | if (phba->cfg_soft_wwnn) | |
2416 | fc_host_node_name(shost) = phba->cfg_soft_wwnn; | |
2417 | ||
2418 | dev_printk(KERN_NOTICE, &phba->pcidev->dev, | |
2419 | "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no); | |
2420 | ||
2421 | stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE); | |
2422 | if (stat1) | |
2423 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
2424 | "0463 lpfc_soft_wwpn attribute set failed to " | |
2425 | "reinit adapter - %d\n", stat1); | |
2426 | init_completion(&online_compl); | |
2427 | rc = lpfc_workq_post_event(phba, &stat2, &online_compl, | |
2428 | LPFC_EVT_ONLINE); | |
2429 | if (rc == 0) | |
2430 | return -ENOMEM; | |
2431 | ||
2432 | wait_for_completion(&online_compl); | |
2433 | if (stat2) | |
2434 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
2435 | "0464 lpfc_soft_wwpn attribute set failed to " | |
2436 | "reinit adapter - %d\n", stat2); | |
2437 | return (stat1 || stat2) ? -EIO : count; | |
2438 | } | |
2439 | static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR, | |
2440 | lpfc_soft_wwpn_show, lpfc_soft_wwpn_store); | |
2441 | ||
2442 | /** | |
2443 | * lpfc_soft_wwnn_show - Return the cfg soft ww node name for the adapter | |
2444 | * @dev: class device that is converted into a Scsi_host. | |
2445 | * @attr: device attribute, not used. | |
2446 | * @buf: on return contains the wwnn in hexadecimal. | |
2447 | * | |
2448 | * Returns: size of formatted string. | |
2449 | **/ | |
2450 | static ssize_t | |
2451 | lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr, | |
2452 | char *buf) | |
2453 | { | |
2454 | struct Scsi_Host *shost = class_to_shost(dev); | |
2455 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
2456 | return snprintf(buf, PAGE_SIZE, "0x%llx\n", | |
2457 | (unsigned long long)phba->cfg_soft_wwnn); | |
2458 | } | |
2459 | ||
2460 | /** | |
2461 | * lpfc_soft_wwnn_store - sets the ww node name of the adapter | |
2462 | * @cdev: class device that is converted into a Scsi_host. | |
2463 | * @buf: contains the ww node name in hexadecimal. | |
2464 | * @count: number of wwnn bytes in buf. | |
2465 | * | |
2466 | * Returns: | |
2467 | * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid | |
2468 | * value of count on success | |
2469 | **/ | |
2470 | static ssize_t | |
2471 | lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr, | |
2472 | const char *buf, size_t count) | |
2473 | { | |
2474 | struct Scsi_Host *shost = class_to_shost(dev); | |
2475 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
2476 | unsigned int cnt = count; | |
2477 | u8 wwnn[WWN_SZ]; | |
2478 | int rc; | |
2479 | ||
2480 | /* count may include a LF at end of string */ | |
2481 | if (buf[cnt-1] == '\n') | |
2482 | cnt--; | |
2483 | ||
2484 | if (!phba->soft_wwn_enable) | |
2485 | return -EINVAL; | |
2486 | ||
2487 | rc = lpfc_wwn_set(buf, cnt, wwnn); | |
e2934ed1 | 2488 | if (rc) { |
352e5fd1 JS |
2489 | /* Allow wwnn to be set many times, as long as the enable |
2490 | * is set. However, once the wwpn is set, everything locks. | |
2491 | */ | |
2492 | return rc; | |
2493 | } | |
2494 | ||
2495 | phba->cfg_soft_wwnn = wwn_to_u64(wwnn); | |
2496 | ||
2497 | dev_printk(KERN_NOTICE, &phba->pcidev->dev, | |
2498 | "lpfc%d: soft_wwnn set. Value will take effect upon " | |
2499 | "setting of the soft_wwpn\n", phba->brd_no); | |
2500 | ||
2501 | return count; | |
2502 | } | |
2503 | static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR, | |
2504 | lpfc_soft_wwnn_show, lpfc_soft_wwnn_store); | |
a12e07bc | 2505 | |
1ba981fd JS |
2506 | /** |
2507 | * lpfc_oas_tgt_show - Return wwpn of target whose luns maybe enabled for | |
2508 | * Optimized Access Storage (OAS) operations. | |
2509 | * @dev: class device that is converted into a Scsi_host. | |
2510 | * @attr: device attribute, not used. | |
2511 | * @buf: buffer for passing information. | |
2512 | * | |
2513 | * Returns: | |
2514 | * value of count | |
2515 | **/ | |
2516 | static ssize_t | |
2517 | lpfc_oas_tgt_show(struct device *dev, struct device_attribute *attr, | |
2518 | char *buf) | |
2519 | { | |
2520 | struct Scsi_Host *shost = class_to_shost(dev); | |
2521 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
2522 | ||
2523 | return snprintf(buf, PAGE_SIZE, "0x%llx\n", | |
2524 | wwn_to_u64(phba->cfg_oas_tgt_wwpn)); | |
2525 | } | |
2526 | ||
2527 | /** | |
2528 | * lpfc_oas_tgt_store - Store wwpn of target whose luns maybe enabled for | |
2529 | * Optimized Access Storage (OAS) operations. | |
2530 | * @dev: class device that is converted into a Scsi_host. | |
2531 | * @attr: device attribute, not used. | |
2532 | * @buf: buffer for passing information. | |
2533 | * @count: Size of the data buffer. | |
2534 | * | |
2535 | * Returns: | |
2536 | * -EINVAL count is invalid, invalid wwpn byte invalid | |
2537 | * -EPERM oas is not supported by hba | |
2538 | * value of count on success | |
2539 | **/ | |
2540 | static ssize_t | |
2541 | lpfc_oas_tgt_store(struct device *dev, struct device_attribute *attr, | |
2542 | const char *buf, size_t count) | |
2543 | { | |
2544 | struct Scsi_Host *shost = class_to_shost(dev); | |
2545 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
2546 | unsigned int cnt = count; | |
2547 | uint8_t wwpn[WWN_SZ]; | |
2548 | int rc; | |
2549 | ||
f38fa0bb | 2550 | if (!phba->cfg_fof) |
1ba981fd JS |
2551 | return -EPERM; |
2552 | ||
2553 | /* count may include a LF at end of string */ | |
2554 | if (buf[cnt-1] == '\n') | |
2555 | cnt--; | |
2556 | ||
2557 | rc = lpfc_wwn_set(buf, cnt, wwpn); | |
2558 | if (rc) | |
2559 | return rc; | |
2560 | ||
2561 | memcpy(phba->cfg_oas_tgt_wwpn, wwpn, (8 * sizeof(uint8_t))); | |
2562 | memcpy(phba->sli4_hba.oas_next_tgt_wwpn, wwpn, (8 * sizeof(uint8_t))); | |
2563 | if (wwn_to_u64(wwpn) == 0) | |
2564 | phba->cfg_oas_flags |= OAS_FIND_ANY_TARGET; | |
2565 | else | |
2566 | phba->cfg_oas_flags &= ~OAS_FIND_ANY_TARGET; | |
2567 | phba->cfg_oas_flags &= ~OAS_LUN_VALID; | |
2568 | phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN; | |
2569 | return count; | |
2570 | } | |
2571 | static DEVICE_ATTR(lpfc_xlane_tgt, S_IRUGO | S_IWUSR, | |
2572 | lpfc_oas_tgt_show, lpfc_oas_tgt_store); | |
2573 | ||
c92c841c JS |
2574 | /** |
2575 | * lpfc_oas_priority_show - Return wwpn of target whose luns maybe enabled for | |
2576 | * Optimized Access Storage (OAS) operations. | |
2577 | * @dev: class device that is converted into a Scsi_host. | |
2578 | * @attr: device attribute, not used. | |
2579 | * @buf: buffer for passing information. | |
2580 | * | |
2581 | * Returns: | |
2582 | * value of count | |
2583 | **/ | |
2584 | static ssize_t | |
2585 | lpfc_oas_priority_show(struct device *dev, struct device_attribute *attr, | |
2586 | char *buf) | |
2587 | { | |
2588 | struct Scsi_Host *shost = class_to_shost(dev); | |
2589 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
2590 | ||
2591 | return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_priority); | |
2592 | } | |
2593 | ||
2594 | /** | |
2595 | * lpfc_oas_priority_store - Store wwpn of target whose luns maybe enabled for | |
2596 | * Optimized Access Storage (OAS) operations. | |
2597 | * @dev: class device that is converted into a Scsi_host. | |
2598 | * @attr: device attribute, not used. | |
2599 | * @buf: buffer for passing information. | |
2600 | * @count: Size of the data buffer. | |
2601 | * | |
2602 | * Returns: | |
2603 | * -EINVAL count is invalid, invalid wwpn byte invalid | |
2604 | * -EPERM oas is not supported by hba | |
2605 | * value of count on success | |
2606 | **/ | |
2607 | static ssize_t | |
2608 | lpfc_oas_priority_store(struct device *dev, struct device_attribute *attr, | |
2609 | const char *buf, size_t count) | |
2610 | { | |
2611 | struct Scsi_Host *shost = class_to_shost(dev); | |
2612 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
2613 | unsigned int cnt = count; | |
2614 | unsigned long val; | |
2615 | int ret; | |
2616 | ||
2617 | if (!phba->cfg_fof) | |
2618 | return -EPERM; | |
2619 | ||
2620 | /* count may include a LF at end of string */ | |
2621 | if (buf[cnt-1] == '\n') | |
2622 | cnt--; | |
2623 | ||
2624 | ret = kstrtoul(buf, 0, &val); | |
2625 | if (ret || (val > 0x7f)) | |
2626 | return -EINVAL; | |
2627 | ||
2628 | if (val) | |
2629 | phba->cfg_oas_priority = (uint8_t)val; | |
2630 | else | |
2631 | phba->cfg_oas_priority = phba->cfg_XLanePriority; | |
2632 | return count; | |
2633 | } | |
2634 | static DEVICE_ATTR(lpfc_xlane_priority, S_IRUGO | S_IWUSR, | |
2635 | lpfc_oas_priority_show, lpfc_oas_priority_store); | |
2636 | ||
1ba981fd JS |
2637 | /** |
2638 | * lpfc_oas_vpt_show - Return wwpn of vport whose targets maybe enabled | |
2639 | * for Optimized Access Storage (OAS) operations. | |
2640 | * @dev: class device that is converted into a Scsi_host. | |
2641 | * @attr: device attribute, not used. | |
2642 | * @buf: buffer for passing information. | |
2643 | * | |
2644 | * Returns: | |
2645 | * value of count on success | |
2646 | **/ | |
2647 | static ssize_t | |
2648 | lpfc_oas_vpt_show(struct device *dev, struct device_attribute *attr, | |
2649 | char *buf) | |
2650 | { | |
2651 | struct Scsi_Host *shost = class_to_shost(dev); | |
2652 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
2653 | ||
2654 | return snprintf(buf, PAGE_SIZE, "0x%llx\n", | |
2655 | wwn_to_u64(phba->cfg_oas_vpt_wwpn)); | |
2656 | } | |
2657 | ||
2658 | /** | |
2659 | * lpfc_oas_vpt_store - Store wwpn of vport whose targets maybe enabled | |
2660 | * for Optimized Access Storage (OAS) operations. | |
2661 | * @dev: class device that is converted into a Scsi_host. | |
2662 | * @attr: device attribute, not used. | |
2663 | * @buf: buffer for passing information. | |
2664 | * @count: Size of the data buffer. | |
2665 | * | |
2666 | * Returns: | |
2667 | * -EINVAL count is invalid, invalid wwpn byte invalid | |
2668 | * -EPERM oas is not supported by hba | |
2669 | * value of count on success | |
2670 | **/ | |
2671 | static ssize_t | |
2672 | lpfc_oas_vpt_store(struct device *dev, struct device_attribute *attr, | |
2673 | const char *buf, size_t count) | |
2674 | { | |
2675 | struct Scsi_Host *shost = class_to_shost(dev); | |
2676 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
2677 | unsigned int cnt = count; | |
2678 | uint8_t wwpn[WWN_SZ]; | |
2679 | int rc; | |
2680 | ||
f38fa0bb | 2681 | if (!phba->cfg_fof) |
1ba981fd JS |
2682 | return -EPERM; |
2683 | ||
2684 | /* count may include a LF at end of string */ | |
2685 | if (buf[cnt-1] == '\n') | |
2686 | cnt--; | |
2687 | ||
2688 | rc = lpfc_wwn_set(buf, cnt, wwpn); | |
2689 | if (rc) | |
2690 | return rc; | |
2691 | ||
2692 | memcpy(phba->cfg_oas_vpt_wwpn, wwpn, (8 * sizeof(uint8_t))); | |
2693 | memcpy(phba->sli4_hba.oas_next_vpt_wwpn, wwpn, (8 * sizeof(uint8_t))); | |
2694 | if (wwn_to_u64(wwpn) == 0) | |
2695 | phba->cfg_oas_flags |= OAS_FIND_ANY_VPORT; | |
2696 | else | |
2697 | phba->cfg_oas_flags &= ~OAS_FIND_ANY_VPORT; | |
2698 | phba->cfg_oas_flags &= ~OAS_LUN_VALID; | |
b5749fe1 JS |
2699 | if (phba->cfg_oas_priority == 0) |
2700 | phba->cfg_oas_priority = phba->cfg_XLanePriority; | |
1ba981fd JS |
2701 | phba->sli4_hba.oas_next_lun = FIND_FIRST_OAS_LUN; |
2702 | return count; | |
2703 | } | |
2704 | static DEVICE_ATTR(lpfc_xlane_vpt, S_IRUGO | S_IWUSR, | |
2705 | lpfc_oas_vpt_show, lpfc_oas_vpt_store); | |
2706 | ||
2707 | /** | |
2708 | * lpfc_oas_lun_state_show - Return the current state (enabled or disabled) | |
2709 | * of whether luns will be enabled or disabled | |
2710 | * for Optimized Access Storage (OAS) operations. | |
2711 | * @dev: class device that is converted into a Scsi_host. | |
2712 | * @attr: device attribute, not used. | |
2713 | * @buf: buffer for passing information. | |
2714 | * | |
2715 | * Returns: | |
2716 | * size of formatted string. | |
2717 | **/ | |
2718 | static ssize_t | |
2719 | lpfc_oas_lun_state_show(struct device *dev, struct device_attribute *attr, | |
2720 | char *buf) | |
2721 | { | |
2722 | struct Scsi_Host *shost = class_to_shost(dev); | |
2723 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
2724 | ||
2725 | return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_state); | |
2726 | } | |
2727 | ||
2728 | /** | |
2729 | * lpfc_oas_lun_state_store - Store the state (enabled or disabled) | |
2730 | * of whether luns will be enabled or disabled | |
2731 | * for Optimized Access Storage (OAS) operations. | |
2732 | * @dev: class device that is converted into a Scsi_host. | |
2733 | * @attr: device attribute, not used. | |
2734 | * @buf: buffer for passing information. | |
2735 | * @count: Size of the data buffer. | |
2736 | * | |
2737 | * Returns: | |
2738 | * -EINVAL count is invalid, invalid wwpn byte invalid | |
2739 | * -EPERM oas is not supported by hba | |
2740 | * value of count on success | |
2741 | **/ | |
2742 | static ssize_t | |
2743 | lpfc_oas_lun_state_store(struct device *dev, struct device_attribute *attr, | |
2744 | const char *buf, size_t count) | |
2745 | { | |
2746 | struct Scsi_Host *shost = class_to_shost(dev); | |
2747 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
2748 | int val = 0; | |
2749 | ||
f38fa0bb | 2750 | if (!phba->cfg_fof) |
1ba981fd JS |
2751 | return -EPERM; |
2752 | ||
2753 | if (!isdigit(buf[0])) | |
2754 | return -EINVAL; | |
2755 | ||
2756 | if (sscanf(buf, "%i", &val) != 1) | |
2757 | return -EINVAL; | |
2758 | ||
2759 | if ((val != 0) && (val != 1)) | |
2760 | return -EINVAL; | |
2761 | ||
2762 | phba->cfg_oas_lun_state = val; | |
1ba981fd JS |
2763 | return strlen(buf); |
2764 | } | |
2765 | static DEVICE_ATTR(lpfc_xlane_lun_state, S_IRUGO | S_IWUSR, | |
2766 | lpfc_oas_lun_state_show, lpfc_oas_lun_state_store); | |
2767 | ||
2768 | /** | |
2769 | * lpfc_oas_lun_status_show - Return the status of the Optimized Access | |
2770 | * Storage (OAS) lun returned by the | |
2771 | * lpfc_oas_lun_show function. | |
2772 | * @dev: class device that is converted into a Scsi_host. | |
2773 | * @attr: device attribute, not used. | |
2774 | * @buf: buffer for passing information. | |
2775 | * | |
2776 | * Returns: | |
2777 | * size of formatted string. | |
2778 | **/ | |
2779 | static ssize_t | |
2780 | lpfc_oas_lun_status_show(struct device *dev, struct device_attribute *attr, | |
2781 | char *buf) | |
2782 | { | |
2783 | struct Scsi_Host *shost = class_to_shost(dev); | |
2784 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
2785 | ||
2786 | if (!(phba->cfg_oas_flags & OAS_LUN_VALID)) | |
2787 | return -EFAULT; | |
2788 | ||
2789 | return snprintf(buf, PAGE_SIZE, "%d\n", phba->cfg_oas_lun_status); | |
2790 | } | |
2791 | static DEVICE_ATTR(lpfc_xlane_lun_status, S_IRUGO, | |
2792 | lpfc_oas_lun_status_show, NULL); | |
2793 | ||
2794 | ||
2795 | /** | |
2796 | * lpfc_oas_lun_state_set - enable or disable a lun for Optimized Access Storage | |
2797 | * (OAS) operations. | |
2798 | * @phba: lpfc_hba pointer. | |
2799 | * @ndlp: pointer to fcp target node. | |
2800 | * @lun: the fc lun for setting oas state. | |
2801 | * @oas_state: the oas state to be set to the lun. | |
2802 | * | |
2803 | * Returns: | |
2804 | * SUCCESS : 0 | |
2805 | * -EPERM OAS is not enabled or not supported by this port. | |
2806 | * | |
2807 | */ | |
2808 | static size_t | |
2809 | lpfc_oas_lun_state_set(struct lpfc_hba *phba, uint8_t vpt_wwpn[], | |
c92c841c JS |
2810 | uint8_t tgt_wwpn[], uint64_t lun, |
2811 | uint32_t oas_state, uint8_t pri) | |
1ba981fd JS |
2812 | { |
2813 | ||
2814 | int rc = 0; | |
2815 | ||
f38fa0bb | 2816 | if (!phba->cfg_fof) |
1ba981fd JS |
2817 | return -EPERM; |
2818 | ||
2819 | if (oas_state) { | |
2820 | if (!lpfc_enable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn, | |
c92c841c JS |
2821 | (struct lpfc_name *)tgt_wwpn, |
2822 | lun, pri)) | |
1ba981fd JS |
2823 | rc = -ENOMEM; |
2824 | } else { | |
2825 | lpfc_disable_oas_lun(phba, (struct lpfc_name *)vpt_wwpn, | |
b5749fe1 | 2826 | (struct lpfc_name *)tgt_wwpn, lun, pri); |
1ba981fd JS |
2827 | } |
2828 | return rc; | |
2829 | ||
2830 | } | |
2831 | ||
2832 | /** | |
2833 | * lpfc_oas_lun_get_next - get the next lun that has been enabled for Optimized | |
2834 | * Access Storage (OAS) operations. | |
2835 | * @phba: lpfc_hba pointer. | |
2836 | * @vpt_wwpn: wwpn of the vport associated with the returned lun | |
2837 | * @tgt_wwpn: wwpn of the target associated with the returned lun | |
2838 | * @lun_status: status of the lun returned lun | |
2839 | * | |
2840 | * Returns the first or next lun enabled for OAS operations for the vport/target | |
2841 | * specified. If a lun is found, its vport wwpn, target wwpn and status is | |
2842 | * returned. If the lun is not found, NOT_OAS_ENABLED_LUN is returned. | |
2843 | * | |
2844 | * Return: | |
2845 | * lun that is OAS enabled for the vport/target | |
2846 | * NOT_OAS_ENABLED_LUN when no oas enabled lun found. | |
2847 | */ | |
2848 | static uint64_t | |
2849 | lpfc_oas_lun_get_next(struct lpfc_hba *phba, uint8_t vpt_wwpn[], | |
b5749fe1 JS |
2850 | uint8_t tgt_wwpn[], uint32_t *lun_status, |
2851 | uint32_t *lun_pri) | |
1ba981fd JS |
2852 | { |
2853 | uint64_t found_lun; | |
2854 | ||
2855 | if (unlikely(!phba) || !vpt_wwpn || !tgt_wwpn) | |
2856 | return NOT_OAS_ENABLED_LUN; | |
2857 | if (lpfc_find_next_oas_lun(phba, (struct lpfc_name *) | |
2858 | phba->sli4_hba.oas_next_vpt_wwpn, | |
2859 | (struct lpfc_name *) | |
2860 | phba->sli4_hba.oas_next_tgt_wwpn, | |
2861 | &phba->sli4_hba.oas_next_lun, | |
2862 | (struct lpfc_name *)vpt_wwpn, | |
2863 | (struct lpfc_name *)tgt_wwpn, | |
b5749fe1 | 2864 | &found_lun, lun_status, lun_pri)) |
1ba981fd JS |
2865 | return found_lun; |
2866 | else | |
2867 | return NOT_OAS_ENABLED_LUN; | |
2868 | } | |
2869 | ||
2870 | /** | |
2871 | * lpfc_oas_lun_state_change - enable/disable a lun for OAS operations | |
2872 | * @phba: lpfc_hba pointer. | |
2873 | * @vpt_wwpn: vport wwpn by reference. | |
2874 | * @tgt_wwpn: target wwpn by reference. | |
2875 | * @lun: the fc lun for setting oas state. | |
2876 | * @oas_state: the oas state to be set to the oas_lun. | |
2877 | * | |
2878 | * This routine enables (OAS_LUN_ENABLE) or disables (OAS_LUN_DISABLE) | |
2879 | * a lun for OAS operations. | |
2880 | * | |
2881 | * Return: | |
2882 | * SUCCESS: 0 | |
2883 | * -ENOMEM: failed to enable an lun for OAS operations | |
2884 | * -EPERM: OAS is not enabled | |
2885 | */ | |
2886 | static ssize_t | |
2887 | lpfc_oas_lun_state_change(struct lpfc_hba *phba, uint8_t vpt_wwpn[], | |
2888 | uint8_t tgt_wwpn[], uint64_t lun, | |
c92c841c | 2889 | uint32_t oas_state, uint8_t pri) |
1ba981fd JS |
2890 | { |
2891 | ||
2892 | int rc; | |
2893 | ||
2894 | rc = lpfc_oas_lun_state_set(phba, vpt_wwpn, tgt_wwpn, lun, | |
c92c841c | 2895 | oas_state, pri); |
1ba981fd JS |
2896 | return rc; |
2897 | } | |
2898 | ||
2899 | /** | |
2900 | * lpfc_oas_lun_show - Return oas enabled luns from a chosen target | |
2901 | * @dev: class device that is converted into a Scsi_host. | |
2902 | * @attr: device attribute, not used. | |
2903 | * @buf: buffer for passing information. | |
2904 | * | |
2905 | * This routine returns a lun enabled for OAS each time the function | |
2906 | * is called. | |
2907 | * | |
2908 | * Returns: | |
2909 | * SUCCESS: size of formatted string. | |
2910 | * -EFAULT: target or vport wwpn was not set properly. | |
2911 | * -EPERM: oas is not enabled. | |
2912 | **/ | |
2913 | static ssize_t | |
2914 | lpfc_oas_lun_show(struct device *dev, struct device_attribute *attr, | |
2915 | char *buf) | |
2916 | { | |
2917 | struct Scsi_Host *shost = class_to_shost(dev); | |
2918 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
2919 | ||
2920 | uint64_t oas_lun; | |
2921 | int len = 0; | |
2922 | ||
f38fa0bb | 2923 | if (!phba->cfg_fof) |
1ba981fd JS |
2924 | return -EPERM; |
2925 | ||
2926 | if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0) | |
2927 | if (!(phba->cfg_oas_flags & OAS_FIND_ANY_VPORT)) | |
2928 | return -EFAULT; | |
2929 | ||
2930 | if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0) | |
2931 | if (!(phba->cfg_oas_flags & OAS_FIND_ANY_TARGET)) | |
2932 | return -EFAULT; | |
2933 | ||
2934 | oas_lun = lpfc_oas_lun_get_next(phba, phba->cfg_oas_vpt_wwpn, | |
2935 | phba->cfg_oas_tgt_wwpn, | |
b5749fe1 JS |
2936 | &phba->cfg_oas_lun_status, |
2937 | &phba->cfg_oas_priority); | |
1ba981fd JS |
2938 | if (oas_lun != NOT_OAS_ENABLED_LUN) |
2939 | phba->cfg_oas_flags |= OAS_LUN_VALID; | |
2940 | ||
2941 | len += snprintf(buf + len, PAGE_SIZE-len, "0x%llx", oas_lun); | |
2942 | ||
2943 | return len; | |
2944 | } | |
2945 | ||
2946 | /** | |
2947 | * lpfc_oas_lun_store - Sets the OAS state for lun | |
2948 | * @dev: class device that is converted into a Scsi_host. | |
2949 | * @attr: device attribute, not used. | |
2950 | * @buf: buffer for passing information. | |
2951 | * | |
2952 | * This function sets the OAS state for lun. Before this function is called, | |
2953 | * the vport wwpn, target wwpn, and oas state need to be set. | |
2954 | * | |
2955 | * Returns: | |
2956 | * SUCCESS: size of formatted string. | |
2957 | * -EFAULT: target or vport wwpn was not set properly. | |
2958 | * -EPERM: oas is not enabled. | |
2959 | * size of formatted string. | |
2960 | **/ | |
2961 | static ssize_t | |
2962 | lpfc_oas_lun_store(struct device *dev, struct device_attribute *attr, | |
2963 | const char *buf, size_t count) | |
2964 | { | |
2965 | struct Scsi_Host *shost = class_to_shost(dev); | |
2966 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; | |
2967 | uint64_t scsi_lun; | |
b5749fe1 | 2968 | uint32_t pri; |
1ba981fd JS |
2969 | ssize_t rc; |
2970 | ||
f38fa0bb | 2971 | if (!phba->cfg_fof) |
1ba981fd JS |
2972 | return -EPERM; |
2973 | ||
2974 | if (wwn_to_u64(phba->cfg_oas_vpt_wwpn) == 0) | |
2975 | return -EFAULT; | |
2976 | ||
2977 | if (wwn_to_u64(phba->cfg_oas_tgt_wwpn) == 0) | |
2978 | return -EFAULT; | |
2979 | ||
2980 | if (!isdigit(buf[0])) | |
2981 | return -EINVAL; | |
2982 | ||
2983 | if (sscanf(buf, "0x%llx", &scsi_lun) != 1) | |
2984 | return -EINVAL; | |
2985 | ||
b5749fe1 JS |
2986 | pri = phba->cfg_oas_priority; |
2987 | if (pri == 0) | |
2988 | pri = phba->cfg_XLanePriority; | |
2989 | ||
1ba981fd | 2990 | lpfc_printf_log(phba, KERN_INFO, LOG_INIT, |
c92c841c JS |
2991 | "3372 Try to set vport 0x%llx target 0x%llx lun:0x%llx " |
2992 | "priority 0x%x with oas state %d\n", | |
1ba981fd JS |
2993 | wwn_to_u64(phba->cfg_oas_vpt_wwpn), |
2994 | wwn_to_u64(phba->cfg_oas_tgt_wwpn), scsi_lun, | |
b5749fe1 | 2995 | pri, phba->cfg_oas_lun_state); |
1ba981fd JS |
2996 | |
2997 | rc = lpfc_oas_lun_state_change(phba, phba->cfg_oas_vpt_wwpn, | |
c92c841c | 2998 | phba->cfg_oas_tgt_wwpn, scsi_lun, |
b5749fe1 | 2999 | phba->cfg_oas_lun_state, pri); |
1ba981fd JS |
3000 | if (rc) |
3001 | return rc; | |
3002 | ||
3003 | return count; | |
3004 | } | |
3005 | static DEVICE_ATTR(lpfc_xlane_lun, S_IRUGO | S_IWUSR, | |
3006 | lpfc_oas_lun_show, lpfc_oas_lun_store); | |
c3f28afa | 3007 | |
f358dd0c JS |
3008 | int lpfc_enable_nvmet_cnt; |
3009 | unsigned long long lpfc_enable_nvmet[LPFC_NVMET_MAX_PORTS] = { | |
3010 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
3011 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; | |
3012 | module_param_array(lpfc_enable_nvmet, ullong, &lpfc_enable_nvmet_cnt, 0444); | |
3013 | MODULE_PARM_DESC(lpfc_enable_nvmet, "Enable HBA port(s) WWPN as a NVME Target"); | |
3014 | ||
875fbdfe | 3015 | static int lpfc_poll = 0; |
ab56dc2e | 3016 | module_param(lpfc_poll, int, S_IRUGO); |
875fbdfe JSEC |
3017 | MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:" |
3018 | " 0 - none," | |
3019 | " 1 - poll with interrupts enabled" | |
3020 | " 3 - poll and disable FCP ring interrupts"); | |
3021 | ||
ee959b00 TJ |
3022 | static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR, |
3023 | lpfc_poll_show, lpfc_poll_store); | |
dea3101e | 3024 | |
96418b5e JS |
3025 | int lpfc_no_hba_reset_cnt; |
3026 | unsigned long lpfc_no_hba_reset[MAX_HBAS_NO_RESET] = { | |
3027 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; | |
3028 | module_param_array(lpfc_no_hba_reset, ulong, &lpfc_no_hba_reset_cnt, 0444); | |
3029 | MODULE_PARM_DESC(lpfc_no_hba_reset, "WWPN of HBAs that should not be reset"); | |
3030 | ||
12247e81 JS |
3031 | LPFC_ATTR(sli_mode, 0, 0, 3, |
3032 | "SLI mode selector:" | |
3033 | " 0 - auto (SLI-3 if supported)," | |
3034 | " 2 - select SLI-2 even on SLI-3 capable HBAs," | |
3035 | " 3 - select SLI-3"); | |
92d7f7b0 | 3036 | |
458c083e JS |
3037 | LPFC_ATTR_R(enable_npiv, 1, 0, 1, |
3038 | "Enable NPIV functionality"); | |
92d7f7b0 | 3039 | |
7d791df7 JS |
3040 | LPFC_ATTR_R(fcf_failover_policy, 1, 1, 2, |
3041 | "FCF Fast failover=1 Priority failover=2"); | |
3042 | ||
e5771b4d JS |
3043 | /* |
3044 | # lpfc_enable_rrq: Track XRI/OXID reuse after IO failures | |
3045 | # 0x0 = disabled, XRI/OXID use not tracked. | |
3046 | # 0x1 = XRI/OXID reuse is timed with ratov, RRQ sent. | |
3047 | # 0x2 = XRI/OXID reuse is timed with ratov, No RRQ sent. | |
3048 | */ | |
31202b0e JS |
3049 | LPFC_ATTR_R(enable_rrq, 2, 0, 2, |
3050 | "Enable RRQ functionality"); | |
19ca7609 | 3051 | |
84d1b006 JS |
3052 | /* |
3053 | # lpfc_suppress_link_up: Bring link up at initialization | |
3054 | # 0x0 = bring link up (issue MBX_INIT_LINK) | |
3055 | # 0x1 = do NOT bring link up at initialization(MBX_INIT_LINK) | |
3056 | # 0x2 = never bring up link | |
3057 | # Default value is 0. | |
3058 | */ | |
e40a02c1 JS |
3059 | LPFC_ATTR_R(suppress_link_up, LPFC_INITIALIZE_LINK, LPFC_INITIALIZE_LINK, |
3060 | LPFC_DELAY_INIT_LINK_INDEFINITELY, | |
3061 | "Suppress Link Up at initialization"); | |
2a9bf3d0 JS |
3062 | /* |
3063 | # lpfc_cnt: Number of IOCBs allocated for ELS, CT, and ABTS | |
3064 | # 1 - (1024) | |
3065 | # 2 - (2048) | |
3066 | # 3 - (3072) | |
3067 | # 4 - (4096) | |
3068 | # 5 - (5120) | |
3069 | */ | |
3070 | static ssize_t | |
3071 | lpfc_iocb_hw_show(struct device *dev, struct device_attribute *attr, char *buf) | |
3072 | { | |
3073 | struct Scsi_Host *shost = class_to_shost(dev); | |
3074 | struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba; | |
3075 | ||
3076 | return snprintf(buf, PAGE_SIZE, "%d\n", phba->iocb_max); | |
3077 | } | |
3078 | ||
3079 | static DEVICE_ATTR(iocb_hw, S_IRUGO, | |
3080 | lpfc_iocb_hw_show, NULL); | |
3081 | static ssize_t | |
3082 | lpfc_txq_hw_show(struct device *dev, struct device_attribute *attr, char *buf) | |
3083 | { | |
3084 | struct Scsi_Host *shost = class_to_shost(dev); | |
3085 | struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba; | |
895427bd | 3086 | struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba); |
2a9bf3d0 | 3087 | |
895427bd | 3088 | return snprintf(buf, PAGE_SIZE, "%d\n", pring->txq_max); |
2a9bf3d0 JS |
3089 | } |
3090 | ||
3091 | static DEVICE_ATTR(txq_hw, S_IRUGO, | |
3092 | lpfc_txq_hw_show, NULL); | |
3093 | static ssize_t | |
3094 | lpfc_txcmplq_hw_show(struct device *dev, struct device_attribute *attr, | |
3095 | char *buf) | |
3096 | { | |
3097 | struct Scsi_Host *shost = class_to_shost(dev); | |
3098 | struct lpfc_hba *phba = ((struct lpfc_vport *) shost->hostdata)->phba; | |
895427bd | 3099 | struct lpfc_sli_ring *pring = lpfc_phba_elsring(phba); |
2a9bf3d0 | 3100 | |
895427bd | 3101 | return snprintf(buf, PAGE_SIZE, "%d\n", pring->txcmplq_max); |
2a9bf3d0 JS |
3102 | } |
3103 | ||
3104 | static DEVICE_ATTR(txcmplq_hw, S_IRUGO, | |
3105 | lpfc_txcmplq_hw_show, NULL); | |
3106 | ||
0d8c8ba3 | 3107 | LPFC_ATTR_R(iocb_cnt, 2, 1, 5, |
2a9bf3d0 | 3108 | "Number of IOCBs alloc for ELS, CT, and ABTS: 1k to 5k IOCBs"); |
84d1b006 | 3109 | |
c01f3208 JS |
3110 | /* |
3111 | # lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear | |
3112 | # until the timer expires. Value range is [0,255]. Default value is 30. | |
3113 | */ | |
3114 | static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO; | |
3115 | static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO; | |
3116 | module_param(lpfc_nodev_tmo, int, 0); | |
3117 | MODULE_PARM_DESC(lpfc_nodev_tmo, | |
3118 | "Seconds driver will hold I/O waiting " | |
3119 | "for a device to come back"); | |
e59058c4 JS |
3120 | |
3121 | /** | |
3621a710 | 3122 | * lpfc_nodev_tmo_show - Return the hba dev loss timeout value |
e59058c4 JS |
3123 | * @dev: class converted to a Scsi_host structure. |
3124 | * @attr: device attribute, not used. | |
3125 | * @buf: on return contains the dev loss timeout in decimal. | |
3126 | * | |
3127 | * Returns: size of formatted string. | |
3128 | **/ | |
c01f3208 | 3129 | static ssize_t |
ee959b00 TJ |
3130 | lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr, |
3131 | char *buf) | |
c01f3208 | 3132 | { |
ee959b00 | 3133 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 | 3134 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
e40a02c1 | 3135 | |
3de2a653 | 3136 | return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo); |
c01f3208 JS |
3137 | } |
3138 | ||
e59058c4 | 3139 | /** |
3621a710 | 3140 | * lpfc_nodev_tmo_init - Set the hba nodev timeout value |
e59058c4 JS |
3141 | * @vport: lpfc vport structure pointer. |
3142 | * @val: contains the nodev timeout value. | |
3143 | * | |
3144 | * Description: | |
3145 | * If the devloss tmo is already set then nodev tmo is set to devloss tmo, | |
3146 | * a kernel error message is printed and zero is returned. | |
3147 | * Else if val is in range then nodev tmo and devloss tmo are set to val. | |
3148 | * Otherwise nodev tmo is set to the default value. | |
3149 | * | |
3150 | * Returns: | |
3151 | * zero if already set or if val is in range | |
3152 | * -EINVAL val out of range | |
3153 | **/ | |
c01f3208 | 3154 | static int |
3de2a653 JS |
3155 | lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val) |
3156 | { | |
3157 | if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) { | |
3158 | vport->cfg_nodev_tmo = vport->cfg_devloss_tmo; | |
3159 | if (val != LPFC_DEF_DEVLOSS_TMO) | |
e8b62011 | 3160 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
6c86068d JS |
3161 | "0407 Ignoring lpfc_nodev_tmo module " |
3162 | "parameter because lpfc_devloss_tmo " | |
3163 | "is set.\n"); | |
c01f3208 JS |
3164 | return 0; |
3165 | } | |
3166 | ||
3167 | if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) { | |
3de2a653 JS |
3168 | vport->cfg_nodev_tmo = val; |
3169 | vport->cfg_devloss_tmo = val; | |
c01f3208 JS |
3170 | return 0; |
3171 | } | |
e8b62011 JS |
3172 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
3173 | "0400 lpfc_nodev_tmo attribute cannot be set to" | |
3174 | " %d, allowed range is [%d, %d]\n", | |
3175 | val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO); | |
3de2a653 | 3176 | vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO; |
c01f3208 JS |
3177 | return -EINVAL; |
3178 | } | |
3179 | ||
e59058c4 | 3180 | /** |
3621a710 | 3181 | * lpfc_update_rport_devloss_tmo - Update dev loss tmo value |
e59058c4 JS |
3182 | * @vport: lpfc vport structure pointer. |
3183 | * | |
3184 | * Description: | |
3185 | * Update all the ndlp's dev loss tmo with the vport devloss tmo value. | |
3186 | **/ | |
7054a606 | 3187 | static void |
3de2a653 | 3188 | lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport) |
7054a606 | 3189 | { |
858c9f6c | 3190 | struct Scsi_Host *shost; |
7054a606 JS |
3191 | struct lpfc_nodelist *ndlp; |
3192 | ||
51ef4c26 JS |
3193 | shost = lpfc_shost_from_vport(vport); |
3194 | spin_lock_irq(shost->host_lock); | |
3195 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) | |
e47c9093 | 3196 | if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport) |
51ef4c26 JS |
3197 | ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo; |
3198 | spin_unlock_irq(shost->host_lock); | |
7054a606 JS |
3199 | } |
3200 | ||
e59058c4 | 3201 | /** |
3621a710 | 3202 | * lpfc_nodev_tmo_set - Set the vport nodev tmo and devloss tmo values |
e59058c4 JS |
3203 | * @vport: lpfc vport structure pointer. |
3204 | * @val: contains the tmo value. | |
3205 | * | |
3206 | * Description: | |
3207 | * If the devloss tmo is already set or the vport dev loss tmo has changed | |
3208 | * then a kernel error message is printed and zero is returned. | |
3209 | * Else if val is in range then nodev tmo and devloss tmo are set to val. | |
3210 | * Otherwise nodev tmo is set to the default value. | |
3211 | * | |
3212 | * Returns: | |
3213 | * zero if already set or if val is in range | |
3214 | * -EINVAL val out of range | |
3215 | **/ | |
c01f3208 | 3216 | static int |
3de2a653 | 3217 | lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val) |
c01f3208 | 3218 | { |
3de2a653 JS |
3219 | if (vport->dev_loss_tmo_changed || |
3220 | (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) { | |
e8b62011 | 3221 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
6c86068d JS |
3222 | "0401 Ignoring change to lpfc_nodev_tmo " |
3223 | "because lpfc_devloss_tmo is set.\n"); | |
c01f3208 JS |
3224 | return 0; |
3225 | } | |
c01f3208 | 3226 | if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) { |
3de2a653 JS |
3227 | vport->cfg_nodev_tmo = val; |
3228 | vport->cfg_devloss_tmo = val; | |
0af5d708 MC |
3229 | /* |
3230 | * For compat: set the fc_host dev loss so new rports | |
3231 | * will get the value. | |
3232 | */ | |
3233 | fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val; | |
3de2a653 | 3234 | lpfc_update_rport_devloss_tmo(vport); |
c01f3208 JS |
3235 | return 0; |
3236 | } | |
e8b62011 | 3237 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
6c86068d | 3238 | "0403 lpfc_nodev_tmo attribute cannot be set to " |
e8b62011 JS |
3239 | "%d, allowed range is [%d, %d]\n", |
3240 | val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO); | |
c01f3208 JS |
3241 | return -EINVAL; |
3242 | } | |
3243 | ||
3de2a653 | 3244 | lpfc_vport_param_store(nodev_tmo) |
c01f3208 | 3245 | |
ee959b00 TJ |
3246 | static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR, |
3247 | lpfc_nodev_tmo_show, lpfc_nodev_tmo_store); | |
c01f3208 JS |
3248 | |
3249 | /* | |
3250 | # lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that | |
3251 | # disappear until the timer expires. Value range is [0,255]. Default | |
3252 | # value is 30. | |
3253 | */ | |
ab56dc2e | 3254 | module_param(lpfc_devloss_tmo, int, S_IRUGO); |
c01f3208 JS |
3255 | MODULE_PARM_DESC(lpfc_devloss_tmo, |
3256 | "Seconds driver will hold I/O waiting " | |
3257 | "for a device to come back"); | |
3de2a653 JS |
3258 | lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO, |
3259 | LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO) | |
3260 | lpfc_vport_param_show(devloss_tmo) | |
e59058c4 JS |
3261 | |
3262 | /** | |
3621a710 | 3263 | * lpfc_devloss_tmo_set - Sets vport nodev tmo, devloss tmo values, changed bit |
e59058c4 JS |
3264 | * @vport: lpfc vport structure pointer. |
3265 | * @val: contains the tmo value. | |
3266 | * | |
3267 | * Description: | |
3268 | * If val is in a valid range then set the vport nodev tmo, | |
3269 | * devloss tmo, also set the vport dev loss tmo changed flag. | |
3270 | * Else a kernel error message is printed. | |
3271 | * | |
3272 | * Returns: | |
3273 | * zero if val is in range | |
3274 | * -EINVAL val out of range | |
3275 | **/ | |
c01f3208 | 3276 | static int |
3de2a653 | 3277 | lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val) |
c01f3208 JS |
3278 | { |
3279 | if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) { | |
3de2a653 JS |
3280 | vport->cfg_nodev_tmo = val; |
3281 | vport->cfg_devloss_tmo = val; | |
3282 | vport->dev_loss_tmo_changed = 1; | |
0af5d708 | 3283 | fc_host_dev_loss_tmo(lpfc_shost_from_vport(vport)) = val; |
3de2a653 | 3284 | lpfc_update_rport_devloss_tmo(vport); |
c01f3208 JS |
3285 | return 0; |
3286 | } | |
3287 | ||
e8b62011 | 3288 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
6c86068d JS |
3289 | "0404 lpfc_devloss_tmo attribute cannot be set to " |
3290 | "%d, allowed range is [%d, %d]\n", | |
e8b62011 | 3291 | val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO); |
c01f3208 JS |
3292 | return -EINVAL; |
3293 | } | |
3294 | ||
3de2a653 | 3295 | lpfc_vport_param_store(devloss_tmo) |
ee959b00 TJ |
3296 | static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR, |
3297 | lpfc_devloss_tmo_show, lpfc_devloss_tmo_store); | |
c01f3208 | 3298 | |
f358dd0c JS |
3299 | /* |
3300 | * lpfc_suppress_rsp: Enable suppress rsp feature is firmware supports it | |
3301 | * lpfc_suppress_rsp = 0 Disable | |
3302 | * lpfc_suppress_rsp = 1 Enable (default) | |
3303 | * | |
3304 | */ | |
3305 | LPFC_ATTR_R(suppress_rsp, 1, 0, 1, | |
3306 | "Enable suppress rsp feature is firmware supports it"); | |
3307 | ||
2d7dbc4c JS |
3308 | /* |
3309 | * lpfc_nvmet_mrq: Specify number of RQ pairs for processing NVMET cmds | |
3310 | * lpfc_nvmet_mrq = 1 use a single RQ pair | |
3311 | * lpfc_nvmet_mrq >= 2 use specified RQ pairs for MRQ | |
3312 | * | |
3313 | */ | |
3314 | LPFC_ATTR_R(nvmet_mrq, | |
3315 | 1, 1, 16, | |
3316 | "Specify number of RQ pairs for processing NVMET cmds"); | |
3317 | ||
3318 | /* | |
3319 | * lpfc_nvmet_mrq_post: Specify number buffers to post on every MRQ | |
3320 | * | |
3321 | */ | |
3322 | LPFC_ATTR_R(nvmet_mrq_post, LPFC_DEF_MRQ_POST, | |
3323 | LPFC_MIN_MRQ_POST, LPFC_MAX_MRQ_POST, | |
3324 | "Specify number of buffers to post on every MRQ"); | |
3325 | ||
895427bd JS |
3326 | /* |
3327 | * lpfc_enable_fc4_type: Defines what FC4 types are supported. | |
3328 | * Supported Values: 1 - register just FCP | |
3329 | * 3 - register both FCP and NVME | |
7d708033 | 3330 | * Supported values are [1,3]. Default value is 1 |
895427bd | 3331 | */ |
7d708033 | 3332 | LPFC_ATTR_R(enable_fc4_type, LPFC_ENABLE_FCP, |
895427bd JS |
3333 | LPFC_ENABLE_FCP, LPFC_ENABLE_BOTH, |
3334 | "Define fc4 type to register with fabric."); | |
3335 | ||
3336 | /* | |
3337 | * lpfc_xri_split: Defines the division of XRI resources between SCSI and NVME | |
3338 | * This parameter is only used if: | |
f358dd0c JS |
3339 | * lpfc_enable_fc4_type is 3 - register both FCP and NVME and |
3340 | * port is not configured for NVMET. | |
895427bd JS |
3341 | * |
3342 | * ELS/CT always get 10% of XRIs, up to a maximum of 250 | |
3343 | * The remaining XRIs get split up based on lpfc_xri_split per port: | |
3344 | * | |
3345 | * Supported Values are in percentages | |
3346 | * the xri_split value is the percentage the SCSI port will get. The remaining | |
3347 | * percentage will go to NVME. | |
3348 | */ | |
3349 | LPFC_ATTR_R(xri_split, 50, 10, 90, | |
4410a67a | 3350 | "Division of XRI resources between SCSI and NVME"); |
895427bd | 3351 | |
dea3101e JB |
3352 | /* |
3353 | # lpfc_log_verbose: Only turn this flag on if you are willing to risk being | |
3354 | # deluged with LOTS of information. | |
3355 | # You can set a bit mask to record specific types of verbose messages: | |
f4b4c68f | 3356 | # See lpfc_logmsh.h for definitions. |
dea3101e | 3357 | */ |
f4b4c68f | 3358 | LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffffffff, |
e8b62011 | 3359 | "Verbose logging bit-mask"); |
dea3101e | 3360 | |
7ee5d43e JS |
3361 | /* |
3362 | # lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters | |
3363 | # objects that have been registered with the nameserver after login. | |
3364 | */ | |
cf971240 | 3365 | LPFC_VPORT_ATTR_R(enable_da_id, 1, 0, 1, |
7ee5d43e JS |
3366 | "Deregister nameserver objects before LOGO"); |
3367 | ||
dea3101e JB |
3368 | /* |
3369 | # lun_queue_depth: This parameter is used to limit the number of outstanding | |
572709e2 JS |
3370 | # commands per FCP LUN. Value range is [1,512]. Default value is 30. |
3371 | # If this parameter value is greater than 1/8th the maximum number of exchanges | |
3372 | # supported by the HBA port, then the lun queue depth will be reduced to | |
3373 | # 1/8th the maximum number of exchanges. | |
dea3101e | 3374 | */ |
572709e2 | 3375 | LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 512, |
3de2a653 | 3376 | "Max number of FCP commands we can queue to a specific LUN"); |
dea3101e | 3377 | |
7dc517df JS |
3378 | /* |
3379 | # tgt_queue_depth: This parameter is used to limit the number of outstanding | |
3380 | # commands per target port. Value range is [10,65535]. Default value is 65535. | |
3381 | */ | |
3382 | LPFC_VPORT_ATTR_R(tgt_queue_depth, 65535, 10, 65535, | |
572709e2 | 3383 | "Max number of FCP commands we can queue to a specific target port"); |
7dc517df | 3384 | |
b28485ac JW |
3385 | /* |
3386 | # hba_queue_depth: This parameter is used to limit the number of outstanding | |
3387 | # commands per lpfc HBA. Value range is [32,8192]. If this parameter | |
3388 | # value is greater than the maximum number of exchanges supported by the HBA, | |
3389 | # then maximum number of exchanges supported by the HBA is used to determine | |
3390 | # the hba_queue_depth. | |
3391 | */ | |
3392 | LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192, | |
3393 | "Max number of FCP commands we can queue to a lpfc HBA"); | |
3394 | ||
92d7f7b0 JS |
3395 | /* |
3396 | # peer_port_login: This parameter allows/prevents logins | |
3397 | # between peer ports hosted on the same physical port. | |
3398 | # When this parameter is set 0 peer ports of same physical port | |
3399 | # are not allowed to login to each other. | |
3400 | # When this parameter is set 1 peer ports of same physical port | |
3401 | # are allowed to login to each other. | |
3402 | # Default value of this parameter is 0. | |
3403 | */ | |
3de2a653 JS |
3404 | LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1, |
3405 | "Allow peer ports on the same physical port to login to each " | |
3406 | "other."); | |
92d7f7b0 JS |
3407 | |
3408 | /* | |
3de2a653 | 3409 | # restrict_login: This parameter allows/prevents logins |
92d7f7b0 JS |
3410 | # between Virtual Ports and remote initiators. |
3411 | # When this parameter is not set (0) Virtual Ports will accept PLOGIs from | |
3412 | # other initiators and will attempt to PLOGI all remote ports. | |
3413 | # When this parameter is set (1) Virtual Ports will reject PLOGIs from | |
3414 | # remote ports and will not attempt to PLOGI to other initiators. | |
3415 | # This parameter does not restrict to the physical port. | |
3416 | # This parameter does not restrict logins to Fabric resident remote ports. | |
3417 | # Default value of this parameter is 1. | |
3418 | */ | |
3de2a653 | 3419 | static int lpfc_restrict_login = 1; |
ab56dc2e | 3420 | module_param(lpfc_restrict_login, int, S_IRUGO); |
3de2a653 JS |
3421 | MODULE_PARM_DESC(lpfc_restrict_login, |
3422 | "Restrict virtual ports login to remote initiators."); | |
3423 | lpfc_vport_param_show(restrict_login); | |
3424 | ||
e59058c4 | 3425 | /** |
3621a710 | 3426 | * lpfc_restrict_login_init - Set the vport restrict login flag |
e59058c4 JS |
3427 | * @vport: lpfc vport structure pointer. |
3428 | * @val: contains the restrict login value. | |
3429 | * | |
3430 | * Description: | |
3431 | * If val is not in a valid range then log a kernel error message and set | |
3432 | * the vport restrict login to one. | |
3433 | * If the port type is physical clear the restrict login flag and return. | |
3434 | * Else set the restrict login flag to val. | |
3435 | * | |
3436 | * Returns: | |
3437 | * zero if val is in range | |
3438 | * -EINVAL val out of range | |
3439 | **/ | |
3de2a653 JS |
3440 | static int |
3441 | lpfc_restrict_login_init(struct lpfc_vport *vport, int val) | |
3442 | { | |
3443 | if (val < 0 || val > 1) { | |
e8b62011 | 3444 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
d7c255b2 | 3445 | "0422 lpfc_restrict_login attribute cannot " |
e8b62011 JS |
3446 | "be set to %d, allowed range is [0, 1]\n", |
3447 | val); | |
3de2a653 JS |
3448 | vport->cfg_restrict_login = 1; |
3449 | return -EINVAL; | |
3450 | } | |
3451 | if (vport->port_type == LPFC_PHYSICAL_PORT) { | |
3452 | vport->cfg_restrict_login = 0; | |
3453 | return 0; | |
3454 | } | |
3455 | vport->cfg_restrict_login = val; | |
3456 | return 0; | |
3457 | } | |
3458 | ||
e59058c4 | 3459 | /** |
3621a710 | 3460 | * lpfc_restrict_login_set - Set the vport restrict login flag |
e59058c4 JS |
3461 | * @vport: lpfc vport structure pointer. |
3462 | * @val: contains the restrict login value. | |
3463 | * | |
3464 | * Description: | |
3465 | * If val is not in a valid range then log a kernel error message and set | |
3466 | * the vport restrict login to one. | |
3467 | * If the port type is physical and the val is not zero log a kernel | |
3468 | * error message, clear the restrict login flag and return zero. | |
3469 | * Else set the restrict login flag to val. | |
3470 | * | |
3471 | * Returns: | |
3472 | * zero if val is in range | |
3473 | * -EINVAL val out of range | |
3474 | **/ | |
3de2a653 JS |
3475 | static int |
3476 | lpfc_restrict_login_set(struct lpfc_vport *vport, int val) | |
3477 | { | |
3478 | if (val < 0 || val > 1) { | |
e8b62011 | 3479 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
d7c255b2 | 3480 | "0425 lpfc_restrict_login attribute cannot " |
e8b62011 JS |
3481 | "be set to %d, allowed range is [0, 1]\n", |
3482 | val); | |
3de2a653 JS |
3483 | vport->cfg_restrict_login = 1; |
3484 | return -EINVAL; | |
3485 | } | |
3486 | if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) { | |
e8b62011 JS |
3487 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
3488 | "0468 lpfc_restrict_login must be 0 for " | |
3489 | "Physical ports.\n"); | |
3de2a653 JS |
3490 | vport->cfg_restrict_login = 0; |
3491 | return 0; | |
3492 | } | |
3493 | vport->cfg_restrict_login = val; | |
3494 | return 0; | |
3495 | } | |
3496 | lpfc_vport_param_store(restrict_login); | |
ee959b00 TJ |
3497 | static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR, |
3498 | lpfc_restrict_login_show, lpfc_restrict_login_store); | |
92d7f7b0 | 3499 | |
dea3101e JB |
3500 | /* |
3501 | # Some disk devices have a "select ID" or "select Target" capability. | |
3502 | # From a protocol standpoint "select ID" usually means select the | |
3503 | # Fibre channel "ALPA". In the FC-AL Profile there is an "informative | |
3504 | # annex" which contains a table that maps a "select ID" (a number | |
3505 | # between 0 and 7F) to an ALPA. By default, for compatibility with | |
3506 | # older drivers, the lpfc driver scans this table from low ALPA to high | |
3507 | # ALPA. | |
3508 | # | |
3509 | # Turning on the scan-down variable (on = 1, off = 0) will | |
3510 | # cause the lpfc driver to use an inverted table, effectively | |
3511 | # scanning ALPAs from high to low. Value range is [0,1]. Default value is 1. | |
3512 | # | |
3513 | # (Note: This "select ID" functionality is a LOOP ONLY characteristic | |
3514 | # and will not work across a fabric. Also this parameter will take | |
3515 | # effect only in the case when ALPA map is not available.) | |
3516 | */ | |
3de2a653 JS |
3517 | LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1, |
3518 | "Start scanning for devices from highest ALPA to lowest"); | |
dea3101e | 3519 | |
dea3101e JB |
3520 | /* |
3521 | # lpfc_topology: link topology for init link | |
3522 | # 0x0 = attempt loop mode then point-to-point | |
367c2713 | 3523 | # 0x01 = internal loopback mode |
dea3101e JB |
3524 | # 0x02 = attempt point-to-point mode only |
3525 | # 0x04 = attempt loop mode only | |
3526 | # 0x06 = attempt point-to-point mode then loop | |
3527 | # Set point-to-point mode if you want to run as an N_Port. | |
3528 | # Set loop mode if you want to run as an NL_Port. Value range is [0,0x6]. | |
3529 | # Default value is 0. | |
3530 | */ | |
0a035439 JS |
3531 | LPFC_ATTR(topology, 0, 0, 6, |
3532 | "Select Fibre Channel topology"); | |
e59058c4 JS |
3533 | |
3534 | /** | |
3621a710 | 3535 | * lpfc_topology_set - Set the adapters topology field |
e59058c4 JS |
3536 | * @phba: lpfc_hba pointer. |
3537 | * @val: topology value. | |
3538 | * | |
3539 | * Description: | |
3540 | * If val is in a valid range then set the adapter's topology field and | |
3541 | * issue a lip; if the lip fails reset the topology to the old value. | |
3542 | * | |
3543 | * If the value is not in range log a kernel error message and return an error. | |
3544 | * | |
3545 | * Returns: | |
3546 | * zero if val is in range and lip okay | |
3547 | * non-zero return value from lpfc_issue_lip() | |
3548 | * -EINVAL val out of range | |
3549 | **/ | |
a257bf90 JS |
3550 | static ssize_t |
3551 | lpfc_topology_store(struct device *dev, struct device_attribute *attr, | |
3552 | const char *buf, size_t count) | |
83108bd3 | 3553 | { |
a257bf90 JS |
3554 | struct Scsi_Host *shost = class_to_shost(dev); |
3555 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
3556 | struct lpfc_hba *phba = vport->phba; | |
3557 | int val = 0; | |
3558 | int nolip = 0; | |
3559 | const char *val_buf = buf; | |
83108bd3 JS |
3560 | int err; |
3561 | uint32_t prev_val; | |
a257bf90 JS |
3562 | |
3563 | if (!strncmp(buf, "nolip ", strlen("nolip "))) { | |
3564 | nolip = 1; | |
3565 | val_buf = &buf[strlen("nolip ")]; | |
3566 | } | |
3567 | ||
3568 | if (!isdigit(val_buf[0])) | |
3569 | return -EINVAL; | |
3570 | if (sscanf(val_buf, "%i", &val) != 1) | |
3571 | return -EINVAL; | |
3572 | ||
83108bd3 JS |
3573 | if (val >= 0 && val <= 6) { |
3574 | prev_val = phba->cfg_topology; | |
ff78d8f9 JS |
3575 | if (phba->cfg_link_speed == LPFC_USER_LINK_SPEED_16G && |
3576 | val == 4) { | |
3577 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, | |
3578 | "3113 Loop mode not supported at speed %d\n", | |
d38dd52c | 3579 | val); |
ff78d8f9 JS |
3580 | return -EINVAL; |
3581 | } | |
d38dd52c JS |
3582 | if (phba->pcidev->device == PCI_DEVICE_ID_LANCER_G6_FC && |
3583 | val == 4) { | |
3584 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, | |
3585 | "3114 Loop mode not supported\n"); | |
3586 | return -EINVAL; | |
3587 | } | |
3588 | phba->cfg_topology = val; | |
a257bf90 JS |
3589 | if (nolip) |
3590 | return strlen(buf); | |
3591 | ||
88a2cfbb JS |
3592 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
3593 | "3054 lpfc_topology changed from %d to %d\n", | |
3594 | prev_val, val); | |
e74c03c8 JS |
3595 | if (prev_val != val && phba->sli_rev == LPFC_SLI_REV4) |
3596 | phba->fc_topology_changed = 1; | |
83108bd3 | 3597 | err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport)); |
a257bf90 | 3598 | if (err) { |
83108bd3 | 3599 | phba->cfg_topology = prev_val; |
a257bf90 JS |
3600 | return -EINVAL; |
3601 | } else | |
3602 | return strlen(buf); | |
83108bd3 JS |
3603 | } |
3604 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
3605 | "%d:0467 lpfc_topology attribute cannot be set to %d, " | |
3606 | "allowed range is [0, 6]\n", | |
3607 | phba->brd_no, val); | |
3608 | return -EINVAL; | |
3609 | } | |
0a035439 | 3610 | |
83108bd3 | 3611 | lpfc_param_show(topology) |
ee959b00 | 3612 | static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR, |
83108bd3 | 3613 | lpfc_topology_show, lpfc_topology_store); |
dea3101e | 3614 | |
21e9a0a5 JS |
3615 | /** |
3616 | * lpfc_static_vport_show: Read callback function for | |
3617 | * lpfc_static_vport sysfs file. | |
3618 | * @dev: Pointer to class device object. | |
3619 | * @attr: device attribute structure. | |
3620 | * @buf: Data buffer. | |
3621 | * | |
3622 | * This function is the read call back function for | |
3623 | * lpfc_static_vport sysfs file. The lpfc_static_vport | |
3624 | * sysfs file report the mageability of the vport. | |
3625 | **/ | |
3626 | static ssize_t | |
3627 | lpfc_static_vport_show(struct device *dev, struct device_attribute *attr, | |
3628 | char *buf) | |
3629 | { | |
3630 | struct Scsi_Host *shost = class_to_shost(dev); | |
3631 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
3632 | if (vport->vport_flag & STATIC_VPORT) | |
3633 | sprintf(buf, "1\n"); | |
3634 | else | |
3635 | sprintf(buf, "0\n"); | |
3636 | ||
3637 | return strlen(buf); | |
3638 | } | |
3639 | ||
3640 | /* | |
3641 | * Sysfs attribute to control the statistical data collection. | |
3642 | */ | |
3643 | static DEVICE_ATTR(lpfc_static_vport, S_IRUGO, | |
3644 | lpfc_static_vport_show, NULL); | |
ea2151b4 JS |
3645 | |
3646 | /** | |
3621a710 | 3647 | * lpfc_stat_data_ctrl_store - write call back for lpfc_stat_data_ctrl sysfs file |
ea2151b4 JS |
3648 | * @dev: Pointer to class device. |
3649 | * @buf: Data buffer. | |
3650 | * @count: Size of the data buffer. | |
3651 | * | |
9332ef9d | 3652 | * This function get called when a user write to the lpfc_stat_data_ctrl |
ea2151b4 JS |
3653 | * sysfs file. This function parse the command written to the sysfs file |
3654 | * and take appropriate action. These commands are used for controlling | |
3655 | * driver statistical data collection. | |
3656 | * Following are the command this function handles. | |
3657 | * | |
3658 | * setbucket <bucket_type> <base> <step> | |
3659 | * = Set the latency buckets. | |
3660 | * destroybucket = destroy all the buckets. | |
3661 | * start = start data collection | |
3662 | * stop = stop data collection | |
3663 | * reset = reset the collected data | |
3664 | **/ | |
3665 | static ssize_t | |
3666 | lpfc_stat_data_ctrl_store(struct device *dev, struct device_attribute *attr, | |
3667 | const char *buf, size_t count) | |
3668 | { | |
3669 | struct Scsi_Host *shost = class_to_shost(dev); | |
3670 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
3671 | struct lpfc_hba *phba = vport->phba; | |
3672 | #define LPFC_MAX_DATA_CTRL_LEN 1024 | |
3673 | static char bucket_data[LPFC_MAX_DATA_CTRL_LEN]; | |
3674 | unsigned long i; | |
3675 | char *str_ptr, *token; | |
3676 | struct lpfc_vport **vports; | |
3677 | struct Scsi_Host *v_shost; | |
3678 | char *bucket_type_str, *base_str, *step_str; | |
3679 | unsigned long base, step, bucket_type; | |
3680 | ||
3681 | if (!strncmp(buf, "setbucket", strlen("setbucket"))) { | |
a257bf90 | 3682 | if (strlen(buf) > (LPFC_MAX_DATA_CTRL_LEN - 1)) |
ea2151b4 JS |
3683 | return -EINVAL; |
3684 | ||
eb016566 | 3685 | strncpy(bucket_data, buf, LPFC_MAX_DATA_CTRL_LEN); |
ea2151b4 JS |
3686 | str_ptr = &bucket_data[0]; |
3687 | /* Ignore this token - this is command token */ | |
3688 | token = strsep(&str_ptr, "\t "); | |
3689 | if (!token) | |
3690 | return -EINVAL; | |
3691 | ||
3692 | bucket_type_str = strsep(&str_ptr, "\t "); | |
3693 | if (!bucket_type_str) | |
3694 | return -EINVAL; | |
3695 | ||
3696 | if (!strncmp(bucket_type_str, "linear", strlen("linear"))) | |
3697 | bucket_type = LPFC_LINEAR_BUCKET; | |
3698 | else if (!strncmp(bucket_type_str, "power2", strlen("power2"))) | |
3699 | bucket_type = LPFC_POWER2_BUCKET; | |
3700 | else | |
3701 | return -EINVAL; | |
3702 | ||
3703 | base_str = strsep(&str_ptr, "\t "); | |
3704 | if (!base_str) | |
3705 | return -EINVAL; | |
3706 | base = simple_strtoul(base_str, NULL, 0); | |
3707 | ||
3708 | step_str = strsep(&str_ptr, "\t "); | |
3709 | if (!step_str) | |
3710 | return -EINVAL; | |
3711 | step = simple_strtoul(step_str, NULL, 0); | |
3712 | if (!step) | |
3713 | return -EINVAL; | |
3714 | ||
3715 | /* Block the data collection for every vport */ | |
3716 | vports = lpfc_create_vport_work_array(phba); | |
3717 | if (vports == NULL) | |
3718 | return -ENOMEM; | |
3719 | ||
f4b4c68f | 3720 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
ea2151b4 JS |
3721 | v_shost = lpfc_shost_from_vport(vports[i]); |
3722 | spin_lock_irq(v_shost->host_lock); | |
3723 | /* Block and reset data collection */ | |
3724 | vports[i]->stat_data_blocked = 1; | |
3725 | if (vports[i]->stat_data_enabled) | |
3726 | lpfc_vport_reset_stat_data(vports[i]); | |
3727 | spin_unlock_irq(v_shost->host_lock); | |
3728 | } | |
3729 | ||
3730 | /* Set the bucket attributes */ | |
3731 | phba->bucket_type = bucket_type; | |
3732 | phba->bucket_base = base; | |
3733 | phba->bucket_step = step; | |
3734 | ||
f4b4c68f | 3735 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
ea2151b4 JS |
3736 | v_shost = lpfc_shost_from_vport(vports[i]); |
3737 | ||
3738 | /* Unblock data collection */ | |
3739 | spin_lock_irq(v_shost->host_lock); | |
3740 | vports[i]->stat_data_blocked = 0; | |
3741 | spin_unlock_irq(v_shost->host_lock); | |
3742 | } | |
3743 | lpfc_destroy_vport_work_array(phba, vports); | |
3744 | return strlen(buf); | |
3745 | } | |
3746 | ||
3747 | if (!strncmp(buf, "destroybucket", strlen("destroybucket"))) { | |
3748 | vports = lpfc_create_vport_work_array(phba); | |
3749 | if (vports == NULL) | |
3750 | return -ENOMEM; | |
3751 | ||
f4b4c68f | 3752 | for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) { |
ea2151b4 JS |
3753 | v_shost = lpfc_shost_from_vport(vports[i]); |
3754 | spin_lock_irq(shost->host_lock); | |
3755 | vports[i]->stat_data_blocked = 1; | |
3756 | lpfc_free_bucket(vport); | |
3757 | vport->stat_data_enabled = 0; | |
3758 | vports[i]->stat_data_blocked = 0; | |
3759 | spin_unlock_irq(shost->host_lock); | |
3760 | } | |
3761 | lpfc_destroy_vport_work_array(phba, vports); | |
3762 | phba->bucket_type = LPFC_NO_BUCKET; | |
3763 | phba->bucket_base = 0; | |
3764 | phba->bucket_step = 0; | |
3765 | return strlen(buf); | |
3766 | } | |
3767 | ||
3768 | if (!strncmp(buf, "start", strlen("start"))) { | |
3769 | /* If no buckets configured return error */ | |
3770 | if (phba->bucket_type == LPFC_NO_BUCKET) | |
3771 | return -EINVAL; | |
3772 | spin_lock_irq(shost->host_lock); | |
3773 | if (vport->stat_data_enabled) { | |
3774 | spin_unlock_irq(shost->host_lock); | |
3775 | return strlen(buf); | |
3776 | } | |
3777 | lpfc_alloc_bucket(vport); | |
3778 | vport->stat_data_enabled = 1; | |
3779 | spin_unlock_irq(shost->host_lock); | |
3780 | return strlen(buf); | |
3781 | } | |
3782 | ||
3783 | if (!strncmp(buf, "stop", strlen("stop"))) { | |
3784 | spin_lock_irq(shost->host_lock); | |
3785 | if (vport->stat_data_enabled == 0) { | |
3786 | spin_unlock_irq(shost->host_lock); | |
3787 | return strlen(buf); | |
3788 | } | |
3789 | lpfc_free_bucket(vport); | |
3790 | vport->stat_data_enabled = 0; | |
3791 | spin_unlock_irq(shost->host_lock); | |
3792 | return strlen(buf); | |
3793 | } | |
3794 | ||
3795 | if (!strncmp(buf, "reset", strlen("reset"))) { | |
3796 | if ((phba->bucket_type == LPFC_NO_BUCKET) | |
3797 | || !vport->stat_data_enabled) | |
3798 | return strlen(buf); | |
3799 | spin_lock_irq(shost->host_lock); | |
3800 | vport->stat_data_blocked = 1; | |
3801 | lpfc_vport_reset_stat_data(vport); | |
3802 | vport->stat_data_blocked = 0; | |
3803 | spin_unlock_irq(shost->host_lock); | |
3804 | return strlen(buf); | |
3805 | } | |
3806 | return -EINVAL; | |
3807 | } | |
3808 | ||
3809 | ||
3810 | /** | |
3621a710 | 3811 | * lpfc_stat_data_ctrl_show - Read function for lpfc_stat_data_ctrl sysfs file |
ea2151b4 JS |
3812 | * @dev: Pointer to class device object. |
3813 | * @buf: Data buffer. | |
3814 | * | |
3815 | * This function is the read call back function for | |
3816 | * lpfc_stat_data_ctrl sysfs file. This function report the | |
3817 | * current statistical data collection state. | |
3818 | **/ | |
3819 | static ssize_t | |
3820 | lpfc_stat_data_ctrl_show(struct device *dev, struct device_attribute *attr, | |
3821 | char *buf) | |
3822 | { | |
3823 | struct Scsi_Host *shost = class_to_shost(dev); | |
3824 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
3825 | struct lpfc_hba *phba = vport->phba; | |
3826 | int index = 0; | |
3827 | int i; | |
3828 | char *bucket_type; | |
3829 | unsigned long bucket_value; | |
3830 | ||
3831 | switch (phba->bucket_type) { | |
3832 | case LPFC_LINEAR_BUCKET: | |
3833 | bucket_type = "linear"; | |
3834 | break; | |
3835 | case LPFC_POWER2_BUCKET: | |
3836 | bucket_type = "power2"; | |
3837 | break; | |
3838 | default: | |
3839 | bucket_type = "No Bucket"; | |
3840 | break; | |
3841 | } | |
3842 | ||
3843 | sprintf(&buf[index], "Statistical Data enabled :%d, " | |
3844 | "blocked :%d, Bucket type :%s, Bucket base :%d," | |
3845 | " Bucket step :%d\nLatency Ranges :", | |
3846 | vport->stat_data_enabled, vport->stat_data_blocked, | |
3847 | bucket_type, phba->bucket_base, phba->bucket_step); | |
3848 | index = strlen(buf); | |
3849 | if (phba->bucket_type != LPFC_NO_BUCKET) { | |
3850 | for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) { | |
3851 | if (phba->bucket_type == LPFC_LINEAR_BUCKET) | |
3852 | bucket_value = phba->bucket_base + | |
3853 | phba->bucket_step * i; | |
3854 | else | |
3855 | bucket_value = phba->bucket_base + | |
3856 | (1 << i) * phba->bucket_step; | |
3857 | ||
3858 | if (index + 10 > PAGE_SIZE) | |
3859 | break; | |
3860 | sprintf(&buf[index], "%08ld ", bucket_value); | |
3861 | index = strlen(buf); | |
3862 | } | |
3863 | } | |
3864 | sprintf(&buf[index], "\n"); | |
3865 | return strlen(buf); | |
3866 | } | |
3867 | ||
3868 | /* | |
3869 | * Sysfs attribute to control the statistical data collection. | |
3870 | */ | |
3871 | static DEVICE_ATTR(lpfc_stat_data_ctrl, S_IRUGO | S_IWUSR, | |
3872 | lpfc_stat_data_ctrl_show, lpfc_stat_data_ctrl_store); | |
3873 | ||
3874 | /* | |
3875 | * lpfc_drvr_stat_data: sysfs attr to get driver statistical data. | |
3876 | */ | |
3877 | ||
3878 | /* | |
3879 | * Each Bucket takes 11 characters and 1 new line + 17 bytes WWN | |
3880 | * for each target. | |
3881 | */ | |
3882 | #define STAT_DATA_SIZE_PER_TARGET(NUM_BUCKETS) ((NUM_BUCKETS) * 11 + 18) | |
3883 | #define MAX_STAT_DATA_SIZE_PER_TARGET \ | |
3884 | STAT_DATA_SIZE_PER_TARGET(LPFC_MAX_BUCKET_COUNT) | |
3885 | ||
3886 | ||
3887 | /** | |
3621a710 | 3888 | * sysfs_drvr_stat_data_read - Read function for lpfc_drvr_stat_data attribute |
2c3c8bea | 3889 | * @filp: sysfs file |
ea2151b4 JS |
3890 | * @kobj: Pointer to the kernel object |
3891 | * @bin_attr: Attribute object | |
3892 | * @buff: Buffer pointer | |
3893 | * @off: File offset | |
3894 | * @count: Buffer size | |
3895 | * | |
3896 | * This function is the read call back function for lpfc_drvr_stat_data | |
3897 | * sysfs file. This function export the statistical data to user | |
3898 | * applications. | |
3899 | **/ | |
3900 | static ssize_t | |
2c3c8bea CW |
3901 | sysfs_drvr_stat_data_read(struct file *filp, struct kobject *kobj, |
3902 | struct bin_attribute *bin_attr, | |
ea2151b4 JS |
3903 | char *buf, loff_t off, size_t count) |
3904 | { | |
3905 | struct device *dev = container_of(kobj, struct device, | |
3906 | kobj); | |
3907 | struct Scsi_Host *shost = class_to_shost(dev); | |
3908 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
3909 | struct lpfc_hba *phba = vport->phba; | |
3910 | int i = 0, index = 0; | |
3911 | unsigned long nport_index; | |
3912 | struct lpfc_nodelist *ndlp = NULL; | |
3913 | nport_index = (unsigned long)off / | |
3914 | MAX_STAT_DATA_SIZE_PER_TARGET; | |
3915 | ||
3916 | if (!vport->stat_data_enabled || vport->stat_data_blocked | |
3917 | || (phba->bucket_type == LPFC_NO_BUCKET)) | |
3918 | return 0; | |
3919 | ||
3920 | spin_lock_irq(shost->host_lock); | |
3921 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { | |
3922 | if (!NLP_CHK_NODE_ACT(ndlp) || !ndlp->lat_data) | |
3923 | continue; | |
3924 | ||
3925 | if (nport_index > 0) { | |
3926 | nport_index--; | |
3927 | continue; | |
3928 | } | |
3929 | ||
3930 | if ((index + MAX_STAT_DATA_SIZE_PER_TARGET) | |
3931 | > count) | |
3932 | break; | |
3933 | ||
3934 | if (!ndlp->lat_data) | |
3935 | continue; | |
3936 | ||
3937 | /* Print the WWN */ | |
3938 | sprintf(&buf[index], "%02x%02x%02x%02x%02x%02x%02x%02x:", | |
3939 | ndlp->nlp_portname.u.wwn[0], | |
3940 | ndlp->nlp_portname.u.wwn[1], | |
3941 | ndlp->nlp_portname.u.wwn[2], | |
3942 | ndlp->nlp_portname.u.wwn[3], | |
3943 | ndlp->nlp_portname.u.wwn[4], | |
3944 | ndlp->nlp_portname.u.wwn[5], | |
3945 | ndlp->nlp_portname.u.wwn[6], | |
3946 | ndlp->nlp_portname.u.wwn[7]); | |
3947 | ||
3948 | index = strlen(buf); | |
3949 | ||
3950 | for (i = 0; i < LPFC_MAX_BUCKET_COUNT; i++) { | |
3951 | sprintf(&buf[index], "%010u,", | |
3952 | ndlp->lat_data[i].cmd_count); | |
3953 | index = strlen(buf); | |
3954 | } | |
3955 | sprintf(&buf[index], "\n"); | |
3956 | index = strlen(buf); | |
3957 | } | |
3958 | spin_unlock_irq(shost->host_lock); | |
3959 | return index; | |
3960 | } | |
3961 | ||
3962 | static struct bin_attribute sysfs_drvr_stat_data_attr = { | |
3963 | .attr = { | |
3964 | .name = "lpfc_drvr_stat_data", | |
3965 | .mode = S_IRUSR, | |
ea2151b4 JS |
3966 | }, |
3967 | .size = LPFC_MAX_TARGET * MAX_STAT_DATA_SIZE_PER_TARGET, | |
3968 | .read = sysfs_drvr_stat_data_read, | |
3969 | .write = NULL, | |
3970 | }; | |
3971 | ||
dea3101e JB |
3972 | /* |
3973 | # lpfc_link_speed: Link speed selection for initializing the Fibre Channel | |
3974 | # connection. | |
76a95d75 | 3975 | # Value range is [0,16]. Default value is 0. |
dea3101e | 3976 | */ |
e59058c4 | 3977 | /** |
3621a710 | 3978 | * lpfc_link_speed_set - Set the adapters link speed |
e59058c4 JS |
3979 | * @phba: lpfc_hba pointer. |
3980 | * @val: link speed value. | |
3981 | * | |
3982 | * Description: | |
3983 | * If val is in a valid range then set the adapter's link speed field and | |
3984 | * issue a lip; if the lip fails reset the link speed to the old value. | |
3985 | * | |
3986 | * Notes: | |
3987 | * If the value is not in range log a kernel error message and return an error. | |
3988 | * | |
3989 | * Returns: | |
3990 | * zero if val is in range and lip okay. | |
3991 | * non-zero return value from lpfc_issue_lip() | |
3992 | * -EINVAL val out of range | |
3993 | **/ | |
a257bf90 JS |
3994 | static ssize_t |
3995 | lpfc_link_speed_store(struct device *dev, struct device_attribute *attr, | |
3996 | const char *buf, size_t count) | |
83108bd3 | 3997 | { |
a257bf90 JS |
3998 | struct Scsi_Host *shost = class_to_shost(dev); |
3999 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
4000 | struct lpfc_hba *phba = vport->phba; | |
76a95d75 | 4001 | int val = LPFC_USER_LINK_SPEED_AUTO; |
a257bf90 JS |
4002 | int nolip = 0; |
4003 | const char *val_buf = buf; | |
83108bd3 | 4004 | int err; |
c691816e JS |
4005 | uint32_t prev_val, if_type; |
4006 | ||
4007 | if_type = bf_get(lpfc_sli_intf_if_type, &phba->sli4_hba.sli_intf); | |
4008 | if (if_type == LPFC_SLI_INTF_IF_TYPE_2 && | |
4009 | phba->hba_flag & HBA_FORCED_LINK_SPEED) | |
4010 | return -EPERM; | |
83108bd3 | 4011 | |
a257bf90 JS |
4012 | if (!strncmp(buf, "nolip ", strlen("nolip "))) { |
4013 | nolip = 1; | |
4014 | val_buf = &buf[strlen("nolip ")]; | |
4015 | } | |
4016 | ||
4017 | if (!isdigit(val_buf[0])) | |
4018 | return -EINVAL; | |
4019 | if (sscanf(val_buf, "%i", &val) != 1) | |
4020 | return -EINVAL; | |
4021 | ||
88a2cfbb JS |
4022 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
4023 | "3055 lpfc_link_speed changed from %d to %d %s\n", | |
4024 | phba->cfg_link_speed, val, nolip ? "(nolip)" : "(lip)"); | |
4025 | ||
76a95d75 JS |
4026 | if (((val == LPFC_USER_LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) || |
4027 | ((val == LPFC_USER_LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) || | |
4028 | ((val == LPFC_USER_LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) || | |
4029 | ((val == LPFC_USER_LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) || | |
4030 | ((val == LPFC_USER_LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)) || | |
d38dd52c JS |
4031 | ((val == LPFC_USER_LINK_SPEED_16G) && !(phba->lmt & LMT_16Gb)) || |
4032 | ((val == LPFC_USER_LINK_SPEED_32G) && !(phba->lmt & LMT_32Gb))) { | |
76a95d75 JS |
4033 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
4034 | "2879 lpfc_link_speed attribute cannot be set " | |
4035 | "to %d. Speed is not supported by this port.\n", | |
4036 | val); | |
83108bd3 | 4037 | return -EINVAL; |
76a95d75 | 4038 | } |
ff78d8f9 JS |
4039 | if (val == LPFC_USER_LINK_SPEED_16G && |
4040 | phba->fc_topology == LPFC_TOPOLOGY_LOOP) { | |
4041 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4042 | "3112 lpfc_link_speed attribute cannot be set " | |
4043 | "to %d. Speed is not supported in loop mode.\n", | |
4044 | val); | |
4045 | return -EINVAL; | |
4046 | } | |
76a95d75 JS |
4047 | if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) && |
4048 | (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) { | |
83108bd3 JS |
4049 | prev_val = phba->cfg_link_speed; |
4050 | phba->cfg_link_speed = val; | |
a257bf90 JS |
4051 | if (nolip) |
4052 | return strlen(buf); | |
4053 | ||
83108bd3 | 4054 | err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport)); |
a257bf90 | 4055 | if (err) { |
83108bd3 | 4056 | phba->cfg_link_speed = prev_val; |
a257bf90 JS |
4057 | return -EINVAL; |
4058 | } else | |
4059 | return strlen(buf); | |
83108bd3 | 4060 | } |
83108bd3 | 4061 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, |
76a95d75 JS |
4062 | "0469 lpfc_link_speed attribute cannot be set to %d, " |
4063 | "allowed values are ["LPFC_LINK_SPEED_STRING"]\n", val); | |
83108bd3 JS |
4064 | return -EINVAL; |
4065 | } | |
4066 | ||
4067 | static int lpfc_link_speed = 0; | |
ab56dc2e | 4068 | module_param(lpfc_link_speed, int, S_IRUGO); |
83108bd3 JS |
4069 | MODULE_PARM_DESC(lpfc_link_speed, "Select link speed"); |
4070 | lpfc_param_show(link_speed) | |
e59058c4 JS |
4071 | |
4072 | /** | |
3621a710 | 4073 | * lpfc_link_speed_init - Set the adapters link speed |
e59058c4 JS |
4074 | * @phba: lpfc_hba pointer. |
4075 | * @val: link speed value. | |
4076 | * | |
4077 | * Description: | |
4078 | * If val is in a valid range then set the adapter's link speed field. | |
4079 | * | |
4080 | * Notes: | |
4081 | * If the value is not in range log a kernel error message, clear the link | |
4082 | * speed and return an error. | |
4083 | * | |
4084 | * Returns: | |
4085 | * zero if val saved. | |
4086 | * -EINVAL val out of range | |
4087 | **/ | |
83108bd3 JS |
4088 | static int |
4089 | lpfc_link_speed_init(struct lpfc_hba *phba, int val) | |
4090 | { | |
ff78d8f9 JS |
4091 | if (val == LPFC_USER_LINK_SPEED_16G && phba->cfg_topology == 4) { |
4092 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4093 | "3111 lpfc_link_speed of %d cannot " | |
4094 | "support loop mode, setting topology to default.\n", | |
4095 | val); | |
4096 | phba->cfg_topology = 0; | |
4097 | } | |
76a95d75 JS |
4098 | if ((val >= 0) && (val <= LPFC_USER_LINK_SPEED_MAX) && |
4099 | (LPFC_USER_LINK_SPEED_BITMAP & (1 << val))) { | |
83108bd3 JS |
4100 | phba->cfg_link_speed = val; |
4101 | return 0; | |
4102 | } | |
4103 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
d7c255b2 | 4104 | "0405 lpfc_link_speed attribute cannot " |
83108bd3 JS |
4105 | "be set to %d, allowed values are " |
4106 | "["LPFC_LINK_SPEED_STRING"]\n", val); | |
76a95d75 | 4107 | phba->cfg_link_speed = LPFC_USER_LINK_SPEED_AUTO; |
83108bd3 JS |
4108 | return -EINVAL; |
4109 | } | |
4110 | ||
ee959b00 | 4111 | static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR, |
76a95d75 | 4112 | lpfc_link_speed_show, lpfc_link_speed_store); |
dea3101e | 4113 | |
0d878419 JS |
4114 | /* |
4115 | # lpfc_aer_support: Support PCIe device Advanced Error Reporting (AER) | |
4116 | # 0 = aer disabled or not supported | |
4117 | # 1 = aer supported and enabled (default) | |
4118 | # Value range is [0,1]. Default value is 1. | |
4119 | */ | |
506139a2 JS |
4120 | LPFC_ATTR(aer_support, 1, 0, 1, |
4121 | "Enable PCIe device AER support"); | |
4122 | lpfc_param_show(aer_support) | |
0d878419 JS |
4123 | |
4124 | /** | |
4125 | * lpfc_aer_support_store - Set the adapter for aer support | |
4126 | * | |
4127 | * @dev: class device that is converted into a Scsi_host. | |
4128 | * @attr: device attribute, not used. | |
912e3acd | 4129 | * @buf: containing enable or disable aer flag. |
0d878419 JS |
4130 | * @count: unused variable. |
4131 | * | |
4132 | * Description: | |
4133 | * If the val is 1 and currently the device's AER capability was not | |
4134 | * enabled, invoke the kernel's enable AER helper routine, trying to | |
4135 | * enable the device's AER capability. If the helper routine enabling | |
4136 | * AER returns success, update the device's cfg_aer_support flag to | |
4137 | * indicate AER is supported by the device; otherwise, if the device | |
4138 | * AER capability is already enabled to support AER, then do nothing. | |
4139 | * | |
4140 | * If the val is 0 and currently the device's AER support was enabled, | |
4141 | * invoke the kernel's disable AER helper routine. After that, update | |
4142 | * the device's cfg_aer_support flag to indicate AER is not supported | |
4143 | * by the device; otherwise, if the device AER capability is already | |
4144 | * disabled from supporting AER, then do nothing. | |
4145 | * | |
4146 | * Returns: | |
4147 | * length of the buf on success if val is in range the intended mode | |
4148 | * is supported. | |
4149 | * -EINVAL if val out of range or intended mode is not supported. | |
4150 | **/ | |
4151 | static ssize_t | |
4152 | lpfc_aer_support_store(struct device *dev, struct device_attribute *attr, | |
4153 | const char *buf, size_t count) | |
4154 | { | |
4155 | struct Scsi_Host *shost = class_to_shost(dev); | |
4156 | struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata; | |
4157 | struct lpfc_hba *phba = vport->phba; | |
4158 | int val = 0, rc = -EINVAL; | |
4159 | ||
4160 | if (!isdigit(buf[0])) | |
4161 | return -EINVAL; | |
4162 | if (sscanf(buf, "%i", &val) != 1) | |
4163 | return -EINVAL; | |
4164 | ||
4165 | switch (val) { | |
4166 | case 0: | |
4167 | if (phba->hba_flag & HBA_AER_ENABLED) { | |
4168 | rc = pci_disable_pcie_error_reporting(phba->pcidev); | |
4169 | if (!rc) { | |
4170 | spin_lock_irq(&phba->hbalock); | |
4171 | phba->hba_flag &= ~HBA_AER_ENABLED; | |
4172 | spin_unlock_irq(&phba->hbalock); | |
4173 | phba->cfg_aer_support = 0; | |
4174 | rc = strlen(buf); | |
4175 | } else | |
891478a2 JS |
4176 | rc = -EPERM; |
4177 | } else { | |
0d878419 | 4178 | phba->cfg_aer_support = 0; |
891478a2 JS |
4179 | rc = strlen(buf); |
4180 | } | |
0d878419 JS |
4181 | break; |
4182 | case 1: | |
4183 | if (!(phba->hba_flag & HBA_AER_ENABLED)) { | |
4184 | rc = pci_enable_pcie_error_reporting(phba->pcidev); | |
4185 | if (!rc) { | |
4186 | spin_lock_irq(&phba->hbalock); | |
4187 | phba->hba_flag |= HBA_AER_ENABLED; | |
4188 | spin_unlock_irq(&phba->hbalock); | |
4189 | phba->cfg_aer_support = 1; | |
4190 | rc = strlen(buf); | |
4191 | } else | |
891478a2 JS |
4192 | rc = -EPERM; |
4193 | } else { | |
0d878419 | 4194 | phba->cfg_aer_support = 1; |
891478a2 JS |
4195 | rc = strlen(buf); |
4196 | } | |
0d878419 JS |
4197 | break; |
4198 | default: | |
4199 | rc = -EINVAL; | |
4200 | break; | |
4201 | } | |
4202 | return rc; | |
4203 | } | |
4204 | ||
0d878419 JS |
4205 | static DEVICE_ATTR(lpfc_aer_support, S_IRUGO | S_IWUSR, |
4206 | lpfc_aer_support_show, lpfc_aer_support_store); | |
4207 | ||
4208 | /** | |
4209 | * lpfc_aer_cleanup_state - Clean up aer state to the aer enabled device | |
4210 | * @dev: class device that is converted into a Scsi_host. | |
4211 | * @attr: device attribute, not used. | |
912e3acd | 4212 | * @buf: containing flag 1 for aer cleanup state. |
0d878419 JS |
4213 | * @count: unused variable. |
4214 | * | |
4215 | * Description: | |
4216 | * If the @buf contains 1 and the device currently has the AER support | |
4217 | * enabled, then invokes the kernel AER helper routine | |
4218 | * pci_cleanup_aer_uncorrect_error_status to clean up the uncorrectable | |
4219 | * error status register. | |
4220 | * | |
4221 | * Notes: | |
4222 | * | |
4223 | * Returns: | |
4224 | * -EINVAL if the buf does not contain the 1 or the device is not currently | |
4225 | * enabled with the AER support. | |
4226 | **/ | |
4227 | static ssize_t | |
4228 | lpfc_aer_cleanup_state(struct device *dev, struct device_attribute *attr, | |
4229 | const char *buf, size_t count) | |
4230 | { | |
4231 | struct Scsi_Host *shost = class_to_shost(dev); | |
4232 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
4233 | struct lpfc_hba *phba = vport->phba; | |
4234 | int val, rc = -1; | |
4235 | ||
4236 | if (!isdigit(buf[0])) | |
4237 | return -EINVAL; | |
4238 | if (sscanf(buf, "%i", &val) != 1) | |
4239 | return -EINVAL; | |
891478a2 JS |
4240 | if (val != 1) |
4241 | return -EINVAL; | |
0d878419 | 4242 | |
891478a2 | 4243 | if (phba->hba_flag & HBA_AER_ENABLED) |
0d878419 JS |
4244 | rc = pci_cleanup_aer_uncorrect_error_status(phba->pcidev); |
4245 | ||
4246 | if (rc == 0) | |
4247 | return strlen(buf); | |
4248 | else | |
891478a2 | 4249 | return -EPERM; |
0d878419 JS |
4250 | } |
4251 | ||
4252 | static DEVICE_ATTR(lpfc_aer_state_cleanup, S_IWUSR, NULL, | |
4253 | lpfc_aer_cleanup_state); | |
4254 | ||
912e3acd JS |
4255 | /** |
4256 | * lpfc_sriov_nr_virtfn_store - Enable the adapter for sr-iov virtual functions | |
4257 | * | |
4258 | * @dev: class device that is converted into a Scsi_host. | |
4259 | * @attr: device attribute, not used. | |
4260 | * @buf: containing the string the number of vfs to be enabled. | |
4261 | * @count: unused variable. | |
4262 | * | |
4263 | * Description: | |
4264 | * When this api is called either through user sysfs, the driver shall | |
4265 | * try to enable or disable SR-IOV virtual functions according to the | |
4266 | * following: | |
4267 | * | |
4268 | * If zero virtual function has been enabled to the physical function, | |
4269 | * the driver shall invoke the pci enable virtual function api trying | |
4270 | * to enable the virtual functions. If the nr_vfn provided is greater | |
4271 | * than the maximum supported, the maximum virtual function number will | |
4272 | * be used for invoking the api; otherwise, the nr_vfn provided shall | |
4273 | * be used for invoking the api. If the api call returned success, the | |
4274 | * actual number of virtual functions enabled will be set to the driver | |
4275 | * cfg_sriov_nr_virtfn; otherwise, -EINVAL shall be returned and driver | |
4276 | * cfg_sriov_nr_virtfn remains zero. | |
4277 | * | |
4278 | * If none-zero virtual functions have already been enabled to the | |
4279 | * physical function, as reflected by the driver's cfg_sriov_nr_virtfn, | |
4280 | * -EINVAL will be returned and the driver does nothing; | |
4281 | * | |
4282 | * If the nr_vfn provided is zero and none-zero virtual functions have | |
4283 | * been enabled, as indicated by the driver's cfg_sriov_nr_virtfn, the | |
4284 | * disabling virtual function api shall be invoded to disable all the | |
4285 | * virtual functions and driver's cfg_sriov_nr_virtfn shall be set to | |
4286 | * zero. Otherwise, if zero virtual function has been enabled, do | |
4287 | * nothing. | |
4288 | * | |
4289 | * Returns: | |
4290 | * length of the buf on success if val is in range the intended mode | |
4291 | * is supported. | |
4292 | * -EINVAL if val out of range or intended mode is not supported. | |
4293 | **/ | |
4294 | static ssize_t | |
4295 | lpfc_sriov_nr_virtfn_store(struct device *dev, struct device_attribute *attr, | |
4296 | const char *buf, size_t count) | |
4297 | { | |
4298 | struct Scsi_Host *shost = class_to_shost(dev); | |
4299 | struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata; | |
4300 | struct lpfc_hba *phba = vport->phba; | |
4301 | struct pci_dev *pdev = phba->pcidev; | |
4302 | int val = 0, rc = -EINVAL; | |
4303 | ||
4304 | /* Sanity check on user data */ | |
4305 | if (!isdigit(buf[0])) | |
4306 | return -EINVAL; | |
4307 | if (sscanf(buf, "%i", &val) != 1) | |
4308 | return -EINVAL; | |
4309 | if (val < 0) | |
4310 | return -EINVAL; | |
4311 | ||
4312 | /* Request disabling virtual functions */ | |
4313 | if (val == 0) { | |
4314 | if (phba->cfg_sriov_nr_virtfn > 0) { | |
4315 | pci_disable_sriov(pdev); | |
4316 | phba->cfg_sriov_nr_virtfn = 0; | |
4317 | } | |
4318 | return strlen(buf); | |
4319 | } | |
4320 | ||
4321 | /* Request enabling virtual functions */ | |
4322 | if (phba->cfg_sriov_nr_virtfn > 0) { | |
4323 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4324 | "3018 There are %d virtual functions " | |
4325 | "enabled on physical function.\n", | |
4326 | phba->cfg_sriov_nr_virtfn); | |
4327 | return -EEXIST; | |
4328 | } | |
4329 | ||
4330 | if (val <= LPFC_MAX_VFN_PER_PFN) | |
4331 | phba->cfg_sriov_nr_virtfn = val; | |
4332 | else { | |
4333 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
4334 | "3019 Enabling %d virtual functions is not " | |
4335 | "allowed.\n", val); | |
4336 | return -EINVAL; | |
4337 | } | |
4338 | ||
4339 | rc = lpfc_sli_probe_sriov_nr_virtfn(phba, phba->cfg_sriov_nr_virtfn); | |
4340 | if (rc) { | |
4341 | phba->cfg_sriov_nr_virtfn = 0; | |
4342 | rc = -EPERM; | |
4343 | } else | |
4344 | rc = strlen(buf); | |
4345 | ||
4346 | return rc; | |
4347 | } | |
4348 | ||
0cfbbf2f JS |
4349 | LPFC_ATTR(sriov_nr_virtfn, LPFC_DEF_VFN_PER_PFN, 0, LPFC_MAX_VFN_PER_PFN, |
4350 | "Enable PCIe device SR-IOV virtual fn"); | |
912e3acd | 4351 | |
0cfbbf2f | 4352 | lpfc_param_show(sriov_nr_virtfn) |
912e3acd JS |
4353 | static DEVICE_ATTR(lpfc_sriov_nr_virtfn, S_IRUGO | S_IWUSR, |
4354 | lpfc_sriov_nr_virtfn_show, lpfc_sriov_nr_virtfn_store); | |
4355 | ||
c71ab861 JS |
4356 | /** |
4357 | * lpfc_request_firmware_store - Request for Linux generic firmware upgrade | |
4358 | * | |
4359 | * @dev: class device that is converted into a Scsi_host. | |
4360 | * @attr: device attribute, not used. | |
4361 | * @buf: containing the string the number of vfs to be enabled. | |
4362 | * @count: unused variable. | |
4363 | * | |
4364 | * Description: | |
4365 | * | |
4366 | * Returns: | |
4367 | * length of the buf on success if val is in range the intended mode | |
4368 | * is supported. | |
4369 | * -EINVAL if val out of range or intended mode is not supported. | |
4370 | **/ | |
4371 | static ssize_t | |
4372 | lpfc_request_firmware_upgrade_store(struct device *dev, | |
4373 | struct device_attribute *attr, | |
4374 | const char *buf, size_t count) | |
4375 | { | |
4376 | struct Scsi_Host *shost = class_to_shost(dev); | |
4377 | struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata; | |
4378 | struct lpfc_hba *phba = vport->phba; | |
4379 | int val = 0, rc = -EINVAL; | |
4380 | ||
4381 | /* Sanity check on user data */ | |
4382 | if (!isdigit(buf[0])) | |
4383 | return -EINVAL; | |
4384 | if (sscanf(buf, "%i", &val) != 1) | |
4385 | return -EINVAL; | |
4386 | if (val != 1) | |
4387 | return -EINVAL; | |
4388 | ||
4389 | rc = lpfc_sli4_request_firmware_update(phba, RUN_FW_UPGRADE); | |
4390 | if (rc) | |
4391 | rc = -EPERM; | |
4392 | else | |
4393 | rc = strlen(buf); | |
4394 | return rc; | |
4395 | } | |
4396 | ||
4397 | static int lpfc_req_fw_upgrade; | |
4398 | module_param(lpfc_req_fw_upgrade, int, S_IRUGO|S_IWUSR); | |
4399 | MODULE_PARM_DESC(lpfc_req_fw_upgrade, "Enable Linux generic firmware upgrade"); | |
4400 | lpfc_param_show(request_firmware_upgrade) | |
4401 | ||
4402 | /** | |
4403 | * lpfc_request_firmware_upgrade_init - Enable initial linux generic fw upgrade | |
4404 | * @phba: lpfc_hba pointer. | |
4405 | * @val: 0 or 1. | |
4406 | * | |
4407 | * Description: | |
4408 | * Set the initial Linux generic firmware upgrade enable or disable flag. | |
4409 | * | |
4410 | * Returns: | |
4411 | * zero if val saved. | |
4412 | * -EINVAL val out of range | |
4413 | **/ | |
4414 | static int | |
4415 | lpfc_request_firmware_upgrade_init(struct lpfc_hba *phba, int val) | |
4416 | { | |
4417 | if (val >= 0 && val <= 1) { | |
4418 | phba->cfg_request_firmware_upgrade = val; | |
4419 | return 0; | |
4420 | } | |
4421 | return -EINVAL; | |
4422 | } | |
4423 | static DEVICE_ATTR(lpfc_req_fw_upgrade, S_IRUGO | S_IWUSR, | |
4424 | lpfc_request_firmware_upgrade_show, | |
4425 | lpfc_request_firmware_upgrade_store); | |
4426 | ||
173edbb2 JS |
4427 | /** |
4428 | * lpfc_fcp_imax_store | |
4429 | * | |
4430 | * @dev: class device that is converted into a Scsi_host. | |
4431 | * @attr: device attribute, not used. | |
4432 | * @buf: string with the number of fast-path FCP interrupts per second. | |
4433 | * @count: unused variable. | |
4434 | * | |
4435 | * Description: | |
4436 | * If val is in a valid range [636,651042], then set the adapter's | |
4437 | * maximum number of fast-path FCP interrupts per second. | |
4438 | * | |
4439 | * Returns: | |
4440 | * length of the buf on success if val is in range the intended mode | |
4441 | * is supported. | |
4442 | * -EINVAL if val out of range or intended mode is not supported. | |
4443 | **/ | |
4444 | static ssize_t | |
4445 | lpfc_fcp_imax_store(struct device *dev, struct device_attribute *attr, | |
4446 | const char *buf, size_t count) | |
4447 | { | |
4448 | struct Scsi_Host *shost = class_to_shost(dev); | |
4449 | struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata; | |
4450 | struct lpfc_hba *phba = vport->phba; | |
4451 | int val = 0, i; | |
4452 | ||
bf8dae83 JS |
4453 | /* fcp_imax is only valid for SLI4 */ |
4454 | if (phba->sli_rev != LPFC_SLI_REV4) | |
4455 | return -EINVAL; | |
4456 | ||
173edbb2 JS |
4457 | /* Sanity check on user data */ |
4458 | if (!isdigit(buf[0])) | |
4459 | return -EINVAL; | |
4460 | if (sscanf(buf, "%i", &val) != 1) | |
4461 | return -EINVAL; | |
4462 | ||
bf8dae83 JS |
4463 | /* |
4464 | * Value range for the HBA is [5000,5000000] | |
4465 | * The value for each EQ depends on how many EQs are configured. | |
895427bd | 4466 | * Allow value == 0 |
bf8dae83 | 4467 | */ |
895427bd | 4468 | if (val && (val < LPFC_MIN_IMAX || val > LPFC_MAX_IMAX)) |
173edbb2 JS |
4469 | return -EINVAL; |
4470 | ||
4471 | phba->cfg_fcp_imax = (uint32_t)val; | |
43140ca6 JS |
4472 | |
4473 | for (i = 0; i < phba->io_channel_irqs; i += LPFC_MAX_EQ_DELAY_EQID_CNT) | |
895427bd | 4474 | lpfc_modify_hba_eq_delay(phba, i); |
173edbb2 JS |
4475 | |
4476 | return strlen(buf); | |
4477 | } | |
4478 | ||
4479 | /* | |
4480 | # lpfc_fcp_imax: The maximum number of fast-path FCP interrupts per second | |
bf8dae83 | 4481 | # for the HBA. |
173edbb2 | 4482 | # |
bf8dae83 | 4483 | # Value range is [5,000 to 5,000,000]. Default value is 50,000. |
173edbb2 | 4484 | */ |
bf8dae83 | 4485 | static int lpfc_fcp_imax = LPFC_DEF_IMAX; |
173edbb2 JS |
4486 | module_param(lpfc_fcp_imax, int, S_IRUGO|S_IWUSR); |
4487 | MODULE_PARM_DESC(lpfc_fcp_imax, | |
bf8dae83 | 4488 | "Set the maximum number of FCP interrupts per second per HBA"); |
173edbb2 JS |
4489 | lpfc_param_show(fcp_imax) |
4490 | ||
4491 | /** | |
4492 | * lpfc_fcp_imax_init - Set the initial sr-iov virtual function enable | |
4493 | * @phba: lpfc_hba pointer. | |
4494 | * @val: link speed value. | |
4495 | * | |
4496 | * Description: | |
4497 | * If val is in a valid range [636,651042], then initialize the adapter's | |
4498 | * maximum number of fast-path FCP interrupts per second. | |
4499 | * | |
4500 | * Returns: | |
4501 | * zero if val saved. | |
4502 | * -EINVAL val out of range | |
4503 | **/ | |
4504 | static int | |
4505 | lpfc_fcp_imax_init(struct lpfc_hba *phba, int val) | |
4506 | { | |
bf8dae83 JS |
4507 | if (phba->sli_rev != LPFC_SLI_REV4) { |
4508 | phba->cfg_fcp_imax = 0; | |
4509 | return 0; | |
4510 | } | |
4511 | ||
895427bd JS |
4512 | if ((val >= LPFC_MIN_IMAX && val <= LPFC_MAX_IMAX) || |
4513 | (val == 0)) { | |
173edbb2 JS |
4514 | phba->cfg_fcp_imax = val; |
4515 | return 0; | |
4516 | } | |
4517 | ||
4518 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6c86068d JS |
4519 | "3016 lpfc_fcp_imax: %d out of range, using default\n", |
4520 | val); | |
bf8dae83 | 4521 | phba->cfg_fcp_imax = LPFC_DEF_IMAX; |
173edbb2 JS |
4522 | |
4523 | return 0; | |
4524 | } | |
4525 | ||
4526 | static DEVICE_ATTR(lpfc_fcp_imax, S_IRUGO | S_IWUSR, | |
4527 | lpfc_fcp_imax_show, lpfc_fcp_imax_store); | |
4528 | ||
7bb03bbf JS |
4529 | /** |
4530 | * lpfc_state_show - Display current driver CPU affinity | |
4531 | * @dev: class converted to a Scsi_host structure. | |
4532 | * @attr: device attribute, not used. | |
4533 | * @buf: on return contains text describing the state of the link. | |
4534 | * | |
4535 | * Returns: size of formatted string. | |
4536 | **/ | |
4537 | static ssize_t | |
4538 | lpfc_fcp_cpu_map_show(struct device *dev, struct device_attribute *attr, | |
4539 | char *buf) | |
4540 | { | |
4541 | struct Scsi_Host *shost = class_to_shost(dev); | |
4542 | struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata; | |
4543 | struct lpfc_hba *phba = vport->phba; | |
4544 | struct lpfc_vector_map_info *cpup; | |
76fd07a6 | 4545 | int len = 0; |
7bb03bbf JS |
4546 | |
4547 | if ((phba->sli_rev != LPFC_SLI_REV4) || | |
4548 | (phba->intr_type != MSIX)) | |
4549 | return len; | |
4550 | ||
4551 | switch (phba->cfg_fcp_cpu_map) { | |
4552 | case 0: | |
4553 | len += snprintf(buf + len, PAGE_SIZE-len, | |
4554 | "fcp_cpu_map: No mapping (%d)\n", | |
4555 | phba->cfg_fcp_cpu_map); | |
4556 | return len; | |
4557 | case 1: | |
4558 | len += snprintf(buf + len, PAGE_SIZE-len, | |
4559 | "fcp_cpu_map: HBA centric mapping (%d): " | |
4560 | "%d online CPUs\n", | |
4561 | phba->cfg_fcp_cpu_map, | |
4562 | phba->sli4_hba.num_online_cpu); | |
4563 | break; | |
4564 | case 2: | |
4565 | len += snprintf(buf + len, PAGE_SIZE-len, | |
4566 | "fcp_cpu_map: Driver centric mapping (%d): " | |
4567 | "%d online CPUs\n", | |
4568 | phba->cfg_fcp_cpu_map, | |
4569 | phba->sli4_hba.num_online_cpu); | |
4570 | break; | |
4571 | } | |
4572 | ||
76fd07a6 JS |
4573 | while (phba->sli4_hba.curr_disp_cpu < phba->sli4_hba.num_present_cpu) { |
4574 | cpup = &phba->sli4_hba.cpu_map[phba->sli4_hba.curr_disp_cpu]; | |
4575 | ||
4576 | /* margin should fit in this and the truncated message */ | |
7bb03bbf JS |
4577 | if (cpup->irq == LPFC_VECTOR_MAP_EMPTY) |
4578 | len += snprintf(buf + len, PAGE_SIZE-len, | |
4579 | "CPU %02d io_chan %02d " | |
4580 | "physid %d coreid %d\n", | |
76fd07a6 JS |
4581 | phba->sli4_hba.curr_disp_cpu, |
4582 | cpup->channel_id, cpup->phys_id, | |
7bb03bbf JS |
4583 | cpup->core_id); |
4584 | else | |
4585 | len += snprintf(buf + len, PAGE_SIZE-len, | |
4586 | "CPU %02d io_chan %02d " | |
4587 | "physid %d coreid %d IRQ %d\n", | |
76fd07a6 JS |
4588 | phba->sli4_hba.curr_disp_cpu, |
4589 | cpup->channel_id, cpup->phys_id, | |
7bb03bbf JS |
4590 | cpup->core_id, cpup->irq); |
4591 | ||
76fd07a6 JS |
4592 | phba->sli4_hba.curr_disp_cpu++; |
4593 | ||
4594 | /* display max number of CPUs keeping some margin */ | |
4595 | if (phba->sli4_hba.curr_disp_cpu < | |
4596 | phba->sli4_hba.num_present_cpu && | |
4597 | (len >= (PAGE_SIZE - 64))) { | |
4598 | len += snprintf(buf + len, PAGE_SIZE-len, "more...\n"); | |
4599 | break; | |
4600 | } | |
7bb03bbf | 4601 | } |
76fd07a6 JS |
4602 | |
4603 | if (phba->sli4_hba.curr_disp_cpu == phba->sli4_hba.num_present_cpu) | |
4604 | phba->sli4_hba.curr_disp_cpu = 0; | |
4605 | ||
7bb03bbf JS |
4606 | return len; |
4607 | } | |
4608 | ||
4609 | /** | |
4610 | * lpfc_fcp_cpu_map_store - Change CPU affinity of driver vectors | |
4611 | * @dev: class device that is converted into a Scsi_host. | |
4612 | * @attr: device attribute, not used. | |
4613 | * @buf: one or more lpfc_polling_flags values. | |
4614 | * @count: not used. | |
4615 | * | |
4616 | * Returns: | |
4617 | * -EINVAL - Not implemented yet. | |
4618 | **/ | |
4619 | static ssize_t | |
4620 | lpfc_fcp_cpu_map_store(struct device *dev, struct device_attribute *attr, | |
4621 | const char *buf, size_t count) | |
4622 | { | |
4623 | int status = -EINVAL; | |
4624 | return status; | |
4625 | } | |
4626 | ||
4627 | /* | |
4628 | # lpfc_fcp_cpu_map: Defines how to map CPUs to IRQ vectors | |
4629 | # for the HBA. | |
4630 | # | |
4631 | # Value range is [0 to 2]. Default value is LPFC_DRIVER_CPU_MAP (2). | |
4632 | # 0 - Do not affinitze IRQ vectors | |
4633 | # 1 - Affintize HBA vectors with respect to each HBA | |
4634 | # (start with CPU0 for each HBA) | |
4635 | # 2 - Affintize HBA vectors with respect to the entire driver | |
4636 | # (round robin thru all CPUs across all HBAs) | |
4637 | */ | |
4638 | static int lpfc_fcp_cpu_map = LPFC_DRIVER_CPU_MAP; | |
4639 | module_param(lpfc_fcp_cpu_map, int, S_IRUGO|S_IWUSR); | |
4640 | MODULE_PARM_DESC(lpfc_fcp_cpu_map, | |
4641 | "Defines how to map CPUs to IRQ vectors per HBA"); | |
4642 | ||
4643 | /** | |
4644 | * lpfc_fcp_cpu_map_init - Set the initial sr-iov virtual function enable | |
4645 | * @phba: lpfc_hba pointer. | |
4646 | * @val: link speed value. | |
4647 | * | |
4648 | * Description: | |
4649 | * If val is in a valid range [0-2], then affinitze the adapter's | |
4650 | * MSIX vectors. | |
4651 | * | |
4652 | * Returns: | |
4653 | * zero if val saved. | |
4654 | * -EINVAL val out of range | |
4655 | **/ | |
4656 | static int | |
4657 | lpfc_fcp_cpu_map_init(struct lpfc_hba *phba, int val) | |
4658 | { | |
4659 | if (phba->sli_rev != LPFC_SLI_REV4) { | |
4660 | phba->cfg_fcp_cpu_map = 0; | |
4661 | return 0; | |
4662 | } | |
4663 | ||
4664 | if (val >= LPFC_MIN_CPU_MAP && val <= LPFC_MAX_CPU_MAP) { | |
4665 | phba->cfg_fcp_cpu_map = val; | |
4666 | return 0; | |
4667 | } | |
4668 | ||
4669 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
6c86068d JS |
4670 | "3326 lpfc_fcp_cpu_map: %d out of range, using " |
4671 | "default\n", val); | |
7bb03bbf JS |
4672 | phba->cfg_fcp_cpu_map = LPFC_DRIVER_CPU_MAP; |
4673 | ||
4674 | return 0; | |
4675 | } | |
4676 | ||
4677 | static DEVICE_ATTR(lpfc_fcp_cpu_map, S_IRUGO | S_IWUSR, | |
4678 | lpfc_fcp_cpu_map_show, lpfc_fcp_cpu_map_store); | |
4679 | ||
dea3101e JB |
4680 | /* |
4681 | # lpfc_fcp_class: Determines FC class to use for the FCP protocol. | |
4682 | # Value range is [2,3]. Default value is 3. | |
4683 | */ | |
3de2a653 JS |
4684 | LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3, |
4685 | "Select Fibre Channel class of service for FCP sequences"); | |
dea3101e JB |
4686 | |
4687 | /* | |
4688 | # lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range | |
4689 | # is [0,1]. Default value is 0. | |
4690 | */ | |
3de2a653 JS |
4691 | LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1, |
4692 | "Use ADISC on rediscovery to authenticate FCP devices"); | |
dea3101e | 4693 | |
3cb01c57 JS |
4694 | /* |
4695 | # lpfc_first_burst_size: First burst size to use on the NPorts | |
4696 | # that support first burst. | |
4697 | # Value range is [0,65536]. Default value is 0. | |
4698 | */ | |
4699 | LPFC_VPORT_ATTR_RW(first_burst_size, 0, 0, 65536, | |
4700 | "First burst size for Targets that support first burst"); | |
4701 | ||
895427bd | 4702 | /* |
2d7dbc4c JS |
4703 | * lpfc_nvmet_fb_size: NVME Target mode supported first burst size. |
4704 | * When the driver is configured as an NVME target, this value is | |
4705 | * communicated to the NVME initiator in the PRLI response. It is | |
4706 | * used only when the lpfc_nvme_enable_fb and lpfc_nvmet_support | |
4707 | * parameters are set and the target is sending the PRLI RSP. | |
895427bd | 4708 | * Parameter supported on physical port only - no NPIV support. |
2d7dbc4c | 4709 | * Value range is [0,65536]. Default value is 0. |
895427bd | 4710 | */ |
2d7dbc4c JS |
4711 | LPFC_ATTR_RW(nvmet_fb_size, 0, 0, 65536, |
4712 | "NVME Target mode first burst size in 512B increments."); | |
4713 | ||
4714 | /* | |
4715 | * lpfc_nvme_enable_fb: Enable NVME first burst on I and T functions. | |
4716 | * For the Initiator (I), enabling this parameter means that an NVMET | |
4717 | * PRLI response with FBA enabled and an FB_SIZE set to a nonzero value will be | |
4718 | * processed by the initiator for subsequent NVME FCP IO. For the target | |
4719 | * function (T), enabling this parameter qualifies the lpfc_nvmet_fb_size | |
4720 | * driver parameter as the target function's first burst size returned to the | |
4721 | * initiator in the target's NVME PRLI response. Parameter supported on physical | |
4722 | * port only - no NPIV support. | |
4723 | * Value range is [0,1]. Default value is 0 (disabled). | |
4724 | */ | |
895427bd JS |
4725 | LPFC_ATTR_RW(nvme_enable_fb, 0, 0, 1, |
4726 | "Enable First Burst feature on I and T functions."); | |
4727 | ||
977b5a0a JS |
4728 | /* |
4729 | # lpfc_max_scsicmpl_time: Use scsi command completion time to control I/O queue | |
4730 | # depth. Default value is 0. When the value of this parameter is zero the | |
4731 | # SCSI command completion time is not used for controlling I/O queue depth. When | |
4732 | # the parameter is set to a non-zero value, the I/O queue depth is controlled | |
4733 | # to limit the I/O completion time to the parameter value. | |
4734 | # The value is set in milliseconds. | |
4735 | */ | |
ed5b1529 | 4736 | LPFC_VPORT_ATTR(max_scsicmpl_time, 0, 0, 60000, |
977b5a0a | 4737 | "Use command completion time to control queue depth"); |
ed5b1529 | 4738 | |
977b5a0a | 4739 | lpfc_vport_param_show(max_scsicmpl_time); |
977b5a0a JS |
4740 | static int |
4741 | lpfc_max_scsicmpl_time_set(struct lpfc_vport *vport, int val) | |
4742 | { | |
4743 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); | |
4744 | struct lpfc_nodelist *ndlp, *next_ndlp; | |
4745 | ||
4746 | if (val == vport->cfg_max_scsicmpl_time) | |
4747 | return 0; | |
4748 | if ((val < 0) || (val > 60000)) | |
4749 | return -EINVAL; | |
4750 | vport->cfg_max_scsicmpl_time = val; | |
4751 | ||
4752 | spin_lock_irq(shost->host_lock); | |
4753 | list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) { | |
4754 | if (!NLP_CHK_NODE_ACT(ndlp)) | |
4755 | continue; | |
4756 | if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) | |
4757 | continue; | |
7dc517df | 4758 | ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth; |
977b5a0a JS |
4759 | } |
4760 | spin_unlock_irq(shost->host_lock); | |
4761 | return 0; | |
4762 | } | |
4763 | lpfc_vport_param_store(max_scsicmpl_time); | |
4764 | static DEVICE_ATTR(lpfc_max_scsicmpl_time, S_IRUGO | S_IWUSR, | |
4765 | lpfc_max_scsicmpl_time_show, | |
4766 | lpfc_max_scsicmpl_time_store); | |
4767 | ||
dea3101e JB |
4768 | /* |
4769 | # lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value | |
4770 | # range is [0,1]. Default value is 0. | |
4771 | */ | |
4772 | LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support"); | |
4773 | ||
49aa143d | 4774 | /* |
895427bd JS |
4775 | * lpfc_io_sched: Determine scheduling algrithmn for issuing FCP cmds |
4776 | * range is [0,1]. Default value is 0. | |
4777 | * For [0], FCP commands are issued to Work Queues ina round robin fashion. | |
4778 | * For [1], FCP commands are issued to a Work Queue associated with the | |
4779 | * current CPU. | |
4780 | * | |
4781 | * LPFC_FCP_SCHED_ROUND_ROBIN == 0 | |
4782 | * LPFC_FCP_SCHED_BY_CPU == 1 | |
4783 | * | |
4784 | * The driver dynamically sets this to 1 (BY_CPU) if it's able to set up cpu | |
4785 | * affinity for FCP/NVME I/Os through Work Queues associated with the current | |
4786 | * CPU. Otherwise, the default 0 (Round Robin) scheduling of FCP/NVME I/Os | |
4787 | * through WQs will be used. | |
4788 | */ | |
4789 | LPFC_ATTR_RW(fcp_io_sched, LPFC_FCP_SCHED_ROUND_ROBIN, | |
4790 | LPFC_FCP_SCHED_ROUND_ROBIN, | |
4791 | LPFC_FCP_SCHED_BY_CPU, | |
4792 | "Determine scheduling algorithm for " | |
4793 | "issuing commands [0] - Round Robin, [1] - Current CPU"); | |
49aa143d | 4794 | |
a6571c6e JS |
4795 | /* |
4796 | # lpfc_fcp2_no_tgt_reset: Determine bus reset behavior | |
4797 | # range is [0,1]. Default value is 0. | |
4798 | # For [0], bus reset issues target reset to ALL devices | |
4799 | # For [1], bus reset issues target reset to non-FCP2 devices | |
4800 | */ | |
4801 | LPFC_ATTR_RW(fcp2_no_tgt_reset, 0, 0, 1, "Determine bus reset behavior for " | |
4802 | "FCP2 devices [0] - issue tgt reset, [1] - no tgt reset"); | |
4803 | ||
4804 | ||
dea3101e JB |
4805 | /* |
4806 | # lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing | |
4807 | # cr_delay (msec) or cr_count outstanding commands. cr_delay can take | |
7054a606 | 4808 | # value [0,63]. cr_count can take value [1,255]. Default value of cr_delay |
dea3101e JB |
4809 | # is 0. Default value of cr_count is 1. The cr_count feature is disabled if |
4810 | # cr_delay is set to 0. | |
4811 | */ | |
8189fd19 | 4812 | LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an " |
dea3101e JB |
4813 | "interrupt response is generated"); |
4814 | ||
8189fd19 | 4815 | LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an " |
dea3101e JB |
4816 | "interrupt response is generated"); |
4817 | ||
cf5bf97e JW |
4818 | /* |
4819 | # lpfc_multi_ring_support: Determines how many rings to spread available | |
4820 | # cmd/rsp IOCB entries across. | |
4821 | # Value range is [1,2]. Default value is 1. | |
4822 | */ | |
4823 | LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary " | |
4824 | "SLI rings to spread IOCB entries across"); | |
4825 | ||
a4bc3379 JS |
4826 | /* |
4827 | # lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this | |
4828 | # identifies what rctl value to configure the additional ring for. | |
4829 | # Value range is [1,0xff]. Default value is 4 (Unsolicated Data). | |
4830 | */ | |
6a9c52cf | 4831 | LPFC_ATTR_R(multi_ring_rctl, FC_RCTL_DD_UNSOL_DATA, 1, |
a4bc3379 JS |
4832 | 255, "Identifies RCTL for additional ring configuration"); |
4833 | ||
4834 | /* | |
4835 | # lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this | |
4836 | # identifies what type value to configure the additional ring for. | |
4837 | # Value range is [1,0xff]. Default value is 5 (LLC/SNAP). | |
4838 | */ | |
6a9c52cf | 4839 | LPFC_ATTR_R(multi_ring_type, FC_TYPE_IP, 1, |
a4bc3379 JS |
4840 | 255, "Identifies TYPE for additional ring configuration"); |
4841 | ||
dea3101e | 4842 | /* |
4258e98e JS |
4843 | # lpfc_enable_SmartSAN: Sets up FDMI support for SmartSAN |
4844 | # 0 = SmartSAN functionality disabled (default) | |
4845 | # 1 = SmartSAN functionality enabled | |
4846 | # This parameter will override the value of lpfc_fdmi_on module parameter. | |
4847 | # Value range is [0,1]. Default value is 0. | |
dea3101e | 4848 | */ |
4258e98e JS |
4849 | LPFC_ATTR_R(enable_SmartSAN, 0, 0, 1, "Enable SmartSAN functionality"); |
4850 | ||
4851 | /* | |
4852 | # lpfc_fdmi_on: Controls FDMI support. | |
4853 | # 0 No FDMI support (default) | |
4854 | # 1 Traditional FDMI support | |
8663cbbe JS |
4855 | # Traditional FDMI support means the driver will assume FDMI-2 support; |
4856 | # however, if that fails, it will fallback to FDMI-1. | |
4857 | # If lpfc_enable_SmartSAN is set to 1, the driver ignores lpfc_fdmi_on. | |
4858 | # If lpfc_enable_SmartSAN is set 0, the driver uses the current value of | |
4859 | # lpfc_fdmi_on. | |
4860 | # Value range [0,1]. Default value is 0. | |
4258e98e | 4861 | */ |
8663cbbe | 4862 | LPFC_ATTR_R(fdmi_on, 0, 0, 1, "Enable FDMI support"); |
dea3101e JB |
4863 | |
4864 | /* | |
4865 | # Specifies the maximum number of ELS cmds we can have outstanding (for | |
4866 | # discovery). Value range is [1,64]. Default value = 32. | |
4867 | */ | |
3de2a653 | 4868 | LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands " |
dea3101e JB |
4869 | "during discovery"); |
4870 | ||
4871 | /* | |
c4a7c922 JS |
4872 | # lpfc_max_luns: maximum allowed LUN ID. This is the highest LUN ID that |
4873 | # will be scanned by the SCSI midlayer when sequential scanning is | |
4874 | # used; and is also the highest LUN ID allowed when the SCSI midlayer | |
4875 | # parses REPORT_LUN responses. The lpfc driver has no LUN count or | |
4876 | # LUN ID limit, but the SCSI midlayer requires this field for the uses | |
4877 | # above. The lpfc driver limits the default value to 255 for two reasons. | |
4878 | # As it bounds the sequential scan loop, scanning for thousands of luns | |
4879 | # on a target can take minutes of wall clock time. Additionally, | |
4880 | # there are FC targets, such as JBODs, that only recognize 8-bits of | |
4881 | # LUN ID. When they receive a value greater than 8 bits, they chop off | |
4882 | # the high order bits. In other words, they see LUN IDs 0, 256, 512, | |
4883 | # and so on all as LUN ID 0. This causes the linux kernel, which sees | |
4884 | # valid responses at each of the LUN IDs, to believe there are multiple | |
4885 | # devices present, when in fact, there is only 1. | |
4886 | # A customer that is aware of their target behaviors, and the results as | |
4887 | # indicated above, is welcome to increase the lpfc_max_luns value. | |
4888 | # As mentioned, this value is not used by the lpfc driver, only the | |
4889 | # SCSI midlayer. | |
65a29c16 JS |
4890 | # Value range is [0,65535]. Default value is 255. |
4891 | # NOTE: The SCSI layer might probe all allowed LUN on some old targets. | |
dea3101e | 4892 | */ |
1abf635d | 4893 | LPFC_VPORT_ULL_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN ID"); |
dea3101e | 4894 | |
875fbdfe JSEC |
4895 | /* |
4896 | # lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring. | |
4897 | # Value range is [1,255], default value is 10. | |
4898 | */ | |
4899 | LPFC_ATTR_RW(poll_tmo, 10, 1, 255, | |
4900 | "Milliseconds driver will wait between polling FCP ring"); | |
4901 | ||
4ff43246 | 4902 | /* |
0c411222 JS |
4903 | # lpfc_task_mgmt_tmo: Maximum time to wait for task management commands |
4904 | # to complete in seconds. Value range is [5,180], default value is 60. | |
4905 | */ | |
4906 | LPFC_ATTR_RW(task_mgmt_tmo, 60, 5, 180, | |
4907 | "Maximum time to wait for task management commands to complete"); | |
4908 | /* | |
4ff43246 JS |
4909 | # lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that |
4910 | # support this feature | |
8605c46c | 4911 | # 0 = MSI disabled |
4ff43246 | 4912 | # 1 = MSI enabled |
8605c46c GK |
4913 | # 2 = MSI-X enabled (default) |
4914 | # Value range is [0,2]. Default value is 2. | |
4ff43246 | 4915 | */ |
8605c46c | 4916 | LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or " |
db2378e0 | 4917 | "MSI-X (2), if possible"); |
4ff43246 | 4918 | |
67d12733 | 4919 | /* |
f358dd0c | 4920 | * lpfc_nvme_oas: Use the oas bit when sending NVME/NVMET IOs |
895427bd JS |
4921 | * |
4922 | * 0 = NVME OAS disabled | |
4923 | * 1 = NVME OAS enabled | |
4924 | * | |
4925 | * Value range is [0,1]. Default value is 0. | |
4926 | */ | |
4927 | LPFC_ATTR_RW(nvme_oas, 0, 0, 1, | |
4928 | "Use OAS bit on NVME IOs"); | |
4929 | ||
4930 | /* | |
4931 | * lpfc_fcp_io_channel: Set the number of FCP IO channels the driver | |
4932 | * will advertise it supports to the SCSI layer. This also will map to | |
4933 | * the number of WQs the driver will create. | |
4934 | * | |
4935 | * 0 = Configure the number of io channels to the number of active CPUs. | |
4936 | * 1,32 = Manually specify how many io channels to use. | |
4937 | * | |
4938 | * Value range is [0,32]. Default value is 4. | |
4939 | */ | |
4940 | LPFC_ATTR_R(fcp_io_channel, | |
4941 | LPFC_FCP_IO_CHAN_DEF, | |
4942 | LPFC_HBA_IO_CHAN_MIN, LPFC_HBA_IO_CHAN_MAX, | |
67d12733 JS |
4943 | "Set the number of FCP I/O channels"); |
4944 | ||
895427bd JS |
4945 | /* |
4946 | * lpfc_nvme_io_channel: Set the number of IO hardware queues the driver | |
4947 | * will advertise it supports to the NVME layer. This also will map to | |
4948 | * the number of WQs the driver will create. | |
4949 | * | |
4950 | * This module parameter is valid when lpfc_enable_fc4_type is set | |
4951 | * to support NVME. | |
4952 | * | |
4953 | * The NVME Layer will try to create this many, plus 1 administrative | |
4954 | * hardware queue. The administrative queue will always map to WQ 0 | |
4955 | * A hardware IO queue maps (qidx) to a specific driver WQ. | |
4956 | * | |
4957 | * 0 = Configure the number of io channels to the number of active CPUs. | |
4958 | * 1,32 = Manually specify how many io channels to use. | |
4959 | * | |
4960 | * Value range is [0,32]. Default value is 0. | |
4961 | */ | |
4962 | LPFC_ATTR_R(nvme_io_channel, | |
4963 | LPFC_NVME_IO_CHAN_DEF, | |
4964 | LPFC_HBA_IO_CHAN_MIN, LPFC_HBA_IO_CHAN_MAX, | |
4965 | "Set the number of NVME I/O channels"); | |
4966 | ||
13815c83 JS |
4967 | /* |
4968 | # lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware. | |
4969 | # 0 = HBA resets disabled | |
4970 | # 1 = HBA resets enabled (default) | |
4971 | # Value range is [0,1]. Default value is 1. | |
4972 | */ | |
4973 | LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver."); | |
c3f28afa | 4974 | |
13815c83 | 4975 | /* |
eb7a339e | 4976 | # lpfc_enable_hba_heartbeat: Disable HBA heartbeat timer.. |
13815c83 JS |
4977 | # 0 = HBA Heartbeat disabled |
4978 | # 1 = HBA Heartbeat enabled (default) | |
4979 | # Value range is [0,1]. Default value is 1. | |
4980 | */ | |
eb7a339e | 4981 | LPFC_ATTR_R(enable_hba_heartbeat, 0, 0, 1, "Enable HBA Heartbeat."); |
92d7f7b0 | 4982 | |
1ba981fd JS |
4983 | /* |
4984 | # lpfc_EnableXLane: Enable Express Lane Feature | |
4985 | # 0x0 Express Lane Feature disabled | |
4986 | # 0x1 Express Lane Feature enabled | |
4987 | # Value range is [0,1]. Default value is 0. | |
4988 | */ | |
4989 | LPFC_ATTR_R(EnableXLane, 0, 0, 1, "Enable Express Lane Feature."); | |
4990 | ||
4991 | /* | |
4992 | # lpfc_XLanePriority: Define CS_CTL priority for Express Lane Feature | |
4993 | # 0x0 - 0x7f = CS_CTL field in FC header (high 7 bits) | |
4994 | # Value range is [0x0,0x7f]. Default value is 0 | |
4995 | */ | |
28d7f3df | 4996 | LPFC_ATTR_RW(XLanePriority, 0, 0x0, 0x7f, "CS_CTL for Express Lane Feature."); |
1ba981fd | 4997 | |
81301a9b JS |
4998 | /* |
4999 | # lpfc_enable_bg: Enable BlockGuard (Emulex's Implementation of T10-DIF) | |
5000 | # 0 = BlockGuard disabled (default) | |
5001 | # 1 = BlockGuard enabled | |
5002 | # Value range is [0,1]. Default value is 0. | |
5003 | */ | |
5004 | LPFC_ATTR_R(enable_bg, 0, 0, 1, "Enable BlockGuard Support"); | |
5005 | ||
ba20c853 JS |
5006 | /* |
5007 | # lpfc_fcp_look_ahead: Look ahead for completions in FCP start routine | |
5008 | # 0 = disabled (default) | |
5009 | # 1 = enabled | |
5010 | # Value range is [0,1]. Default value is 0. | |
5688d670 JS |
5011 | # |
5012 | # This feature in under investigation and may be supported in the future. | |
ba20c853 JS |
5013 | */ |
5014 | unsigned int lpfc_fcp_look_ahead = LPFC_LOOK_AHEAD_OFF; | |
5015 | ||
81301a9b JS |
5016 | /* |
5017 | # lpfc_prot_mask: i | |
5018 | # - Bit mask of host protection capabilities used to register with the | |
5019 | # SCSI mid-layer | |
5020 | # - Only meaningful if BG is turned on (lpfc_enable_bg=1). | |
5021 | # - Allows you to ultimately specify which profiles to use | |
5022 | # - Default will result in registering capabilities for all profiles. | |
005ffa70 JS |
5023 | # - SHOST_DIF_TYPE1_PROTECTION 1 |
5024 | # HBA supports T10 DIF Type 1: HBA to Target Type 1 Protection | |
5025 | # - SHOST_DIX_TYPE0_PROTECTION 8 | |
5026 | # HBA supports DIX Type 0: Host to HBA protection only | |
5027 | # - SHOST_DIX_TYPE1_PROTECTION 16 | |
5028 | # HBA supports DIX Type 1: Host to HBA Type 1 protection | |
81301a9b JS |
5029 | # |
5030 | */ | |
b3b98b74 JS |
5031 | LPFC_ATTR(prot_mask, |
5032 | (SHOST_DIF_TYPE1_PROTECTION | | |
5033 | SHOST_DIX_TYPE0_PROTECTION | | |
5034 | SHOST_DIX_TYPE1_PROTECTION), | |
5035 | 0, | |
5036 | (SHOST_DIF_TYPE1_PROTECTION | | |
5037 | SHOST_DIX_TYPE0_PROTECTION | | |
5038 | SHOST_DIX_TYPE1_PROTECTION), | |
5039 | "T10-DIF host protection capabilities mask"); | |
81301a9b JS |
5040 | |
5041 | /* | |
5042 | # lpfc_prot_guard: i | |
5043 | # - Bit mask of protection guard types to register with the SCSI mid-layer | |
005ffa70 | 5044 | # - Guard types are currently either 1) T10-DIF CRC 2) IP checksum |
81301a9b JS |
5045 | # - Allows you to ultimately specify which profiles to use |
5046 | # - Default will result in registering capabilities for all guard types | |
5047 | # | |
5048 | */ | |
b3b98b74 JS |
5049 | LPFC_ATTR(prot_guard, |
5050 | SHOST_DIX_GUARD_IP, SHOST_DIX_GUARD_CRC, SHOST_DIX_GUARD_IP, | |
5051 | "T10-DIF host protection guard type"); | |
81301a9b | 5052 | |
92494144 JS |
5053 | /* |
5054 | * Delay initial NPort discovery when Clean Address bit is cleared in | |
5055 | * FLOGI/FDISC accept and FCID/Fabric name/Fabric portname is changed. | |
5056 | * This parameter can have value 0 or 1. | |
5057 | * When this parameter is set to 0, no delay is added to the initial | |
5058 | * discovery. | |
5059 | * When this parameter is set to non-zero value, initial Nport discovery is | |
5060 | * delayed by ra_tov seconds when Clean Address bit is cleared in FLOGI/FDISC | |
5061 | * accept and FCID/Fabric name/Fabric portname is changed. | |
5062 | * Driver always delay Nport discovery for subsequent FLOGI/FDISC completion | |
5063 | * when Clean Address bit is cleared in FLOGI/FDISC | |
5064 | * accept and FCID/Fabric name/Fabric portname is changed. | |
5065 | * Default value is 0. | |
5066 | */ | |
8eb8b960 JS |
5067 | LPFC_ATTR(delay_discovery, 0, 0, 1, |
5068 | "Delay NPort discovery when Clean Address bit is cleared."); | |
81301a9b | 5069 | |
83108bd3 | 5070 | /* |
3621a710 | 5071 | * lpfc_sg_seg_cnt - Initial Maximum DMA Segment Count |
96f7077f | 5072 | * This value can be set to values between 64 and 4096. The default value is |
83108bd3 JS |
5073 | * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer |
5074 | * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE). | |
96f7077f JS |
5075 | * Because of the additional overhead involved in setting up T10-DIF, |
5076 | * this parameter will be limited to 128 if BlockGuard is enabled under SLI4 | |
5077 | * and will be limited to 512 if BlockGuard is enabled under SLI3. | |
83108bd3 JS |
5078 | */ |
5079 | LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT, | |
5080 | LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count"); | |
5081 | ||
7bdedb34 JS |
5082 | /* |
5083 | * lpfc_enable_mds_diags: Enable MDS Diagnostics | |
5084 | * 0 = MDS Diagnostics disabled (default) | |
5085 | * 1 = MDS Diagnostics enabled | |
5086 | * Value range is [0,1]. Default value is 0. | |
5087 | */ | |
5088 | LPFC_ATTR_R(enable_mds_diags, 0, 0, 1, "Enable MDS Diagnostics"); | |
5089 | ||
ee959b00 | 5090 | struct device_attribute *lpfc_hba_attrs[] = { |
895427bd | 5091 | &dev_attr_nvme_info, |
81301a9b JS |
5092 | &dev_attr_bg_info, |
5093 | &dev_attr_bg_guard_err, | |
5094 | &dev_attr_bg_apptag_err, | |
5095 | &dev_attr_bg_reftag_err, | |
ee959b00 TJ |
5096 | &dev_attr_info, |
5097 | &dev_attr_serialnum, | |
5098 | &dev_attr_modeldesc, | |
5099 | &dev_attr_modelname, | |
5100 | &dev_attr_programtype, | |
5101 | &dev_attr_portnum, | |
5102 | &dev_attr_fwrev, | |
5103 | &dev_attr_hdw, | |
5104 | &dev_attr_option_rom_version, | |
bbd1ae41 | 5105 | &dev_attr_link_state, |
ee959b00 | 5106 | &dev_attr_num_discovered_ports, |
84774a4d | 5107 | &dev_attr_menlo_mgmt_mode, |
ee959b00 | 5108 | &dev_attr_lpfc_drvr_version, |
45ed1190 | 5109 | &dev_attr_lpfc_enable_fip, |
ee959b00 TJ |
5110 | &dev_attr_lpfc_temp_sensor, |
5111 | &dev_attr_lpfc_log_verbose, | |
5112 | &dev_attr_lpfc_lun_queue_depth, | |
7dc517df | 5113 | &dev_attr_lpfc_tgt_queue_depth, |
ee959b00 TJ |
5114 | &dev_attr_lpfc_hba_queue_depth, |
5115 | &dev_attr_lpfc_peer_port_login, | |
5116 | &dev_attr_lpfc_nodev_tmo, | |
5117 | &dev_attr_lpfc_devloss_tmo, | |
895427bd JS |
5118 | &dev_attr_lpfc_enable_fc4_type, |
5119 | &dev_attr_lpfc_xri_split, | |
ee959b00 TJ |
5120 | &dev_attr_lpfc_fcp_class, |
5121 | &dev_attr_lpfc_use_adisc, | |
3cb01c57 | 5122 | &dev_attr_lpfc_first_burst_size, |
ee959b00 TJ |
5123 | &dev_attr_lpfc_ack0, |
5124 | &dev_attr_lpfc_topology, | |
5125 | &dev_attr_lpfc_scan_down, | |
5126 | &dev_attr_lpfc_link_speed, | |
49aa143d | 5127 | &dev_attr_lpfc_fcp_io_sched, |
a6571c6e | 5128 | &dev_attr_lpfc_fcp2_no_tgt_reset, |
ee959b00 TJ |
5129 | &dev_attr_lpfc_cr_delay, |
5130 | &dev_attr_lpfc_cr_count, | |
5131 | &dev_attr_lpfc_multi_ring_support, | |
5132 | &dev_attr_lpfc_multi_ring_rctl, | |
5133 | &dev_attr_lpfc_multi_ring_type, | |
5134 | &dev_attr_lpfc_fdmi_on, | |
4258e98e | 5135 | &dev_attr_lpfc_enable_SmartSAN, |
ee959b00 TJ |
5136 | &dev_attr_lpfc_max_luns, |
5137 | &dev_attr_lpfc_enable_npiv, | |
7d791df7 | 5138 | &dev_attr_lpfc_fcf_failover_policy, |
19ca7609 | 5139 | &dev_attr_lpfc_enable_rrq, |
ee959b00 TJ |
5140 | &dev_attr_nport_evt_cnt, |
5141 | &dev_attr_board_mode, | |
5142 | &dev_attr_max_vpi, | |
5143 | &dev_attr_used_vpi, | |
5144 | &dev_attr_max_rpi, | |
5145 | &dev_attr_used_rpi, | |
5146 | &dev_attr_max_xri, | |
5147 | &dev_attr_used_xri, | |
5148 | &dev_attr_npiv_info, | |
5149 | &dev_attr_issue_reset, | |
5150 | &dev_attr_lpfc_poll, | |
5151 | &dev_attr_lpfc_poll_tmo, | |
0c411222 | 5152 | &dev_attr_lpfc_task_mgmt_tmo, |
ee959b00 | 5153 | &dev_attr_lpfc_use_msi, |
895427bd | 5154 | &dev_attr_lpfc_nvme_oas, |
da0436e9 | 5155 | &dev_attr_lpfc_fcp_imax, |
7bb03bbf | 5156 | &dev_attr_lpfc_fcp_cpu_map, |
67d12733 | 5157 | &dev_attr_lpfc_fcp_io_channel, |
f358dd0c | 5158 | &dev_attr_lpfc_suppress_rsp, |
895427bd | 5159 | &dev_attr_lpfc_nvme_io_channel, |
2d7dbc4c JS |
5160 | &dev_attr_lpfc_nvmet_mrq, |
5161 | &dev_attr_lpfc_nvmet_mrq_post, | |
895427bd | 5162 | &dev_attr_lpfc_nvme_enable_fb, |
2d7dbc4c | 5163 | &dev_attr_lpfc_nvmet_fb_size, |
81301a9b | 5164 | &dev_attr_lpfc_enable_bg, |
352e5fd1 JS |
5165 | &dev_attr_lpfc_soft_wwnn, |
5166 | &dev_attr_lpfc_soft_wwpn, | |
5167 | &dev_attr_lpfc_soft_wwn_enable, | |
ee959b00 TJ |
5168 | &dev_attr_lpfc_enable_hba_reset, |
5169 | &dev_attr_lpfc_enable_hba_heartbeat, | |
1ba981fd JS |
5170 | &dev_attr_lpfc_EnableXLane, |
5171 | &dev_attr_lpfc_XLanePriority, | |
5172 | &dev_attr_lpfc_xlane_lun, | |
5173 | &dev_attr_lpfc_xlane_tgt, | |
5174 | &dev_attr_lpfc_xlane_vpt, | |
5175 | &dev_attr_lpfc_xlane_lun_state, | |
5176 | &dev_attr_lpfc_xlane_lun_status, | |
c92c841c | 5177 | &dev_attr_lpfc_xlane_priority, |
ee959b00 | 5178 | &dev_attr_lpfc_sg_seg_cnt, |
977b5a0a | 5179 | &dev_attr_lpfc_max_scsicmpl_time, |
ea2151b4 | 5180 | &dev_attr_lpfc_stat_data_ctrl, |
0d878419 JS |
5181 | &dev_attr_lpfc_aer_support, |
5182 | &dev_attr_lpfc_aer_state_cleanup, | |
912e3acd | 5183 | &dev_attr_lpfc_sriov_nr_virtfn, |
c71ab861 | 5184 | &dev_attr_lpfc_req_fw_upgrade, |
84d1b006 | 5185 | &dev_attr_lpfc_suppress_link_up, |
2a9bf3d0 JS |
5186 | &dev_attr_lpfc_iocb_cnt, |
5187 | &dev_attr_iocb_hw, | |
5188 | &dev_attr_txq_hw, | |
5189 | &dev_attr_txcmplq_hw, | |
bc73905a JS |
5190 | &dev_attr_lpfc_fips_level, |
5191 | &dev_attr_lpfc_fips_rev, | |
ab56dc2e | 5192 | &dev_attr_lpfc_dss, |
912e3acd | 5193 | &dev_attr_lpfc_sriov_hw_max_virtfn, |
026abb87 | 5194 | &dev_attr_protocol, |
1ba981fd | 5195 | &dev_attr_lpfc_xlane_supported, |
7bdedb34 | 5196 | &dev_attr_lpfc_enable_mds_diags, |
dea3101e JB |
5197 | NULL, |
5198 | }; | |
5199 | ||
ee959b00 TJ |
5200 | struct device_attribute *lpfc_vport_attrs[] = { |
5201 | &dev_attr_info, | |
bbd1ae41 | 5202 | &dev_attr_link_state, |
ee959b00 TJ |
5203 | &dev_attr_num_discovered_ports, |
5204 | &dev_attr_lpfc_drvr_version, | |
5205 | &dev_attr_lpfc_log_verbose, | |
5206 | &dev_attr_lpfc_lun_queue_depth, | |
7dc517df | 5207 | &dev_attr_lpfc_tgt_queue_depth, |
ee959b00 TJ |
5208 | &dev_attr_lpfc_nodev_tmo, |
5209 | &dev_attr_lpfc_devloss_tmo, | |
5210 | &dev_attr_lpfc_hba_queue_depth, | |
5211 | &dev_attr_lpfc_peer_port_login, | |
5212 | &dev_attr_lpfc_restrict_login, | |
5213 | &dev_attr_lpfc_fcp_class, | |
5214 | &dev_attr_lpfc_use_adisc, | |
3cb01c57 | 5215 | &dev_attr_lpfc_first_burst_size, |
ee959b00 TJ |
5216 | &dev_attr_lpfc_max_luns, |
5217 | &dev_attr_nport_evt_cnt, | |
5218 | &dev_attr_npiv_info, | |
5219 | &dev_attr_lpfc_enable_da_id, | |
ea2151b4 JS |
5220 | &dev_attr_lpfc_max_scsicmpl_time, |
5221 | &dev_attr_lpfc_stat_data_ctrl, | |
21e9a0a5 | 5222 | &dev_attr_lpfc_static_vport, |
bc73905a JS |
5223 | &dev_attr_lpfc_fips_level, |
5224 | &dev_attr_lpfc_fips_rev, | |
3de2a653 JS |
5225 | NULL, |
5226 | }; | |
5227 | ||
e59058c4 | 5228 | /** |
3621a710 | 5229 | * sysfs_ctlreg_write - Write method for writing to ctlreg |
2c3c8bea | 5230 | * @filp: open sysfs file |
e59058c4 JS |
5231 | * @kobj: kernel kobject that contains the kernel class device. |
5232 | * @bin_attr: kernel attributes passed to us. | |
5233 | * @buf: contains the data to be written to the adapter IOREG space. | |
5234 | * @off: offset into buffer to beginning of data. | |
5235 | * @count: bytes to transfer. | |
5236 | * | |
5237 | * Description: | |
5238 | * Accessed via /sys/class/scsi_host/hostxxx/ctlreg. | |
5239 | * Uses the adapter io control registers to send buf contents to the adapter. | |
5240 | * | |
5241 | * Returns: | |
5242 | * -ERANGE off and count combo out of range | |
5243 | * -EINVAL off, count or buff address invalid | |
5244 | * -EPERM adapter is offline | |
5245 | * value of count, buf contents written | |
5246 | **/ | |
dea3101e | 5247 | static ssize_t |
2c3c8bea CW |
5248 | sysfs_ctlreg_write(struct file *filp, struct kobject *kobj, |
5249 | struct bin_attribute *bin_attr, | |
91a69029 | 5250 | char *buf, loff_t off, size_t count) |
dea3101e JB |
5251 | { |
5252 | size_t buf_off; | |
ee959b00 TJ |
5253 | struct device *dev = container_of(kobj, struct device, kobj); |
5254 | struct Scsi_Host *shost = class_to_shost(dev); | |
2e0fef85 JS |
5255 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
5256 | struct lpfc_hba *phba = vport->phba; | |
dea3101e | 5257 | |
f1126688 JS |
5258 | if (phba->sli_rev >= LPFC_SLI_REV4) |
5259 | return -EPERM; | |
5260 | ||
dea3101e JB |
5261 | if ((off + count) > FF_REG_AREA_SIZE) |
5262 | return -ERANGE; | |
5263 | ||
f7a919b4 JS |
5264 | if (count <= LPFC_REG_WRITE_KEY_SIZE) |
5265 | return 0; | |
dea3101e JB |
5266 | |
5267 | if (off % 4 || count % 4 || (unsigned long)buf % 4) | |
5268 | return -EINVAL; | |
5269 | ||
f7a919b4 JS |
5270 | /* This is to protect HBA registers from accidental writes. */ |
5271 | if (memcmp(buf, LPFC_REG_WRITE_KEY, LPFC_REG_WRITE_KEY_SIZE)) | |
5272 | return -EINVAL; | |
5273 | ||
5274 | if (!(vport->fc_flag & FC_OFFLINE_MODE)) | |
dea3101e | 5275 | return -EPERM; |
dea3101e | 5276 | |
2e0fef85 | 5277 | spin_lock_irq(&phba->hbalock); |
f7a919b4 JS |
5278 | for (buf_off = 0; buf_off < count - LPFC_REG_WRITE_KEY_SIZE; |
5279 | buf_off += sizeof(uint32_t)) | |
5280 | writel(*((uint32_t *)(buf + buf_off + LPFC_REG_WRITE_KEY_SIZE)), | |
dea3101e JB |
5281 | phba->ctrl_regs_memmap_p + off + buf_off); |
5282 | ||
2e0fef85 | 5283 | spin_unlock_irq(&phba->hbalock); |
dea3101e JB |
5284 | |
5285 | return count; | |
5286 | } | |
5287 | ||
e59058c4 | 5288 | /** |
3621a710 | 5289 | * sysfs_ctlreg_read - Read method for reading from ctlreg |
2c3c8bea | 5290 | * @filp: open sysfs file |
e59058c4 JS |
5291 | * @kobj: kernel kobject that contains the kernel class device. |
5292 | * @bin_attr: kernel attributes passed to us. | |
af901ca1 | 5293 | * @buf: if successful contains the data from the adapter IOREG space. |
e59058c4 JS |
5294 | * @off: offset into buffer to beginning of data. |
5295 | * @count: bytes to transfer. | |
5296 | * | |
5297 | * Description: | |
5298 | * Accessed via /sys/class/scsi_host/hostxxx/ctlreg. | |
5299 | * Uses the adapter io control registers to read data into buf. | |
5300 | * | |
5301 | * Returns: | |
5302 | * -ERANGE off and count combo out of range | |
5303 | * -EINVAL off, count or buff address invalid | |
5304 | * value of count, buf contents read | |
5305 | **/ | |
dea3101e | 5306 | static ssize_t |
2c3c8bea CW |
5307 | sysfs_ctlreg_read(struct file *filp, struct kobject *kobj, |
5308 | struct bin_attribute *bin_attr, | |
91a69029 | 5309 | char *buf, loff_t off, size_t count) |
dea3101e JB |
5310 | { |
5311 | size_t buf_off; | |
5312 | uint32_t * tmp_ptr; | |
ee959b00 TJ |
5313 | struct device *dev = container_of(kobj, struct device, kobj); |
5314 | struct Scsi_Host *shost = class_to_shost(dev); | |
2e0fef85 JS |
5315 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
5316 | struct lpfc_hba *phba = vport->phba; | |
dea3101e | 5317 | |
f1126688 JS |
5318 | if (phba->sli_rev >= LPFC_SLI_REV4) |
5319 | return -EPERM; | |
5320 | ||
dea3101e JB |
5321 | if (off > FF_REG_AREA_SIZE) |
5322 | return -ERANGE; | |
5323 | ||
5324 | if ((off + count) > FF_REG_AREA_SIZE) | |
5325 | count = FF_REG_AREA_SIZE - off; | |
5326 | ||
5327 | if (count == 0) return 0; | |
5328 | ||
5329 | if (off % 4 || count % 4 || (unsigned long)buf % 4) | |
5330 | return -EINVAL; | |
5331 | ||
2e0fef85 | 5332 | spin_lock_irq(&phba->hbalock); |
dea3101e JB |
5333 | |
5334 | for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) { | |
5335 | tmp_ptr = (uint32_t *)(buf + buf_off); | |
5336 | *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off); | |
5337 | } | |
5338 | ||
2e0fef85 | 5339 | spin_unlock_irq(&phba->hbalock); |
dea3101e JB |
5340 | |
5341 | return count; | |
5342 | } | |
5343 | ||
5344 | static struct bin_attribute sysfs_ctlreg_attr = { | |
5345 | .attr = { | |
5346 | .name = "ctlreg", | |
5347 | .mode = S_IRUSR | S_IWUSR, | |
dea3101e JB |
5348 | }, |
5349 | .size = 256, | |
5350 | .read = sysfs_ctlreg_read, | |
5351 | .write = sysfs_ctlreg_write, | |
5352 | }; | |
5353 | ||
e59058c4 | 5354 | /** |
3621a710 | 5355 | * sysfs_mbox_write - Write method for writing information via mbox |
2c3c8bea | 5356 | * @filp: open sysfs file |
e59058c4 JS |
5357 | * @kobj: kernel kobject that contains the kernel class device. |
5358 | * @bin_attr: kernel attributes passed to us. | |
5359 | * @buf: contains the data to be written to sysfs mbox. | |
5360 | * @off: offset into buffer to beginning of data. | |
5361 | * @count: bytes to transfer. | |
5362 | * | |
5363 | * Description: | |
026abb87 JS |
5364 | * Deprecated function. All mailbox access from user space is performed via the |
5365 | * bsg interface. | |
e59058c4 JS |
5366 | * |
5367 | * Returns: | |
026abb87 | 5368 | * -EPERM operation not permitted |
e59058c4 | 5369 | **/ |
dea3101e | 5370 | static ssize_t |
2c3c8bea CW |
5371 | sysfs_mbox_write(struct file *filp, struct kobject *kobj, |
5372 | struct bin_attribute *bin_attr, | |
91a69029 | 5373 | char *buf, loff_t off, size_t count) |
dea3101e | 5374 | { |
026abb87 | 5375 | return -EPERM; |
dea3101e JB |
5376 | } |
5377 | ||
e59058c4 | 5378 | /** |
3621a710 | 5379 | * sysfs_mbox_read - Read method for reading information via mbox |
2c3c8bea | 5380 | * @filp: open sysfs file |
e59058c4 JS |
5381 | * @kobj: kernel kobject that contains the kernel class device. |
5382 | * @bin_attr: kernel attributes passed to us. | |
5383 | * @buf: contains the data to be read from sysfs mbox. | |
5384 | * @off: offset into buffer to beginning of data. | |
5385 | * @count: bytes to transfer. | |
5386 | * | |
5387 | * Description: | |
026abb87 JS |
5388 | * Deprecated function. All mailbox access from user space is performed via the |
5389 | * bsg interface. | |
e59058c4 JS |
5390 | * |
5391 | * Returns: | |
026abb87 | 5392 | * -EPERM operation not permitted |
e59058c4 | 5393 | **/ |
dea3101e | 5394 | static ssize_t |
2c3c8bea CW |
5395 | sysfs_mbox_read(struct file *filp, struct kobject *kobj, |
5396 | struct bin_attribute *bin_attr, | |
91a69029 | 5397 | char *buf, loff_t off, size_t count) |
dea3101e | 5398 | { |
026abb87 | 5399 | return -EPERM; |
dea3101e JB |
5400 | } |
5401 | ||
5402 | static struct bin_attribute sysfs_mbox_attr = { | |
5403 | .attr = { | |
5404 | .name = "mbox", | |
5405 | .mode = S_IRUSR | S_IWUSR, | |
dea3101e | 5406 | }, |
c0c11512 | 5407 | .size = MAILBOX_SYSFS_MAX, |
dea3101e JB |
5408 | .read = sysfs_mbox_read, |
5409 | .write = sysfs_mbox_write, | |
5410 | }; | |
5411 | ||
e59058c4 | 5412 | /** |
3621a710 | 5413 | * lpfc_alloc_sysfs_attr - Creates the ctlreg and mbox entries |
e59058c4 JS |
5414 | * @vport: address of lpfc vport structure. |
5415 | * | |
5416 | * Return codes: | |
5417 | * zero on success | |
5418 | * error return code from sysfs_create_bin_file() | |
5419 | **/ | |
dea3101e | 5420 | int |
2e0fef85 | 5421 | lpfc_alloc_sysfs_attr(struct lpfc_vport *vport) |
dea3101e | 5422 | { |
2e0fef85 | 5423 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
dea3101e JB |
5424 | int error; |
5425 | ||
ee959b00 | 5426 | error = sysfs_create_bin_file(&shost->shost_dev.kobj, |
eada272d JS |
5427 | &sysfs_drvr_stat_data_attr); |
5428 | ||
5429 | /* Virtual ports do not need ctrl_reg and mbox */ | |
5430 | if (error || vport->port_type == LPFC_NPIV_PORT) | |
dea3101e JB |
5431 | goto out; |
5432 | ||
ee959b00 | 5433 | error = sysfs_create_bin_file(&shost->shost_dev.kobj, |
eada272d | 5434 | &sysfs_ctlreg_attr); |
dea3101e | 5435 | if (error) |
eada272d | 5436 | goto out_remove_stat_attr; |
dea3101e | 5437 | |
ea2151b4 | 5438 | error = sysfs_create_bin_file(&shost->shost_dev.kobj, |
eada272d | 5439 | &sysfs_mbox_attr); |
ea2151b4 | 5440 | if (error) |
eada272d | 5441 | goto out_remove_ctlreg_attr; |
ea2151b4 | 5442 | |
dea3101e JB |
5443 | return 0; |
5444 | out_remove_ctlreg_attr: | |
ee959b00 | 5445 | sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr); |
eada272d JS |
5446 | out_remove_stat_attr: |
5447 | sysfs_remove_bin_file(&shost->shost_dev.kobj, | |
5448 | &sysfs_drvr_stat_data_attr); | |
dea3101e JB |
5449 | out: |
5450 | return error; | |
5451 | } | |
5452 | ||
e59058c4 | 5453 | /** |
3621a710 | 5454 | * lpfc_free_sysfs_attr - Removes the ctlreg and mbox entries |
e59058c4 JS |
5455 | * @vport: address of lpfc vport structure. |
5456 | **/ | |
dea3101e | 5457 | void |
2e0fef85 | 5458 | lpfc_free_sysfs_attr(struct lpfc_vport *vport) |
dea3101e | 5459 | { |
2e0fef85 | 5460 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
ea2151b4 JS |
5461 | sysfs_remove_bin_file(&shost->shost_dev.kobj, |
5462 | &sysfs_drvr_stat_data_attr); | |
eada272d JS |
5463 | /* Virtual ports do not need ctrl_reg and mbox */ |
5464 | if (vport->port_type == LPFC_NPIV_PORT) | |
5465 | return; | |
ee959b00 TJ |
5466 | sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr); |
5467 | sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr); | |
dea3101e JB |
5468 | } |
5469 | ||
dea3101e JB |
5470 | /* |
5471 | * Dynamic FC Host Attributes Support | |
5472 | */ | |
5473 | ||
6c9231f6 JS |
5474 | /** |
5475 | * lpfc_get_host_symbolic_name - Copy symbolic name into the scsi host | |
5476 | * @shost: kernel scsi host pointer. | |
5477 | **/ | |
5478 | static void | |
5479 | lpfc_get_host_symbolic_name(struct Scsi_Host *shost) | |
5480 | { | |
5481 | struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata; | |
5482 | ||
5483 | lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost), | |
5484 | sizeof fc_host_symbolic_name(shost)); | |
5485 | } | |
5486 | ||
e59058c4 | 5487 | /** |
3621a710 | 5488 | * lpfc_get_host_port_id - Copy the vport DID into the scsi host port id |
e59058c4 JS |
5489 | * @shost: kernel scsi host pointer. |
5490 | **/ | |
dea3101e JB |
5491 | static void |
5492 | lpfc_get_host_port_id(struct Scsi_Host *shost) | |
5493 | { | |
2e0fef85 JS |
5494 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
5495 | ||
dea3101e | 5496 | /* note: fc_myDID already in cpu endianness */ |
2e0fef85 | 5497 | fc_host_port_id(shost) = vport->fc_myDID; |
dea3101e JB |
5498 | } |
5499 | ||
e59058c4 | 5500 | /** |
3621a710 | 5501 | * lpfc_get_host_port_type - Set the value of the scsi host port type |
e59058c4 JS |
5502 | * @shost: kernel scsi host pointer. |
5503 | **/ | |
dea3101e JB |
5504 | static void |
5505 | lpfc_get_host_port_type(struct Scsi_Host *shost) | |
5506 | { | |
2e0fef85 JS |
5507 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
5508 | struct lpfc_hba *phba = vport->phba; | |
dea3101e JB |
5509 | |
5510 | spin_lock_irq(shost->host_lock); | |
5511 | ||
92d7f7b0 JS |
5512 | if (vport->port_type == LPFC_NPIV_PORT) { |
5513 | fc_host_port_type(shost) = FC_PORTTYPE_NPIV; | |
5514 | } else if (lpfc_is_link_up(phba)) { | |
76a95d75 | 5515 | if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
2e0fef85 | 5516 | if (vport->fc_flag & FC_PUBLIC_LOOP) |
dea3101e JB |
5517 | fc_host_port_type(shost) = FC_PORTTYPE_NLPORT; |
5518 | else | |
5519 | fc_host_port_type(shost) = FC_PORTTYPE_LPORT; | |
5520 | } else { | |
2e0fef85 | 5521 | if (vport->fc_flag & FC_FABRIC) |
dea3101e JB |
5522 | fc_host_port_type(shost) = FC_PORTTYPE_NPORT; |
5523 | else | |
5524 | fc_host_port_type(shost) = FC_PORTTYPE_PTP; | |
5525 | } | |
5526 | } else | |
5527 | fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN; | |
5528 | ||
5529 | spin_unlock_irq(shost->host_lock); | |
5530 | } | |
5531 | ||
e59058c4 | 5532 | /** |
3621a710 | 5533 | * lpfc_get_host_port_state - Set the value of the scsi host port state |
e59058c4 JS |
5534 | * @shost: kernel scsi host pointer. |
5535 | **/ | |
dea3101e JB |
5536 | static void |
5537 | lpfc_get_host_port_state(struct Scsi_Host *shost) | |
5538 | { | |
2e0fef85 JS |
5539 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
5540 | struct lpfc_hba *phba = vport->phba; | |
dea3101e JB |
5541 | |
5542 | spin_lock_irq(shost->host_lock); | |
5543 | ||
2e0fef85 | 5544 | if (vport->fc_flag & FC_OFFLINE_MODE) |
dea3101e JB |
5545 | fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE; |
5546 | else { | |
2e0fef85 JS |
5547 | switch (phba->link_state) { |
5548 | case LPFC_LINK_UNKNOWN: | |
dea3101e JB |
5549 | case LPFC_LINK_DOWN: |
5550 | fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN; | |
5551 | break; | |
5552 | case LPFC_LINK_UP: | |
dea3101e JB |
5553 | case LPFC_CLEAR_LA: |
5554 | case LPFC_HBA_READY: | |
026abb87 JS |
5555 | /* Links up, reports port state accordingly */ |
5556 | if (vport->port_state < LPFC_VPORT_READY) | |
5557 | fc_host_port_state(shost) = | |
5558 | FC_PORTSTATE_BYPASSED; | |
5559 | else | |
5560 | fc_host_port_state(shost) = | |
5561 | FC_PORTSTATE_ONLINE; | |
dea3101e JB |
5562 | break; |
5563 | case LPFC_HBA_ERROR: | |
5564 | fc_host_port_state(shost) = FC_PORTSTATE_ERROR; | |
5565 | break; | |
5566 | default: | |
5567 | fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN; | |
5568 | break; | |
5569 | } | |
5570 | } | |
5571 | ||
5572 | spin_unlock_irq(shost->host_lock); | |
5573 | } | |
5574 | ||
e59058c4 | 5575 | /** |
3621a710 | 5576 | * lpfc_get_host_speed - Set the value of the scsi host speed |
e59058c4 JS |
5577 | * @shost: kernel scsi host pointer. |
5578 | **/ | |
dea3101e JB |
5579 | static void |
5580 | lpfc_get_host_speed(struct Scsi_Host *shost) | |
5581 | { | |
2e0fef85 JS |
5582 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
5583 | struct lpfc_hba *phba = vport->phba; | |
dea3101e JB |
5584 | |
5585 | spin_lock_irq(shost->host_lock); | |
5586 | ||
a085e87c | 5587 | if ((lpfc_is_link_up(phba)) && (!(phba->hba_flag & HBA_FCOE_MODE))) { |
dea3101e | 5588 | switch(phba->fc_linkspeed) { |
76a95d75 JS |
5589 | case LPFC_LINK_SPEED_1GHZ: |
5590 | fc_host_speed(shost) = FC_PORTSPEED_1GBIT; | |
dea3101e | 5591 | break; |
76a95d75 JS |
5592 | case LPFC_LINK_SPEED_2GHZ: |
5593 | fc_host_speed(shost) = FC_PORTSPEED_2GBIT; | |
dea3101e | 5594 | break; |
76a95d75 JS |
5595 | case LPFC_LINK_SPEED_4GHZ: |
5596 | fc_host_speed(shost) = FC_PORTSPEED_4GBIT; | |
dea3101e | 5597 | break; |
76a95d75 JS |
5598 | case LPFC_LINK_SPEED_8GHZ: |
5599 | fc_host_speed(shost) = FC_PORTSPEED_8GBIT; | |
b87eab38 | 5600 | break; |
76a95d75 JS |
5601 | case LPFC_LINK_SPEED_10GHZ: |
5602 | fc_host_speed(shost) = FC_PORTSPEED_10GBIT; | |
f4b4c68f | 5603 | break; |
76a95d75 JS |
5604 | case LPFC_LINK_SPEED_16GHZ: |
5605 | fc_host_speed(shost) = FC_PORTSPEED_16GBIT; | |
5606 | break; | |
d38dd52c JS |
5607 | case LPFC_LINK_SPEED_32GHZ: |
5608 | fc_host_speed(shost) = FC_PORTSPEED_32GBIT; | |
5609 | break; | |
76a95d75 JS |
5610 | default: |
5611 | fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN; | |
dea3101e JB |
5612 | break; |
5613 | } | |
09372820 JS |
5614 | } else |
5615 | fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN; | |
dea3101e JB |
5616 | |
5617 | spin_unlock_irq(shost->host_lock); | |
5618 | } | |
5619 | ||
e59058c4 | 5620 | /** |
3621a710 | 5621 | * lpfc_get_host_fabric_name - Set the value of the scsi host fabric name |
e59058c4 JS |
5622 | * @shost: kernel scsi host pointer. |
5623 | **/ | |
dea3101e JB |
5624 | static void |
5625 | lpfc_get_host_fabric_name (struct Scsi_Host *shost) | |
5626 | { | |
2e0fef85 JS |
5627 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
5628 | struct lpfc_hba *phba = vport->phba; | |
f631b4be | 5629 | u64 node_name; |
dea3101e JB |
5630 | |
5631 | spin_lock_irq(shost->host_lock); | |
5632 | ||
73d91e50 JS |
5633 | if ((vport->port_state > LPFC_FLOGI) && |
5634 | ((vport->fc_flag & FC_FABRIC) || | |
5635 | ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) && | |
5636 | (vport->fc_flag & FC_PUBLIC_LOOP)))) | |
68ce1eb5 | 5637 | node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn); |
dea3101e JB |
5638 | else |
5639 | /* fabric is local port if there is no F/FL_Port */ | |
09372820 | 5640 | node_name = 0; |
dea3101e JB |
5641 | |
5642 | spin_unlock_irq(shost->host_lock); | |
5643 | ||
f631b4be | 5644 | fc_host_fabric_name(shost) = node_name; |
dea3101e JB |
5645 | } |
5646 | ||
e59058c4 | 5647 | /** |
3621a710 | 5648 | * lpfc_get_stats - Return statistical information about the adapter |
e59058c4 JS |
5649 | * @shost: kernel scsi host pointer. |
5650 | * | |
5651 | * Notes: | |
5652 | * NULL on error for link down, no mbox pool, sli2 active, | |
5653 | * management not allowed, memory allocation error, or mbox error. | |
5654 | * | |
5655 | * Returns: | |
5656 | * NULL for error | |
5657 | * address of the adapter host statistics | |
5658 | **/ | |
dea3101e JB |
5659 | static struct fc_host_statistics * |
5660 | lpfc_get_stats(struct Scsi_Host *shost) | |
5661 | { | |
2e0fef85 JS |
5662 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
5663 | struct lpfc_hba *phba = vport->phba; | |
5664 | struct lpfc_sli *psli = &phba->sli; | |
f888ba3c | 5665 | struct fc_host_statistics *hs = &phba->link_stats; |
64ba8818 | 5666 | struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets; |
dea3101e JB |
5667 | LPFC_MBOXQ_t *pmboxq; |
5668 | MAILBOX_t *pmb; | |
64ba8818 | 5669 | unsigned long seconds; |
433c3579 | 5670 | int rc = 0; |
dea3101e | 5671 | |
92d7f7b0 JS |
5672 | /* |
5673 | * prevent udev from issuing mailbox commands until the port is | |
5674 | * configured. | |
5675 | */ | |
2e0fef85 JS |
5676 | if (phba->link_state < LPFC_LINK_DOWN || |
5677 | !phba->mbox_mem_pool || | |
f4b4c68f | 5678 | (phba->sli.sli_flag & LPFC_SLI_ACTIVE) == 0) |
92d7f7b0 | 5679 | return NULL; |
2e0fef85 JS |
5680 | |
5681 | if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) | |
46fa311e JS |
5682 | return NULL; |
5683 | ||
dea3101e JB |
5684 | pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
5685 | if (!pmboxq) | |
5686 | return NULL; | |
5687 | memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t)); | |
5688 | ||
04c68496 | 5689 | pmb = &pmboxq->u.mb; |
dea3101e JB |
5690 | pmb->mbxCommand = MBX_READ_STATUS; |
5691 | pmb->mbxOwner = OWN_HOST; | |
5692 | pmboxq->context1 = NULL; | |
92d7f7b0 | 5693 | pmboxq->vport = vport; |
dea3101e | 5694 | |
75baf696 | 5695 | if (vport->fc_flag & FC_OFFLINE_MODE) |
dea3101e | 5696 | rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL); |
433c3579 | 5697 | else |
dea3101e JB |
5698 | rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2); |
5699 | ||
5700 | if (rc != MBX_SUCCESS) { | |
858c9f6c | 5701 | if (rc != MBX_TIMEOUT) |
433c3579 | 5702 | mempool_free(pmboxq, phba->mbox_mem_pool); |
dea3101e JB |
5703 | return NULL; |
5704 | } | |
5705 | ||
f888ba3c JSEC |
5706 | memset(hs, 0, sizeof (struct fc_host_statistics)); |
5707 | ||
dea3101e | 5708 | hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt; |
73d91e50 JS |
5709 | /* |
5710 | * The MBX_READ_STATUS returns tx_k_bytes which has to | |
5711 | * converted to words | |
5712 | */ | |
5713 | hs->tx_words = (uint64_t) | |
5714 | ((uint64_t)pmb->un.varRdStatus.xmitByteCnt | |
5715 | * (uint64_t)256); | |
dea3101e | 5716 | hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt; |
73d91e50 JS |
5717 | hs->rx_words = (uint64_t) |
5718 | ((uint64_t)pmb->un.varRdStatus.rcvByteCnt | |
5719 | * (uint64_t)256); | |
dea3101e | 5720 | |
433c3579 | 5721 | memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t)); |
dea3101e JB |
5722 | pmb->mbxCommand = MBX_READ_LNK_STAT; |
5723 | pmb->mbxOwner = OWN_HOST; | |
5724 | pmboxq->context1 = NULL; | |
92d7f7b0 | 5725 | pmboxq->vport = vport; |
dea3101e | 5726 | |
75baf696 | 5727 | if (vport->fc_flag & FC_OFFLINE_MODE) |
dea3101e | 5728 | rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL); |
433c3579 | 5729 | else |
dea3101e JB |
5730 | rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2); |
5731 | ||
5732 | if (rc != MBX_SUCCESS) { | |
858c9f6c | 5733 | if (rc != MBX_TIMEOUT) |
92d7f7b0 | 5734 | mempool_free(pmboxq, phba->mbox_mem_pool); |
dea3101e JB |
5735 | return NULL; |
5736 | } | |
5737 | ||
5738 | hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt; | |
5739 | hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt; | |
5740 | hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt; | |
5741 | hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt; | |
5742 | hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord; | |
5743 | hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt; | |
5744 | hs->error_frames = pmb->un.varRdLnk.crcCnt; | |
5745 | ||
64ba8818 JS |
5746 | hs->link_failure_count -= lso->link_failure_count; |
5747 | hs->loss_of_sync_count -= lso->loss_of_sync_count; | |
5748 | hs->loss_of_signal_count -= lso->loss_of_signal_count; | |
5749 | hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count; | |
5750 | hs->invalid_tx_word_count -= lso->invalid_tx_word_count; | |
5751 | hs->invalid_crc_count -= lso->invalid_crc_count; | |
5752 | hs->error_frames -= lso->error_frames; | |
5753 | ||
76a95d75 | 5754 | if (phba->hba_flag & HBA_FCOE_MODE) { |
4d9ab994 JS |
5755 | hs->lip_count = -1; |
5756 | hs->nos_count = (phba->link_events >> 1); | |
5757 | hs->nos_count -= lso->link_events; | |
76a95d75 | 5758 | } else if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) { |
dea3101e | 5759 | hs->lip_count = (phba->fc_eventTag >> 1); |
64ba8818 | 5760 | hs->lip_count -= lso->link_events; |
dea3101e JB |
5761 | hs->nos_count = -1; |
5762 | } else { | |
5763 | hs->lip_count = -1; | |
5764 | hs->nos_count = (phba->fc_eventTag >> 1); | |
64ba8818 | 5765 | hs->nos_count -= lso->link_events; |
dea3101e JB |
5766 | } |
5767 | ||
5768 | hs->dumped_frames = -1; | |
5769 | ||
64ba8818 JS |
5770 | seconds = get_seconds(); |
5771 | if (seconds < psli->stats_start) | |
5772 | hs->seconds_since_last_reset = seconds + | |
5773 | ((unsigned long)-1 - psli->stats_start); | |
5774 | else | |
5775 | hs->seconds_since_last_reset = seconds - psli->stats_start; | |
dea3101e | 5776 | |
1dcb58e5 JS |
5777 | mempool_free(pmboxq, phba->mbox_mem_pool); |
5778 | ||
dea3101e JB |
5779 | return hs; |
5780 | } | |
5781 | ||
e59058c4 | 5782 | /** |
3621a710 | 5783 | * lpfc_reset_stats - Copy the adapter link stats information |
e59058c4 JS |
5784 | * @shost: kernel scsi host pointer. |
5785 | **/ | |
64ba8818 JS |
5786 | static void |
5787 | lpfc_reset_stats(struct Scsi_Host *shost) | |
5788 | { | |
2e0fef85 JS |
5789 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
5790 | struct lpfc_hba *phba = vport->phba; | |
5791 | struct lpfc_sli *psli = &phba->sli; | |
5792 | struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets; | |
64ba8818 JS |
5793 | LPFC_MBOXQ_t *pmboxq; |
5794 | MAILBOX_t *pmb; | |
5795 | int rc = 0; | |
5796 | ||
2e0fef85 | 5797 | if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) |
46fa311e JS |
5798 | return; |
5799 | ||
64ba8818 JS |
5800 | pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
5801 | if (!pmboxq) | |
5802 | return; | |
5803 | memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t)); | |
5804 | ||
04c68496 | 5805 | pmb = &pmboxq->u.mb; |
64ba8818 JS |
5806 | pmb->mbxCommand = MBX_READ_STATUS; |
5807 | pmb->mbxOwner = OWN_HOST; | |
5808 | pmb->un.varWords[0] = 0x1; /* reset request */ | |
5809 | pmboxq->context1 = NULL; | |
92d7f7b0 | 5810 | pmboxq->vport = vport; |
64ba8818 | 5811 | |
2e0fef85 | 5812 | if ((vport->fc_flag & FC_OFFLINE_MODE) || |
f4b4c68f | 5813 | (!(psli->sli_flag & LPFC_SLI_ACTIVE))) |
64ba8818 JS |
5814 | rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL); |
5815 | else | |
5816 | rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2); | |
5817 | ||
5818 | if (rc != MBX_SUCCESS) { | |
858c9f6c | 5819 | if (rc != MBX_TIMEOUT) |
64ba8818 JS |
5820 | mempool_free(pmboxq, phba->mbox_mem_pool); |
5821 | return; | |
5822 | } | |
5823 | ||
5824 | memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t)); | |
5825 | pmb->mbxCommand = MBX_READ_LNK_STAT; | |
5826 | pmb->mbxOwner = OWN_HOST; | |
5827 | pmboxq->context1 = NULL; | |
92d7f7b0 | 5828 | pmboxq->vport = vport; |
64ba8818 | 5829 | |
2e0fef85 | 5830 | if ((vport->fc_flag & FC_OFFLINE_MODE) || |
f4b4c68f | 5831 | (!(psli->sli_flag & LPFC_SLI_ACTIVE))) |
64ba8818 JS |
5832 | rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL); |
5833 | else | |
5834 | rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2); | |
5835 | ||
5836 | if (rc != MBX_SUCCESS) { | |
858c9f6c | 5837 | if (rc != MBX_TIMEOUT) |
64ba8818 JS |
5838 | mempool_free( pmboxq, phba->mbox_mem_pool); |
5839 | return; | |
5840 | } | |
5841 | ||
5842 | lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt; | |
5843 | lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt; | |
5844 | lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt; | |
5845 | lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt; | |
5846 | lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord; | |
5847 | lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt; | |
5848 | lso->error_frames = pmb->un.varRdLnk.crcCnt; | |
76a95d75 | 5849 | if (phba->hba_flag & HBA_FCOE_MODE) |
4d9ab994 JS |
5850 | lso->link_events = (phba->link_events >> 1); |
5851 | else | |
5852 | lso->link_events = (phba->fc_eventTag >> 1); | |
64ba8818 JS |
5853 | |
5854 | psli->stats_start = get_seconds(); | |
5855 | ||
1dcb58e5 JS |
5856 | mempool_free(pmboxq, phba->mbox_mem_pool); |
5857 | ||
64ba8818 JS |
5858 | return; |
5859 | } | |
dea3101e JB |
5860 | |
5861 | /* | |
5862 | * The LPFC driver treats linkdown handling as target loss events so there | |
5863 | * are no sysfs handlers for link_down_tmo. | |
5864 | */ | |
685f0bf7 | 5865 | |
e59058c4 | 5866 | /** |
3621a710 | 5867 | * lpfc_get_node_by_target - Return the nodelist for a target |
e59058c4 JS |
5868 | * @starget: kernel scsi target pointer. |
5869 | * | |
5870 | * Returns: | |
5871 | * address of the node list if found | |
5872 | * NULL target not found | |
5873 | **/ | |
685f0bf7 JS |
5874 | static struct lpfc_nodelist * |
5875 | lpfc_get_node_by_target(struct scsi_target *starget) | |
dea3101e | 5876 | { |
2e0fef85 JS |
5877 | struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); |
5878 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
685f0bf7 | 5879 | struct lpfc_nodelist *ndlp; |
dea3101e JB |
5880 | |
5881 | spin_lock_irq(shost->host_lock); | |
685f0bf7 | 5882 | /* Search for this, mapped, target ID */ |
2e0fef85 | 5883 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
e47c9093 JS |
5884 | if (NLP_CHK_NODE_ACT(ndlp) && |
5885 | ndlp->nlp_state == NLP_STE_MAPPED_NODE && | |
685f0bf7 JS |
5886 | starget->id == ndlp->nlp_sid) { |
5887 | spin_unlock_irq(shost->host_lock); | |
5888 | return ndlp; | |
dea3101e JB |
5889 | } |
5890 | } | |
5891 | spin_unlock_irq(shost->host_lock); | |
685f0bf7 JS |
5892 | return NULL; |
5893 | } | |
dea3101e | 5894 | |
e59058c4 | 5895 | /** |
3621a710 | 5896 | * lpfc_get_starget_port_id - Set the target port id to the ndlp DID or -1 |
e59058c4 JS |
5897 | * @starget: kernel scsi target pointer. |
5898 | **/ | |
685f0bf7 JS |
5899 | static void |
5900 | lpfc_get_starget_port_id(struct scsi_target *starget) | |
5901 | { | |
5902 | struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget); | |
5903 | ||
5904 | fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1; | |
dea3101e JB |
5905 | } |
5906 | ||
e59058c4 | 5907 | /** |
3621a710 | 5908 | * lpfc_get_starget_node_name - Set the target node name |
e59058c4 JS |
5909 | * @starget: kernel scsi target pointer. |
5910 | * | |
5911 | * Description: Set the target node name to the ndlp node name wwn or zero. | |
5912 | **/ | |
dea3101e JB |
5913 | static void |
5914 | lpfc_get_starget_node_name(struct scsi_target *starget) | |
5915 | { | |
685f0bf7 | 5916 | struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget); |
dea3101e | 5917 | |
685f0bf7 JS |
5918 | fc_starget_node_name(starget) = |
5919 | ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0; | |
dea3101e JB |
5920 | } |
5921 | ||
e59058c4 | 5922 | /** |
3621a710 | 5923 | * lpfc_get_starget_port_name - Set the target port name |
e59058c4 JS |
5924 | * @starget: kernel scsi target pointer. |
5925 | * | |
5926 | * Description: set the target port name to the ndlp port name wwn or zero. | |
5927 | **/ | |
dea3101e JB |
5928 | static void |
5929 | lpfc_get_starget_port_name(struct scsi_target *starget) | |
5930 | { | |
685f0bf7 | 5931 | struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget); |
dea3101e | 5932 | |
685f0bf7 JS |
5933 | fc_starget_port_name(starget) = |
5934 | ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0; | |
dea3101e JB |
5935 | } |
5936 | ||
e59058c4 | 5937 | /** |
3621a710 | 5938 | * lpfc_set_rport_loss_tmo - Set the rport dev loss tmo |
e59058c4 JS |
5939 | * @rport: fc rport address. |
5940 | * @timeout: new value for dev loss tmo. | |
5941 | * | |
5942 | * Description: | |
5943 | * If timeout is non zero set the dev_loss_tmo to timeout, else set | |
5944 | * dev_loss_tmo to one. | |
5945 | **/ | |
dea3101e JB |
5946 | static void |
5947 | lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout) | |
5948 | { | |
dea3101e | 5949 | if (timeout) |
c01f3208 | 5950 | rport->dev_loss_tmo = timeout; |
dea3101e | 5951 | else |
c01f3208 | 5952 | rport->dev_loss_tmo = 1; |
dea3101e JB |
5953 | } |
5954 | ||
e59058c4 | 5955 | /** |
3621a710 | 5956 | * lpfc_rport_show_function - Return rport target information |
e59058c4 JS |
5957 | * |
5958 | * Description: | |
5959 | * Macro that uses field to generate a function with the name lpfc_show_rport_ | |
5960 | * | |
5961 | * lpfc_show_rport_##field: returns the bytes formatted in buf | |
5962 | * @cdev: class converted to an fc_rport. | |
5963 | * @buf: on return contains the target_field or zero. | |
5964 | * | |
5965 | * Returns: size of formatted string. | |
5966 | **/ | |
dea3101e JB |
5967 | #define lpfc_rport_show_function(field, format_string, sz, cast) \ |
5968 | static ssize_t \ | |
ee959b00 TJ |
5969 | lpfc_show_rport_##field (struct device *dev, \ |
5970 | struct device_attribute *attr, \ | |
5971 | char *buf) \ | |
dea3101e | 5972 | { \ |
ee959b00 | 5973 | struct fc_rport *rport = transport_class_to_rport(dev); \ |
dea3101e JB |
5974 | struct lpfc_rport_data *rdata = rport->hostdata; \ |
5975 | return snprintf(buf, sz, format_string, \ | |
5976 | (rdata->target) ? cast rdata->target->field : 0); \ | |
5977 | } | |
5978 | ||
5979 | #define lpfc_rport_rd_attr(field, format_string, sz) \ | |
5980 | lpfc_rport_show_function(field, format_string, sz, ) \ | |
5981 | static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL) | |
5982 | ||
eada272d | 5983 | /** |
3621a710 | 5984 | * lpfc_set_vport_symbolic_name - Set the vport's symbolic name |
eada272d JS |
5985 | * @fc_vport: The fc_vport who's symbolic name has been changed. |
5986 | * | |
5987 | * Description: | |
5988 | * This function is called by the transport after the @fc_vport's symbolic name | |
5989 | * has been changed. This function re-registers the symbolic name with the | |
25985edc | 5990 | * switch to propagate the change into the fabric if the vport is active. |
eada272d JS |
5991 | **/ |
5992 | static void | |
5993 | lpfc_set_vport_symbolic_name(struct fc_vport *fc_vport) | |
5994 | { | |
5995 | struct lpfc_vport *vport = *(struct lpfc_vport **)fc_vport->dd_data; | |
5996 | ||
5997 | if (vport->port_state == LPFC_VPORT_READY) | |
5998 | lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0); | |
5999 | } | |
dea3101e | 6000 | |
f4b4c68f JS |
6001 | /** |
6002 | * lpfc_hba_log_verbose_init - Set hba's log verbose level | |
6003 | * @phba: Pointer to lpfc_hba struct. | |
6004 | * | |
6005 | * This function is called by the lpfc_get_cfgparam() routine to set the | |
6006 | * module lpfc_log_verbose into the @phba cfg_log_verbose for use with | |
70f23fd6 | 6007 | * log message according to the module's lpfc_log_verbose parameter setting |
f4b4c68f JS |
6008 | * before hba port or vport created. |
6009 | **/ | |
6010 | static void | |
6011 | lpfc_hba_log_verbose_init(struct lpfc_hba *phba, uint32_t verbose) | |
6012 | { | |
6013 | phba->cfg_log_verbose = verbose; | |
6014 | } | |
6015 | ||
dea3101e JB |
6016 | struct fc_function_template lpfc_transport_functions = { |
6017 | /* fixed attributes the driver supports */ | |
6018 | .show_host_node_name = 1, | |
6019 | .show_host_port_name = 1, | |
6020 | .show_host_supported_classes = 1, | |
6021 | .show_host_supported_fc4s = 1, | |
dea3101e JB |
6022 | .show_host_supported_speeds = 1, |
6023 | .show_host_maxframe_size = 1, | |
6c9231f6 JS |
6024 | |
6025 | .get_host_symbolic_name = lpfc_get_host_symbolic_name, | |
eada272d | 6026 | .show_host_symbolic_name = 1, |
dea3101e JB |
6027 | |
6028 | /* dynamic attributes the driver supports */ | |
6029 | .get_host_port_id = lpfc_get_host_port_id, | |
6030 | .show_host_port_id = 1, | |
6031 | ||
6032 | .get_host_port_type = lpfc_get_host_port_type, | |
6033 | .show_host_port_type = 1, | |
6034 | ||
6035 | .get_host_port_state = lpfc_get_host_port_state, | |
6036 | .show_host_port_state = 1, | |
6037 | ||
6038 | /* active_fc4s is shown but doesn't change (thus no get function) */ | |
6039 | .show_host_active_fc4s = 1, | |
6040 | ||
6041 | .get_host_speed = lpfc_get_host_speed, | |
6042 | .show_host_speed = 1, | |
6043 | ||
6044 | .get_host_fabric_name = lpfc_get_host_fabric_name, | |
6045 | .show_host_fabric_name = 1, | |
6046 | ||
6047 | /* | |
6048 | * The LPFC driver treats linkdown handling as target loss events | |
6049 | * so there are no sysfs handlers for link_down_tmo. | |
6050 | */ | |
6051 | ||
6052 | .get_fc_host_stats = lpfc_get_stats, | |
64ba8818 | 6053 | .reset_fc_host_stats = lpfc_reset_stats, |
dea3101e JB |
6054 | |
6055 | .dd_fcrport_size = sizeof(struct lpfc_rport_data), | |
6056 | .show_rport_maxframe_size = 1, | |
6057 | .show_rport_supported_classes = 1, | |
6058 | ||
dea3101e JB |
6059 | .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo, |
6060 | .show_rport_dev_loss_tmo = 1, | |
6061 | ||
6062 | .get_starget_port_id = lpfc_get_starget_port_id, | |
6063 | .show_starget_port_id = 1, | |
6064 | ||
6065 | .get_starget_node_name = lpfc_get_starget_node_name, | |
6066 | .show_starget_node_name = 1, | |
6067 | ||
6068 | .get_starget_port_name = lpfc_get_starget_port_name, | |
6069 | .show_starget_port_name = 1, | |
91ca7b01 AV |
6070 | |
6071 | .issue_fc_host_lip = lpfc_issue_lip, | |
c01f3208 JS |
6072 | .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk, |
6073 | .terminate_rport_io = lpfc_terminate_rport_io, | |
92d7f7b0 | 6074 | |
92d7f7b0 | 6075 | .dd_fcvport_size = sizeof(struct lpfc_vport *), |
eada272d JS |
6076 | |
6077 | .vport_disable = lpfc_vport_disable, | |
6078 | ||
6079 | .set_vport_symbolic_name = lpfc_set_vport_symbolic_name, | |
f1c3b0fc JS |
6080 | |
6081 | .bsg_request = lpfc_bsg_request, | |
6082 | .bsg_timeout = lpfc_bsg_timeout, | |
92d7f7b0 JS |
6083 | }; |
6084 | ||
98c9ea5c JS |
6085 | struct fc_function_template lpfc_vport_transport_functions = { |
6086 | /* fixed attributes the driver supports */ | |
6087 | .show_host_node_name = 1, | |
6088 | .show_host_port_name = 1, | |
6089 | .show_host_supported_classes = 1, | |
6090 | .show_host_supported_fc4s = 1, | |
6091 | .show_host_supported_speeds = 1, | |
6092 | .show_host_maxframe_size = 1, | |
6c9231f6 JS |
6093 | |
6094 | .get_host_symbolic_name = lpfc_get_host_symbolic_name, | |
eada272d | 6095 | .show_host_symbolic_name = 1, |
98c9ea5c JS |
6096 | |
6097 | /* dynamic attributes the driver supports */ | |
6098 | .get_host_port_id = lpfc_get_host_port_id, | |
6099 | .show_host_port_id = 1, | |
6100 | ||
6101 | .get_host_port_type = lpfc_get_host_port_type, | |
6102 | .show_host_port_type = 1, | |
6103 | ||
6104 | .get_host_port_state = lpfc_get_host_port_state, | |
6105 | .show_host_port_state = 1, | |
6106 | ||
6107 | /* active_fc4s is shown but doesn't change (thus no get function) */ | |
6108 | .show_host_active_fc4s = 1, | |
6109 | ||
6110 | .get_host_speed = lpfc_get_host_speed, | |
6111 | .show_host_speed = 1, | |
6112 | ||
6113 | .get_host_fabric_name = lpfc_get_host_fabric_name, | |
6114 | .show_host_fabric_name = 1, | |
6115 | ||
6116 | /* | |
6117 | * The LPFC driver treats linkdown handling as target loss events | |
6118 | * so there are no sysfs handlers for link_down_tmo. | |
6119 | */ | |
6120 | ||
6121 | .get_fc_host_stats = lpfc_get_stats, | |
6122 | .reset_fc_host_stats = lpfc_reset_stats, | |
6123 | ||
6124 | .dd_fcrport_size = sizeof(struct lpfc_rport_data), | |
6125 | .show_rport_maxframe_size = 1, | |
6126 | .show_rport_supported_classes = 1, | |
6127 | ||
6128 | .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo, | |
6129 | .show_rport_dev_loss_tmo = 1, | |
6130 | ||
6131 | .get_starget_port_id = lpfc_get_starget_port_id, | |
6132 | .show_starget_port_id = 1, | |
6133 | ||
6134 | .get_starget_node_name = lpfc_get_starget_node_name, | |
6135 | .show_starget_node_name = 1, | |
6136 | ||
6137 | .get_starget_port_name = lpfc_get_starget_port_name, | |
6138 | .show_starget_port_name = 1, | |
6139 | ||
6140 | .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk, | |
6141 | .terminate_rport_io = lpfc_terminate_rport_io, | |
6142 | ||
6143 | .vport_disable = lpfc_vport_disable, | |
eada272d JS |
6144 | |
6145 | .set_vport_symbolic_name = lpfc_set_vport_symbolic_name, | |
98c9ea5c JS |
6146 | }; |
6147 | ||
e59058c4 | 6148 | /** |
3621a710 | 6149 | * lpfc_get_cfgparam - Used during probe_one to init the adapter structure |
e59058c4 JS |
6150 | * @phba: lpfc_hba pointer. |
6151 | **/ | |
dea3101e JB |
6152 | void |
6153 | lpfc_get_cfgparam(struct lpfc_hba *phba) | |
6154 | { | |
49aa143d | 6155 | lpfc_fcp_io_sched_init(phba, lpfc_fcp_io_sched); |
a6571c6e | 6156 | lpfc_fcp2_no_tgt_reset_init(phba, lpfc_fcp2_no_tgt_reset); |
7bcbb752 JSEC |
6157 | lpfc_cr_delay_init(phba, lpfc_cr_delay); |
6158 | lpfc_cr_count_init(phba, lpfc_cr_count); | |
cf5bf97e | 6159 | lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support); |
a4bc3379 JS |
6160 | lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl); |
6161 | lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type); | |
7bcbb752 JSEC |
6162 | lpfc_ack0_init(phba, lpfc_ack0); |
6163 | lpfc_topology_init(phba, lpfc_topology); | |
7bcbb752 | 6164 | lpfc_link_speed_init(phba, lpfc_link_speed); |
875fbdfe | 6165 | lpfc_poll_tmo_init(phba, lpfc_poll_tmo); |
0c411222 | 6166 | lpfc_task_mgmt_tmo_init(phba, lpfc_task_mgmt_tmo); |
78b2d852 | 6167 | lpfc_enable_npiv_init(phba, lpfc_enable_npiv); |
7d791df7 | 6168 | lpfc_fcf_failover_policy_init(phba, lpfc_fcf_failover_policy); |
19ca7609 | 6169 | lpfc_enable_rrq_init(phba, lpfc_enable_rrq); |
4258e98e JS |
6170 | lpfc_fdmi_on_init(phba, lpfc_fdmi_on); |
6171 | lpfc_enable_SmartSAN_init(phba, lpfc_enable_SmartSAN); | |
4ff43246 | 6172 | lpfc_use_msi_init(phba, lpfc_use_msi); |
895427bd | 6173 | lpfc_nvme_oas_init(phba, lpfc_nvme_oas); |
da0436e9 | 6174 | lpfc_fcp_imax_init(phba, lpfc_fcp_imax); |
7bb03bbf | 6175 | lpfc_fcp_cpu_map_init(phba, lpfc_fcp_cpu_map); |
13815c83 JS |
6176 | lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset); |
6177 | lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat); | |
2ea259ee | 6178 | |
1ba981fd JS |
6179 | lpfc_EnableXLane_init(phba, lpfc_EnableXLane); |
6180 | if (phba->sli_rev != LPFC_SLI_REV4) | |
6181 | phba->cfg_EnableXLane = 0; | |
6182 | lpfc_XLanePriority_init(phba, lpfc_XLanePriority); | |
2ea259ee | 6183 | |
1ba981fd JS |
6184 | memset(phba->cfg_oas_tgt_wwpn, 0, (8 * sizeof(uint8_t))); |
6185 | memset(phba->cfg_oas_vpt_wwpn, 0, (8 * sizeof(uint8_t))); | |
6186 | phba->cfg_oas_lun_state = 0; | |
6187 | phba->cfg_oas_lun_status = 0; | |
6188 | phba->cfg_oas_flags = 0; | |
c92c841c | 6189 | phba->cfg_oas_priority = 0; |
81301a9b | 6190 | lpfc_enable_bg_init(phba, lpfc_enable_bg); |
b3b98b74 JS |
6191 | lpfc_prot_mask_init(phba, lpfc_prot_mask); |
6192 | lpfc_prot_guard_init(phba, lpfc_prot_guard); | |
45ed1190 JS |
6193 | if (phba->sli_rev == LPFC_SLI_REV4) |
6194 | phba->cfg_poll = 0; | |
6195 | else | |
1ba981fd | 6196 | phba->cfg_poll = lpfc_poll; |
f358dd0c | 6197 | lpfc_suppress_rsp_init(phba, lpfc_suppress_rsp); |
4258e98e | 6198 | |
895427bd | 6199 | lpfc_enable_fc4_type_init(phba, lpfc_enable_fc4_type); |
2d7dbc4c JS |
6200 | lpfc_nvmet_mrq_init(phba, lpfc_nvmet_mrq); |
6201 | lpfc_nvmet_mrq_post_init(phba, lpfc_nvmet_mrq_post); | |
895427bd JS |
6202 | |
6203 | /* Initialize first burst. Target vs Initiator are different. */ | |
6204 | lpfc_nvme_enable_fb_init(phba, lpfc_nvme_enable_fb); | |
2d7dbc4c | 6205 | lpfc_nvmet_fb_size_init(phba, lpfc_nvmet_fb_size); |
895427bd JS |
6206 | lpfc_fcp_io_channel_init(phba, lpfc_fcp_io_channel); |
6207 | lpfc_nvme_io_channel_init(phba, lpfc_nvme_io_channel); | |
6208 | ||
6209 | if (phba->sli_rev != LPFC_SLI_REV4) { | |
6210 | /* NVME only supported on SLI4 */ | |
6211 | phba->nvmet_support = 0; | |
6212 | phba->cfg_enable_fc4_type = LPFC_ENABLE_FCP; | |
6213 | } else { | |
6214 | /* We MUST have FCP support */ | |
6215 | if (!(phba->cfg_enable_fc4_type & LPFC_ENABLE_FCP)) | |
6216 | phba->cfg_enable_fc4_type |= LPFC_ENABLE_FCP; | |
6217 | } | |
6218 | ||
6219 | /* A value of 0 means use the number of CPUs found in the system */ | |
895427bd JS |
6220 | if (phba->cfg_fcp_io_channel == 0) |
6221 | phba->cfg_fcp_io_channel = phba->sli4_hba.num_present_cpu; | |
f358dd0c JS |
6222 | if (phba->cfg_nvme_io_channel == 0) |
6223 | phba->cfg_nvme_io_channel = phba->sli4_hba.num_present_cpu; | |
895427bd JS |
6224 | |
6225 | if (phba->cfg_enable_fc4_type == LPFC_ENABLE_NVME) | |
6226 | phba->cfg_fcp_io_channel = 0; | |
6227 | ||
f358dd0c JS |
6228 | if (phba->cfg_enable_fc4_type == LPFC_ENABLE_FCP) |
6229 | phba->cfg_nvme_io_channel = 0; | |
6230 | ||
895427bd JS |
6231 | if (phba->cfg_fcp_io_channel > phba->cfg_nvme_io_channel) |
6232 | phba->io_channel_irqs = phba->cfg_fcp_io_channel; | |
6233 | else | |
6234 | phba->io_channel_irqs = phba->cfg_nvme_io_channel; | |
4258e98e | 6235 | |
352e5fd1 JS |
6236 | phba->cfg_soft_wwnn = 0L; |
6237 | phba->cfg_soft_wwpn = 0L; | |
895427bd | 6238 | lpfc_xri_split_init(phba, lpfc_xri_split); |
83108bd3 | 6239 | lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt); |
7054a606 | 6240 | lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth); |
6fb120a7 | 6241 | lpfc_hba_log_verbose_init(phba, lpfc_log_verbose); |
0d878419 | 6242 | lpfc_aer_support_init(phba, lpfc_aer_support); |
912e3acd | 6243 | lpfc_sriov_nr_virtfn_init(phba, lpfc_sriov_nr_virtfn); |
c71ab861 | 6244 | lpfc_request_firmware_upgrade_init(phba, lpfc_req_fw_upgrade); |
84d1b006 | 6245 | lpfc_suppress_link_up_init(phba, lpfc_suppress_link_up); |
2a9bf3d0 | 6246 | lpfc_iocb_cnt_init(phba, lpfc_iocb_cnt); |
8eb8b960 | 6247 | lpfc_delay_discovery_init(phba, lpfc_delay_discovery); |
12247e81 | 6248 | lpfc_sli_mode_init(phba, lpfc_sli_mode); |
ab56dc2e | 6249 | phba->cfg_enable_dss = 1; |
7bdedb34 | 6250 | lpfc_enable_mds_diags_init(phba, lpfc_enable_mds_diags); |
3de2a653 JS |
6251 | return; |
6252 | } | |
b28485ac | 6253 | |
895427bd JS |
6254 | /** |
6255 | * lpfc_nvme_mod_param_dep - Adjust module parameter value based on | |
6256 | * dependencies between protocols and roles. | |
6257 | * @phba: lpfc_hba pointer. | |
6258 | **/ | |
6259 | void | |
6260 | lpfc_nvme_mod_param_dep(struct lpfc_hba *phba) | |
6261 | { | |
895427bd JS |
6262 | if (phba->cfg_nvme_io_channel > phba->sli4_hba.num_present_cpu) |
6263 | phba->cfg_nvme_io_channel = phba->sli4_hba.num_present_cpu; | |
f358dd0c | 6264 | |
895427bd JS |
6265 | if (phba->cfg_fcp_io_channel > phba->sli4_hba.num_present_cpu) |
6266 | phba->cfg_fcp_io_channel = phba->sli4_hba.num_present_cpu; | |
6267 | ||
f358dd0c JS |
6268 | if (phba->cfg_enable_fc4_type & LPFC_ENABLE_NVME && |
6269 | phba->nvmet_support) { | |
6270 | phba->cfg_enable_fc4_type &= ~LPFC_ENABLE_FCP; | |
6271 | phba->cfg_fcp_io_channel = 0; | |
2d7dbc4c JS |
6272 | |
6273 | lpfc_printf_log(phba, KERN_INFO, LOG_NVME_DISC, | |
6274 | "6013 %s x%x fb_size x%x, fb_max x%x\n", | |
6275 | "NVME Target PRLI ACC enable_fb ", | |
6276 | phba->cfg_nvme_enable_fb, | |
6277 | phba->cfg_nvmet_fb_size, | |
6278 | LPFC_NVMET_FB_SZ_MAX); | |
6279 | ||
6280 | if (phba->cfg_nvme_enable_fb == 0) | |
6281 | phba->cfg_nvmet_fb_size = 0; | |
6282 | else { | |
6283 | if (phba->cfg_nvmet_fb_size > LPFC_NVMET_FB_SZ_MAX) | |
6284 | phba->cfg_nvmet_fb_size = LPFC_NVMET_FB_SZ_MAX; | |
6285 | } | |
6286 | ||
6287 | /* Adjust lpfc_nvmet_mrq to avoid running out of WQE slots */ | |
6288 | if (phba->cfg_nvmet_mrq > phba->cfg_nvme_io_channel) { | |
6289 | phba->cfg_nvmet_mrq = phba->cfg_nvme_io_channel; | |
6290 | lpfc_printf_log(phba, KERN_ERR, LOG_NVME_DISC, | |
6291 | "6018 Adjust lpfc_nvmet_mrq to %d\n", | |
6292 | phba->cfg_nvmet_mrq); | |
6293 | } | |
6294 | } else { | |
f358dd0c JS |
6295 | /* Not NVME Target mode. Turn off Target parameters. */ |
6296 | phba->nvmet_support = 0; | |
2d7dbc4c JS |
6297 | phba->cfg_nvmet_mrq = 0; |
6298 | phba->cfg_nvmet_mrq_post = 0; | |
6299 | phba->cfg_nvmet_fb_size = 0; | |
6300 | } | |
f358dd0c | 6301 | |
895427bd JS |
6302 | if (phba->cfg_fcp_io_channel > phba->cfg_nvme_io_channel) |
6303 | phba->io_channel_irqs = phba->cfg_fcp_io_channel; | |
6304 | else | |
6305 | phba->io_channel_irqs = phba->cfg_nvme_io_channel; | |
6306 | } | |
6307 | ||
e59058c4 | 6308 | /** |
3621a710 | 6309 | * lpfc_get_vport_cfgparam - Used during port create, init the vport structure |
e59058c4 JS |
6310 | * @vport: lpfc_vport pointer. |
6311 | **/ | |
3de2a653 JS |
6312 | void |
6313 | lpfc_get_vport_cfgparam(struct lpfc_vport *vport) | |
6314 | { | |
e8b62011 | 6315 | lpfc_log_verbose_init(vport, lpfc_log_verbose); |
3de2a653 | 6316 | lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth); |
7dc517df | 6317 | lpfc_tgt_queue_depth_init(vport, lpfc_tgt_queue_depth); |
3de2a653 JS |
6318 | lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo); |
6319 | lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo); | |
6320 | lpfc_peer_port_login_init(vport, lpfc_peer_port_login); | |
6321 | lpfc_restrict_login_init(vport, lpfc_restrict_login); | |
6322 | lpfc_fcp_class_init(vport, lpfc_fcp_class); | |
6323 | lpfc_use_adisc_init(vport, lpfc_use_adisc); | |
3cb01c57 | 6324 | lpfc_first_burst_size_init(vport, lpfc_first_burst_size); |
977b5a0a | 6325 | lpfc_max_scsicmpl_time_init(vport, lpfc_max_scsicmpl_time); |
3de2a653 JS |
6326 | lpfc_discovery_threads_init(vport, lpfc_discovery_threads); |
6327 | lpfc_max_luns_init(vport, lpfc_max_luns); | |
6328 | lpfc_scan_down_init(vport, lpfc_scan_down); | |
7ee5d43e | 6329 | lpfc_enable_da_id_init(vport, lpfc_enable_da_id); |
dea3101e JB |
6330 | return; |
6331 | } |