Commit | Line | Data |
---|---|---|
dea3101e | 1 | /******************************************************************* |
2 | * This file is part of the Emulex Linux Device Driver for * | |
c44ce173 | 3 | * Fibre Channel Host Bus Adapters. * |
09372820 | 4 | * Copyright (C) 2004-2008 Emulex. All rights reserved. * |
c44ce173 | 5 | * EMULEX and SLI are trademarks of Emulex. * |
dea3101e | 6 | * www.emulex.com * |
c44ce173 | 7 | * Portions Copyright (C) 2004-2005 Christoph Hellwig * |
dea3101e | 8 | * * |
9 | * This program is free software; you can redistribute it and/or * | |
c44ce173 JSEC |
10 | * modify it under the terms of version 2 of the GNU General * |
11 | * Public License as published by the Free Software Foundation. * | |
12 | * This program is distributed in the hope that it will be useful. * | |
13 | * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * | |
14 | * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * | |
15 | * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE * | |
16 | * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD * | |
17 | * TO BE LEGALLY INVALID. See the GNU General Public License for * | |
18 | * more details, a copy of which can be found in the file COPYING * | |
19 | * included with this package. * | |
dea3101e | 20 | *******************************************************************/ |
21 | ||
dea3101e | 22 | #include <linux/ctype.h> |
46fa311e | 23 | #include <linux/delay.h> |
dea3101e | 24 | #include <linux/pci.h> |
25 | #include <linux/interrupt.h> | |
26 | ||
91886523 | 27 | #include <scsi/scsi.h> |
dea3101e | 28 | #include <scsi/scsi_device.h> |
29 | #include <scsi/scsi_host.h> | |
30 | #include <scsi/scsi_tcq.h> | |
31 | #include <scsi/scsi_transport_fc.h> | |
32 | ||
33 | #include "lpfc_hw.h" | |
34 | #include "lpfc_sli.h" | |
35 | #include "lpfc_disc.h" | |
36 | #include "lpfc_scsi.h" | |
37 | #include "lpfc.h" | |
38 | #include "lpfc_logmsg.h" | |
39 | #include "lpfc_version.h" | |
40 | #include "lpfc_compat.h" | |
41 | #include "lpfc_crtn.h" | |
92d7f7b0 | 42 | #include "lpfc_vport.h" |
dea3101e | 43 | |
c01f3208 JS |
44 | #define LPFC_DEF_DEVLOSS_TMO 30 |
45 | #define LPFC_MIN_DEVLOSS_TMO 1 | |
46 | #define LPFC_MAX_DEVLOSS_TMO 255 | |
dea3101e | 47 | |
83108bd3 JS |
48 | #define LPFC_MAX_LINK_SPEED 8 |
49 | #define LPFC_LINK_SPEED_BITMAP 0x00000117 | |
50 | #define LPFC_LINK_SPEED_STRING "0, 1, 2, 4, 8" | |
51 | ||
e59058c4 JS |
52 | /** |
53 | * lpfc_jedec_to_ascii: Hex to ascii convertor according to JEDEC rules. | |
54 | * @incr: integer to convert. | |
55 | * @hdw: ascii string holding converted integer plus a string terminator. | |
56 | * | |
57 | * Description: | |
58 | * JEDEC Joint Electron Device Engineering Council. | |
59 | * Convert a 32 bit integer composed of 8 nibbles into an 8 byte ascii | |
60 | * character string. The string is then terminated with a NULL in byte 9. | |
61 | * Hex 0-9 becomes ascii '0' to '9'. | |
62 | * Hex a-f becomes ascii '=' to 'B' capital B. | |
63 | * | |
64 | * Notes: | |
65 | * Coded for 32 bit integers only. | |
66 | **/ | |
dea3101e | 67 | static void |
68 | lpfc_jedec_to_ascii(int incr, char hdw[]) | |
69 | { | |
70 | int i, j; | |
71 | for (i = 0; i < 8; i++) { | |
72 | j = (incr & 0xf); | |
73 | if (j <= 9) | |
74 | hdw[7 - i] = 0x30 + j; | |
75 | else | |
76 | hdw[7 - i] = 0x61 + j - 10; | |
77 | incr = (incr >> 4); | |
78 | } | |
79 | hdw[8] = 0; | |
80 | return; | |
81 | } | |
82 | ||
e59058c4 JS |
83 | /** |
84 | * lpfc_drvr_version_show: Return the Emulex driver string with version number. | |
85 | * @dev: class unused variable. | |
86 | * @attr: device attribute, not used. | |
87 | * @buf: on return contains the module description text. | |
88 | * | |
89 | * Returns: size of formatted string. | |
90 | **/ | |
dea3101e | 91 | static ssize_t |
ee959b00 TJ |
92 | lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr, |
93 | char *buf) | |
dea3101e | 94 | { |
95 | return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n"); | |
96 | } | |
97 | ||
e59058c4 JS |
98 | /** |
99 | * lpfc_info_show: Return some pci info about the host in ascii. | |
100 | * @dev: class converted to a Scsi_host structure. | |
101 | * @attr: device attribute, not used. | |
102 | * @buf: on return contains the formatted text from lpfc_info(). | |
103 | * | |
104 | * Returns: size of formatted string. | |
105 | **/ | |
dea3101e | 106 | static ssize_t |
ee959b00 TJ |
107 | lpfc_info_show(struct device *dev, struct device_attribute *attr, |
108 | char *buf) | |
dea3101e | 109 | { |
ee959b00 | 110 | struct Scsi_Host *host = class_to_shost(dev); |
2e0fef85 | 111 | |
dea3101e | 112 | return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host)); |
113 | } | |
114 | ||
e59058c4 JS |
115 | /** |
116 | * lpfc_serialnum_show: Return the hba serial number in ascii. | |
117 | * @dev: class converted to a Scsi_host structure. | |
118 | * @attr: device attribute, not used. | |
119 | * @buf: on return contains the formatted text serial number. | |
120 | * | |
121 | * Returns: size of formatted string. | |
122 | **/ | |
dea3101e | 123 | static ssize_t |
ee959b00 TJ |
124 | lpfc_serialnum_show(struct device *dev, struct device_attribute *attr, |
125 | char *buf) | |
dea3101e | 126 | { |
ee959b00 | 127 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 JS |
128 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
129 | struct lpfc_hba *phba = vport->phba; | |
130 | ||
dea3101e | 131 | return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber); |
132 | } | |
133 | ||
e59058c4 JS |
134 | /** |
135 | * lpfc_temp_sensor_show: Return the temperature sensor level. | |
136 | * @dev: class converted to a Scsi_host structure. | |
137 | * @attr: device attribute, not used. | |
138 | * @buf: on return contains the formatted support level. | |
139 | * | |
140 | * Description: | |
141 | * Returns a number indicating the temperature sensor level currently | |
142 | * supported, zero or one in ascii. | |
143 | * | |
144 | * Returns: size of formatted string. | |
145 | **/ | |
57127f15 | 146 | static ssize_t |
ee959b00 TJ |
147 | lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr, |
148 | char *buf) | |
57127f15 | 149 | { |
ee959b00 | 150 | struct Scsi_Host *shost = class_to_shost(dev); |
57127f15 JS |
151 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
152 | struct lpfc_hba *phba = vport->phba; | |
153 | return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support); | |
154 | } | |
155 | ||
e59058c4 JS |
156 | /** |
157 | * lpfc_modeldesc_show: Return the model description of the hba. | |
158 | * @dev: class converted to a Scsi_host structure. | |
159 | * @attr: device attribute, not used. | |
160 | * @buf: on return contains the scsi vpd model description. | |
161 | * | |
162 | * Returns: size of formatted string. | |
163 | **/ | |
dea3101e | 164 | static ssize_t |
ee959b00 TJ |
165 | lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr, |
166 | char *buf) | |
dea3101e | 167 | { |
ee959b00 | 168 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 JS |
169 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
170 | struct lpfc_hba *phba = vport->phba; | |
171 | ||
dea3101e | 172 | return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc); |
173 | } | |
174 | ||
e59058c4 JS |
175 | /** |
176 | * lpfc_modelname_show: Return the model name of the hba. | |
177 | * @dev: class converted to a Scsi_host structure. | |
178 | * @attr: device attribute, not used. | |
179 | * @buf: on return contains the scsi vpd model name. | |
180 | * | |
181 | * Returns: size of formatted string. | |
182 | **/ | |
dea3101e | 183 | static ssize_t |
ee959b00 TJ |
184 | lpfc_modelname_show(struct device *dev, struct device_attribute *attr, |
185 | char *buf) | |
dea3101e | 186 | { |
ee959b00 | 187 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 JS |
188 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
189 | struct lpfc_hba *phba = vport->phba; | |
190 | ||
dea3101e | 191 | return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName); |
192 | } | |
193 | ||
e59058c4 JS |
194 | /** |
195 | * lpfc_programtype_show: Return the program type of the hba. | |
196 | * @dev: class converted to a Scsi_host structure. | |
197 | * @attr: device attribute, not used. | |
198 | * @buf: on return contains the scsi vpd program type. | |
199 | * | |
200 | * Returns: size of formatted string. | |
201 | **/ | |
dea3101e | 202 | static ssize_t |
ee959b00 TJ |
203 | lpfc_programtype_show(struct device *dev, struct device_attribute *attr, |
204 | char *buf) | |
dea3101e | 205 | { |
ee959b00 | 206 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 JS |
207 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
208 | struct lpfc_hba *phba = vport->phba; | |
209 | ||
dea3101e | 210 | return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType); |
211 | } | |
212 | ||
84774a4d JS |
213 | /** |
214 | * lpfc_mlomgmt_show: Return the Menlo Maintenance sli flag. | |
215 | * @dev: class converted to a Scsi_host structure. | |
216 | * @attr: device attribute, not used. | |
217 | * @buf: on return contains the Menlo Maintenance sli flag. | |
218 | * | |
219 | * Returns: size of formatted string. | |
220 | **/ | |
221 | static ssize_t | |
222 | lpfc_mlomgmt_show(struct device *dev, struct device_attribute *attr, char *buf) | |
223 | { | |
224 | struct Scsi_Host *shost = class_to_shost(dev); | |
225 | struct lpfc_vport *vport = (struct lpfc_vport *)shost->hostdata; | |
226 | struct lpfc_hba *phba = vport->phba; | |
227 | ||
228 | return snprintf(buf, PAGE_SIZE, "%d\n", | |
229 | (phba->sli.sli_flag & LPFC_MENLO_MAINT)); | |
230 | } | |
231 | ||
e59058c4 JS |
232 | /** |
233 | * lpfc_vportnum_show: Return the port number in ascii of the hba. | |
234 | * @dev: class converted to a Scsi_host structure. | |
235 | * @attr: device attribute, not used. | |
236 | * @buf: on return contains scsi vpd program type. | |
237 | * | |
238 | * Returns: size of formatted string. | |
239 | **/ | |
dea3101e | 240 | static ssize_t |
ee959b00 TJ |
241 | lpfc_vportnum_show(struct device *dev, struct device_attribute *attr, |
242 | char *buf) | |
dea3101e | 243 | { |
ee959b00 | 244 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 JS |
245 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
246 | struct lpfc_hba *phba = vport->phba; | |
247 | ||
dea3101e | 248 | return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port); |
249 | } | |
250 | ||
e59058c4 JS |
251 | /** |
252 | * lpfc_fwrev_show: Return the firmware rev running in the hba. | |
253 | * @dev: class converted to a Scsi_host structure. | |
254 | * @attr: device attribute, not used. | |
255 | * @buf: on return contains the scsi vpd program type. | |
256 | * | |
257 | * Returns: size of formatted string. | |
258 | **/ | |
dea3101e | 259 | static ssize_t |
ee959b00 TJ |
260 | lpfc_fwrev_show(struct device *dev, struct device_attribute *attr, |
261 | char *buf) | |
dea3101e | 262 | { |
ee959b00 | 263 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 JS |
264 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
265 | struct lpfc_hba *phba = vport->phba; | |
dea3101e | 266 | char fwrev[32]; |
2e0fef85 | 267 | |
dea3101e | 268 | lpfc_decode_firmware_rev(phba, fwrev, 1); |
92d7f7b0 | 269 | return snprintf(buf, PAGE_SIZE, "%s, sli-%d\n", fwrev, phba->sli_rev); |
dea3101e | 270 | } |
271 | ||
e59058c4 JS |
272 | /** |
273 | * lpfc_hdw_show: Return the jedec information about the hba. | |
274 | * @dev: class converted to a Scsi_host structure. | |
275 | * @attr: device attribute, not used. | |
276 | * @buf: on return contains the scsi vpd program type. | |
277 | * | |
278 | * Returns: size of formatted string. | |
279 | **/ | |
dea3101e | 280 | static ssize_t |
ee959b00 | 281 | lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf) |
dea3101e | 282 | { |
283 | char hdw[9]; | |
ee959b00 | 284 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 JS |
285 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
286 | struct lpfc_hba *phba = vport->phba; | |
dea3101e | 287 | lpfc_vpd_t *vp = &phba->vpd; |
2e0fef85 | 288 | |
dea3101e | 289 | lpfc_jedec_to_ascii(vp->rev.biuRev, hdw); |
290 | return snprintf(buf, PAGE_SIZE, "%s\n", hdw); | |
291 | } | |
e59058c4 JS |
292 | |
293 | /** | |
294 | * lpfc_option_rom_version_show: Return the adapter ROM FCode version. | |
295 | * @dev: class converted to a Scsi_host structure. | |
296 | * @attr: device attribute, not used. | |
297 | * @buf: on return contains the ROM and FCode ascii strings. | |
298 | * | |
299 | * Returns: size of formatted string. | |
300 | **/ | |
dea3101e | 301 | static ssize_t |
ee959b00 TJ |
302 | lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr, |
303 | char *buf) | |
dea3101e | 304 | { |
ee959b00 | 305 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 JS |
306 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
307 | struct lpfc_hba *phba = vport->phba; | |
308 | ||
dea3101e | 309 | return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion); |
310 | } | |
e59058c4 JS |
311 | |
312 | /** | |
313 | * lpfc_state_show: Return the link state of the port. | |
314 | * @dev: class converted to a Scsi_host structure. | |
315 | * @attr: device attribute, not used. | |
316 | * @buf: on return contains text describing the state of the link. | |
317 | * | |
318 | * Notes: | |
319 | * The switch statement has no default so zero will be returned. | |
320 | * | |
321 | * Returns: size of formatted string. | |
322 | **/ | |
dea3101e | 323 | static ssize_t |
bbd1ae41 HR |
324 | lpfc_link_state_show(struct device *dev, struct device_attribute *attr, |
325 | char *buf) | |
dea3101e | 326 | { |
ee959b00 | 327 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 JS |
328 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
329 | struct lpfc_hba *phba = vport->phba; | |
330 | int len = 0; | |
331 | ||
332 | switch (phba->link_state) { | |
333 | case LPFC_LINK_UNKNOWN: | |
41415862 | 334 | case LPFC_WARM_START: |
dea3101e | 335 | case LPFC_INIT_START: |
336 | case LPFC_INIT_MBX_CMDS: | |
337 | case LPFC_LINK_DOWN: | |
2e0fef85 | 338 | case LPFC_HBA_ERROR: |
dea3101e | 339 | len += snprintf(buf + len, PAGE_SIZE-len, "Link Down\n"); |
340 | break; | |
341 | case LPFC_LINK_UP: | |
dea3101e | 342 | case LPFC_CLEAR_LA: |
dea3101e | 343 | case LPFC_HBA_READY: |
a8adb832 | 344 | len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - "); |
2e0fef85 JS |
345 | |
346 | switch (vport->port_state) { | |
2e0fef85 JS |
347 | case LPFC_LOCAL_CFG_LINK: |
348 | len += snprintf(buf + len, PAGE_SIZE-len, | |
92d7f7b0 | 349 | "Configuring Link\n"); |
2e0fef85 | 350 | break; |
92d7f7b0 | 351 | case LPFC_FDISC: |
2e0fef85 JS |
352 | case LPFC_FLOGI: |
353 | case LPFC_FABRIC_CFG_LINK: | |
354 | case LPFC_NS_REG: | |
355 | case LPFC_NS_QRY: | |
356 | case LPFC_BUILD_DISC_LIST: | |
357 | case LPFC_DISC_AUTH: | |
358 | len += snprintf(buf + len, PAGE_SIZE - len, | |
359 | "Discovery\n"); | |
360 | break; | |
361 | case LPFC_VPORT_READY: | |
362 | len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n"); | |
363 | break; | |
364 | ||
92d7f7b0 JS |
365 | case LPFC_VPORT_FAILED: |
366 | len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n"); | |
367 | break; | |
368 | ||
369 | case LPFC_VPORT_UNKNOWN: | |
2e0fef85 JS |
370 | len += snprintf(buf + len, PAGE_SIZE - len, |
371 | "Unknown\n"); | |
372 | break; | |
373 | } | |
84774a4d JS |
374 | if (phba->sli.sli_flag & LPFC_MENLO_MAINT) |
375 | len += snprintf(buf + len, PAGE_SIZE-len, | |
376 | " Menlo Maint Mode\n"); | |
377 | else if (phba->fc_topology == TOPOLOGY_LOOP) { | |
2e0fef85 | 378 | if (vport->fc_flag & FC_PUBLIC_LOOP) |
dea3101e | 379 | len += snprintf(buf + len, PAGE_SIZE-len, |
380 | " Public Loop\n"); | |
381 | else | |
382 | len += snprintf(buf + len, PAGE_SIZE-len, | |
383 | " Private Loop\n"); | |
384 | } else { | |
2e0fef85 | 385 | if (vport->fc_flag & FC_FABRIC) |
dea3101e | 386 | len += snprintf(buf + len, PAGE_SIZE-len, |
387 | " Fabric\n"); | |
388 | else | |
389 | len += snprintf(buf + len, PAGE_SIZE-len, | |
390 | " Point-2-Point\n"); | |
391 | } | |
392 | } | |
2e0fef85 | 393 | |
dea3101e | 394 | return len; |
395 | } | |
396 | ||
e59058c4 JS |
397 | /** |
398 | * lpfc_num_discovered_ports_show: Return sum of mapped and unmapped vports. | |
399 | * @dev: class device that is converted into a Scsi_host. | |
400 | * @attr: device attribute, not used. | |
401 | * @buf: on return contains the sum of fc mapped and unmapped. | |
402 | * | |
403 | * Description: | |
404 | * Returns the ascii text number of the sum of the fc mapped and unmapped | |
405 | * vport counts. | |
406 | * | |
407 | * Returns: size of formatted string. | |
408 | **/ | |
dea3101e | 409 | static ssize_t |
ee959b00 TJ |
410 | lpfc_num_discovered_ports_show(struct device *dev, |
411 | struct device_attribute *attr, char *buf) | |
dea3101e | 412 | { |
ee959b00 | 413 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 JS |
414 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
415 | ||
416 | return snprintf(buf, PAGE_SIZE, "%d\n", | |
417 | vport->fc_map_cnt + vport->fc_unmap_cnt); | |
dea3101e | 418 | } |
419 | ||
e59058c4 JS |
420 | /** |
421 | * lpfc_issue_lip: Misnomer, name carried over from long ago. | |
422 | * @shost: Scsi_Host pointer. | |
423 | * | |
424 | * Description: | |
425 | * Bring the link down gracefully then re-init the link. The firmware will | |
426 | * re-init the fiber channel interface as required. Does not issue a LIP. | |
427 | * | |
428 | * Returns: | |
429 | * -EPERM port offline or management commands are being blocked | |
430 | * -ENOMEM cannot allocate memory for the mailbox command | |
431 | * -EIO error sending the mailbox command | |
432 | * zero for success | |
433 | **/ | |
91ca7b01 | 434 | static int |
2e0fef85 | 435 | lpfc_issue_lip(struct Scsi_Host *shost) |
dea3101e | 436 | { |
2e0fef85 JS |
437 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
438 | struct lpfc_hba *phba = vport->phba; | |
dea3101e | 439 | LPFC_MBOXQ_t *pmboxq; |
440 | int mbxstatus = MBXERR_ERROR; | |
441 | ||
2e0fef85 | 442 | if ((vport->fc_flag & FC_OFFLINE_MODE) || |
83108bd3 | 443 | (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)) |
dea3101e | 444 | return -EPERM; |
445 | ||
446 | pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL); | |
447 | ||
448 | if (!pmboxq) | |
449 | return -ENOMEM; | |
450 | ||
451 | memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t)); | |
4db621e0 JS |
452 | pmboxq->mb.mbxCommand = MBX_DOWN_LINK; |
453 | pmboxq->mb.mbxOwner = OWN_HOST; | |
454 | ||
33ccf8d1 | 455 | mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2); |
dea3101e | 456 | |
4db621e0 JS |
457 | if ((mbxstatus == MBX_SUCCESS) && (pmboxq->mb.mbxStatus == 0)) { |
458 | memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t)); | |
459 | lpfc_init_link(phba, pmboxq, phba->cfg_topology, | |
460 | phba->cfg_link_speed); | |
461 | mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, | |
462 | phba->fc_ratov * 2); | |
463 | } | |
464 | ||
5b8bd0c9 | 465 | lpfc_set_loopback_flag(phba); |
858c9f6c | 466 | if (mbxstatus != MBX_TIMEOUT) |
433c3579 | 467 | mempool_free(pmboxq, phba->mbox_mem_pool); |
dea3101e | 468 | |
469 | if (mbxstatus == MBXERR_ERROR) | |
470 | return -EIO; | |
471 | ||
91ca7b01 | 472 | return 0; |
dea3101e | 473 | } |
474 | ||
e59058c4 JS |
475 | /** |
476 | * lpfc_do_offline: Issues a mailbox command to bring the link down. | |
477 | * @phba: lpfc_hba pointer. | |
478 | * @type: LPFC_EVT_OFFLINE, LPFC_EVT_WARM_START, LPFC_EVT_KILL. | |
479 | * | |
480 | * Notes: | |
481 | * Assumes any error from lpfc_do_offline() will be negative. | |
482 | * Can wait up to 5 seconds for the port ring buffers count | |
483 | * to reach zero, prints a warning if it is not zero and continues. | |
484 | * lpfc_workq_post_event() returns a non-zero return coce if call fails. | |
485 | * | |
486 | * Returns: | |
487 | * -EIO error posting the event | |
488 | * zero for success | |
489 | **/ | |
40496f07 | 490 | static int |
46fa311e | 491 | lpfc_do_offline(struct lpfc_hba *phba, uint32_t type) |
40496f07 JS |
492 | { |
493 | struct completion online_compl; | |
46fa311e JS |
494 | struct lpfc_sli_ring *pring; |
495 | struct lpfc_sli *psli; | |
40496f07 | 496 | int status = 0; |
46fa311e JS |
497 | int cnt = 0; |
498 | int i; | |
40496f07 JS |
499 | |
500 | init_completion(&online_compl); | |
501 | lpfc_workq_post_event(phba, &status, &online_compl, | |
46fa311e JS |
502 | LPFC_EVT_OFFLINE_PREP); |
503 | wait_for_completion(&online_compl); | |
504 | ||
505 | if (status != 0) | |
506 | return -EIO; | |
507 | ||
508 | psli = &phba->sli; | |
509 | ||
09372820 JS |
510 | /* Wait a little for things to settle down, but not |
511 | * long enough for dev loss timeout to expire. | |
512 | */ | |
46fa311e JS |
513 | for (i = 0; i < psli->num_rings; i++) { |
514 | pring = &psli->ring[i]; | |
46fa311e JS |
515 | while (pring->txcmplq_cnt) { |
516 | msleep(10); | |
09372820 | 517 | if (cnt++ > 500) { /* 5 secs */ |
46fa311e JS |
518 | lpfc_printf_log(phba, |
519 | KERN_WARNING, LOG_INIT, | |
e8b62011 JS |
520 | "0466 Outstanding IO when " |
521 | "bringing Adapter offline\n"); | |
46fa311e JS |
522 | break; |
523 | } | |
524 | } | |
525 | } | |
526 | ||
527 | init_completion(&online_compl); | |
528 | lpfc_workq_post_event(phba, &status, &online_compl, type); | |
40496f07 JS |
529 | wait_for_completion(&online_compl); |
530 | ||
531 | if (status != 0) | |
532 | return -EIO; | |
533 | ||
46fa311e JS |
534 | return 0; |
535 | } | |
536 | ||
e59058c4 JS |
537 | /** |
538 | * lpfc_selective_reset: Offline then onlines the port. | |
539 | * @phba: lpfc_hba pointer. | |
540 | * | |
541 | * Description: | |
542 | * If the port is configured to allow a reset then the hba is brought | |
543 | * offline then online. | |
544 | * | |
545 | * Notes: | |
546 | * Assumes any error from lpfc_do_offline() will be negative. | |
547 | * | |
548 | * Returns: | |
549 | * lpfc_do_offline() return code if not zero | |
550 | * -EIO reset not configured or error posting the event | |
551 | * zero for success | |
552 | **/ | |
46fa311e JS |
553 | static int |
554 | lpfc_selective_reset(struct lpfc_hba *phba) | |
555 | { | |
556 | struct completion online_compl; | |
557 | int status = 0; | |
558 | ||
13815c83 JS |
559 | if (!phba->cfg_enable_hba_reset) |
560 | return -EIO; | |
561 | ||
46fa311e JS |
562 | status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE); |
563 | ||
564 | if (status != 0) | |
565 | return status; | |
566 | ||
40496f07 JS |
567 | init_completion(&online_compl); |
568 | lpfc_workq_post_event(phba, &status, &online_compl, | |
569 | LPFC_EVT_ONLINE); | |
570 | wait_for_completion(&online_compl); | |
571 | ||
572 | if (status != 0) | |
573 | return -EIO; | |
574 | ||
575 | return 0; | |
576 | } | |
577 | ||
e59058c4 JS |
578 | /** |
579 | * lpfc_issue_reset: Selectively resets an adapter. | |
580 | * @dev: class device that is converted into a Scsi_host. | |
581 | * @attr: device attribute, not used. | |
582 | * @buf: containing the string "selective". | |
583 | * @count: unused variable. | |
584 | * | |
585 | * Description: | |
586 | * If the buf contains the string "selective" then lpfc_selective_reset() | |
587 | * is called to perform the reset. | |
588 | * | |
589 | * Notes: | |
590 | * Assumes any error from lpfc_selective_reset() will be negative. | |
591 | * If lpfc_selective_reset() returns zero then the length of the buffer | |
592 | * is returned which indicates succcess | |
593 | * | |
594 | * Returns: | |
595 | * -EINVAL if the buffer does not contain the string "selective" | |
596 | * length of buf if lpfc-selective_reset() if the call succeeds | |
597 | * return value of lpfc_selective_reset() if the call fails | |
598 | **/ | |
40496f07 | 599 | static ssize_t |
ee959b00 TJ |
600 | lpfc_issue_reset(struct device *dev, struct device_attribute *attr, |
601 | const char *buf, size_t count) | |
40496f07 | 602 | { |
ee959b00 | 603 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 JS |
604 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
605 | struct lpfc_hba *phba = vport->phba; | |
606 | ||
40496f07 JS |
607 | int status = -EINVAL; |
608 | ||
609 | if (strncmp(buf, "selective", sizeof("selective") - 1) == 0) | |
610 | status = lpfc_selective_reset(phba); | |
611 | ||
612 | if (status == 0) | |
613 | return strlen(buf); | |
614 | else | |
615 | return status; | |
616 | } | |
617 | ||
e59058c4 JS |
618 | /** |
619 | * lpfc_nport_evt_cnt_show: Return the number of nport events. | |
620 | * @dev: class device that is converted into a Scsi_host. | |
621 | * @attr: device attribute, not used. | |
622 | * @buf: on return contains the ascii number of nport events. | |
623 | * | |
624 | * Returns: size of formatted string. | |
625 | **/ | |
dea3101e | 626 | static ssize_t |
ee959b00 TJ |
627 | lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr, |
628 | char *buf) | |
dea3101e | 629 | { |
ee959b00 | 630 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 JS |
631 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
632 | struct lpfc_hba *phba = vport->phba; | |
633 | ||
dea3101e | 634 | return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt); |
635 | } | |
636 | ||
e59058c4 JS |
637 | /** |
638 | * lpfc_board_mode_show: Return the state of the board. | |
639 | * @dev: class device that is converted into a Scsi_host. | |
640 | * @attr: device attribute, not used. | |
641 | * @buf: on return contains the state of the adapter. | |
642 | * | |
643 | * Returns: size of formatted string. | |
644 | **/ | |
41415862 | 645 | static ssize_t |
ee959b00 TJ |
646 | lpfc_board_mode_show(struct device *dev, struct device_attribute *attr, |
647 | char *buf) | |
41415862 | 648 | { |
ee959b00 | 649 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 JS |
650 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
651 | struct lpfc_hba *phba = vport->phba; | |
41415862 JW |
652 | char * state; |
653 | ||
2e0fef85 | 654 | if (phba->link_state == LPFC_HBA_ERROR) |
41415862 | 655 | state = "error"; |
2e0fef85 | 656 | else if (phba->link_state == LPFC_WARM_START) |
41415862 | 657 | state = "warm start"; |
2e0fef85 | 658 | else if (phba->link_state == LPFC_INIT_START) |
41415862 JW |
659 | state = "offline"; |
660 | else | |
661 | state = "online"; | |
662 | ||
663 | return snprintf(buf, PAGE_SIZE, "%s\n", state); | |
664 | } | |
665 | ||
e59058c4 JS |
666 | /** |
667 | * lpfc_board_mode_store: Puts the hba in online, offline, warm or error state. | |
668 | * @dev: class device that is converted into a Scsi_host. | |
669 | * @attr: device attribute, not used. | |
670 | * @buf: containing one of the strings "online", "offline", "warm" or "error". | |
671 | * @count: unused variable. | |
672 | * | |
673 | * Returns: | |
674 | * -EACCES if enable hba reset not enabled | |
675 | * -EINVAL if the buffer does not contain a valid string (see above) | |
676 | * -EIO if lpfc_workq_post_event() or lpfc_do_offline() fails | |
677 | * buf length greater than zero indicates success | |
678 | **/ | |
41415862 | 679 | static ssize_t |
ee959b00 TJ |
680 | lpfc_board_mode_store(struct device *dev, struct device_attribute *attr, |
681 | const char *buf, size_t count) | |
41415862 | 682 | { |
ee959b00 | 683 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 JS |
684 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
685 | struct lpfc_hba *phba = vport->phba; | |
41415862 JW |
686 | struct completion online_compl; |
687 | int status=0; | |
688 | ||
13815c83 JS |
689 | if (!phba->cfg_enable_hba_reset) |
690 | return -EACCES; | |
41415862 JW |
691 | init_completion(&online_compl); |
692 | ||
46fa311e | 693 | if(strncmp(buf, "online", sizeof("online") - 1) == 0) { |
41415862 JW |
694 | lpfc_workq_post_event(phba, &status, &online_compl, |
695 | LPFC_EVT_ONLINE); | |
46fa311e JS |
696 | wait_for_completion(&online_compl); |
697 | } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0) | |
698 | status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE); | |
41415862 | 699 | else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0) |
46fa311e JS |
700 | status = lpfc_do_offline(phba, LPFC_EVT_WARM_START); |
701 | else if (strncmp(buf, "error", sizeof("error") - 1) == 0) | |
702 | status = lpfc_do_offline(phba, LPFC_EVT_KILL); | |
41415862 JW |
703 | else |
704 | return -EINVAL; | |
705 | ||
41415862 JW |
706 | if (!status) |
707 | return strlen(buf); | |
708 | else | |
709 | return -EIO; | |
710 | } | |
711 | ||
e59058c4 JS |
712 | /** |
713 | * lpfc_get_hba_info: Return various bits of informaton about the adapter. | |
714 | * @phba: pointer to the adapter structure. | |
715 | * @mxri max xri count. | |
716 | * @axri available xri count. | |
717 | * @mrpi max rpi count. | |
718 | * @arpi available rpi count. | |
719 | * @mvpi max vpi count. | |
720 | * @avpi available vpi count. | |
721 | * | |
722 | * Description: | |
723 | * If an integer pointer for an count is not null then the value for the | |
724 | * count is returned. | |
725 | * | |
726 | * Returns: | |
727 | * zero on error | |
728 | * one for success | |
729 | **/ | |
311464ec | 730 | static int |
858c9f6c JS |
731 | lpfc_get_hba_info(struct lpfc_hba *phba, |
732 | uint32_t *mxri, uint32_t *axri, | |
733 | uint32_t *mrpi, uint32_t *arpi, | |
734 | uint32_t *mvpi, uint32_t *avpi) | |
92d7f7b0 JS |
735 | { |
736 | struct lpfc_sli *psli = &phba->sli; | |
737 | LPFC_MBOXQ_t *pmboxq; | |
738 | MAILBOX_t *pmb; | |
739 | int rc = 0; | |
740 | ||
741 | /* | |
742 | * prevent udev from issuing mailbox commands until the port is | |
743 | * configured. | |
744 | */ | |
745 | if (phba->link_state < LPFC_LINK_DOWN || | |
746 | !phba->mbox_mem_pool || | |
747 | (phba->sli.sli_flag & LPFC_SLI2_ACTIVE) == 0) | |
748 | return 0; | |
749 | ||
750 | if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) | |
751 | return 0; | |
752 | ||
753 | pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
754 | if (!pmboxq) | |
755 | return 0; | |
756 | memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t)); | |
757 | ||
758 | pmb = &pmboxq->mb; | |
759 | pmb->mbxCommand = MBX_READ_CONFIG; | |
760 | pmb->mbxOwner = OWN_HOST; | |
761 | pmboxq->context1 = NULL; | |
762 | ||
763 | if ((phba->pport->fc_flag & FC_OFFLINE_MODE) || | |
764 | (!(psli->sli_flag & LPFC_SLI2_ACTIVE))) | |
765 | rc = MBX_NOT_FINISHED; | |
766 | else | |
767 | rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2); | |
768 | ||
769 | if (rc != MBX_SUCCESS) { | |
858c9f6c | 770 | if (rc != MBX_TIMEOUT) |
92d7f7b0 JS |
771 | mempool_free(pmboxq, phba->mbox_mem_pool); |
772 | return 0; | |
773 | } | |
774 | ||
775 | if (mrpi) | |
776 | *mrpi = pmb->un.varRdConfig.max_rpi; | |
777 | if (arpi) | |
778 | *arpi = pmb->un.varRdConfig.avail_rpi; | |
779 | if (mxri) | |
780 | *mxri = pmb->un.varRdConfig.max_xri; | |
781 | if (axri) | |
782 | *axri = pmb->un.varRdConfig.avail_xri; | |
858c9f6c JS |
783 | if (mvpi) |
784 | *mvpi = pmb->un.varRdConfig.max_vpi; | |
785 | if (avpi) | |
786 | *avpi = pmb->un.varRdConfig.avail_vpi; | |
92d7f7b0 JS |
787 | |
788 | mempool_free(pmboxq, phba->mbox_mem_pool); | |
789 | return 1; | |
790 | } | |
791 | ||
e59058c4 JS |
792 | /** |
793 | * lpfc_max_rpi_show: Return maximum rpi. | |
794 | * @dev: class device that is converted into a Scsi_host. | |
795 | * @attr: device attribute, not used. | |
796 | * @buf: on return contains the maximum rpi count in decimal or "Unknown". | |
797 | * | |
798 | * Description: | |
799 | * Calls lpfc_get_hba_info() asking for just the mrpi count. | |
800 | * If lpfc_get_hba_info() returns zero (failure) the buffer text is set | |
801 | * to "Unknown" and the buffer length is returned, therefore the caller | |
802 | * must check for "Unknown" in the buffer to detect a failure. | |
803 | * | |
804 | * Returns: size of formatted string. | |
805 | **/ | |
92d7f7b0 | 806 | static ssize_t |
ee959b00 TJ |
807 | lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr, |
808 | char *buf) | |
92d7f7b0 | 809 | { |
ee959b00 | 810 | struct Scsi_Host *shost = class_to_shost(dev); |
92d7f7b0 JS |
811 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
812 | struct lpfc_hba *phba = vport->phba; | |
813 | uint32_t cnt; | |
814 | ||
858c9f6c | 815 | if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL)) |
92d7f7b0 JS |
816 | return snprintf(buf, PAGE_SIZE, "%d\n", cnt); |
817 | return snprintf(buf, PAGE_SIZE, "Unknown\n"); | |
818 | } | |
819 | ||
e59058c4 JS |
820 | /** |
821 | * lpfc_used_rpi_show: Return maximum rpi minus available rpi. | |
822 | * @dev: class device that is converted into a Scsi_host. | |
823 | * @attr: device attribute, not used. | |
824 | * @buf: containing the used rpi count in decimal or "Unknown". | |
825 | * | |
826 | * Description: | |
827 | * Calls lpfc_get_hba_info() asking for just the mrpi and arpi counts. | |
828 | * If lpfc_get_hba_info() returns zero (failure) the buffer text is set | |
829 | * to "Unknown" and the buffer length is returned, therefore the caller | |
830 | * must check for "Unknown" in the buffer to detect a failure. | |
831 | * | |
832 | * Returns: size of formatted string. | |
833 | **/ | |
92d7f7b0 | 834 | static ssize_t |
ee959b00 TJ |
835 | lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr, |
836 | char *buf) | |
92d7f7b0 | 837 | { |
ee959b00 | 838 | struct Scsi_Host *shost = class_to_shost(dev); |
92d7f7b0 JS |
839 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
840 | struct lpfc_hba *phba = vport->phba; | |
841 | uint32_t cnt, acnt; | |
842 | ||
858c9f6c | 843 | if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL)) |
92d7f7b0 JS |
844 | return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt)); |
845 | return snprintf(buf, PAGE_SIZE, "Unknown\n"); | |
846 | } | |
847 | ||
e59058c4 JS |
848 | /** |
849 | * lpfc_max_xri_show: Return maximum xri. | |
850 | * @dev: class device that is converted into a Scsi_host. | |
851 | * @attr: device attribute, not used. | |
852 | * @buf: on return contains the maximum xri count in decimal or "Unknown". | |
853 | * | |
854 | * Description: | |
855 | * Calls lpfc_get_hba_info() asking for just the mrpi count. | |
856 | * If lpfc_get_hba_info() returns zero (failure) the buffer text is set | |
857 | * to "Unknown" and the buffer length is returned, therefore the caller | |
858 | * must check for "Unknown" in the buffer to detect a failure. | |
859 | * | |
860 | * Returns: size of formatted string. | |
861 | **/ | |
92d7f7b0 | 862 | static ssize_t |
ee959b00 TJ |
863 | lpfc_max_xri_show(struct device *dev, struct device_attribute *attr, |
864 | char *buf) | |
92d7f7b0 | 865 | { |
ee959b00 | 866 | struct Scsi_Host *shost = class_to_shost(dev); |
92d7f7b0 JS |
867 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
868 | struct lpfc_hba *phba = vport->phba; | |
869 | uint32_t cnt; | |
870 | ||
858c9f6c | 871 | if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL)) |
92d7f7b0 JS |
872 | return snprintf(buf, PAGE_SIZE, "%d\n", cnt); |
873 | return snprintf(buf, PAGE_SIZE, "Unknown\n"); | |
874 | } | |
875 | ||
e59058c4 JS |
876 | /** |
877 | * lpfc_used_xri_show: Return maximum xpi minus the available xpi. | |
878 | * @dev: class device that is converted into a Scsi_host. | |
879 | * @attr: device attribute, not used. | |
880 | * @buf: on return contains the used xri count in decimal or "Unknown". | |
881 | * | |
882 | * Description: | |
883 | * Calls lpfc_get_hba_info() asking for just the mxri and axri counts. | |
884 | * If lpfc_get_hba_info() returns zero (failure) the buffer text is set | |
885 | * to "Unknown" and the buffer length is returned, therefore the caller | |
886 | * must check for "Unknown" in the buffer to detect a failure. | |
887 | * | |
888 | * Returns: size of formatted string. | |
889 | **/ | |
92d7f7b0 | 890 | static ssize_t |
ee959b00 TJ |
891 | lpfc_used_xri_show(struct device *dev, struct device_attribute *attr, |
892 | char *buf) | |
92d7f7b0 | 893 | { |
ee959b00 | 894 | struct Scsi_Host *shost = class_to_shost(dev); |
92d7f7b0 JS |
895 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
896 | struct lpfc_hba *phba = vport->phba; | |
897 | uint32_t cnt, acnt; | |
898 | ||
858c9f6c JS |
899 | if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL)) |
900 | return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt)); | |
901 | return snprintf(buf, PAGE_SIZE, "Unknown\n"); | |
902 | } | |
903 | ||
e59058c4 JS |
904 | /** |
905 | * lpfc_max_vpi_show: Return maximum vpi. | |
906 | * @dev: class device that is converted into a Scsi_host. | |
907 | * @attr: device attribute, not used. | |
908 | * @buf: on return contains the maximum vpi count in decimal or "Unknown". | |
909 | * | |
910 | * Description: | |
911 | * Calls lpfc_get_hba_info() asking for just the mvpi count. | |
912 | * If lpfc_get_hba_info() returns zero (failure) the buffer text is set | |
913 | * to "Unknown" and the buffer length is returned, therefore the caller | |
914 | * must check for "Unknown" in the buffer to detect a failure. | |
915 | * | |
916 | * Returns: size of formatted string. | |
917 | **/ | |
858c9f6c | 918 | static ssize_t |
ee959b00 TJ |
919 | lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr, |
920 | char *buf) | |
858c9f6c | 921 | { |
ee959b00 | 922 | struct Scsi_Host *shost = class_to_shost(dev); |
858c9f6c JS |
923 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
924 | struct lpfc_hba *phba = vport->phba; | |
925 | uint32_t cnt; | |
926 | ||
927 | if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL)) | |
928 | return snprintf(buf, PAGE_SIZE, "%d\n", cnt); | |
929 | return snprintf(buf, PAGE_SIZE, "Unknown\n"); | |
930 | } | |
931 | ||
e59058c4 JS |
932 | /** |
933 | * lpfc_used_vpi_show: Return maximum vpi minus the available vpi. | |
934 | * @dev: class device that is converted into a Scsi_host. | |
935 | * @attr: device attribute, not used. | |
936 | * @buf: on return contains the used vpi count in decimal or "Unknown". | |
937 | * | |
938 | * Description: | |
939 | * Calls lpfc_get_hba_info() asking for just the mvpi and avpi counts. | |
940 | * If lpfc_get_hba_info() returns zero (failure) the buffer text is set | |
941 | * to "Unknown" and the buffer length is returned, therefore the caller | |
942 | * must check for "Unknown" in the buffer to detect a failure. | |
943 | * | |
944 | * Returns: size of formatted string. | |
945 | **/ | |
858c9f6c | 946 | static ssize_t |
ee959b00 TJ |
947 | lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr, |
948 | char *buf) | |
858c9f6c | 949 | { |
ee959b00 | 950 | struct Scsi_Host *shost = class_to_shost(dev); |
858c9f6c JS |
951 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
952 | struct lpfc_hba *phba = vport->phba; | |
953 | uint32_t cnt, acnt; | |
954 | ||
955 | if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt)) | |
92d7f7b0 JS |
956 | return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt)); |
957 | return snprintf(buf, PAGE_SIZE, "Unknown\n"); | |
958 | } | |
959 | ||
e59058c4 JS |
960 | /** |
961 | * lpfc_npiv_info_show: Return text about NPIV support for the adapter. | |
962 | * @dev: class device that is converted into a Scsi_host. | |
963 | * @attr: device attribute, not used. | |
964 | * @buf: text that must be interpreted to determine if npiv is supported. | |
965 | * | |
966 | * Description: | |
967 | * Buffer will contain text indicating npiv is not suppoerted on the port, | |
968 | * the port is an NPIV physical port, or it is an npiv virtual port with | |
969 | * the id of the vport. | |
970 | * | |
971 | * Returns: size of formatted string. | |
972 | **/ | |
92d7f7b0 | 973 | static ssize_t |
ee959b00 TJ |
974 | lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr, |
975 | char *buf) | |
92d7f7b0 | 976 | { |
ee959b00 | 977 | struct Scsi_Host *shost = class_to_shost(dev); |
92d7f7b0 JS |
978 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
979 | struct lpfc_hba *phba = vport->phba; | |
980 | ||
981 | if (!(phba->max_vpi)) | |
982 | return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n"); | |
983 | if (vport->port_type == LPFC_PHYSICAL_PORT) | |
984 | return snprintf(buf, PAGE_SIZE, "NPIV Physical\n"); | |
985 | return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi); | |
986 | } | |
987 | ||
e59058c4 JS |
988 | /** |
989 | * lpfc_poll_show: Return text about poll support for the adapter. | |
990 | * @dev: class device that is converted into a Scsi_host. | |
991 | * @attr: device attribute, not used. | |
992 | * @buf: on return contains the cfg_poll in hex. | |
993 | * | |
994 | * Notes: | |
995 | * cfg_poll should be a lpfc_polling_flags type. | |
996 | * | |
997 | * Returns: size of formatted string. | |
998 | **/ | |
875fbdfe | 999 | static ssize_t |
ee959b00 TJ |
1000 | lpfc_poll_show(struct device *dev, struct device_attribute *attr, |
1001 | char *buf) | |
875fbdfe | 1002 | { |
ee959b00 | 1003 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 JS |
1004 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
1005 | struct lpfc_hba *phba = vport->phba; | |
875fbdfe JSEC |
1006 | |
1007 | return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll); | |
1008 | } | |
1009 | ||
e59058c4 JS |
1010 | /** |
1011 | * lpfc_poll_store: Set the value of cfg_poll for the adapter. | |
1012 | * @dev: class device that is converted into a Scsi_host. | |
1013 | * @attr: device attribute, not used. | |
1014 | * @buf: one or more lpfc_polling_flags values. | |
1015 | * @count: not used. | |
1016 | * | |
1017 | * Notes: | |
1018 | * buf contents converted to integer and checked for a valid value. | |
1019 | * | |
1020 | * Returns: | |
1021 | * -EINVAL if the buffer connot be converted or is out of range | |
1022 | * length of the buf on success | |
1023 | **/ | |
875fbdfe | 1024 | static ssize_t |
ee959b00 TJ |
1025 | lpfc_poll_store(struct device *dev, struct device_attribute *attr, |
1026 | const char *buf, size_t count) | |
875fbdfe | 1027 | { |
ee959b00 | 1028 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 JS |
1029 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
1030 | struct lpfc_hba *phba = vport->phba; | |
875fbdfe JSEC |
1031 | uint32_t creg_val; |
1032 | uint32_t old_val; | |
1033 | int val=0; | |
1034 | ||
1035 | if (!isdigit(buf[0])) | |
1036 | return -EINVAL; | |
1037 | ||
1038 | if (sscanf(buf, "%i", &val) != 1) | |
1039 | return -EINVAL; | |
1040 | ||
1041 | if ((val & 0x3) != val) | |
1042 | return -EINVAL; | |
1043 | ||
2e0fef85 | 1044 | spin_lock_irq(&phba->hbalock); |
875fbdfe JSEC |
1045 | |
1046 | old_val = phba->cfg_poll; | |
1047 | ||
1048 | if (val & ENABLE_FCP_RING_POLLING) { | |
1049 | if ((val & DISABLE_FCP_RING_INT) && | |
1050 | !(old_val & DISABLE_FCP_RING_INT)) { | |
1051 | creg_val = readl(phba->HCregaddr); | |
1052 | creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING); | |
1053 | writel(creg_val, phba->HCregaddr); | |
1054 | readl(phba->HCregaddr); /* flush */ | |
1055 | ||
1056 | lpfc_poll_start_timer(phba); | |
1057 | } | |
1058 | } else if (val != 0x0) { | |
2e0fef85 | 1059 | spin_unlock_irq(&phba->hbalock); |
875fbdfe JSEC |
1060 | return -EINVAL; |
1061 | } | |
1062 | ||
1063 | if (!(val & DISABLE_FCP_RING_INT) && | |
1064 | (old_val & DISABLE_FCP_RING_INT)) | |
1065 | { | |
2e0fef85 | 1066 | spin_unlock_irq(&phba->hbalock); |
875fbdfe | 1067 | del_timer(&phba->fcp_poll_timer); |
2e0fef85 | 1068 | spin_lock_irq(&phba->hbalock); |
875fbdfe JSEC |
1069 | creg_val = readl(phba->HCregaddr); |
1070 | creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING); | |
1071 | writel(creg_val, phba->HCregaddr); | |
1072 | readl(phba->HCregaddr); /* flush */ | |
1073 | } | |
1074 | ||
1075 | phba->cfg_poll = val; | |
1076 | ||
2e0fef85 | 1077 | spin_unlock_irq(&phba->hbalock); |
875fbdfe JSEC |
1078 | |
1079 | return strlen(buf); | |
1080 | } | |
dea3101e | 1081 | |
e59058c4 JS |
1082 | /** |
1083 | * lpfc_param_show: Return a cfg attribute value in decimal. | |
1084 | * | |
1085 | * Description: | |
1086 | * Macro that given an attr e.g. hba_queue_depth expands | |
1087 | * into a function with the name lpfc_hba_queue_depth_show. | |
1088 | * | |
1089 | * lpfc_##attr##_show: Return the decimal value of an adapters cfg_xxx field. | |
1090 | * @dev: class device that is converted into a Scsi_host. | |
1091 | * @attr: device attribute, not used. | |
1092 | * @buf: on return contains the attribute value in decimal. | |
1093 | * | |
1094 | * Returns: size of formatted string. | |
1095 | **/ | |
dea3101e | 1096 | #define lpfc_param_show(attr) \ |
1097 | static ssize_t \ | |
ee959b00 TJ |
1098 | lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \ |
1099 | char *buf) \ | |
dea3101e | 1100 | { \ |
ee959b00 | 1101 | struct Scsi_Host *shost = class_to_shost(dev);\ |
2e0fef85 JS |
1102 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\ |
1103 | struct lpfc_hba *phba = vport->phba;\ | |
dea3101e | 1104 | int val = 0;\ |
7bcbb752 JSEC |
1105 | val = phba->cfg_##attr;\ |
1106 | return snprintf(buf, PAGE_SIZE, "%d\n",\ | |
1107 | phba->cfg_##attr);\ | |
1108 | } | |
1109 | ||
e59058c4 JS |
1110 | /** |
1111 | * lpfc_param_hex_show: Return a cfg attribute value in hex. | |
1112 | * | |
1113 | * Description: | |
1114 | * Macro that given an attr e.g. hba_queue_depth expands | |
1115 | * into a function with the name lpfc_hba_queue_depth_show | |
1116 | * | |
1117 | * lpfc_##attr##_show: Return the hex value of an adapters cfg_xxx field. | |
1118 | * @dev: class device that is converted into a Scsi_host. | |
1119 | * @attr: device attribute, not used. | |
1120 | * @buf: on return contains the attribute value in hexidecimal. | |
1121 | * | |
1122 | * Returns: size of formatted string. | |
1123 | **/ | |
93a20f74 JSEC |
1124 | #define lpfc_param_hex_show(attr) \ |
1125 | static ssize_t \ | |
ee959b00 TJ |
1126 | lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \ |
1127 | char *buf) \ | |
93a20f74 | 1128 | { \ |
ee959b00 | 1129 | struct Scsi_Host *shost = class_to_shost(dev);\ |
2e0fef85 JS |
1130 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\ |
1131 | struct lpfc_hba *phba = vport->phba;\ | |
93a20f74 JSEC |
1132 | int val = 0;\ |
1133 | val = phba->cfg_##attr;\ | |
1134 | return snprintf(buf, PAGE_SIZE, "%#x\n",\ | |
1135 | phba->cfg_##attr);\ | |
1136 | } | |
1137 | ||
e59058c4 JS |
1138 | /** |
1139 | * lpfc_param_init: Intializes a cfg attribute. | |
1140 | * | |
1141 | * Description: | |
1142 | * Macro that given an attr e.g. hba_queue_depth expands | |
1143 | * into a function with the name lpfc_hba_queue_depth_init. The macro also | |
1144 | * takes a default argument, a minimum and maximum argument. | |
1145 | * | |
1146 | * lpfc_##attr##_init: Initializes an attribute. | |
1147 | * @phba: pointer the the adapter structure. | |
1148 | * @val: integer attribute value. | |
1149 | * | |
1150 | * Validates the min and max values then sets the adapter config field | |
1151 | * accordingly, or uses the default if out of range and prints an error message. | |
1152 | * | |
1153 | * Returns: | |
1154 | * zero on success | |
1155 | * -EINVAL if default used | |
1156 | **/ | |
7bcbb752 JSEC |
1157 | #define lpfc_param_init(attr, default, minval, maxval) \ |
1158 | static int \ | |
1159 | lpfc_##attr##_init(struct lpfc_hba *phba, int val) \ | |
1160 | { \ | |
1161 | if (val >= minval && val <= maxval) {\ | |
1162 | phba->cfg_##attr = val;\ | |
1163 | return 0;\ | |
dea3101e | 1164 | }\ |
7bcbb752 | 1165 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \ |
e8b62011 JS |
1166 | "0449 lpfc_"#attr" attribute cannot be set to %d, "\ |
1167 | "allowed range is ["#minval", "#maxval"]\n", val); \ | |
7bcbb752 JSEC |
1168 | phba->cfg_##attr = default;\ |
1169 | return -EINVAL;\ | |
dea3101e | 1170 | } |
1171 | ||
e59058c4 JS |
1172 | /** |
1173 | * lpfc_param_set: Set a cfg attribute value. | |
1174 | * | |
1175 | * Description: | |
1176 | * Macro that given an attr e.g. hba_queue_depth expands | |
1177 | * into a function with the name lpfc_hba_queue_depth_set | |
1178 | * | |
1179 | * lpfc_##attr##_set: Sets an attribute value. | |
1180 | * @phba: pointer the the adapter structure. | |
1181 | * @val: integer attribute value. | |
1182 | * | |
1183 | * Description: | |
1184 | * Validates the min and max values then sets the | |
1185 | * adapter config field if in the valid range. prints error message | |
1186 | * and does not set the parameter if invalid. | |
1187 | * | |
1188 | * Returns: | |
1189 | * zero on success | |
1190 | * -EINVAL if val is invalid | |
1191 | **/ | |
7bcbb752 JSEC |
1192 | #define lpfc_param_set(attr, default, minval, maxval) \ |
1193 | static int \ | |
1194 | lpfc_##attr##_set(struct lpfc_hba *phba, int val) \ | |
1195 | { \ | |
1196 | if (val >= minval && val <= maxval) {\ | |
1197 | phba->cfg_##attr = val;\ | |
1198 | return 0;\ | |
1199 | }\ | |
1200 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \ | |
e8b62011 JS |
1201 | "0450 lpfc_"#attr" attribute cannot be set to %d, "\ |
1202 | "allowed range is ["#minval", "#maxval"]\n", val); \ | |
7bcbb752 JSEC |
1203 | return -EINVAL;\ |
1204 | } | |
1205 | ||
e59058c4 JS |
1206 | /** |
1207 | * lpfc_param_store: Set a vport attribute value. | |
1208 | * | |
1209 | * Description: | |
1210 | * Macro that given an attr e.g. hba_queue_depth expands | |
1211 | * into a function with the name lpfc_hba_queue_depth_store. | |
1212 | * | |
1213 | * lpfc_##attr##_store: Set an sttribute value. | |
1214 | * @dev: class device that is converted into a Scsi_host. | |
1215 | * @attr: device attribute, not used. | |
1216 | * @buf: contains the attribute value in ascii. | |
1217 | * @count: not used. | |
1218 | * | |
1219 | * Description: | |
1220 | * Convert the ascii text number to an integer, then | |
1221 | * use the lpfc_##attr##_set function to set the value. | |
1222 | * | |
1223 | * Returns: | |
1224 | * -EINVAL if val is invalid or lpfc_##attr##_set() fails | |
1225 | * length of buffer upon success. | |
1226 | **/ | |
7bcbb752 | 1227 | #define lpfc_param_store(attr) \ |
dea3101e | 1228 | static ssize_t \ |
ee959b00 TJ |
1229 | lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \ |
1230 | const char *buf, size_t count) \ | |
dea3101e | 1231 | { \ |
ee959b00 | 1232 | struct Scsi_Host *shost = class_to_shost(dev);\ |
2e0fef85 JS |
1233 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\ |
1234 | struct lpfc_hba *phba = vport->phba;\ | |
7bcbb752 | 1235 | int val=0;\ |
93a20f74 JSEC |
1236 | if (!isdigit(buf[0]))\ |
1237 | return -EINVAL;\ | |
1238 | if (sscanf(buf, "%i", &val) != 1)\ | |
1239 | return -EINVAL;\ | |
7bcbb752 | 1240 | if (lpfc_##attr##_set(phba, val) == 0) \ |
755c0d06 | 1241 | return strlen(buf);\ |
7bcbb752 JSEC |
1242 | else \ |
1243 | return -EINVAL;\ | |
dea3101e | 1244 | } |
1245 | ||
e59058c4 JS |
1246 | /** |
1247 | * lpfc_vport_param_show: Return decimal formatted cfg attribute value. | |
1248 | * | |
1249 | * Description: | |
1250 | * Macro that given an attr e.g. hba_queue_depth expands | |
1251 | * into a function with the name lpfc_hba_queue_depth_show | |
1252 | * | |
1253 | * lpfc_##attr##_show: prints the attribute value in decimal. | |
1254 | * @dev: class device that is converted into a Scsi_host. | |
1255 | * @attr: device attribute, not used. | |
1256 | * @buf: on return contains the attribute value in decimal. | |
1257 | * | |
1258 | * Returns: length of formatted string. | |
1259 | **/ | |
3de2a653 JS |
1260 | #define lpfc_vport_param_show(attr) \ |
1261 | static ssize_t \ | |
ee959b00 TJ |
1262 | lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \ |
1263 | char *buf) \ | |
3de2a653 | 1264 | { \ |
ee959b00 | 1265 | struct Scsi_Host *shost = class_to_shost(dev);\ |
3de2a653 JS |
1266 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\ |
1267 | int val = 0;\ | |
1268 | val = vport->cfg_##attr;\ | |
1269 | return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\ | |
1270 | } | |
1271 | ||
e59058c4 JS |
1272 | /** |
1273 | * lpfc_vport_param_hex_show: Return hex formatted attribute value. | |
1274 | * | |
1275 | * Description: | |
1276 | * Macro that given an attr e.g. | |
1277 | * hba_queue_depth expands into a function with the name | |
1278 | * lpfc_hba_queue_depth_show | |
1279 | * | |
1280 | * lpfc_##attr##_show: prints the attribute value in hexidecimal. | |
1281 | * @dev: class device that is converted into a Scsi_host. | |
1282 | * @attr: device attribute, not used. | |
1283 | * @buf: on return contains the attribute value in hexidecimal. | |
1284 | * | |
1285 | * Returns: length of formatted string. | |
1286 | **/ | |
3de2a653 JS |
1287 | #define lpfc_vport_param_hex_show(attr) \ |
1288 | static ssize_t \ | |
ee959b00 TJ |
1289 | lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \ |
1290 | char *buf) \ | |
3de2a653 | 1291 | { \ |
ee959b00 | 1292 | struct Scsi_Host *shost = class_to_shost(dev);\ |
3de2a653 JS |
1293 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\ |
1294 | int val = 0;\ | |
1295 | val = vport->cfg_##attr;\ | |
1296 | return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\ | |
1297 | } | |
1298 | ||
e59058c4 JS |
1299 | /** |
1300 | * lpfc_vport_param_init: Initialize a vport cfg attribute. | |
1301 | * | |
1302 | * Description: | |
1303 | * Macro that given an attr e.g. hba_queue_depth expands | |
1304 | * into a function with the name lpfc_hba_queue_depth_init. The macro also | |
1305 | * takes a default argument, a minimum and maximum argument. | |
1306 | * | |
1307 | * lpfc_##attr##_init: validates the min and max values then sets the | |
1308 | * adapter config field accordingly, or uses the default if out of range | |
1309 | * and prints an error message. | |
1310 | * @phba: pointer the the adapter structure. | |
1311 | * @val: integer attribute value. | |
1312 | * | |
1313 | * Returns: | |
1314 | * zero on success | |
1315 | * -EINVAL if default used | |
1316 | **/ | |
3de2a653 JS |
1317 | #define lpfc_vport_param_init(attr, default, minval, maxval) \ |
1318 | static int \ | |
1319 | lpfc_##attr##_init(struct lpfc_vport *vport, int val) \ | |
1320 | { \ | |
1321 | if (val >= minval && val <= maxval) {\ | |
1322 | vport->cfg_##attr = val;\ | |
1323 | return 0;\ | |
1324 | }\ | |
e8b62011 | 1325 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \ |
d7c255b2 | 1326 | "0423 lpfc_"#attr" attribute cannot be set to %d, "\ |
e8b62011 | 1327 | "allowed range is ["#minval", "#maxval"]\n", val); \ |
3de2a653 JS |
1328 | vport->cfg_##attr = default;\ |
1329 | return -EINVAL;\ | |
1330 | } | |
1331 | ||
e59058c4 JS |
1332 | /** |
1333 | * lpfc_vport_param_set: Set a vport cfg attribute. | |
1334 | * | |
1335 | * Description: | |
1336 | * Macro that given an attr e.g. hba_queue_depth expands | |
1337 | * into a function with the name lpfc_hba_queue_depth_set | |
1338 | * | |
1339 | * lpfc_##attr##_set: validates the min and max values then sets the | |
1340 | * adapter config field if in the valid range. prints error message | |
1341 | * and does not set the parameter if invalid. | |
1342 | * @phba: pointer the the adapter structure. | |
1343 | * @val: integer attribute value. | |
1344 | * | |
1345 | * Returns: | |
1346 | * zero on success | |
1347 | * -EINVAL if val is invalid | |
1348 | **/ | |
3de2a653 JS |
1349 | #define lpfc_vport_param_set(attr, default, minval, maxval) \ |
1350 | static int \ | |
1351 | lpfc_##attr##_set(struct lpfc_vport *vport, int val) \ | |
1352 | { \ | |
1353 | if (val >= minval && val <= maxval) {\ | |
1354 | vport->cfg_##attr = val;\ | |
1355 | return 0;\ | |
1356 | }\ | |
e8b62011 | 1357 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \ |
d7c255b2 | 1358 | "0424 lpfc_"#attr" attribute cannot be set to %d, "\ |
e8b62011 | 1359 | "allowed range is ["#minval", "#maxval"]\n", val); \ |
3de2a653 JS |
1360 | return -EINVAL;\ |
1361 | } | |
1362 | ||
e59058c4 JS |
1363 | /** |
1364 | * lpfc_vport_param_store: Set a vport attribute. | |
1365 | * | |
1366 | * Description: | |
1367 | * Macro that given an attr e.g. hba_queue_depth | |
1368 | * expands into a function with the name lpfc_hba_queue_depth_store | |
1369 | * | |
1370 | * lpfc_##attr##_store: convert the ascii text number to an integer, then | |
1371 | * use the lpfc_##attr##_set function to set the value. | |
1372 | * @cdev: class device that is converted into a Scsi_host. | |
1373 | * @buf: contains the attribute value in decimal. | |
1374 | * @count: not used. | |
1375 | * | |
1376 | * Returns: | |
1377 | * -EINVAL if val is invalid or lpfc_##attr##_set() fails | |
1378 | * length of buffer upon success. | |
1379 | **/ | |
3de2a653 JS |
1380 | #define lpfc_vport_param_store(attr) \ |
1381 | static ssize_t \ | |
ee959b00 TJ |
1382 | lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \ |
1383 | const char *buf, size_t count) \ | |
3de2a653 | 1384 | { \ |
ee959b00 | 1385 | struct Scsi_Host *shost = class_to_shost(dev);\ |
3de2a653 JS |
1386 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\ |
1387 | int val=0;\ | |
1388 | if (!isdigit(buf[0]))\ | |
1389 | return -EINVAL;\ | |
1390 | if (sscanf(buf, "%i", &val) != 1)\ | |
1391 | return -EINVAL;\ | |
1392 | if (lpfc_##attr##_set(vport, val) == 0) \ | |
1393 | return strlen(buf);\ | |
1394 | else \ | |
1395 | return -EINVAL;\ | |
1396 | } | |
1397 | ||
1398 | ||
7bcbb752 JSEC |
1399 | #define LPFC_ATTR(name, defval, minval, maxval, desc) \ |
1400 | static int lpfc_##name = defval;\ | |
dea3101e | 1401 | module_param(lpfc_##name, int, 0);\ |
1402 | MODULE_PARM_DESC(lpfc_##name, desc);\ | |
7bcbb752 | 1403 | lpfc_param_init(name, defval, minval, maxval) |
dea3101e | 1404 | |
1405 | #define LPFC_ATTR_R(name, defval, minval, maxval, desc) \ | |
1406 | static int lpfc_##name = defval;\ | |
1407 | module_param(lpfc_##name, int, 0);\ | |
1408 | MODULE_PARM_DESC(lpfc_##name, desc);\ | |
1409 | lpfc_param_show(name)\ | |
7bcbb752 | 1410 | lpfc_param_init(name, defval, minval, maxval)\ |
ee959b00 | 1411 | static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL) |
dea3101e | 1412 | |
1413 | #define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \ | |
1414 | static int lpfc_##name = defval;\ | |
1415 | module_param(lpfc_##name, int, 0);\ | |
1416 | MODULE_PARM_DESC(lpfc_##name, desc);\ | |
1417 | lpfc_param_show(name)\ | |
7bcbb752 JSEC |
1418 | lpfc_param_init(name, defval, minval, maxval)\ |
1419 | lpfc_param_set(name, defval, minval, maxval)\ | |
1420 | lpfc_param_store(name)\ | |
ee959b00 TJ |
1421 | static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\ |
1422 | lpfc_##name##_show, lpfc_##name##_store) | |
dea3101e | 1423 | |
93a20f74 JSEC |
1424 | #define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \ |
1425 | static int lpfc_##name = defval;\ | |
1426 | module_param(lpfc_##name, int, 0);\ | |
1427 | MODULE_PARM_DESC(lpfc_##name, desc);\ | |
1428 | lpfc_param_hex_show(name)\ | |
1429 | lpfc_param_init(name, defval, minval, maxval)\ | |
ee959b00 | 1430 | static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL) |
93a20f74 JSEC |
1431 | |
1432 | #define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \ | |
1433 | static int lpfc_##name = defval;\ | |
1434 | module_param(lpfc_##name, int, 0);\ | |
1435 | MODULE_PARM_DESC(lpfc_##name, desc);\ | |
1436 | lpfc_param_hex_show(name)\ | |
1437 | lpfc_param_init(name, defval, minval, maxval)\ | |
1438 | lpfc_param_set(name, defval, minval, maxval)\ | |
1439 | lpfc_param_store(name)\ | |
ee959b00 TJ |
1440 | static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\ |
1441 | lpfc_##name##_show, lpfc_##name##_store) | |
93a20f74 | 1442 | |
3de2a653 JS |
1443 | #define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \ |
1444 | static int lpfc_##name = defval;\ | |
1445 | module_param(lpfc_##name, int, 0);\ | |
1446 | MODULE_PARM_DESC(lpfc_##name, desc);\ | |
1447 | lpfc_vport_param_init(name, defval, minval, maxval) | |
1448 | ||
1449 | #define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \ | |
1450 | static int lpfc_##name = defval;\ | |
1451 | module_param(lpfc_##name, int, 0);\ | |
1452 | MODULE_PARM_DESC(lpfc_##name, desc);\ | |
1453 | lpfc_vport_param_show(name)\ | |
1454 | lpfc_vport_param_init(name, defval, minval, maxval)\ | |
ee959b00 | 1455 | static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL) |
3de2a653 JS |
1456 | |
1457 | #define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \ | |
1458 | static int lpfc_##name = defval;\ | |
1459 | module_param(lpfc_##name, int, 0);\ | |
1460 | MODULE_PARM_DESC(lpfc_##name, desc);\ | |
1461 | lpfc_vport_param_show(name)\ | |
1462 | lpfc_vport_param_init(name, defval, minval, maxval)\ | |
1463 | lpfc_vport_param_set(name, defval, minval, maxval)\ | |
1464 | lpfc_vport_param_store(name)\ | |
ee959b00 TJ |
1465 | static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\ |
1466 | lpfc_##name##_show, lpfc_##name##_store) | |
3de2a653 JS |
1467 | |
1468 | #define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \ | |
1469 | static int lpfc_##name = defval;\ | |
1470 | module_param(lpfc_##name, int, 0);\ | |
1471 | MODULE_PARM_DESC(lpfc_##name, desc);\ | |
1472 | lpfc_vport_param_hex_show(name)\ | |
1473 | lpfc_vport_param_init(name, defval, minval, maxval)\ | |
ee959b00 | 1474 | static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL) |
3de2a653 JS |
1475 | |
1476 | #define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \ | |
1477 | static int lpfc_##name = defval;\ | |
1478 | module_param(lpfc_##name, int, 0);\ | |
1479 | MODULE_PARM_DESC(lpfc_##name, desc);\ | |
1480 | lpfc_vport_param_hex_show(name)\ | |
1481 | lpfc_vport_param_init(name, defval, minval, maxval)\ | |
1482 | lpfc_vport_param_set(name, defval, minval, maxval)\ | |
1483 | lpfc_vport_param_store(name)\ | |
ee959b00 TJ |
1484 | static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\ |
1485 | lpfc_##name##_show, lpfc_##name##_store) | |
1486 | ||
1487 | static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL); | |
1488 | static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL); | |
1489 | static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL); | |
1490 | static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL); | |
1491 | static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL); | |
1492 | static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL); | |
1493 | static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL); | |
1494 | static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL); | |
bbd1ae41 | 1495 | static DEVICE_ATTR(link_state, S_IRUGO, lpfc_link_state_show, NULL); |
ee959b00 TJ |
1496 | static DEVICE_ATTR(option_rom_version, S_IRUGO, |
1497 | lpfc_option_rom_version_show, NULL); | |
1498 | static DEVICE_ATTR(num_discovered_ports, S_IRUGO, | |
1499 | lpfc_num_discovered_ports_show, NULL); | |
84774a4d | 1500 | static DEVICE_ATTR(menlo_mgmt_mode, S_IRUGO, lpfc_mlomgmt_show, NULL); |
ee959b00 TJ |
1501 | static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL); |
1502 | static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL); | |
1503 | static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR, | |
1504 | lpfc_board_mode_show, lpfc_board_mode_store); | |
1505 | static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset); | |
1506 | static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL); | |
1507 | static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL); | |
1508 | static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL); | |
1509 | static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL); | |
1510 | static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL); | |
1511 | static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL); | |
1512 | static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL); | |
1513 | static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL); | |
dea3101e | 1514 | |
c3f28afa | 1515 | |
a12e07bc | 1516 | static char *lpfc_soft_wwn_key = "C99G71SL8032A"; |
c3f28afa | 1517 | |
e59058c4 JS |
1518 | /** |
1519 | * lpfc_soft_wwn_enable_store: Allows setting of the wwn if the key is valid. | |
1520 | * @dev: class device that is converted into a Scsi_host. | |
1521 | * @attr: device attribute, not used. | |
1522 | * @buf: containing the string lpfc_soft_wwn_key. | |
1523 | * @count: must be size of lpfc_soft_wwn_key. | |
1524 | * | |
1525 | * Returns: | |
1526 | * -EINVAL if the buffer does not contain lpfc_soft_wwn_key | |
1527 | * length of buf indicates success | |
1528 | **/ | |
c3f28afa | 1529 | static ssize_t |
ee959b00 TJ |
1530 | lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr, |
1531 | const char *buf, size_t count) | |
c3f28afa | 1532 | { |
ee959b00 | 1533 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 JS |
1534 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
1535 | struct lpfc_hba *phba = vport->phba; | |
c3f28afa JS |
1536 | unsigned int cnt = count; |
1537 | ||
1538 | /* | |
1539 | * We're doing a simple sanity check for soft_wwpn setting. | |
1540 | * We require that the user write a specific key to enable | |
1541 | * the soft_wwpn attribute to be settable. Once the attribute | |
1542 | * is written, the enable key resets. If further updates are | |
1543 | * desired, the key must be written again to re-enable the | |
1544 | * attribute. | |
1545 | * | |
1546 | * The "key" is not secret - it is a hardcoded string shown | |
1547 | * here. The intent is to protect against the random user or | |
1548 | * application that is just writing attributes. | |
1549 | */ | |
1550 | ||
1551 | /* count may include a LF at end of string */ | |
1552 | if (buf[cnt-1] == '\n') | |
1553 | cnt--; | |
1554 | ||
a12e07bc JS |
1555 | if ((cnt != strlen(lpfc_soft_wwn_key)) || |
1556 | (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0)) | |
c3f28afa JS |
1557 | return -EINVAL; |
1558 | ||
a12e07bc | 1559 | phba->soft_wwn_enable = 1; |
c3f28afa JS |
1560 | return count; |
1561 | } | |
ee959b00 TJ |
1562 | static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL, |
1563 | lpfc_soft_wwn_enable_store); | |
c3f28afa | 1564 | |
e59058c4 JS |
1565 | /** |
1566 | * lpfc_soft_wwpn_show: Return the cfg soft ww port name of the adapter. | |
1567 | * @dev: class device that is converted into a Scsi_host. | |
1568 | * @attr: device attribute, not used. | |
1569 | * @buf: on return contains the wwpn in hexidecimal. | |
1570 | * | |
1571 | * Returns: size of formatted string. | |
1572 | **/ | |
c3f28afa | 1573 | static ssize_t |
ee959b00 TJ |
1574 | lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr, |
1575 | char *buf) | |
c3f28afa | 1576 | { |
ee959b00 | 1577 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 JS |
1578 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
1579 | struct lpfc_hba *phba = vport->phba; | |
1580 | ||
afc071e6 RD |
1581 | return snprintf(buf, PAGE_SIZE, "0x%llx\n", |
1582 | (unsigned long long)phba->cfg_soft_wwpn); | |
c3f28afa JS |
1583 | } |
1584 | ||
e59058c4 JS |
1585 | /** |
1586 | * lpfc_soft_wwpn_store: Set the ww port name of the adapter. | |
1587 | * @dev class device that is converted into a Scsi_host. | |
1588 | * @attr: device attribute, not used. | |
1589 | * @buf: contains the wwpn in hexidecimal. | |
1590 | * @count: number of wwpn bytes in buf | |
1591 | * | |
1592 | * Returns: | |
1593 | * -EACCES hba reset not enabled, adapter over temp | |
1594 | * -EINVAL soft wwn not enabled, count is invalid, invalid wwpn byte invalid | |
1595 | * -EIO error taking adapter offline or online | |
1596 | * value of count on success | |
1597 | **/ | |
c3f28afa | 1598 | static ssize_t |
ee959b00 TJ |
1599 | lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr, |
1600 | const char *buf, size_t count) | |
c3f28afa | 1601 | { |
ee959b00 | 1602 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 JS |
1603 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
1604 | struct lpfc_hba *phba = vport->phba; | |
c3f28afa JS |
1605 | struct completion online_compl; |
1606 | int stat1=0, stat2=0; | |
1607 | unsigned int i, j, cnt=count; | |
1608 | u8 wwpn[8]; | |
1609 | ||
13815c83 JS |
1610 | if (!phba->cfg_enable_hba_reset) |
1611 | return -EACCES; | |
7af67051 JS |
1612 | spin_lock_irq(&phba->hbalock); |
1613 | if (phba->over_temp_state == HBA_OVER_TEMP) { | |
1614 | spin_unlock_irq(&phba->hbalock); | |
09372820 | 1615 | return -EACCES; |
7af67051 JS |
1616 | } |
1617 | spin_unlock_irq(&phba->hbalock); | |
c3f28afa JS |
1618 | /* count may include a LF at end of string */ |
1619 | if (buf[cnt-1] == '\n') | |
1620 | cnt--; | |
1621 | ||
a12e07bc | 1622 | if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) || |
c3f28afa JS |
1623 | ((cnt == 17) && (*buf++ != 'x')) || |
1624 | ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x')))) | |
1625 | return -EINVAL; | |
1626 | ||
a12e07bc | 1627 | phba->soft_wwn_enable = 0; |
c3f28afa JS |
1628 | |
1629 | memset(wwpn, 0, sizeof(wwpn)); | |
1630 | ||
1631 | /* Validate and store the new name */ | |
1632 | for (i=0, j=0; i < 16; i++) { | |
1633 | if ((*buf >= 'a') && (*buf <= 'f')) | |
1634 | j = ((j << 4) | ((*buf++ -'a') + 10)); | |
1635 | else if ((*buf >= 'A') && (*buf <= 'F')) | |
1636 | j = ((j << 4) | ((*buf++ -'A') + 10)); | |
1637 | else if ((*buf >= '0') && (*buf <= '9')) | |
1638 | j = ((j << 4) | (*buf++ -'0')); | |
1639 | else | |
1640 | return -EINVAL; | |
1641 | if (i % 2) { | |
1642 | wwpn[i/2] = j & 0xff; | |
1643 | j = 0; | |
1644 | } | |
1645 | } | |
1646 | phba->cfg_soft_wwpn = wwn_to_u64(wwpn); | |
2e0fef85 | 1647 | fc_host_port_name(shost) = phba->cfg_soft_wwpn; |
a12e07bc | 1648 | if (phba->cfg_soft_wwnn) |
2e0fef85 | 1649 | fc_host_node_name(shost) = phba->cfg_soft_wwnn; |
c3f28afa JS |
1650 | |
1651 | dev_printk(KERN_NOTICE, &phba->pcidev->dev, | |
1652 | "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no); | |
1653 | ||
46fa311e | 1654 | stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE); |
c3f28afa JS |
1655 | if (stat1) |
1656 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
e8b62011 JS |
1657 | "0463 lpfc_soft_wwpn attribute set failed to " |
1658 | "reinit adapter - %d\n", stat1); | |
c3f28afa JS |
1659 | init_completion(&online_compl); |
1660 | lpfc_workq_post_event(phba, &stat2, &online_compl, LPFC_EVT_ONLINE); | |
1661 | wait_for_completion(&online_compl); | |
1662 | if (stat2) | |
1663 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
e8b62011 JS |
1664 | "0464 lpfc_soft_wwpn attribute set failed to " |
1665 | "reinit adapter - %d\n", stat2); | |
c3f28afa JS |
1666 | return (stat1 || stat2) ? -EIO : count; |
1667 | } | |
ee959b00 TJ |
1668 | static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\ |
1669 | lpfc_soft_wwpn_show, lpfc_soft_wwpn_store); | |
c3f28afa | 1670 | |
e59058c4 JS |
1671 | /** |
1672 | * lpfc_soft_wwnn_show: Return the cfg soft ww node name for the adapter. | |
1673 | * @dev: class device that is converted into a Scsi_host. | |
1674 | * @attr: device attribute, not used. | |
1675 | * @buf: on return contains the wwnn in hexidecimal. | |
1676 | * | |
1677 | * Returns: size of formatted string. | |
1678 | **/ | |
a12e07bc | 1679 | static ssize_t |
ee959b00 TJ |
1680 | lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr, |
1681 | char *buf) | |
a12e07bc | 1682 | { |
ee959b00 | 1683 | struct Scsi_Host *shost = class_to_shost(dev); |
51ef4c26 | 1684 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
a12e07bc JS |
1685 | return snprintf(buf, PAGE_SIZE, "0x%llx\n", |
1686 | (unsigned long long)phba->cfg_soft_wwnn); | |
1687 | } | |
1688 | ||
e59058c4 JS |
1689 | /** |
1690 | * lpfc_soft_wwnn_store: sets the ww node name of the adapter. | |
1691 | * @cdev: class device that is converted into a Scsi_host. | |
1692 | * @buf: contains the ww node name in hexidecimal. | |
1693 | * @count: number of wwnn bytes in buf. | |
1694 | * | |
1695 | * Returns: | |
1696 | * -EINVAL soft wwn not enabled, count is invalid, invalid wwnn byte invalid | |
1697 | * value of count on success | |
1698 | **/ | |
a12e07bc | 1699 | static ssize_t |
ee959b00 TJ |
1700 | lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr, |
1701 | const char *buf, size_t count) | |
a12e07bc | 1702 | { |
ee959b00 | 1703 | struct Scsi_Host *shost = class_to_shost(dev); |
51ef4c26 | 1704 | struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba; |
a12e07bc JS |
1705 | unsigned int i, j, cnt=count; |
1706 | u8 wwnn[8]; | |
1707 | ||
1708 | /* count may include a LF at end of string */ | |
1709 | if (buf[cnt-1] == '\n') | |
1710 | cnt--; | |
1711 | ||
1712 | if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) || | |
1713 | ((cnt == 17) && (*buf++ != 'x')) || | |
1714 | ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x')))) | |
1715 | return -EINVAL; | |
1716 | ||
1717 | /* | |
1718 | * Allow wwnn to be set many times, as long as the enable is set. | |
1719 | * However, once the wwpn is set, everything locks. | |
1720 | */ | |
1721 | ||
1722 | memset(wwnn, 0, sizeof(wwnn)); | |
1723 | ||
1724 | /* Validate and store the new name */ | |
1725 | for (i=0, j=0; i < 16; i++) { | |
1726 | if ((*buf >= 'a') && (*buf <= 'f')) | |
1727 | j = ((j << 4) | ((*buf++ -'a') + 10)); | |
1728 | else if ((*buf >= 'A') && (*buf <= 'F')) | |
1729 | j = ((j << 4) | ((*buf++ -'A') + 10)); | |
1730 | else if ((*buf >= '0') && (*buf <= '9')) | |
1731 | j = ((j << 4) | (*buf++ -'0')); | |
1732 | else | |
1733 | return -EINVAL; | |
1734 | if (i % 2) { | |
1735 | wwnn[i/2] = j & 0xff; | |
1736 | j = 0; | |
1737 | } | |
1738 | } | |
1739 | phba->cfg_soft_wwnn = wwn_to_u64(wwnn); | |
1740 | ||
1741 | dev_printk(KERN_NOTICE, &phba->pcidev->dev, | |
1742 | "lpfc%d: soft_wwnn set. Value will take effect upon " | |
1743 | "setting of the soft_wwpn\n", phba->brd_no); | |
1744 | ||
1745 | return count; | |
1746 | } | |
ee959b00 TJ |
1747 | static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,\ |
1748 | lpfc_soft_wwnn_show, lpfc_soft_wwnn_store); | |
a12e07bc | 1749 | |
c3f28afa | 1750 | |
875fbdfe JSEC |
1751 | static int lpfc_poll = 0; |
1752 | module_param(lpfc_poll, int, 0); | |
1753 | MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:" | |
1754 | " 0 - none," | |
1755 | " 1 - poll with interrupts enabled" | |
1756 | " 3 - poll and disable FCP ring interrupts"); | |
1757 | ||
ee959b00 TJ |
1758 | static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR, |
1759 | lpfc_poll_show, lpfc_poll_store); | |
dea3101e | 1760 | |
92d7f7b0 JS |
1761 | int lpfc_sli_mode = 0; |
1762 | module_param(lpfc_sli_mode, int, 0); | |
1763 | MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:" | |
1764 | " 0 - auto (SLI-3 if supported)," | |
1765 | " 2 - select SLI-2 even on SLI-3 capable HBAs," | |
1766 | " 3 - select SLI-3"); | |
1767 | ||
7ee5d43e JS |
1768 | int lpfc_enable_npiv = 0; |
1769 | module_param(lpfc_enable_npiv, int, 0); | |
1770 | MODULE_PARM_DESC(lpfc_enable_npiv, "Enable NPIV functionality"); | |
1771 | lpfc_param_show(enable_npiv); | |
1772 | lpfc_param_init(enable_npiv, 0, 0, 1); | |
ee959b00 | 1773 | static DEVICE_ATTR(lpfc_enable_npiv, S_IRUGO, |
7ee5d43e | 1774 | lpfc_enable_npiv_show, NULL); |
92d7f7b0 | 1775 | |
c01f3208 JS |
1776 | /* |
1777 | # lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear | |
1778 | # until the timer expires. Value range is [0,255]. Default value is 30. | |
1779 | */ | |
1780 | static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO; | |
1781 | static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO; | |
1782 | module_param(lpfc_nodev_tmo, int, 0); | |
1783 | MODULE_PARM_DESC(lpfc_nodev_tmo, | |
1784 | "Seconds driver will hold I/O waiting " | |
1785 | "for a device to come back"); | |
e59058c4 JS |
1786 | |
1787 | /** | |
1788 | * lpfc_nodev_tmo_show: Return the hba dev loss timeout value. | |
1789 | * @dev: class converted to a Scsi_host structure. | |
1790 | * @attr: device attribute, not used. | |
1791 | * @buf: on return contains the dev loss timeout in decimal. | |
1792 | * | |
1793 | * Returns: size of formatted string. | |
1794 | **/ | |
c01f3208 | 1795 | static ssize_t |
ee959b00 TJ |
1796 | lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr, |
1797 | char *buf) | |
c01f3208 | 1798 | { |
ee959b00 | 1799 | struct Scsi_Host *shost = class_to_shost(dev); |
2e0fef85 | 1800 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
c01f3208 | 1801 | int val = 0; |
3de2a653 JS |
1802 | val = vport->cfg_devloss_tmo; |
1803 | return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo); | |
c01f3208 JS |
1804 | } |
1805 | ||
e59058c4 JS |
1806 | /** |
1807 | * lpfc_nodev_tmo_init: Set the hba nodev timeout value. | |
1808 | * @vport: lpfc vport structure pointer. | |
1809 | * @val: contains the nodev timeout value. | |
1810 | * | |
1811 | * Description: | |
1812 | * If the devloss tmo is already set then nodev tmo is set to devloss tmo, | |
1813 | * a kernel error message is printed and zero is returned. | |
1814 | * Else if val is in range then nodev tmo and devloss tmo are set to val. | |
1815 | * Otherwise nodev tmo is set to the default value. | |
1816 | * | |
1817 | * Returns: | |
1818 | * zero if already set or if val is in range | |
1819 | * -EINVAL val out of range | |
1820 | **/ | |
c01f3208 | 1821 | static int |
3de2a653 JS |
1822 | lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val) |
1823 | { | |
1824 | if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) { | |
1825 | vport->cfg_nodev_tmo = vport->cfg_devloss_tmo; | |
1826 | if (val != LPFC_DEF_DEVLOSS_TMO) | |
e8b62011 | 1827 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
d7c255b2 | 1828 | "0407 Ignoring nodev_tmo module " |
e8b62011 JS |
1829 | "parameter because devloss_tmo is " |
1830 | "set.\n"); | |
c01f3208 JS |
1831 | return 0; |
1832 | } | |
1833 | ||
1834 | if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) { | |
3de2a653 JS |
1835 | vport->cfg_nodev_tmo = val; |
1836 | vport->cfg_devloss_tmo = val; | |
c01f3208 JS |
1837 | return 0; |
1838 | } | |
e8b62011 JS |
1839 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
1840 | "0400 lpfc_nodev_tmo attribute cannot be set to" | |
1841 | " %d, allowed range is [%d, %d]\n", | |
1842 | val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO); | |
3de2a653 | 1843 | vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO; |
c01f3208 JS |
1844 | return -EINVAL; |
1845 | } | |
1846 | ||
e59058c4 JS |
1847 | /** |
1848 | * lpfc_update_rport_devloss_tmo: Update dev loss tmo value. | |
1849 | * @vport: lpfc vport structure pointer. | |
1850 | * | |
1851 | * Description: | |
1852 | * Update all the ndlp's dev loss tmo with the vport devloss tmo value. | |
1853 | **/ | |
7054a606 | 1854 | static void |
3de2a653 | 1855 | lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport) |
7054a606 | 1856 | { |
858c9f6c | 1857 | struct Scsi_Host *shost; |
7054a606 JS |
1858 | struct lpfc_nodelist *ndlp; |
1859 | ||
51ef4c26 JS |
1860 | shost = lpfc_shost_from_vport(vport); |
1861 | spin_lock_irq(shost->host_lock); | |
1862 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) | |
e47c9093 | 1863 | if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport) |
51ef4c26 JS |
1864 | ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo; |
1865 | spin_unlock_irq(shost->host_lock); | |
7054a606 JS |
1866 | } |
1867 | ||
e59058c4 JS |
1868 | /** |
1869 | * lpfc_nodev_tmo_set: Set the vport nodev tmo and devloss tmo values. | |
1870 | * @vport: lpfc vport structure pointer. | |
1871 | * @val: contains the tmo value. | |
1872 | * | |
1873 | * Description: | |
1874 | * If the devloss tmo is already set or the vport dev loss tmo has changed | |
1875 | * then a kernel error message is printed and zero is returned. | |
1876 | * Else if val is in range then nodev tmo and devloss tmo are set to val. | |
1877 | * Otherwise nodev tmo is set to the default value. | |
1878 | * | |
1879 | * Returns: | |
1880 | * zero if already set or if val is in range | |
1881 | * -EINVAL val out of range | |
1882 | **/ | |
c01f3208 | 1883 | static int |
3de2a653 | 1884 | lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val) |
c01f3208 | 1885 | { |
3de2a653 JS |
1886 | if (vport->dev_loss_tmo_changed || |
1887 | (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) { | |
e8b62011 JS |
1888 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
1889 | "0401 Ignoring change to nodev_tmo " | |
1890 | "because devloss_tmo is set.\n"); | |
c01f3208 JS |
1891 | return 0; |
1892 | } | |
c01f3208 | 1893 | if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) { |
3de2a653 JS |
1894 | vport->cfg_nodev_tmo = val; |
1895 | vport->cfg_devloss_tmo = val; | |
1896 | lpfc_update_rport_devloss_tmo(vport); | |
c01f3208 JS |
1897 | return 0; |
1898 | } | |
e8b62011 JS |
1899 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
1900 | "0403 lpfc_nodev_tmo attribute cannot be set to" | |
1901 | "%d, allowed range is [%d, %d]\n", | |
1902 | val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO); | |
c01f3208 JS |
1903 | return -EINVAL; |
1904 | } | |
1905 | ||
3de2a653 | 1906 | lpfc_vport_param_store(nodev_tmo) |
c01f3208 | 1907 | |
ee959b00 TJ |
1908 | static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR, |
1909 | lpfc_nodev_tmo_show, lpfc_nodev_tmo_store); | |
c01f3208 JS |
1910 | |
1911 | /* | |
1912 | # lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that | |
1913 | # disappear until the timer expires. Value range is [0,255]. Default | |
1914 | # value is 30. | |
1915 | */ | |
1916 | module_param(lpfc_devloss_tmo, int, 0); | |
1917 | MODULE_PARM_DESC(lpfc_devloss_tmo, | |
1918 | "Seconds driver will hold I/O waiting " | |
1919 | "for a device to come back"); | |
3de2a653 JS |
1920 | lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO, |
1921 | LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO) | |
1922 | lpfc_vport_param_show(devloss_tmo) | |
e59058c4 JS |
1923 | |
1924 | /** | |
1925 | * lpfc_devloss_tmo_set: Sets vport nodev tmo, devloss tmo values, changed bit. | |
1926 | * @vport: lpfc vport structure pointer. | |
1927 | * @val: contains the tmo value. | |
1928 | * | |
1929 | * Description: | |
1930 | * If val is in a valid range then set the vport nodev tmo, | |
1931 | * devloss tmo, also set the vport dev loss tmo changed flag. | |
1932 | * Else a kernel error message is printed. | |
1933 | * | |
1934 | * Returns: | |
1935 | * zero if val is in range | |
1936 | * -EINVAL val out of range | |
1937 | **/ | |
c01f3208 | 1938 | static int |
3de2a653 | 1939 | lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val) |
c01f3208 JS |
1940 | { |
1941 | if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) { | |
3de2a653 JS |
1942 | vport->cfg_nodev_tmo = val; |
1943 | vport->cfg_devloss_tmo = val; | |
1944 | vport->dev_loss_tmo_changed = 1; | |
1945 | lpfc_update_rport_devloss_tmo(vport); | |
c01f3208 JS |
1946 | return 0; |
1947 | } | |
1948 | ||
e8b62011 JS |
1949 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
1950 | "0404 lpfc_devloss_tmo attribute cannot be set to" | |
1951 | " %d, allowed range is [%d, %d]\n", | |
1952 | val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO); | |
c01f3208 JS |
1953 | return -EINVAL; |
1954 | } | |
1955 | ||
3de2a653 | 1956 | lpfc_vport_param_store(devloss_tmo) |
ee959b00 TJ |
1957 | static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR, |
1958 | lpfc_devloss_tmo_show, lpfc_devloss_tmo_store); | |
c01f3208 | 1959 | |
dea3101e | 1960 | /* |
1961 | # lpfc_log_verbose: Only turn this flag on if you are willing to risk being | |
1962 | # deluged with LOTS of information. | |
1963 | # You can set a bit mask to record specific types of verbose messages: | |
1964 | # | |
1965 | # LOG_ELS 0x1 ELS events | |
1966 | # LOG_DISCOVERY 0x2 Link discovery events | |
1967 | # LOG_MBOX 0x4 Mailbox events | |
1968 | # LOG_INIT 0x8 Initialization events | |
1969 | # LOG_LINK_EVENT 0x10 Link events | |
dea3101e | 1970 | # LOG_FCP 0x40 FCP traffic history |
1971 | # LOG_NODE 0x80 Node table events | |
1972 | # LOG_MISC 0x400 Miscellaneous events | |
1973 | # LOG_SLI 0x800 SLI events | |
c7743956 | 1974 | # LOG_FCP_ERROR 0x1000 Only log FCP errors |
dea3101e | 1975 | # LOG_LIBDFC 0x2000 LIBDFC events |
1976 | # LOG_ALL_MSG 0xffff LOG all messages | |
1977 | */ | |
e8b62011 JS |
1978 | LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffff, |
1979 | "Verbose logging bit-mask"); | |
dea3101e | 1980 | |
7ee5d43e JS |
1981 | /* |
1982 | # lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters | |
1983 | # objects that have been registered with the nameserver after login. | |
1984 | */ | |
1985 | LPFC_VPORT_ATTR_R(enable_da_id, 0, 0, 1, | |
1986 | "Deregister nameserver objects before LOGO"); | |
1987 | ||
dea3101e | 1988 | /* |
1989 | # lun_queue_depth: This parameter is used to limit the number of outstanding | |
1990 | # commands per FCP LUN. Value range is [1,128]. Default value is 30. | |
1991 | */ | |
3de2a653 JS |
1992 | LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 128, |
1993 | "Max number of FCP commands we can queue to a specific LUN"); | |
dea3101e | 1994 | |
b28485ac JW |
1995 | /* |
1996 | # hba_queue_depth: This parameter is used to limit the number of outstanding | |
1997 | # commands per lpfc HBA. Value range is [32,8192]. If this parameter | |
1998 | # value is greater than the maximum number of exchanges supported by the HBA, | |
1999 | # then maximum number of exchanges supported by the HBA is used to determine | |
2000 | # the hba_queue_depth. | |
2001 | */ | |
2002 | LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192, | |
2003 | "Max number of FCP commands we can queue to a lpfc HBA"); | |
2004 | ||
92d7f7b0 JS |
2005 | /* |
2006 | # peer_port_login: This parameter allows/prevents logins | |
2007 | # between peer ports hosted on the same physical port. | |
2008 | # When this parameter is set 0 peer ports of same physical port | |
2009 | # are not allowed to login to each other. | |
2010 | # When this parameter is set 1 peer ports of same physical port | |
2011 | # are allowed to login to each other. | |
2012 | # Default value of this parameter is 0. | |
2013 | */ | |
3de2a653 JS |
2014 | LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1, |
2015 | "Allow peer ports on the same physical port to login to each " | |
2016 | "other."); | |
92d7f7b0 JS |
2017 | |
2018 | /* | |
3de2a653 | 2019 | # restrict_login: This parameter allows/prevents logins |
92d7f7b0 JS |
2020 | # between Virtual Ports and remote initiators. |
2021 | # When this parameter is not set (0) Virtual Ports will accept PLOGIs from | |
2022 | # other initiators and will attempt to PLOGI all remote ports. | |
2023 | # When this parameter is set (1) Virtual Ports will reject PLOGIs from | |
2024 | # remote ports and will not attempt to PLOGI to other initiators. | |
2025 | # This parameter does not restrict to the physical port. | |
2026 | # This parameter does not restrict logins to Fabric resident remote ports. | |
2027 | # Default value of this parameter is 1. | |
2028 | */ | |
3de2a653 JS |
2029 | static int lpfc_restrict_login = 1; |
2030 | module_param(lpfc_restrict_login, int, 0); | |
2031 | MODULE_PARM_DESC(lpfc_restrict_login, | |
2032 | "Restrict virtual ports login to remote initiators."); | |
2033 | lpfc_vport_param_show(restrict_login); | |
2034 | ||
e59058c4 JS |
2035 | /** |
2036 | * lpfc_restrict_login_init: Set the vport restrict login flag. | |
2037 | * @vport: lpfc vport structure pointer. | |
2038 | * @val: contains the restrict login value. | |
2039 | * | |
2040 | * Description: | |
2041 | * If val is not in a valid range then log a kernel error message and set | |
2042 | * the vport restrict login to one. | |
2043 | * If the port type is physical clear the restrict login flag and return. | |
2044 | * Else set the restrict login flag to val. | |
2045 | * | |
2046 | * Returns: | |
2047 | * zero if val is in range | |
2048 | * -EINVAL val out of range | |
2049 | **/ | |
3de2a653 JS |
2050 | static int |
2051 | lpfc_restrict_login_init(struct lpfc_vport *vport, int val) | |
2052 | { | |
2053 | if (val < 0 || val > 1) { | |
e8b62011 | 2054 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
d7c255b2 | 2055 | "0422 lpfc_restrict_login attribute cannot " |
e8b62011 JS |
2056 | "be set to %d, allowed range is [0, 1]\n", |
2057 | val); | |
3de2a653 JS |
2058 | vport->cfg_restrict_login = 1; |
2059 | return -EINVAL; | |
2060 | } | |
2061 | if (vport->port_type == LPFC_PHYSICAL_PORT) { | |
2062 | vport->cfg_restrict_login = 0; | |
2063 | return 0; | |
2064 | } | |
2065 | vport->cfg_restrict_login = val; | |
2066 | return 0; | |
2067 | } | |
2068 | ||
e59058c4 JS |
2069 | /** |
2070 | * lpfc_restrict_login_set: Set the vport restrict login flag. | |
2071 | * @vport: lpfc vport structure pointer. | |
2072 | * @val: contains the restrict login value. | |
2073 | * | |
2074 | * Description: | |
2075 | * If val is not in a valid range then log a kernel error message and set | |
2076 | * the vport restrict login to one. | |
2077 | * If the port type is physical and the val is not zero log a kernel | |
2078 | * error message, clear the restrict login flag and return zero. | |
2079 | * Else set the restrict login flag to val. | |
2080 | * | |
2081 | * Returns: | |
2082 | * zero if val is in range | |
2083 | * -EINVAL val out of range | |
2084 | **/ | |
3de2a653 JS |
2085 | static int |
2086 | lpfc_restrict_login_set(struct lpfc_vport *vport, int val) | |
2087 | { | |
2088 | if (val < 0 || val > 1) { | |
e8b62011 | 2089 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
d7c255b2 | 2090 | "0425 lpfc_restrict_login attribute cannot " |
e8b62011 JS |
2091 | "be set to %d, allowed range is [0, 1]\n", |
2092 | val); | |
3de2a653 JS |
2093 | vport->cfg_restrict_login = 1; |
2094 | return -EINVAL; | |
2095 | } | |
2096 | if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) { | |
e8b62011 JS |
2097 | lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, |
2098 | "0468 lpfc_restrict_login must be 0 for " | |
2099 | "Physical ports.\n"); | |
3de2a653 JS |
2100 | vport->cfg_restrict_login = 0; |
2101 | return 0; | |
2102 | } | |
2103 | vport->cfg_restrict_login = val; | |
2104 | return 0; | |
2105 | } | |
2106 | lpfc_vport_param_store(restrict_login); | |
ee959b00 TJ |
2107 | static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR, |
2108 | lpfc_restrict_login_show, lpfc_restrict_login_store); | |
92d7f7b0 | 2109 | |
dea3101e | 2110 | /* |
2111 | # Some disk devices have a "select ID" or "select Target" capability. | |
2112 | # From a protocol standpoint "select ID" usually means select the | |
2113 | # Fibre channel "ALPA". In the FC-AL Profile there is an "informative | |
2114 | # annex" which contains a table that maps a "select ID" (a number | |
2115 | # between 0 and 7F) to an ALPA. By default, for compatibility with | |
2116 | # older drivers, the lpfc driver scans this table from low ALPA to high | |
2117 | # ALPA. | |
2118 | # | |
2119 | # Turning on the scan-down variable (on = 1, off = 0) will | |
2120 | # cause the lpfc driver to use an inverted table, effectively | |
2121 | # scanning ALPAs from high to low. Value range is [0,1]. Default value is 1. | |
2122 | # | |
2123 | # (Note: This "select ID" functionality is a LOOP ONLY characteristic | |
2124 | # and will not work across a fabric. Also this parameter will take | |
2125 | # effect only in the case when ALPA map is not available.) | |
2126 | */ | |
3de2a653 JS |
2127 | LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1, |
2128 | "Start scanning for devices from highest ALPA to lowest"); | |
dea3101e | 2129 | |
dea3101e | 2130 | /* |
2131 | # lpfc_topology: link topology for init link | |
2132 | # 0x0 = attempt loop mode then point-to-point | |
367c2713 | 2133 | # 0x01 = internal loopback mode |
dea3101e | 2134 | # 0x02 = attempt point-to-point mode only |
2135 | # 0x04 = attempt loop mode only | |
2136 | # 0x06 = attempt point-to-point mode then loop | |
2137 | # Set point-to-point mode if you want to run as an N_Port. | |
2138 | # Set loop mode if you want to run as an NL_Port. Value range is [0,0x6]. | |
2139 | # Default value is 0. | |
2140 | */ | |
e59058c4 JS |
2141 | |
2142 | /** | |
2143 | * lpfc_topology_set: Set the adapters topology field. | |
2144 | * @phba: lpfc_hba pointer. | |
2145 | * @val: topology value. | |
2146 | * | |
2147 | * Description: | |
2148 | * If val is in a valid range then set the adapter's topology field and | |
2149 | * issue a lip; if the lip fails reset the topology to the old value. | |
2150 | * | |
2151 | * If the value is not in range log a kernel error message and return an error. | |
2152 | * | |
2153 | * Returns: | |
2154 | * zero if val is in range and lip okay | |
2155 | * non-zero return value from lpfc_issue_lip() | |
2156 | * -EINVAL val out of range | |
2157 | **/ | |
83108bd3 JS |
2158 | static int |
2159 | lpfc_topology_set(struct lpfc_hba *phba, int val) | |
2160 | { | |
2161 | int err; | |
2162 | uint32_t prev_val; | |
2163 | if (val >= 0 && val <= 6) { | |
2164 | prev_val = phba->cfg_topology; | |
2165 | phba->cfg_topology = val; | |
2166 | err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport)); | |
2167 | if (err) | |
2168 | phba->cfg_topology = prev_val; | |
2169 | return err; | |
2170 | } | |
2171 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
2172 | "%d:0467 lpfc_topology attribute cannot be set to %d, " | |
2173 | "allowed range is [0, 6]\n", | |
2174 | phba->brd_no, val); | |
2175 | return -EINVAL; | |
2176 | } | |
2177 | static int lpfc_topology = 0; | |
2178 | module_param(lpfc_topology, int, 0); | |
2179 | MODULE_PARM_DESC(lpfc_topology, "Select Fibre Channel topology"); | |
2180 | lpfc_param_show(topology) | |
2181 | lpfc_param_init(topology, 0, 0, 6) | |
2182 | lpfc_param_store(topology) | |
ee959b00 | 2183 | static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR, |
83108bd3 | 2184 | lpfc_topology_show, lpfc_topology_store); |
dea3101e | 2185 | |
2186 | /* | |
2187 | # lpfc_link_speed: Link speed selection for initializing the Fibre Channel | |
2188 | # connection. | |
2189 | # 0 = auto select (default) | |
2190 | # 1 = 1 Gigabaud | |
2191 | # 2 = 2 Gigabaud | |
2192 | # 4 = 4 Gigabaud | |
b87eab38 JS |
2193 | # 8 = 8 Gigabaud |
2194 | # Value range is [0,8]. Default value is 0. | |
dea3101e | 2195 | */ |
e59058c4 JS |
2196 | |
2197 | /** | |
2198 | * lpfc_link_speed_set: Set the adapters link speed. | |
2199 | * @phba: lpfc_hba pointer. | |
2200 | * @val: link speed value. | |
2201 | * | |
2202 | * Description: | |
2203 | * If val is in a valid range then set the adapter's link speed field and | |
2204 | * issue a lip; if the lip fails reset the link speed to the old value. | |
2205 | * | |
2206 | * Notes: | |
2207 | * If the value is not in range log a kernel error message and return an error. | |
2208 | * | |
2209 | * Returns: | |
2210 | * zero if val is in range and lip okay. | |
2211 | * non-zero return value from lpfc_issue_lip() | |
2212 | * -EINVAL val out of range | |
2213 | **/ | |
83108bd3 JS |
2214 | static int |
2215 | lpfc_link_speed_set(struct lpfc_hba *phba, int val) | |
2216 | { | |
2217 | int err; | |
2218 | uint32_t prev_val; | |
2219 | ||
2220 | if (((val == LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) || | |
2221 | ((val == LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) || | |
2222 | ((val == LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) || | |
2223 | ((val == LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) || | |
2224 | ((val == LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb))) | |
2225 | return -EINVAL; | |
2226 | ||
2227 | if ((val >= 0 && val <= LPFC_MAX_LINK_SPEED) | |
2228 | && (LPFC_LINK_SPEED_BITMAP & (1 << val))) { | |
2229 | prev_val = phba->cfg_link_speed; | |
2230 | phba->cfg_link_speed = val; | |
2231 | err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport)); | |
2232 | if (err) | |
2233 | phba->cfg_link_speed = prev_val; | |
2234 | return err; | |
2235 | } | |
2236 | ||
2237 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
2238 | "%d:0469 lpfc_link_speed attribute cannot be set to %d, " | |
2239 | "allowed range is [0, 8]\n", | |
2240 | phba->brd_no, val); | |
2241 | return -EINVAL; | |
2242 | } | |
2243 | ||
2244 | static int lpfc_link_speed = 0; | |
2245 | module_param(lpfc_link_speed, int, 0); | |
2246 | MODULE_PARM_DESC(lpfc_link_speed, "Select link speed"); | |
2247 | lpfc_param_show(link_speed) | |
e59058c4 JS |
2248 | |
2249 | /** | |
2250 | * lpfc_link_speed_init: Set the adapters link speed. | |
2251 | * @phba: lpfc_hba pointer. | |
2252 | * @val: link speed value. | |
2253 | * | |
2254 | * Description: | |
2255 | * If val is in a valid range then set the adapter's link speed field. | |
2256 | * | |
2257 | * Notes: | |
2258 | * If the value is not in range log a kernel error message, clear the link | |
2259 | * speed and return an error. | |
2260 | * | |
2261 | * Returns: | |
2262 | * zero if val saved. | |
2263 | * -EINVAL val out of range | |
2264 | **/ | |
83108bd3 JS |
2265 | static int |
2266 | lpfc_link_speed_init(struct lpfc_hba *phba, int val) | |
2267 | { | |
2268 | if ((val >= 0 && val <= LPFC_MAX_LINK_SPEED) | |
2269 | && (LPFC_LINK_SPEED_BITMAP & (1 << val))) { | |
2270 | phba->cfg_link_speed = val; | |
2271 | return 0; | |
2272 | } | |
2273 | lpfc_printf_log(phba, KERN_ERR, LOG_INIT, | |
d7c255b2 | 2274 | "0405 lpfc_link_speed attribute cannot " |
83108bd3 JS |
2275 | "be set to %d, allowed values are " |
2276 | "["LPFC_LINK_SPEED_STRING"]\n", val); | |
2277 | phba->cfg_link_speed = 0; | |
2278 | return -EINVAL; | |
2279 | } | |
2280 | ||
2281 | lpfc_param_store(link_speed) | |
ee959b00 | 2282 | static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR, |
83108bd3 | 2283 | lpfc_link_speed_show, lpfc_link_speed_store); |
dea3101e | 2284 | |
2285 | /* | |
2286 | # lpfc_fcp_class: Determines FC class to use for the FCP protocol. | |
2287 | # Value range is [2,3]. Default value is 3. | |
2288 | */ | |
3de2a653 JS |
2289 | LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3, |
2290 | "Select Fibre Channel class of service for FCP sequences"); | |
dea3101e | 2291 | |
2292 | /* | |
2293 | # lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range | |
2294 | # is [0,1]. Default value is 0. | |
2295 | */ | |
3de2a653 JS |
2296 | LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1, |
2297 | "Use ADISC on rediscovery to authenticate FCP devices"); | |
dea3101e | 2298 | |
2299 | /* | |
2300 | # lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value | |
2301 | # range is [0,1]. Default value is 0. | |
2302 | */ | |
2303 | LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support"); | |
2304 | ||
2305 | /* | |
2306 | # lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing | |
2307 | # cr_delay (msec) or cr_count outstanding commands. cr_delay can take | |
7054a606 | 2308 | # value [0,63]. cr_count can take value [1,255]. Default value of cr_delay |
dea3101e | 2309 | # is 0. Default value of cr_count is 1. The cr_count feature is disabled if |
2310 | # cr_delay is set to 0. | |
2311 | */ | |
8189fd19 | 2312 | LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an " |
dea3101e | 2313 | "interrupt response is generated"); |
2314 | ||
8189fd19 | 2315 | LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an " |
dea3101e | 2316 | "interrupt response is generated"); |
2317 | ||
cf5bf97e JW |
2318 | /* |
2319 | # lpfc_multi_ring_support: Determines how many rings to spread available | |
2320 | # cmd/rsp IOCB entries across. | |
2321 | # Value range is [1,2]. Default value is 1. | |
2322 | */ | |
2323 | LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary " | |
2324 | "SLI rings to spread IOCB entries across"); | |
2325 | ||
a4bc3379 JS |
2326 | /* |
2327 | # lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this | |
2328 | # identifies what rctl value to configure the additional ring for. | |
2329 | # Value range is [1,0xff]. Default value is 4 (Unsolicated Data). | |
2330 | */ | |
2331 | LPFC_ATTR_R(multi_ring_rctl, FC_UNSOL_DATA, 1, | |
2332 | 255, "Identifies RCTL for additional ring configuration"); | |
2333 | ||
2334 | /* | |
2335 | # lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this | |
2336 | # identifies what type value to configure the additional ring for. | |
2337 | # Value range is [1,0xff]. Default value is 5 (LLC/SNAP). | |
2338 | */ | |
2339 | LPFC_ATTR_R(multi_ring_type, FC_LLC_SNAP, 1, | |
2340 | 255, "Identifies TYPE for additional ring configuration"); | |
2341 | ||
dea3101e | 2342 | /* |
2343 | # lpfc_fdmi_on: controls FDMI support. | |
2344 | # 0 = no FDMI support | |
2345 | # 1 = support FDMI without attribute of hostname | |
2346 | # 2 = support FDMI with attribute of hostname | |
2347 | # Value range [0,2]. Default value is 0. | |
2348 | */ | |
3de2a653 | 2349 | LPFC_VPORT_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support"); |
dea3101e | 2350 | |
2351 | /* | |
2352 | # Specifies the maximum number of ELS cmds we can have outstanding (for | |
2353 | # discovery). Value range is [1,64]. Default value = 32. | |
2354 | */ | |
3de2a653 | 2355 | LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands " |
dea3101e | 2356 | "during discovery"); |
2357 | ||
2358 | /* | |
65a29c16 JS |
2359 | # lpfc_max_luns: maximum allowed LUN. |
2360 | # Value range is [0,65535]. Default value is 255. | |
2361 | # NOTE: The SCSI layer might probe all allowed LUN on some old targets. | |
dea3101e | 2362 | */ |
3de2a653 | 2363 | LPFC_VPORT_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN"); |
dea3101e | 2364 | |
875fbdfe JSEC |
2365 | /* |
2366 | # lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring. | |
2367 | # Value range is [1,255], default value is 10. | |
2368 | */ | |
2369 | LPFC_ATTR_RW(poll_tmo, 10, 1, 255, | |
2370 | "Milliseconds driver will wait between polling FCP ring"); | |
2371 | ||
4ff43246 JS |
2372 | /* |
2373 | # lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that | |
2374 | # support this feature | |
9399627f | 2375 | # 0 = MSI disabled |
4ff43246 | 2376 | # 1 = MSI enabled |
9399627f JS |
2377 | # 2 = MSI-X enabled (default) |
2378 | # Value range is [0,2]. Default value is 2. | |
4ff43246 | 2379 | */ |
9399627f | 2380 | LPFC_ATTR_R(use_msi, 2, 0, 2, "Use Message Signaled Interrupts (1) or " |
db2378e0 | 2381 | "MSI-X (2), if possible"); |
4ff43246 | 2382 | |
13815c83 JS |
2383 | /* |
2384 | # lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware. | |
2385 | # 0 = HBA resets disabled | |
2386 | # 1 = HBA resets enabled (default) | |
2387 | # Value range is [0,1]. Default value is 1. | |
2388 | */ | |
2389 | LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver."); | |
c3f28afa | 2390 | |
13815c83 JS |
2391 | /* |
2392 | # lpfc_enable_hba_heartbeat: Enable HBA heartbeat timer.. | |
2393 | # 0 = HBA Heartbeat disabled | |
2394 | # 1 = HBA Heartbeat enabled (default) | |
2395 | # Value range is [0,1]. Default value is 1. | |
2396 | */ | |
2397 | LPFC_ATTR_R(enable_hba_heartbeat, 1, 0, 1, "Enable HBA Heartbeat."); | |
92d7f7b0 | 2398 | |
83108bd3 JS |
2399 | /* |
2400 | * lpfc_sg_seg_cnt: Initial Maximum DMA Segment Count | |
2401 | * This value can be set to values between 64 and 256. The default value is | |
2402 | * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer | |
2403 | * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE). | |
2404 | */ | |
2405 | LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT, | |
2406 | LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count"); | |
2407 | ||
ee959b00 TJ |
2408 | struct device_attribute *lpfc_hba_attrs[] = { |
2409 | &dev_attr_info, | |
2410 | &dev_attr_serialnum, | |
2411 | &dev_attr_modeldesc, | |
2412 | &dev_attr_modelname, | |
2413 | &dev_attr_programtype, | |
2414 | &dev_attr_portnum, | |
2415 | &dev_attr_fwrev, | |
2416 | &dev_attr_hdw, | |
2417 | &dev_attr_option_rom_version, | |
bbd1ae41 | 2418 | &dev_attr_link_state, |
ee959b00 | 2419 | &dev_attr_num_discovered_ports, |
84774a4d | 2420 | &dev_attr_menlo_mgmt_mode, |
ee959b00 TJ |
2421 | &dev_attr_lpfc_drvr_version, |
2422 | &dev_attr_lpfc_temp_sensor, | |
2423 | &dev_attr_lpfc_log_verbose, | |
2424 | &dev_attr_lpfc_lun_queue_depth, | |
2425 | &dev_attr_lpfc_hba_queue_depth, | |
2426 | &dev_attr_lpfc_peer_port_login, | |
2427 | &dev_attr_lpfc_nodev_tmo, | |
2428 | &dev_attr_lpfc_devloss_tmo, | |
2429 | &dev_attr_lpfc_fcp_class, | |
2430 | &dev_attr_lpfc_use_adisc, | |
2431 | &dev_attr_lpfc_ack0, | |
2432 | &dev_attr_lpfc_topology, | |
2433 | &dev_attr_lpfc_scan_down, | |
2434 | &dev_attr_lpfc_link_speed, | |
2435 | &dev_attr_lpfc_cr_delay, | |
2436 | &dev_attr_lpfc_cr_count, | |
2437 | &dev_attr_lpfc_multi_ring_support, | |
2438 | &dev_attr_lpfc_multi_ring_rctl, | |
2439 | &dev_attr_lpfc_multi_ring_type, | |
2440 | &dev_attr_lpfc_fdmi_on, | |
2441 | &dev_attr_lpfc_max_luns, | |
2442 | &dev_attr_lpfc_enable_npiv, | |
2443 | &dev_attr_nport_evt_cnt, | |
2444 | &dev_attr_board_mode, | |
2445 | &dev_attr_max_vpi, | |
2446 | &dev_attr_used_vpi, | |
2447 | &dev_attr_max_rpi, | |
2448 | &dev_attr_used_rpi, | |
2449 | &dev_attr_max_xri, | |
2450 | &dev_attr_used_xri, | |
2451 | &dev_attr_npiv_info, | |
2452 | &dev_attr_issue_reset, | |
2453 | &dev_attr_lpfc_poll, | |
2454 | &dev_attr_lpfc_poll_tmo, | |
2455 | &dev_attr_lpfc_use_msi, | |
2456 | &dev_attr_lpfc_soft_wwnn, | |
2457 | &dev_attr_lpfc_soft_wwpn, | |
2458 | &dev_attr_lpfc_soft_wwn_enable, | |
2459 | &dev_attr_lpfc_enable_hba_reset, | |
2460 | &dev_attr_lpfc_enable_hba_heartbeat, | |
2461 | &dev_attr_lpfc_sg_seg_cnt, | |
dea3101e | 2462 | NULL, |
2463 | }; | |
2464 | ||
ee959b00 TJ |
2465 | struct device_attribute *lpfc_vport_attrs[] = { |
2466 | &dev_attr_info, | |
bbd1ae41 | 2467 | &dev_attr_link_state, |
ee959b00 TJ |
2468 | &dev_attr_num_discovered_ports, |
2469 | &dev_attr_lpfc_drvr_version, | |
2470 | &dev_attr_lpfc_log_verbose, | |
2471 | &dev_attr_lpfc_lun_queue_depth, | |
2472 | &dev_attr_lpfc_nodev_tmo, | |
2473 | &dev_attr_lpfc_devloss_tmo, | |
2474 | &dev_attr_lpfc_hba_queue_depth, | |
2475 | &dev_attr_lpfc_peer_port_login, | |
2476 | &dev_attr_lpfc_restrict_login, | |
2477 | &dev_attr_lpfc_fcp_class, | |
2478 | &dev_attr_lpfc_use_adisc, | |
2479 | &dev_attr_lpfc_fdmi_on, | |
2480 | &dev_attr_lpfc_max_luns, | |
2481 | &dev_attr_nport_evt_cnt, | |
2482 | &dev_attr_npiv_info, | |
2483 | &dev_attr_lpfc_enable_da_id, | |
3de2a653 JS |
2484 | NULL, |
2485 | }; | |
2486 | ||
e59058c4 JS |
2487 | /** |
2488 | * sysfs_ctlreg_write: Write method for writing to ctlreg. | |
2489 | * @kobj: kernel kobject that contains the kernel class device. | |
2490 | * @bin_attr: kernel attributes passed to us. | |
2491 | * @buf: contains the data to be written to the adapter IOREG space. | |
2492 | * @off: offset into buffer to beginning of data. | |
2493 | * @count: bytes to transfer. | |
2494 | * | |
2495 | * Description: | |
2496 | * Accessed via /sys/class/scsi_host/hostxxx/ctlreg. | |
2497 | * Uses the adapter io control registers to send buf contents to the adapter. | |
2498 | * | |
2499 | * Returns: | |
2500 | * -ERANGE off and count combo out of range | |
2501 | * -EINVAL off, count or buff address invalid | |
2502 | * -EPERM adapter is offline | |
2503 | * value of count, buf contents written | |
2504 | **/ | |
dea3101e | 2505 | static ssize_t |
91a69029 ZR |
2506 | sysfs_ctlreg_write(struct kobject *kobj, struct bin_attribute *bin_attr, |
2507 | char *buf, loff_t off, size_t count) | |
dea3101e | 2508 | { |
2509 | size_t buf_off; | |
ee959b00 TJ |
2510 | struct device *dev = container_of(kobj, struct device, kobj); |
2511 | struct Scsi_Host *shost = class_to_shost(dev); | |
2e0fef85 JS |
2512 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
2513 | struct lpfc_hba *phba = vport->phba; | |
dea3101e | 2514 | |
2515 | if ((off + count) > FF_REG_AREA_SIZE) | |
2516 | return -ERANGE; | |
2517 | ||
2518 | if (count == 0) return 0; | |
2519 | ||
2520 | if (off % 4 || count % 4 || (unsigned long)buf % 4) | |
2521 | return -EINVAL; | |
2522 | ||
2e0fef85 | 2523 | if (!(vport->fc_flag & FC_OFFLINE_MODE)) { |
dea3101e | 2524 | return -EPERM; |
2525 | } | |
2526 | ||
2e0fef85 | 2527 | spin_lock_irq(&phba->hbalock); |
dea3101e | 2528 | for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) |
2529 | writel(*((uint32_t *)(buf + buf_off)), | |
2530 | phba->ctrl_regs_memmap_p + off + buf_off); | |
2531 | ||
2e0fef85 | 2532 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 2533 | |
2534 | return count; | |
2535 | } | |
2536 | ||
e59058c4 JS |
2537 | /** |
2538 | * sysfs_ctlreg_read: Read method for reading from ctlreg. | |
2539 | * @kobj: kernel kobject that contains the kernel class device. | |
2540 | * @bin_attr: kernel attributes passed to us. | |
2541 | * @buf: if succesful contains the data from the adapter IOREG space. | |
2542 | * @off: offset into buffer to beginning of data. | |
2543 | * @count: bytes to transfer. | |
2544 | * | |
2545 | * Description: | |
2546 | * Accessed via /sys/class/scsi_host/hostxxx/ctlreg. | |
2547 | * Uses the adapter io control registers to read data into buf. | |
2548 | * | |
2549 | * Returns: | |
2550 | * -ERANGE off and count combo out of range | |
2551 | * -EINVAL off, count or buff address invalid | |
2552 | * value of count, buf contents read | |
2553 | **/ | |
dea3101e | 2554 | static ssize_t |
91a69029 ZR |
2555 | sysfs_ctlreg_read(struct kobject *kobj, struct bin_attribute *bin_attr, |
2556 | char *buf, loff_t off, size_t count) | |
dea3101e | 2557 | { |
2558 | size_t buf_off; | |
2559 | uint32_t * tmp_ptr; | |
ee959b00 TJ |
2560 | struct device *dev = container_of(kobj, struct device, kobj); |
2561 | struct Scsi_Host *shost = class_to_shost(dev); | |
2e0fef85 JS |
2562 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
2563 | struct lpfc_hba *phba = vport->phba; | |
dea3101e | 2564 | |
2565 | if (off > FF_REG_AREA_SIZE) | |
2566 | return -ERANGE; | |
2567 | ||
2568 | if ((off + count) > FF_REG_AREA_SIZE) | |
2569 | count = FF_REG_AREA_SIZE - off; | |
2570 | ||
2571 | if (count == 0) return 0; | |
2572 | ||
2573 | if (off % 4 || count % 4 || (unsigned long)buf % 4) | |
2574 | return -EINVAL; | |
2575 | ||
2e0fef85 | 2576 | spin_lock_irq(&phba->hbalock); |
dea3101e | 2577 | |
2578 | for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) { | |
2579 | tmp_ptr = (uint32_t *)(buf + buf_off); | |
2580 | *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off); | |
2581 | } | |
2582 | ||
2e0fef85 | 2583 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 2584 | |
2585 | return count; | |
2586 | } | |
2587 | ||
2588 | static struct bin_attribute sysfs_ctlreg_attr = { | |
2589 | .attr = { | |
2590 | .name = "ctlreg", | |
2591 | .mode = S_IRUSR | S_IWUSR, | |
dea3101e | 2592 | }, |
2593 | .size = 256, | |
2594 | .read = sysfs_ctlreg_read, | |
2595 | .write = sysfs_ctlreg_write, | |
2596 | }; | |
2597 | ||
e59058c4 JS |
2598 | /** |
2599 | * sysfs_mbox_idle: frees the sysfs mailbox. | |
2600 | * @phba: lpfc_hba pointer | |
2601 | **/ | |
dea3101e | 2602 | static void |
2e0fef85 | 2603 | sysfs_mbox_idle(struct lpfc_hba *phba) |
dea3101e | 2604 | { |
2605 | phba->sysfs_mbox.state = SMBOX_IDLE; | |
2606 | phba->sysfs_mbox.offset = 0; | |
2607 | ||
2608 | if (phba->sysfs_mbox.mbox) { | |
2609 | mempool_free(phba->sysfs_mbox.mbox, | |
2610 | phba->mbox_mem_pool); | |
2611 | phba->sysfs_mbox.mbox = NULL; | |
2612 | } | |
2613 | } | |
2614 | ||
e59058c4 JS |
2615 | /** |
2616 | * sysfs_mbox_write: Write method for writing information via mbox. | |
2617 | * @kobj: kernel kobject that contains the kernel class device. | |
2618 | * @bin_attr: kernel attributes passed to us. | |
2619 | * @buf: contains the data to be written to sysfs mbox. | |
2620 | * @off: offset into buffer to beginning of data. | |
2621 | * @count: bytes to transfer. | |
2622 | * | |
2623 | * Description: | |
2624 | * Accessed via /sys/class/scsi_host/hostxxx/mbox. | |
2625 | * Uses the sysfs mbox to send buf contents to the adapter. | |
2626 | * | |
2627 | * Returns: | |
2628 | * -ERANGE off and count combo out of range | |
2629 | * -EINVAL off, count or buff address invalid | |
2630 | * zero if count is zero | |
2631 | * -EPERM adapter is offline | |
2632 | * -ENOMEM failed to allocate memory for the mail box | |
2633 | * -EAGAIN offset, state or mbox is NULL | |
2634 | * count number of bytes transferred | |
2635 | **/ | |
dea3101e | 2636 | static ssize_t |
91a69029 ZR |
2637 | sysfs_mbox_write(struct kobject *kobj, struct bin_attribute *bin_attr, |
2638 | char *buf, loff_t off, size_t count) | |
dea3101e | 2639 | { |
ee959b00 TJ |
2640 | struct device *dev = container_of(kobj, struct device, kobj); |
2641 | struct Scsi_Host *shost = class_to_shost(dev); | |
2e0fef85 JS |
2642 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
2643 | struct lpfc_hba *phba = vport->phba; | |
2644 | struct lpfcMboxq *mbox = NULL; | |
dea3101e | 2645 | |
2646 | if ((count + off) > MAILBOX_CMD_SIZE) | |
2647 | return -ERANGE; | |
2648 | ||
2649 | if (off % 4 || count % 4 || (unsigned long)buf % 4) | |
2650 | return -EINVAL; | |
2651 | ||
2652 | if (count == 0) | |
2653 | return 0; | |
2654 | ||
2655 | if (off == 0) { | |
2656 | mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); | |
2657 | if (!mbox) | |
2658 | return -ENOMEM; | |
fc6c12bc | 2659 | memset(mbox, 0, sizeof (LPFC_MBOXQ_t)); |
dea3101e | 2660 | } |
2661 | ||
2e0fef85 | 2662 | spin_lock_irq(&phba->hbalock); |
dea3101e | 2663 | |
2664 | if (off == 0) { | |
2665 | if (phba->sysfs_mbox.mbox) | |
2666 | mempool_free(mbox, phba->mbox_mem_pool); | |
2667 | else | |
2668 | phba->sysfs_mbox.mbox = mbox; | |
2669 | phba->sysfs_mbox.state = SMBOX_WRITING; | |
2670 | } else { | |
2671 | if (phba->sysfs_mbox.state != SMBOX_WRITING || | |
2672 | phba->sysfs_mbox.offset != off || | |
92d7f7b0 | 2673 | phba->sysfs_mbox.mbox == NULL) { |
dea3101e | 2674 | sysfs_mbox_idle(phba); |
2e0fef85 | 2675 | spin_unlock_irq(&phba->hbalock); |
8f6d98d2 | 2676 | return -EAGAIN; |
dea3101e | 2677 | } |
2678 | } | |
2679 | ||
2680 | memcpy((uint8_t *) & phba->sysfs_mbox.mbox->mb + off, | |
2681 | buf, count); | |
2682 | ||
2683 | phba->sysfs_mbox.offset = off + count; | |
2684 | ||
2e0fef85 | 2685 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 2686 | |
2687 | return count; | |
2688 | } | |
2689 | ||
e59058c4 JS |
2690 | /** |
2691 | * sysfs_mbox_read: Read method for reading information via mbox. | |
2692 | * @kobj: kernel kobject that contains the kernel class device. | |
2693 | * @bin_attr: kernel attributes passed to us. | |
2694 | * @buf: contains the data to be read from sysfs mbox. | |
2695 | * @off: offset into buffer to beginning of data. | |
2696 | * @count: bytes to transfer. | |
2697 | * | |
2698 | * Description: | |
2699 | * Accessed via /sys/class/scsi_host/hostxxx/mbox. | |
2700 | * Uses the sysfs mbox to receive data from to the adapter. | |
2701 | * | |
2702 | * Returns: | |
2703 | * -ERANGE off greater than mailbox command size | |
2704 | * -EINVAL off, count or buff address invalid | |
2705 | * zero if off and count are zero | |
2706 | * -EACCES adapter over temp | |
2707 | * -EPERM garbage can value to catch a multitude of errors | |
2708 | * -EAGAIN management IO not permitted, state or off error | |
2709 | * -ETIME mailbox timeout | |
2710 | * -ENODEV mailbox error | |
2711 | * count number of bytes transferred | |
2712 | **/ | |
dea3101e | 2713 | static ssize_t |
91a69029 ZR |
2714 | sysfs_mbox_read(struct kobject *kobj, struct bin_attribute *bin_attr, |
2715 | char *buf, loff_t off, size_t count) | |
dea3101e | 2716 | { |
ee959b00 TJ |
2717 | struct device *dev = container_of(kobj, struct device, kobj); |
2718 | struct Scsi_Host *shost = class_to_shost(dev); | |
2e0fef85 JS |
2719 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
2720 | struct lpfc_hba *phba = vport->phba; | |
dea3101e | 2721 | int rc; |
2722 | ||
1dcb58e5 | 2723 | if (off > MAILBOX_CMD_SIZE) |
dea3101e | 2724 | return -ERANGE; |
2725 | ||
1dcb58e5 JS |
2726 | if ((count + off) > MAILBOX_CMD_SIZE) |
2727 | count = MAILBOX_CMD_SIZE - off; | |
dea3101e | 2728 | |
2729 | if (off % 4 || count % 4 || (unsigned long)buf % 4) | |
2730 | return -EINVAL; | |
2731 | ||
2732 | if (off && count == 0) | |
2733 | return 0; | |
2734 | ||
2e0fef85 | 2735 | spin_lock_irq(&phba->hbalock); |
dea3101e | 2736 | |
7af67051 JS |
2737 | if (phba->over_temp_state == HBA_OVER_TEMP) { |
2738 | sysfs_mbox_idle(phba); | |
2739 | spin_unlock_irq(&phba->hbalock); | |
09372820 | 2740 | return -EACCES; |
7af67051 JS |
2741 | } |
2742 | ||
dea3101e | 2743 | if (off == 0 && |
2744 | phba->sysfs_mbox.state == SMBOX_WRITING && | |
2745 | phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) { | |
2746 | ||
2747 | switch (phba->sysfs_mbox.mbox->mb.mbxCommand) { | |
2748 | /* Offline only */ | |
dea3101e | 2749 | case MBX_INIT_LINK: |
2750 | case MBX_DOWN_LINK: | |
2751 | case MBX_CONFIG_LINK: | |
2752 | case MBX_CONFIG_RING: | |
2753 | case MBX_RESET_RING: | |
2754 | case MBX_UNREG_LOGIN: | |
2755 | case MBX_CLEAR_LA: | |
2756 | case MBX_DUMP_CONTEXT: | |
2757 | case MBX_RUN_DIAGS: | |
2758 | case MBX_RESTART: | |
dea3101e | 2759 | case MBX_SET_MASK: |
dea3101e | 2760 | case MBX_SET_DEBUG: |
2e0fef85 | 2761 | if (!(vport->fc_flag & FC_OFFLINE_MODE)) { |
dea3101e | 2762 | printk(KERN_WARNING "mbox_read:Command 0x%x " |
2763 | "is illegal in on-line state\n", | |
2764 | phba->sysfs_mbox.mbox->mb.mbxCommand); | |
2765 | sysfs_mbox_idle(phba); | |
2e0fef85 | 2766 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 2767 | return -EPERM; |
2768 | } | |
a8adb832 JS |
2769 | case MBX_WRITE_NV: |
2770 | case MBX_WRITE_VPARMS: | |
dea3101e | 2771 | case MBX_LOAD_SM: |
2772 | case MBX_READ_NV: | |
2773 | case MBX_READ_CONFIG: | |
2774 | case MBX_READ_RCONFIG: | |
2775 | case MBX_READ_STATUS: | |
2776 | case MBX_READ_XRI: | |
2777 | case MBX_READ_REV: | |
2778 | case MBX_READ_LNK_STAT: | |
2779 | case MBX_DUMP_MEMORY: | |
2780 | case MBX_DOWN_LOAD: | |
2781 | case MBX_UPDATE_CFG: | |
41415862 | 2782 | case MBX_KILL_BOARD: |
dea3101e | 2783 | case MBX_LOAD_AREA: |
2784 | case MBX_LOAD_EXP_ROM: | |
41415862 JW |
2785 | case MBX_BEACON: |
2786 | case MBX_DEL_LD_ENTRY: | |
09372820 JS |
2787 | case MBX_SET_VARIABLE: |
2788 | case MBX_WRITE_WWN: | |
84774a4d JS |
2789 | case MBX_PORT_CAPABILITIES: |
2790 | case MBX_PORT_IOV_CONTROL: | |
dea3101e | 2791 | break; |
2792 | case MBX_READ_SPARM64: | |
2793 | case MBX_READ_LA: | |
2794 | case MBX_READ_LA64: | |
2795 | case MBX_REG_LOGIN: | |
2796 | case MBX_REG_LOGIN64: | |
2797 | case MBX_CONFIG_PORT: | |
2798 | case MBX_RUN_BIU_DIAG: | |
2799 | printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n", | |
2800 | phba->sysfs_mbox.mbox->mb.mbxCommand); | |
2801 | sysfs_mbox_idle(phba); | |
2e0fef85 | 2802 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 2803 | return -EPERM; |
2804 | default: | |
2805 | printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n", | |
2806 | phba->sysfs_mbox.mbox->mb.mbxCommand); | |
2807 | sysfs_mbox_idle(phba); | |
2e0fef85 | 2808 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 2809 | return -EPERM; |
2810 | } | |
2811 | ||
09372820 | 2812 | /* If HBA encountered an error attention, allow only DUMP |
1b32f6aa | 2813 | * or RESTART mailbox commands until the HBA is restarted. |
09372820 | 2814 | */ |
d7c255b2 JS |
2815 | if (phba->pport->stopped && |
2816 | phba->sysfs_mbox.mbox->mb.mbxCommand != MBX_DUMP_MEMORY && | |
2817 | phba->sysfs_mbox.mbox->mb.mbxCommand != MBX_RESTART && | |
2818 | phba->sysfs_mbox.mbox->mb.mbxCommand != MBX_WRITE_VPARMS && | |
2819 | phba->sysfs_mbox.mbox->mb.mbxCommand != MBX_WRITE_WWN) | |
2820 | lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX, | |
2821 | "1259 mbox: Issued mailbox cmd " | |
2822 | "0x%x while in stopped state.\n", | |
2823 | phba->sysfs_mbox.mbox->mb.mbxCommand); | |
09372820 | 2824 | |
92d7f7b0 JS |
2825 | phba->sysfs_mbox.mbox->vport = vport; |
2826 | ||
58da1ffb JS |
2827 | /* Don't allow mailbox commands to be sent when blocked |
2828 | * or when in the middle of discovery | |
2829 | */ | |
495a714c | 2830 | if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) { |
46fa311e | 2831 | sysfs_mbox_idle(phba); |
2e0fef85 | 2832 | spin_unlock_irq(&phba->hbalock); |
46fa311e JS |
2833 | return -EAGAIN; |
2834 | } | |
2835 | ||
2e0fef85 | 2836 | if ((vport->fc_flag & FC_OFFLINE_MODE) || |
dea3101e | 2837 | (!(phba->sli.sli_flag & LPFC_SLI2_ACTIVE))){ |
2838 | ||
2e0fef85 | 2839 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 2840 | rc = lpfc_sli_issue_mbox (phba, |
2841 | phba->sysfs_mbox.mbox, | |
2842 | MBX_POLL); | |
2e0fef85 | 2843 | spin_lock_irq(&phba->hbalock); |
dea3101e | 2844 | |
2845 | } else { | |
2e0fef85 | 2846 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 2847 | rc = lpfc_sli_issue_mbox_wait (phba, |
2848 | phba->sysfs_mbox.mbox, | |
a309a6b6 JS |
2849 | lpfc_mbox_tmo_val(phba, |
2850 | phba->sysfs_mbox.mbox->mb.mbxCommand) * HZ); | |
2e0fef85 | 2851 | spin_lock_irq(&phba->hbalock); |
dea3101e | 2852 | } |
2853 | ||
2854 | if (rc != MBX_SUCCESS) { | |
1dcb58e5 | 2855 | if (rc == MBX_TIMEOUT) { |
1dcb58e5 JS |
2856 | phba->sysfs_mbox.mbox = NULL; |
2857 | } | |
dea3101e | 2858 | sysfs_mbox_idle(phba); |
2e0fef85 | 2859 | spin_unlock_irq(&phba->hbalock); |
8f6d98d2 | 2860 | return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV; |
dea3101e | 2861 | } |
2862 | phba->sysfs_mbox.state = SMBOX_READING; | |
2863 | } | |
2864 | else if (phba->sysfs_mbox.offset != off || | |
2865 | phba->sysfs_mbox.state != SMBOX_READING) { | |
2866 | printk(KERN_WARNING "mbox_read: Bad State\n"); | |
2867 | sysfs_mbox_idle(phba); | |
2e0fef85 | 2868 | spin_unlock_irq(&phba->hbalock); |
8f6d98d2 | 2869 | return -EAGAIN; |
dea3101e | 2870 | } |
2871 | ||
2872 | memcpy(buf, (uint8_t *) & phba->sysfs_mbox.mbox->mb + off, count); | |
2873 | ||
2874 | phba->sysfs_mbox.offset = off + count; | |
2875 | ||
1dcb58e5 | 2876 | if (phba->sysfs_mbox.offset == MAILBOX_CMD_SIZE) |
dea3101e | 2877 | sysfs_mbox_idle(phba); |
2878 | ||
2e0fef85 | 2879 | spin_unlock_irq(&phba->hbalock); |
dea3101e | 2880 | |
2881 | return count; | |
2882 | } | |
2883 | ||
2884 | static struct bin_attribute sysfs_mbox_attr = { | |
2885 | .attr = { | |
2886 | .name = "mbox", | |
2887 | .mode = S_IRUSR | S_IWUSR, | |
dea3101e | 2888 | }, |
1dcb58e5 | 2889 | .size = MAILBOX_CMD_SIZE, |
dea3101e | 2890 | .read = sysfs_mbox_read, |
2891 | .write = sysfs_mbox_write, | |
2892 | }; | |
2893 | ||
e59058c4 | 2894 | /** |
84774a4d | 2895 | * lpfc_alloc_sysfs_attr: Creates the ctlreg and mbox entries. |
e59058c4 JS |
2896 | * @vport: address of lpfc vport structure. |
2897 | * | |
2898 | * Return codes: | |
2899 | * zero on success | |
2900 | * error return code from sysfs_create_bin_file() | |
2901 | **/ | |
dea3101e | 2902 | int |
2e0fef85 | 2903 | lpfc_alloc_sysfs_attr(struct lpfc_vport *vport) |
dea3101e | 2904 | { |
2e0fef85 | 2905 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
dea3101e | 2906 | int error; |
2907 | ||
ee959b00 | 2908 | error = sysfs_create_bin_file(&shost->shost_dev.kobj, |
92d7f7b0 | 2909 | &sysfs_ctlreg_attr); |
dea3101e | 2910 | if (error) |
2911 | goto out; | |
2912 | ||
ee959b00 | 2913 | error = sysfs_create_bin_file(&shost->shost_dev.kobj, |
92d7f7b0 | 2914 | &sysfs_mbox_attr); |
dea3101e | 2915 | if (error) |
2916 | goto out_remove_ctlreg_attr; | |
2917 | ||
2918 | return 0; | |
2919 | out_remove_ctlreg_attr: | |
ee959b00 | 2920 | sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr); |
dea3101e | 2921 | out: |
2922 | return error; | |
2923 | } | |
2924 | ||
e59058c4 | 2925 | /** |
84774a4d | 2926 | * lpfc_free_sysfs_attr: Removes the ctlreg and mbox entries. |
e59058c4 JS |
2927 | * @vport: address of lpfc vport structure. |
2928 | **/ | |
dea3101e | 2929 | void |
2e0fef85 | 2930 | lpfc_free_sysfs_attr(struct lpfc_vport *vport) |
dea3101e | 2931 | { |
2e0fef85 | 2932 | struct Scsi_Host *shost = lpfc_shost_from_vport(vport); |
dea3101e | 2933 | |
ee959b00 TJ |
2934 | sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr); |
2935 | sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr); | |
dea3101e | 2936 | } |
2937 | ||
2938 | ||
2939 | /* | |
2940 | * Dynamic FC Host Attributes Support | |
2941 | */ | |
2942 | ||
e59058c4 JS |
2943 | /** |
2944 | * lpfc_get_host_port_id: Copy the vport DID into the scsi host port id. | |
2945 | * @shost: kernel scsi host pointer. | |
2946 | **/ | |
dea3101e | 2947 | static void |
2948 | lpfc_get_host_port_id(struct Scsi_Host *shost) | |
2949 | { | |
2e0fef85 JS |
2950 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
2951 | ||
dea3101e | 2952 | /* note: fc_myDID already in cpu endianness */ |
2e0fef85 | 2953 | fc_host_port_id(shost) = vport->fc_myDID; |
dea3101e | 2954 | } |
2955 | ||
e59058c4 JS |
2956 | /** |
2957 | * lpfc_get_host_port_type: Set the value of the scsi host port type. | |
2958 | * @shost: kernel scsi host pointer. | |
2959 | **/ | |
dea3101e | 2960 | static void |
2961 | lpfc_get_host_port_type(struct Scsi_Host *shost) | |
2962 | { | |
2e0fef85 JS |
2963 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
2964 | struct lpfc_hba *phba = vport->phba; | |
dea3101e | 2965 | |
2966 | spin_lock_irq(shost->host_lock); | |
2967 | ||
92d7f7b0 JS |
2968 | if (vport->port_type == LPFC_NPIV_PORT) { |
2969 | fc_host_port_type(shost) = FC_PORTTYPE_NPIV; | |
2970 | } else if (lpfc_is_link_up(phba)) { | |
dea3101e | 2971 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
2e0fef85 | 2972 | if (vport->fc_flag & FC_PUBLIC_LOOP) |
dea3101e | 2973 | fc_host_port_type(shost) = FC_PORTTYPE_NLPORT; |
2974 | else | |
2975 | fc_host_port_type(shost) = FC_PORTTYPE_LPORT; | |
2976 | } else { | |
2e0fef85 | 2977 | if (vport->fc_flag & FC_FABRIC) |
dea3101e | 2978 | fc_host_port_type(shost) = FC_PORTTYPE_NPORT; |
2979 | else | |
2980 | fc_host_port_type(shost) = FC_PORTTYPE_PTP; | |
2981 | } | |
2982 | } else | |
2983 | fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN; | |
2984 | ||
2985 | spin_unlock_irq(shost->host_lock); | |
2986 | } | |
2987 | ||
e59058c4 JS |
2988 | /** |
2989 | * lpfc_get_host_port_state: Set the value of the scsi host port state. | |
2990 | * @shost: kernel scsi host pointer. | |
2991 | **/ | |
dea3101e | 2992 | static void |
2993 | lpfc_get_host_port_state(struct Scsi_Host *shost) | |
2994 | { | |
2e0fef85 JS |
2995 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
2996 | struct lpfc_hba *phba = vport->phba; | |
dea3101e | 2997 | |
2998 | spin_lock_irq(shost->host_lock); | |
2999 | ||
2e0fef85 | 3000 | if (vport->fc_flag & FC_OFFLINE_MODE) |
dea3101e | 3001 | fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE; |
3002 | else { | |
2e0fef85 JS |
3003 | switch (phba->link_state) { |
3004 | case LPFC_LINK_UNKNOWN: | |
dea3101e | 3005 | case LPFC_LINK_DOWN: |
3006 | fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN; | |
3007 | break; | |
3008 | case LPFC_LINK_UP: | |
dea3101e | 3009 | case LPFC_CLEAR_LA: |
3010 | case LPFC_HBA_READY: | |
3011 | /* Links up, beyond this port_type reports state */ | |
3012 | fc_host_port_state(shost) = FC_PORTSTATE_ONLINE; | |
3013 | break; | |
3014 | case LPFC_HBA_ERROR: | |
3015 | fc_host_port_state(shost) = FC_PORTSTATE_ERROR; | |
3016 | break; | |
3017 | default: | |
3018 | fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN; | |
3019 | break; | |
3020 | } | |
3021 | } | |
3022 | ||
3023 | spin_unlock_irq(shost->host_lock); | |
3024 | } | |
3025 | ||
e59058c4 JS |
3026 | /** |
3027 | * lpfc_get_host_speed: Set the value of the scsi host speed. | |
3028 | * @shost: kernel scsi host pointer. | |
3029 | **/ | |
dea3101e | 3030 | static void |
3031 | lpfc_get_host_speed(struct Scsi_Host *shost) | |
3032 | { | |
2e0fef85 JS |
3033 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
3034 | struct lpfc_hba *phba = vport->phba; | |
dea3101e | 3035 | |
3036 | spin_lock_irq(shost->host_lock); | |
3037 | ||
2e0fef85 | 3038 | if (lpfc_is_link_up(phba)) { |
dea3101e | 3039 | switch(phba->fc_linkspeed) { |
3040 | case LA_1GHZ_LINK: | |
3041 | fc_host_speed(shost) = FC_PORTSPEED_1GBIT; | |
3042 | break; | |
3043 | case LA_2GHZ_LINK: | |
3044 | fc_host_speed(shost) = FC_PORTSPEED_2GBIT; | |
3045 | break; | |
3046 | case LA_4GHZ_LINK: | |
3047 | fc_host_speed(shost) = FC_PORTSPEED_4GBIT; | |
3048 | break; | |
b87eab38 JS |
3049 | case LA_8GHZ_LINK: |
3050 | fc_host_speed(shost) = FC_PORTSPEED_8GBIT; | |
3051 | break; | |
dea3101e | 3052 | default: |
3053 | fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN; | |
3054 | break; | |
3055 | } | |
09372820 JS |
3056 | } else |
3057 | fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN; | |
dea3101e | 3058 | |
3059 | spin_unlock_irq(shost->host_lock); | |
3060 | } | |
3061 | ||
e59058c4 JS |
3062 | /** |
3063 | * lpfc_get_host_fabric_name: Set the value of the scsi host fabric name. | |
3064 | * @shost: kernel scsi host pointer. | |
3065 | **/ | |
dea3101e | 3066 | static void |
3067 | lpfc_get_host_fabric_name (struct Scsi_Host *shost) | |
3068 | { | |
2e0fef85 JS |
3069 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
3070 | struct lpfc_hba *phba = vport->phba; | |
f631b4be | 3071 | u64 node_name; |
dea3101e | 3072 | |
3073 | spin_lock_irq(shost->host_lock); | |
3074 | ||
2e0fef85 | 3075 | if ((vport->fc_flag & FC_FABRIC) || |
dea3101e | 3076 | ((phba->fc_topology == TOPOLOGY_LOOP) && |
2e0fef85 | 3077 | (vport->fc_flag & FC_PUBLIC_LOOP))) |
68ce1eb5 | 3078 | node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn); |
dea3101e | 3079 | else |
3080 | /* fabric is local port if there is no F/FL_Port */ | |
09372820 | 3081 | node_name = 0; |
dea3101e | 3082 | |
3083 | spin_unlock_irq(shost->host_lock); | |
3084 | ||
f631b4be | 3085 | fc_host_fabric_name(shost) = node_name; |
dea3101e | 3086 | } |
3087 | ||
e59058c4 JS |
3088 | /** |
3089 | * lpfc_get_stats: Return statistical information about the adapter. | |
3090 | * @shost: kernel scsi host pointer. | |
3091 | * | |
3092 | * Notes: | |
3093 | * NULL on error for link down, no mbox pool, sli2 active, | |
3094 | * management not allowed, memory allocation error, or mbox error. | |
3095 | * | |
3096 | * Returns: | |
3097 | * NULL for error | |
3098 | * address of the adapter host statistics | |
3099 | **/ | |
dea3101e | 3100 | static struct fc_host_statistics * |
3101 | lpfc_get_stats(struct Scsi_Host *shost) | |
3102 | { | |
2e0fef85 JS |
3103 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
3104 | struct lpfc_hba *phba = vport->phba; | |
3105 | struct lpfc_sli *psli = &phba->sli; | |
f888ba3c | 3106 | struct fc_host_statistics *hs = &phba->link_stats; |
64ba8818 | 3107 | struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets; |
dea3101e | 3108 | LPFC_MBOXQ_t *pmboxq; |
3109 | MAILBOX_t *pmb; | |
64ba8818 | 3110 | unsigned long seconds; |
433c3579 | 3111 | int rc = 0; |
dea3101e | 3112 | |
92d7f7b0 JS |
3113 | /* |
3114 | * prevent udev from issuing mailbox commands until the port is | |
3115 | * configured. | |
3116 | */ | |
2e0fef85 JS |
3117 | if (phba->link_state < LPFC_LINK_DOWN || |
3118 | !phba->mbox_mem_pool || | |
3119 | (phba->sli.sli_flag & LPFC_SLI2_ACTIVE) == 0) | |
92d7f7b0 | 3120 | return NULL; |
2e0fef85 JS |
3121 | |
3122 | if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) | |
46fa311e JS |
3123 | return NULL; |
3124 | ||
dea3101e | 3125 | pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
3126 | if (!pmboxq) | |
3127 | return NULL; | |
3128 | memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t)); | |
3129 | ||
3130 | pmb = &pmboxq->mb; | |
3131 | pmb->mbxCommand = MBX_READ_STATUS; | |
3132 | pmb->mbxOwner = OWN_HOST; | |
3133 | pmboxq->context1 = NULL; | |
92d7f7b0 | 3134 | pmboxq->vport = vport; |
dea3101e | 3135 | |
2e0fef85 | 3136 | if ((vport->fc_flag & FC_OFFLINE_MODE) || |
433c3579 | 3137 | (!(psli->sli_flag & LPFC_SLI2_ACTIVE))) |
dea3101e | 3138 | rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL); |
433c3579 | 3139 | else |
dea3101e | 3140 | rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2); |
3141 | ||
3142 | if (rc != MBX_SUCCESS) { | |
858c9f6c | 3143 | if (rc != MBX_TIMEOUT) |
433c3579 | 3144 | mempool_free(pmboxq, phba->mbox_mem_pool); |
dea3101e | 3145 | return NULL; |
3146 | } | |
3147 | ||
f888ba3c JSEC |
3148 | memset(hs, 0, sizeof (struct fc_host_statistics)); |
3149 | ||
dea3101e | 3150 | hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt; |
3151 | hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256); | |
3152 | hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt; | |
3153 | hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256); | |
3154 | ||
433c3579 | 3155 | memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t)); |
dea3101e | 3156 | pmb->mbxCommand = MBX_READ_LNK_STAT; |
3157 | pmb->mbxOwner = OWN_HOST; | |
3158 | pmboxq->context1 = NULL; | |
92d7f7b0 | 3159 | pmboxq->vport = vport; |
dea3101e | 3160 | |
2e0fef85 | 3161 | if ((vport->fc_flag & FC_OFFLINE_MODE) || |
433c3579 | 3162 | (!(psli->sli_flag & LPFC_SLI2_ACTIVE))) |
dea3101e | 3163 | rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL); |
433c3579 | 3164 | else |
dea3101e | 3165 | rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2); |
3166 | ||
3167 | if (rc != MBX_SUCCESS) { | |
858c9f6c | 3168 | if (rc != MBX_TIMEOUT) |
92d7f7b0 | 3169 | mempool_free(pmboxq, phba->mbox_mem_pool); |
dea3101e | 3170 | return NULL; |
3171 | } | |
3172 | ||
3173 | hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt; | |
3174 | hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt; | |
3175 | hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt; | |
3176 | hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt; | |
3177 | hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord; | |
3178 | hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt; | |
3179 | hs->error_frames = pmb->un.varRdLnk.crcCnt; | |
3180 | ||
64ba8818 JS |
3181 | hs->link_failure_count -= lso->link_failure_count; |
3182 | hs->loss_of_sync_count -= lso->loss_of_sync_count; | |
3183 | hs->loss_of_signal_count -= lso->loss_of_signal_count; | |
3184 | hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count; | |
3185 | hs->invalid_tx_word_count -= lso->invalid_tx_word_count; | |
3186 | hs->invalid_crc_count -= lso->invalid_crc_count; | |
3187 | hs->error_frames -= lso->error_frames; | |
3188 | ||
dea3101e | 3189 | if (phba->fc_topology == TOPOLOGY_LOOP) { |
3190 | hs->lip_count = (phba->fc_eventTag >> 1); | |
64ba8818 | 3191 | hs->lip_count -= lso->link_events; |
dea3101e | 3192 | hs->nos_count = -1; |
3193 | } else { | |
3194 | hs->lip_count = -1; | |
3195 | hs->nos_count = (phba->fc_eventTag >> 1); | |
64ba8818 | 3196 | hs->nos_count -= lso->link_events; |
dea3101e | 3197 | } |
3198 | ||
3199 | hs->dumped_frames = -1; | |
3200 | ||
64ba8818 JS |
3201 | seconds = get_seconds(); |
3202 | if (seconds < psli->stats_start) | |
3203 | hs->seconds_since_last_reset = seconds + | |
3204 | ((unsigned long)-1 - psli->stats_start); | |
3205 | else | |
3206 | hs->seconds_since_last_reset = seconds - psli->stats_start; | |
dea3101e | 3207 | |
1dcb58e5 JS |
3208 | mempool_free(pmboxq, phba->mbox_mem_pool); |
3209 | ||
dea3101e | 3210 | return hs; |
3211 | } | |
3212 | ||
e59058c4 JS |
3213 | /** |
3214 | * lpfc_reset_stats: Copy the adapter link stats information. | |
3215 | * @shost: kernel scsi host pointer. | |
3216 | **/ | |
64ba8818 JS |
3217 | static void |
3218 | lpfc_reset_stats(struct Scsi_Host *shost) | |
3219 | { | |
2e0fef85 JS |
3220 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; |
3221 | struct lpfc_hba *phba = vport->phba; | |
3222 | struct lpfc_sli *psli = &phba->sli; | |
3223 | struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets; | |
64ba8818 JS |
3224 | LPFC_MBOXQ_t *pmboxq; |
3225 | MAILBOX_t *pmb; | |
3226 | int rc = 0; | |
3227 | ||
2e0fef85 | 3228 | if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) |
46fa311e JS |
3229 | return; |
3230 | ||
64ba8818 JS |
3231 | pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); |
3232 | if (!pmboxq) | |
3233 | return; | |
3234 | memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t)); | |
3235 | ||
3236 | pmb = &pmboxq->mb; | |
3237 | pmb->mbxCommand = MBX_READ_STATUS; | |
3238 | pmb->mbxOwner = OWN_HOST; | |
3239 | pmb->un.varWords[0] = 0x1; /* reset request */ | |
3240 | pmboxq->context1 = NULL; | |
92d7f7b0 | 3241 | pmboxq->vport = vport; |
64ba8818 | 3242 | |
2e0fef85 | 3243 | if ((vport->fc_flag & FC_OFFLINE_MODE) || |
64ba8818 JS |
3244 | (!(psli->sli_flag & LPFC_SLI2_ACTIVE))) |
3245 | rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL); | |
3246 | else | |
3247 | rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2); | |
3248 | ||
3249 | if (rc != MBX_SUCCESS) { | |
858c9f6c | 3250 | if (rc != MBX_TIMEOUT) |
64ba8818 JS |
3251 | mempool_free(pmboxq, phba->mbox_mem_pool); |
3252 | return; | |
3253 | } | |
3254 | ||
3255 | memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t)); | |
3256 | pmb->mbxCommand = MBX_READ_LNK_STAT; | |
3257 | pmb->mbxOwner = OWN_HOST; | |
3258 | pmboxq->context1 = NULL; | |
92d7f7b0 | 3259 | pmboxq->vport = vport; |
64ba8818 | 3260 | |
2e0fef85 | 3261 | if ((vport->fc_flag & FC_OFFLINE_MODE) || |
64ba8818 JS |
3262 | (!(psli->sli_flag & LPFC_SLI2_ACTIVE))) |
3263 | rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL); | |
3264 | else | |
3265 | rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2); | |
3266 | ||
3267 | if (rc != MBX_SUCCESS) { | |
858c9f6c | 3268 | if (rc != MBX_TIMEOUT) |
64ba8818 JS |
3269 | mempool_free( pmboxq, phba->mbox_mem_pool); |
3270 | return; | |
3271 | } | |
3272 | ||
3273 | lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt; | |
3274 | lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt; | |
3275 | lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt; | |
3276 | lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt; | |
3277 | lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord; | |
3278 | lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt; | |
3279 | lso->error_frames = pmb->un.varRdLnk.crcCnt; | |
3280 | lso->link_events = (phba->fc_eventTag >> 1); | |
3281 | ||
3282 | psli->stats_start = get_seconds(); | |
3283 | ||
1dcb58e5 JS |
3284 | mempool_free(pmboxq, phba->mbox_mem_pool); |
3285 | ||
64ba8818 JS |
3286 | return; |
3287 | } | |
dea3101e | 3288 | |
3289 | /* | |
3290 | * The LPFC driver treats linkdown handling as target loss events so there | |
3291 | * are no sysfs handlers for link_down_tmo. | |
3292 | */ | |
685f0bf7 | 3293 | |
e59058c4 JS |
3294 | /** |
3295 | * lpfc_get_node_by_target: Return the nodelist for a target. | |
3296 | * @starget: kernel scsi target pointer. | |
3297 | * | |
3298 | * Returns: | |
3299 | * address of the node list if found | |
3300 | * NULL target not found | |
3301 | **/ | |
685f0bf7 JS |
3302 | static struct lpfc_nodelist * |
3303 | lpfc_get_node_by_target(struct scsi_target *starget) | |
dea3101e | 3304 | { |
2e0fef85 JS |
3305 | struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); |
3306 | struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata; | |
685f0bf7 | 3307 | struct lpfc_nodelist *ndlp; |
dea3101e | 3308 | |
3309 | spin_lock_irq(shost->host_lock); | |
685f0bf7 | 3310 | /* Search for this, mapped, target ID */ |
2e0fef85 | 3311 | list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) { |
e47c9093 JS |
3312 | if (NLP_CHK_NODE_ACT(ndlp) && |
3313 | ndlp->nlp_state == NLP_STE_MAPPED_NODE && | |
685f0bf7 JS |
3314 | starget->id == ndlp->nlp_sid) { |
3315 | spin_unlock_irq(shost->host_lock); | |
3316 | return ndlp; | |
dea3101e | 3317 | } |
3318 | } | |
3319 | spin_unlock_irq(shost->host_lock); | |
685f0bf7 JS |
3320 | return NULL; |
3321 | } | |
dea3101e | 3322 | |
e59058c4 JS |
3323 | /** |
3324 | * lpfc_get_starget_port_id: Set the target port id to the ndlp DID or -1. | |
3325 | * @starget: kernel scsi target pointer. | |
3326 | **/ | |
685f0bf7 JS |
3327 | static void |
3328 | lpfc_get_starget_port_id(struct scsi_target *starget) | |
3329 | { | |
3330 | struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget); | |
3331 | ||
3332 | fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1; | |
dea3101e | 3333 | } |
3334 | ||
e59058c4 JS |
3335 | /** |
3336 | * lpfc_get_starget_node_name: Set the target node name. | |
3337 | * @starget: kernel scsi target pointer. | |
3338 | * | |
3339 | * Description: Set the target node name to the ndlp node name wwn or zero. | |
3340 | **/ | |
dea3101e | 3341 | static void |
3342 | lpfc_get_starget_node_name(struct scsi_target *starget) | |
3343 | { | |
685f0bf7 | 3344 | struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget); |
dea3101e | 3345 | |
685f0bf7 JS |
3346 | fc_starget_node_name(starget) = |
3347 | ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0; | |
dea3101e | 3348 | } |
3349 | ||
e59058c4 JS |
3350 | /** |
3351 | * lpfc_get_starget_port_name: Set the target port name. | |
3352 | * @starget: kernel scsi target pointer. | |
3353 | * | |
3354 | * Description: set the target port name to the ndlp port name wwn or zero. | |
3355 | **/ | |
dea3101e | 3356 | static void |
3357 | lpfc_get_starget_port_name(struct scsi_target *starget) | |
3358 | { | |
685f0bf7 | 3359 | struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget); |
dea3101e | 3360 | |
685f0bf7 JS |
3361 | fc_starget_port_name(starget) = |
3362 | ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0; | |
dea3101e | 3363 | } |
3364 | ||
e59058c4 JS |
3365 | /** |
3366 | * lpfc_set_rport_loss_tmo: Set the rport dev loss tmo. | |
3367 | * @rport: fc rport address. | |
3368 | * @timeout: new value for dev loss tmo. | |
3369 | * | |
3370 | * Description: | |
3371 | * If timeout is non zero set the dev_loss_tmo to timeout, else set | |
3372 | * dev_loss_tmo to one. | |
3373 | **/ | |
dea3101e | 3374 | static void |
3375 | lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout) | |
3376 | { | |
dea3101e | 3377 | if (timeout) |
c01f3208 | 3378 | rport->dev_loss_tmo = timeout; |
dea3101e | 3379 | else |
c01f3208 | 3380 | rport->dev_loss_tmo = 1; |
dea3101e | 3381 | } |
3382 | ||
e59058c4 JS |
3383 | /** |
3384 | * lpfc_rport_show_function: Return rport target information. | |
3385 | * | |
3386 | * Description: | |
3387 | * Macro that uses field to generate a function with the name lpfc_show_rport_ | |
3388 | * | |
3389 | * lpfc_show_rport_##field: returns the bytes formatted in buf | |
3390 | * @cdev: class converted to an fc_rport. | |
3391 | * @buf: on return contains the target_field or zero. | |
3392 | * | |
3393 | * Returns: size of formatted string. | |
3394 | **/ | |
dea3101e | 3395 | #define lpfc_rport_show_function(field, format_string, sz, cast) \ |
3396 | static ssize_t \ | |
ee959b00 TJ |
3397 | lpfc_show_rport_##field (struct device *dev, \ |
3398 | struct device_attribute *attr, \ | |
3399 | char *buf) \ | |
dea3101e | 3400 | { \ |
ee959b00 | 3401 | struct fc_rport *rport = transport_class_to_rport(dev); \ |
dea3101e | 3402 | struct lpfc_rport_data *rdata = rport->hostdata; \ |
3403 | return snprintf(buf, sz, format_string, \ | |
3404 | (rdata->target) ? cast rdata->target->field : 0); \ | |
3405 | } | |
3406 | ||
3407 | #define lpfc_rport_rd_attr(field, format_string, sz) \ | |
3408 | lpfc_rport_show_function(field, format_string, sz, ) \ | |
3409 | static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL) | |
3410 | ||
3411 | ||
3412 | struct fc_function_template lpfc_transport_functions = { | |
3413 | /* fixed attributes the driver supports */ | |
3414 | .show_host_node_name = 1, | |
3415 | .show_host_port_name = 1, | |
3416 | .show_host_supported_classes = 1, | |
3417 | .show_host_supported_fc4s = 1, | |
dea3101e | 3418 | .show_host_supported_speeds = 1, |
3419 | .show_host_maxframe_size = 1, | |
3420 | ||
3421 | /* dynamic attributes the driver supports */ | |
3422 | .get_host_port_id = lpfc_get_host_port_id, | |
3423 | .show_host_port_id = 1, | |
3424 | ||
3425 | .get_host_port_type = lpfc_get_host_port_type, | |
3426 | .show_host_port_type = 1, | |
3427 | ||
3428 | .get_host_port_state = lpfc_get_host_port_state, | |
3429 | .show_host_port_state = 1, | |
3430 | ||
3431 | /* active_fc4s is shown but doesn't change (thus no get function) */ | |
3432 | .show_host_active_fc4s = 1, | |
3433 | ||
3434 | .get_host_speed = lpfc_get_host_speed, | |
3435 | .show_host_speed = 1, | |
3436 | ||
3437 | .get_host_fabric_name = lpfc_get_host_fabric_name, | |
3438 | .show_host_fabric_name = 1, | |
3439 | ||
3440 | /* | |
3441 | * The LPFC driver treats linkdown handling as target loss events | |
3442 | * so there are no sysfs handlers for link_down_tmo. | |
3443 | */ | |
3444 | ||
3445 | .get_fc_host_stats = lpfc_get_stats, | |
64ba8818 | 3446 | .reset_fc_host_stats = lpfc_reset_stats, |
dea3101e | 3447 | |
3448 | .dd_fcrport_size = sizeof(struct lpfc_rport_data), | |
3449 | .show_rport_maxframe_size = 1, | |
3450 | .show_rport_supported_classes = 1, | |
3451 | ||
dea3101e | 3452 | .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo, |
3453 | .show_rport_dev_loss_tmo = 1, | |
3454 | ||
3455 | .get_starget_port_id = lpfc_get_starget_port_id, | |
3456 | .show_starget_port_id = 1, | |
3457 | ||
3458 | .get_starget_node_name = lpfc_get_starget_node_name, | |
3459 | .show_starget_node_name = 1, | |
3460 | ||
3461 | .get_starget_port_name = lpfc_get_starget_port_name, | |
3462 | .show_starget_port_name = 1, | |
91ca7b01 AV |
3463 | |
3464 | .issue_fc_host_lip = lpfc_issue_lip, | |
c01f3208 JS |
3465 | .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk, |
3466 | .terminate_rport_io = lpfc_terminate_rport_io, | |
92d7f7b0 | 3467 | |
92d7f7b0 JS |
3468 | .dd_fcvport_size = sizeof(struct lpfc_vport *), |
3469 | }; | |
3470 | ||
98c9ea5c JS |
3471 | struct fc_function_template lpfc_vport_transport_functions = { |
3472 | /* fixed attributes the driver supports */ | |
3473 | .show_host_node_name = 1, | |
3474 | .show_host_port_name = 1, | |
3475 | .show_host_supported_classes = 1, | |
3476 | .show_host_supported_fc4s = 1, | |
3477 | .show_host_supported_speeds = 1, | |
3478 | .show_host_maxframe_size = 1, | |
3479 | ||
3480 | /* dynamic attributes the driver supports */ | |
3481 | .get_host_port_id = lpfc_get_host_port_id, | |
3482 | .show_host_port_id = 1, | |
3483 | ||
3484 | .get_host_port_type = lpfc_get_host_port_type, | |
3485 | .show_host_port_type = 1, | |
3486 | ||
3487 | .get_host_port_state = lpfc_get_host_port_state, | |
3488 | .show_host_port_state = 1, | |
3489 | ||
3490 | /* active_fc4s is shown but doesn't change (thus no get function) */ | |
3491 | .show_host_active_fc4s = 1, | |
3492 | ||
3493 | .get_host_speed = lpfc_get_host_speed, | |
3494 | .show_host_speed = 1, | |
3495 | ||
3496 | .get_host_fabric_name = lpfc_get_host_fabric_name, | |
3497 | .show_host_fabric_name = 1, | |
3498 | ||
3499 | /* | |
3500 | * The LPFC driver treats linkdown handling as target loss events | |
3501 | * so there are no sysfs handlers for link_down_tmo. | |
3502 | */ | |
3503 | ||
3504 | .get_fc_host_stats = lpfc_get_stats, | |
3505 | .reset_fc_host_stats = lpfc_reset_stats, | |
3506 | ||
3507 | .dd_fcrport_size = sizeof(struct lpfc_rport_data), | |
3508 | .show_rport_maxframe_size = 1, | |
3509 | .show_rport_supported_classes = 1, | |
3510 | ||
3511 | .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo, | |
3512 | .show_rport_dev_loss_tmo = 1, | |
3513 | ||
3514 | .get_starget_port_id = lpfc_get_starget_port_id, | |
3515 | .show_starget_port_id = 1, | |
3516 | ||
3517 | .get_starget_node_name = lpfc_get_starget_node_name, | |
3518 | .show_starget_node_name = 1, | |
3519 | ||
3520 | .get_starget_port_name = lpfc_get_starget_port_name, | |
3521 | .show_starget_port_name = 1, | |
3522 | ||
3523 | .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk, | |
3524 | .terminate_rport_io = lpfc_terminate_rport_io, | |
3525 | ||
3526 | .vport_disable = lpfc_vport_disable, | |
3527 | }; | |
3528 | ||
e59058c4 JS |
3529 | /** |
3530 | * lpfc_get_cfgparam: Used during probe_one to init the adapter structure. | |
3531 | * @phba: lpfc_hba pointer. | |
3532 | **/ | |
dea3101e | 3533 | void |
3534 | lpfc_get_cfgparam(struct lpfc_hba *phba) | |
3535 | { | |
7bcbb752 JSEC |
3536 | lpfc_cr_delay_init(phba, lpfc_cr_delay); |
3537 | lpfc_cr_count_init(phba, lpfc_cr_count); | |
cf5bf97e | 3538 | lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support); |
a4bc3379 JS |
3539 | lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl); |
3540 | lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type); | |
7bcbb752 JSEC |
3541 | lpfc_ack0_init(phba, lpfc_ack0); |
3542 | lpfc_topology_init(phba, lpfc_topology); | |
7bcbb752 | 3543 | lpfc_link_speed_init(phba, lpfc_link_speed); |
875fbdfe | 3544 | lpfc_poll_tmo_init(phba, lpfc_poll_tmo); |
78b2d852 | 3545 | lpfc_enable_npiv_init(phba, lpfc_enable_npiv); |
4ff43246 | 3546 | lpfc_use_msi_init(phba, lpfc_use_msi); |
13815c83 JS |
3547 | lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset); |
3548 | lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat); | |
875fbdfe | 3549 | phba->cfg_poll = lpfc_poll; |
a12e07bc | 3550 | phba->cfg_soft_wwnn = 0L; |
c3f28afa | 3551 | phba->cfg_soft_wwpn = 0L; |
83108bd3 JS |
3552 | lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt); |
3553 | /* Also reinitialize the host templates with new values. */ | |
3554 | lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt; | |
3555 | lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt; | |
dea3101e | 3556 | /* |
3557 | * Since the sg_tablesize is module parameter, the sg_dma_buf_size | |
83108bd3 JS |
3558 | * used to create the sg_dma_buf_pool must be dynamically calculated. |
3559 | * 2 segments are added since the IOCB needs a command and response bde. | |
dea3101e | 3560 | */ |
3561 | phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) + | |
3562 | sizeof(struct fcp_rsp) + | |
83108bd3 | 3563 | ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct ulp_bde64)); |
7054a606 | 3564 | lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth); |
3de2a653 JS |
3565 | return; |
3566 | } | |
b28485ac | 3567 | |
e59058c4 JS |
3568 | /** |
3569 | * lpfc_get_vport_cfgparam: Used during port create, init the vport structure. | |
3570 | * @vport: lpfc_vport pointer. | |
3571 | **/ | |
3de2a653 JS |
3572 | void |
3573 | lpfc_get_vport_cfgparam(struct lpfc_vport *vport) | |
3574 | { | |
e8b62011 | 3575 | lpfc_log_verbose_init(vport, lpfc_log_verbose); |
3de2a653 JS |
3576 | lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth); |
3577 | lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo); | |
3578 | lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo); | |
3579 | lpfc_peer_port_login_init(vport, lpfc_peer_port_login); | |
3580 | lpfc_restrict_login_init(vport, lpfc_restrict_login); | |
3581 | lpfc_fcp_class_init(vport, lpfc_fcp_class); | |
3582 | lpfc_use_adisc_init(vport, lpfc_use_adisc); | |
3583 | lpfc_fdmi_on_init(vport, lpfc_fdmi_on); | |
3584 | lpfc_discovery_threads_init(vport, lpfc_discovery_threads); | |
3585 | lpfc_max_luns_init(vport, lpfc_max_luns); | |
3586 | lpfc_scan_down_init(vport, lpfc_scan_down); | |
7ee5d43e | 3587 | lpfc_enable_da_id_init(vport, lpfc_enable_da_id); |
dea3101e | 3588 | return; |
3589 | } |