qla_attr.c 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107
  1. /*
  2. * QLogic Fibre Channel HBA Driver
  3. * Copyright (c) 2003-2011 QLogic Corporation
  4. *
  5. * See LICENSE.qla2xxx for copyright and licensing details.
  6. */
  7. #include "qla_def.h"
  8. #include <linux/kthread.h>
  9. #include <linux/vmalloc.h>
  10. #include <linux/slab.h>
  11. #include <linux/delay.h>
  12. static int qla24xx_vport_disable(struct fc_vport *, bool);
  13. /* SYSFS attributes --------------------------------------------------------- */
  14. static ssize_t
  15. qla2x00_sysfs_read_fw_dump(struct file *filp, struct kobject *kobj,
  16. struct bin_attribute *bin_attr,
  17. char *buf, loff_t off, size_t count)
  18. {
  19. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  20. struct device, kobj)));
  21. struct qla_hw_data *ha = vha->hw;
  22. int rval = 0;
  23. if (ha->fw_dump_reading == 0)
  24. return 0;
  25. if (IS_QLA82XX(ha)) {
  26. if (off < ha->md_template_size) {
  27. rval = memory_read_from_buffer(buf, count,
  28. &off, ha->md_tmplt_hdr, ha->md_template_size);
  29. return rval;
  30. }
  31. off -= ha->md_template_size;
  32. rval = memory_read_from_buffer(buf, count,
  33. &off, ha->md_dump, ha->md_dump_size);
  34. return rval;
  35. } else
  36. return memory_read_from_buffer(buf, count, &off, ha->fw_dump,
  37. ha->fw_dump_len);
  38. }
  39. static ssize_t
  40. qla2x00_sysfs_write_fw_dump(struct file *filp, struct kobject *kobj,
  41. struct bin_attribute *bin_attr,
  42. char *buf, loff_t off, size_t count)
  43. {
  44. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  45. struct device, kobj)));
  46. struct qla_hw_data *ha = vha->hw;
  47. int reading;
  48. if (off != 0)
  49. return (0);
  50. reading = simple_strtol(buf, NULL, 10);
  51. switch (reading) {
  52. case 0:
  53. if (!ha->fw_dump_reading)
  54. break;
  55. ql_log(ql_log_info, vha, 0x705d,
  56. "Firmware dump cleared on (%ld).\n", vha->host_no);
  57. if (IS_QLA82XX(vha->hw)) {
  58. qla82xx_md_free(vha);
  59. qla82xx_md_prep(vha);
  60. }
  61. ha->fw_dump_reading = 0;
  62. ha->fw_dumped = 0;
  63. break;
  64. case 1:
  65. if (ha->fw_dumped && !ha->fw_dump_reading) {
  66. ha->fw_dump_reading = 1;
  67. ql_log(ql_log_info, vha, 0x705e,
  68. "Raw firmware dump ready for read on (%ld).\n",
  69. vha->host_no);
  70. }
  71. break;
  72. case 2:
  73. qla2x00_alloc_fw_dump(vha);
  74. break;
  75. case 3:
  76. if (IS_QLA82XX(ha)) {
  77. qla82xx_idc_lock(ha);
  78. qla82xx_set_reset_owner(vha);
  79. qla82xx_idc_unlock(ha);
  80. } else
  81. qla2x00_system_error(vha);
  82. break;
  83. case 4:
  84. if (IS_QLA82XX(ha)) {
  85. if (ha->md_tmplt_hdr)
  86. ql_dbg(ql_dbg_user, vha, 0x705b,
  87. "MiniDump supported with this firmware.\n");
  88. else
  89. ql_dbg(ql_dbg_user, vha, 0x709d,
  90. "MiniDump not supported with this firmware.\n");
  91. }
  92. break;
  93. case 5:
  94. if (IS_QLA82XX(ha))
  95. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  96. break;
  97. }
  98. return count;
  99. }
  100. static struct bin_attribute sysfs_fw_dump_attr = {
  101. .attr = {
  102. .name = "fw_dump",
  103. .mode = S_IRUSR | S_IWUSR,
  104. },
  105. .size = 0,
  106. .read = qla2x00_sysfs_read_fw_dump,
  107. .write = qla2x00_sysfs_write_fw_dump,
  108. };
  109. static ssize_t
  110. qla2x00_sysfs_read_nvram(struct file *filp, struct kobject *kobj,
  111. struct bin_attribute *bin_attr,
  112. char *buf, loff_t off, size_t count)
  113. {
  114. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  115. struct device, kobj)));
  116. struct qla_hw_data *ha = vha->hw;
  117. if (!capable(CAP_SYS_ADMIN))
  118. return 0;
  119. if (IS_NOCACHE_VPD_TYPE(ha))
  120. ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
  121. ha->nvram_size);
  122. return memory_read_from_buffer(buf, count, &off, ha->nvram,
  123. ha->nvram_size);
  124. }
  125. static ssize_t
  126. qla2x00_sysfs_write_nvram(struct file *filp, struct kobject *kobj,
  127. struct bin_attribute *bin_attr,
  128. char *buf, loff_t off, size_t count)
  129. {
  130. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  131. struct device, kobj)));
  132. struct qla_hw_data *ha = vha->hw;
  133. uint16_t cnt;
  134. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size ||
  135. !ha->isp_ops->write_nvram)
  136. return -EINVAL;
  137. /* Checksum NVRAM. */
  138. if (IS_FWI2_CAPABLE(ha)) {
  139. uint32_t *iter;
  140. uint32_t chksum;
  141. iter = (uint32_t *)buf;
  142. chksum = 0;
  143. for (cnt = 0; cnt < ((count >> 2) - 1); cnt++)
  144. chksum += le32_to_cpu(*iter++);
  145. chksum = ~chksum + 1;
  146. *iter = cpu_to_le32(chksum);
  147. } else {
  148. uint8_t *iter;
  149. uint8_t chksum;
  150. iter = (uint8_t *)buf;
  151. chksum = 0;
  152. for (cnt = 0; cnt < count - 1; cnt++)
  153. chksum += *iter++;
  154. chksum = ~chksum + 1;
  155. *iter = chksum;
  156. }
  157. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  158. ql_log(ql_log_warn, vha, 0x705f,
  159. "HBA not online, failing NVRAM update.\n");
  160. return -EAGAIN;
  161. }
  162. /* Write NVRAM. */
  163. ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->nvram_base, count);
  164. ha->isp_ops->read_nvram(vha, (uint8_t *)ha->nvram, ha->nvram_base,
  165. count);
  166. ql_dbg(ql_dbg_user, vha, 0x7060,
  167. "Setting ISP_ABORT_NEEDED\n");
  168. /* NVRAM settings take effect immediately. */
  169. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  170. qla2xxx_wake_dpc(vha);
  171. qla2x00_wait_for_chip_reset(vha);
  172. return count;
  173. }
  174. static struct bin_attribute sysfs_nvram_attr = {
  175. .attr = {
  176. .name = "nvram",
  177. .mode = S_IRUSR | S_IWUSR,
  178. },
  179. .size = 512,
  180. .read = qla2x00_sysfs_read_nvram,
  181. .write = qla2x00_sysfs_write_nvram,
  182. };
  183. static ssize_t
  184. qla2x00_sysfs_read_optrom(struct file *filp, struct kobject *kobj,
  185. struct bin_attribute *bin_attr,
  186. char *buf, loff_t off, size_t count)
  187. {
  188. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  189. struct device, kobj)));
  190. struct qla_hw_data *ha = vha->hw;
  191. if (ha->optrom_state != QLA_SREADING)
  192. return 0;
  193. return memory_read_from_buffer(buf, count, &off, ha->optrom_buffer,
  194. ha->optrom_region_size);
  195. }
  196. static ssize_t
  197. qla2x00_sysfs_write_optrom(struct file *filp, struct kobject *kobj,
  198. struct bin_attribute *bin_attr,
  199. char *buf, loff_t off, size_t count)
  200. {
  201. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  202. struct device, kobj)));
  203. struct qla_hw_data *ha = vha->hw;
  204. if (ha->optrom_state != QLA_SWRITING)
  205. return -EINVAL;
  206. if (off > ha->optrom_region_size)
  207. return -ERANGE;
  208. if (off + count > ha->optrom_region_size)
  209. count = ha->optrom_region_size - off;
  210. memcpy(&ha->optrom_buffer[off], buf, count);
  211. return count;
  212. }
  213. static struct bin_attribute sysfs_optrom_attr = {
  214. .attr = {
  215. .name = "optrom",
  216. .mode = S_IRUSR | S_IWUSR,
  217. },
  218. .size = 0,
  219. .read = qla2x00_sysfs_read_optrom,
  220. .write = qla2x00_sysfs_write_optrom,
  221. };
  222. static ssize_t
  223. qla2x00_sysfs_write_optrom_ctl(struct file *filp, struct kobject *kobj,
  224. struct bin_attribute *bin_attr,
  225. char *buf, loff_t off, size_t count)
  226. {
  227. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  228. struct device, kobj)));
  229. struct qla_hw_data *ha = vha->hw;
  230. uint32_t start = 0;
  231. uint32_t size = ha->optrom_size;
  232. int val, valid;
  233. if (off)
  234. return -EINVAL;
  235. if (unlikely(pci_channel_offline(ha->pdev)))
  236. return -EAGAIN;
  237. if (sscanf(buf, "%d:%x:%x", &val, &start, &size) < 1)
  238. return -EINVAL;
  239. if (start > ha->optrom_size)
  240. return -EINVAL;
  241. switch (val) {
  242. case 0:
  243. if (ha->optrom_state != QLA_SREADING &&
  244. ha->optrom_state != QLA_SWRITING)
  245. return -EINVAL;
  246. ha->optrom_state = QLA_SWAITING;
  247. ql_dbg(ql_dbg_user, vha, 0x7061,
  248. "Freeing flash region allocation -- 0x%x bytes.\n",
  249. ha->optrom_region_size);
  250. vfree(ha->optrom_buffer);
  251. ha->optrom_buffer = NULL;
  252. break;
  253. case 1:
  254. if (ha->optrom_state != QLA_SWAITING)
  255. return -EINVAL;
  256. ha->optrom_region_start = start;
  257. ha->optrom_region_size = start + size > ha->optrom_size ?
  258. ha->optrom_size - start : size;
  259. ha->optrom_state = QLA_SREADING;
  260. ha->optrom_buffer = vmalloc(ha->optrom_region_size);
  261. if (ha->optrom_buffer == NULL) {
  262. ql_log(ql_log_warn, vha, 0x7062,
  263. "Unable to allocate memory for optrom retrieval "
  264. "(%x).\n", ha->optrom_region_size);
  265. ha->optrom_state = QLA_SWAITING;
  266. return -ENOMEM;
  267. }
  268. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  269. ql_log(ql_log_warn, vha, 0x7063,
  270. "HBA not online, failing NVRAM update.\n");
  271. return -EAGAIN;
  272. }
  273. ql_dbg(ql_dbg_user, vha, 0x7064,
  274. "Reading flash region -- 0x%x/0x%x.\n",
  275. ha->optrom_region_start, ha->optrom_region_size);
  276. memset(ha->optrom_buffer, 0, ha->optrom_region_size);
  277. ha->isp_ops->read_optrom(vha, ha->optrom_buffer,
  278. ha->optrom_region_start, ha->optrom_region_size);
  279. break;
  280. case 2:
  281. if (ha->optrom_state != QLA_SWAITING)
  282. return -EINVAL;
  283. /*
  284. * We need to be more restrictive on which FLASH regions are
  285. * allowed to be updated via user-space. Regions accessible
  286. * via this method include:
  287. *
  288. * ISP21xx/ISP22xx/ISP23xx type boards:
  289. *
  290. * 0x000000 -> 0x020000 -- Boot code.
  291. *
  292. * ISP2322/ISP24xx type boards:
  293. *
  294. * 0x000000 -> 0x07ffff -- Boot code.
  295. * 0x080000 -> 0x0fffff -- Firmware.
  296. *
  297. * ISP25xx type boards:
  298. *
  299. * 0x000000 -> 0x07ffff -- Boot code.
  300. * 0x080000 -> 0x0fffff -- Firmware.
  301. * 0x120000 -> 0x12ffff -- VPD and HBA parameters.
  302. */
  303. valid = 0;
  304. if (ha->optrom_size == OPTROM_SIZE_2300 && start == 0)
  305. valid = 1;
  306. else if (start == (ha->flt_region_boot * 4) ||
  307. start == (ha->flt_region_fw * 4))
  308. valid = 1;
  309. else if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha)
  310. || IS_CNA_CAPABLE(ha) || IS_QLA2031(ha))
  311. valid = 1;
  312. if (!valid) {
  313. ql_log(ql_log_warn, vha, 0x7065,
  314. "Invalid start region 0x%x/0x%x.\n", start, size);
  315. return -EINVAL;
  316. }
  317. ha->optrom_region_start = start;
  318. ha->optrom_region_size = start + size > ha->optrom_size ?
  319. ha->optrom_size - start : size;
  320. ha->optrom_state = QLA_SWRITING;
  321. ha->optrom_buffer = vmalloc(ha->optrom_region_size);
  322. if (ha->optrom_buffer == NULL) {
  323. ql_log(ql_log_warn, vha, 0x7066,
  324. "Unable to allocate memory for optrom update "
  325. "(%x)\n", ha->optrom_region_size);
  326. ha->optrom_state = QLA_SWAITING;
  327. return -ENOMEM;
  328. }
  329. ql_dbg(ql_dbg_user, vha, 0x7067,
  330. "Staging flash region write -- 0x%x/0x%x.\n",
  331. ha->optrom_region_start, ha->optrom_region_size);
  332. memset(ha->optrom_buffer, 0, ha->optrom_region_size);
  333. break;
  334. case 3:
  335. if (ha->optrom_state != QLA_SWRITING)
  336. return -EINVAL;
  337. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  338. ql_log(ql_log_warn, vha, 0x7068,
  339. "HBA not online, failing flash update.\n");
  340. return -EAGAIN;
  341. }
  342. ql_dbg(ql_dbg_user, vha, 0x7069,
  343. "Writing flash region -- 0x%x/0x%x.\n",
  344. ha->optrom_region_start, ha->optrom_region_size);
  345. ha->isp_ops->write_optrom(vha, ha->optrom_buffer,
  346. ha->optrom_region_start, ha->optrom_region_size);
  347. break;
  348. default:
  349. return -EINVAL;
  350. }
  351. return count;
  352. }
  353. static struct bin_attribute sysfs_optrom_ctl_attr = {
  354. .attr = {
  355. .name = "optrom_ctl",
  356. .mode = S_IWUSR,
  357. },
  358. .size = 0,
  359. .write = qla2x00_sysfs_write_optrom_ctl,
  360. };
  361. static ssize_t
  362. qla2x00_sysfs_read_vpd(struct file *filp, struct kobject *kobj,
  363. struct bin_attribute *bin_attr,
  364. char *buf, loff_t off, size_t count)
  365. {
  366. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  367. struct device, kobj)));
  368. struct qla_hw_data *ha = vha->hw;
  369. if (unlikely(pci_channel_offline(ha->pdev)))
  370. return -EAGAIN;
  371. if (!capable(CAP_SYS_ADMIN))
  372. return -EINVAL;
  373. if (IS_NOCACHE_VPD_TYPE(ha))
  374. ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
  375. ha->vpd_size);
  376. return memory_read_from_buffer(buf, count, &off, ha->vpd, ha->vpd_size);
  377. }
  378. static ssize_t
  379. qla2x00_sysfs_write_vpd(struct file *filp, struct kobject *kobj,
  380. struct bin_attribute *bin_attr,
  381. char *buf, loff_t off, size_t count)
  382. {
  383. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  384. struct device, kobj)));
  385. struct qla_hw_data *ha = vha->hw;
  386. uint8_t *tmp_data;
  387. if (unlikely(pci_channel_offline(ha->pdev)))
  388. return 0;
  389. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->vpd_size ||
  390. !ha->isp_ops->write_nvram)
  391. return 0;
  392. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  393. ql_log(ql_log_warn, vha, 0x706a,
  394. "HBA not online, failing VPD update.\n");
  395. return -EAGAIN;
  396. }
  397. /* Write NVRAM. */
  398. ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->vpd_base, count);
  399. ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd, ha->vpd_base, count);
  400. /* Update flash version information for 4Gb & above. */
  401. if (!IS_FWI2_CAPABLE(ha))
  402. return -EINVAL;
  403. tmp_data = vmalloc(256);
  404. if (!tmp_data) {
  405. ql_log(ql_log_warn, vha, 0x706b,
  406. "Unable to allocate memory for VPD information update.\n");
  407. return -ENOMEM;
  408. }
  409. ha->isp_ops->get_flash_version(vha, tmp_data);
  410. vfree(tmp_data);
  411. return count;
  412. }
  413. static struct bin_attribute sysfs_vpd_attr = {
  414. .attr = {
  415. .name = "vpd",
  416. .mode = S_IRUSR | S_IWUSR,
  417. },
  418. .size = 0,
  419. .read = qla2x00_sysfs_read_vpd,
  420. .write = qla2x00_sysfs_write_vpd,
  421. };
  422. static ssize_t
  423. qla2x00_sysfs_read_sfp(struct file *filp, struct kobject *kobj,
  424. struct bin_attribute *bin_attr,
  425. char *buf, loff_t off, size_t count)
  426. {
  427. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  428. struct device, kobj)));
  429. struct qla_hw_data *ha = vha->hw;
  430. uint16_t iter, addr, offset;
  431. int rval;
  432. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != SFP_DEV_SIZE * 2)
  433. return 0;
  434. if (ha->sfp_data)
  435. goto do_read;
  436. ha->sfp_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  437. &ha->sfp_data_dma);
  438. if (!ha->sfp_data) {
  439. ql_log(ql_log_warn, vha, 0x706c,
  440. "Unable to allocate memory for SFP read-data.\n");
  441. return 0;
  442. }
  443. do_read:
  444. memset(ha->sfp_data, 0, SFP_BLOCK_SIZE);
  445. addr = 0xa0;
  446. for (iter = 0, offset = 0; iter < (SFP_DEV_SIZE * 2) / SFP_BLOCK_SIZE;
  447. iter++, offset += SFP_BLOCK_SIZE) {
  448. if (iter == 4) {
  449. /* Skip to next device address. */
  450. addr = 0xa2;
  451. offset = 0;
  452. }
  453. rval = qla2x00_read_sfp(vha, ha->sfp_data_dma, ha->sfp_data,
  454. addr, offset, SFP_BLOCK_SIZE, 0);
  455. if (rval != QLA_SUCCESS) {
  456. ql_log(ql_log_warn, vha, 0x706d,
  457. "Unable to read SFP data (%x/%x/%x).\n", rval,
  458. addr, offset);
  459. return -EIO;
  460. }
  461. memcpy(buf, ha->sfp_data, SFP_BLOCK_SIZE);
  462. buf += SFP_BLOCK_SIZE;
  463. }
  464. return count;
  465. }
  466. static struct bin_attribute sysfs_sfp_attr = {
  467. .attr = {
  468. .name = "sfp",
  469. .mode = S_IRUSR | S_IWUSR,
  470. },
  471. .size = SFP_DEV_SIZE * 2,
  472. .read = qla2x00_sysfs_read_sfp,
  473. };
  474. static ssize_t
  475. qla2x00_sysfs_write_reset(struct file *filp, struct kobject *kobj,
  476. struct bin_attribute *bin_attr,
  477. char *buf, loff_t off, size_t count)
  478. {
  479. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  480. struct device, kobj)));
  481. struct qla_hw_data *ha = vha->hw;
  482. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  483. int type;
  484. if (off != 0)
  485. return -EINVAL;
  486. type = simple_strtol(buf, NULL, 10);
  487. switch (type) {
  488. case 0x2025c:
  489. ql_log(ql_log_info, vha, 0x706e,
  490. "Issuing ISP reset.\n");
  491. scsi_block_requests(vha->host);
  492. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  493. if (IS_QLA82XX(ha)) {
  494. qla82xx_idc_lock(ha);
  495. qla82xx_set_reset_owner(vha);
  496. qla82xx_idc_unlock(ha);
  497. }
  498. qla2xxx_wake_dpc(vha);
  499. qla2x00_wait_for_chip_reset(vha);
  500. scsi_unblock_requests(vha->host);
  501. break;
  502. case 0x2025d:
  503. if (!IS_QLA81XX(ha))
  504. return -EPERM;
  505. ql_log(ql_log_info, vha, 0x706f,
  506. "Issuing MPI reset.\n");
  507. /* Make sure FC side is not in reset */
  508. qla2x00_wait_for_hba_online(vha);
  509. /* Issue MPI reset */
  510. scsi_block_requests(vha->host);
  511. if (qla81xx_restart_mpi_firmware(vha) != QLA_SUCCESS)
  512. ql_log(ql_log_warn, vha, 0x7070,
  513. "MPI reset failed.\n");
  514. scsi_unblock_requests(vha->host);
  515. break;
  516. case 0x2025e:
  517. if (!IS_QLA82XX(ha) || vha != base_vha) {
  518. ql_log(ql_log_info, vha, 0x7071,
  519. "FCoE ctx reset no supported.\n");
  520. return -EPERM;
  521. }
  522. ql_log(ql_log_info, vha, 0x7072,
  523. "Issuing FCoE ctx reset.\n");
  524. set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
  525. qla2xxx_wake_dpc(vha);
  526. qla2x00_wait_for_fcoe_ctx_reset(vha);
  527. break;
  528. }
  529. return count;
  530. }
  531. static struct bin_attribute sysfs_reset_attr = {
  532. .attr = {
  533. .name = "reset",
  534. .mode = S_IWUSR,
  535. },
  536. .size = 0,
  537. .write = qla2x00_sysfs_write_reset,
  538. };
  539. static ssize_t
  540. qla2x00_sysfs_write_edc(struct file *filp, struct kobject *kobj,
  541. struct bin_attribute *bin_attr,
  542. char *buf, loff_t off, size_t count)
  543. {
  544. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  545. struct device, kobj)));
  546. struct qla_hw_data *ha = vha->hw;
  547. uint16_t dev, adr, opt, len;
  548. int rval;
  549. ha->edc_data_len = 0;
  550. if (!capable(CAP_SYS_ADMIN) || off != 0 || count < 8)
  551. return -EINVAL;
  552. if (!ha->edc_data) {
  553. ha->edc_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  554. &ha->edc_data_dma);
  555. if (!ha->edc_data) {
  556. ql_log(ql_log_warn, vha, 0x7073,
  557. "Unable to allocate memory for EDC write.\n");
  558. return -ENOMEM;
  559. }
  560. }
  561. dev = le16_to_cpup((void *)&buf[0]);
  562. adr = le16_to_cpup((void *)&buf[2]);
  563. opt = le16_to_cpup((void *)&buf[4]);
  564. len = le16_to_cpup((void *)&buf[6]);
  565. if (!(opt & BIT_0))
  566. if (len == 0 || len > DMA_POOL_SIZE || len > count - 8)
  567. return -EINVAL;
  568. memcpy(ha->edc_data, &buf[8], len);
  569. rval = qla2x00_write_sfp(vha, ha->edc_data_dma, ha->edc_data,
  570. dev, adr, len, opt);
  571. if (rval != QLA_SUCCESS) {
  572. ql_log(ql_log_warn, vha, 0x7074,
  573. "Unable to write EDC (%x) %02x:%02x:%04x:%02x:%02hhx\n",
  574. rval, dev, adr, opt, len, buf[8]);
  575. return -EIO;
  576. }
  577. return count;
  578. }
  579. static struct bin_attribute sysfs_edc_attr = {
  580. .attr = {
  581. .name = "edc",
  582. .mode = S_IWUSR,
  583. },
  584. .size = 0,
  585. .write = qla2x00_sysfs_write_edc,
  586. };
  587. static ssize_t
  588. qla2x00_sysfs_write_edc_status(struct file *filp, struct kobject *kobj,
  589. struct bin_attribute *bin_attr,
  590. char *buf, loff_t off, size_t count)
  591. {
  592. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  593. struct device, kobj)));
  594. struct qla_hw_data *ha = vha->hw;
  595. uint16_t dev, adr, opt, len;
  596. int rval;
  597. ha->edc_data_len = 0;
  598. if (!capable(CAP_SYS_ADMIN) || off != 0 || count < 8)
  599. return -EINVAL;
  600. if (!ha->edc_data) {
  601. ha->edc_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  602. &ha->edc_data_dma);
  603. if (!ha->edc_data) {
  604. ql_log(ql_log_warn, vha, 0x708c,
  605. "Unable to allocate memory for EDC status.\n");
  606. return -ENOMEM;
  607. }
  608. }
  609. dev = le16_to_cpup((void *)&buf[0]);
  610. adr = le16_to_cpup((void *)&buf[2]);
  611. opt = le16_to_cpup((void *)&buf[4]);
  612. len = le16_to_cpup((void *)&buf[6]);
  613. if (!(opt & BIT_0))
  614. if (len == 0 || len > DMA_POOL_SIZE)
  615. return -EINVAL;
  616. memset(ha->edc_data, 0, len);
  617. rval = qla2x00_read_sfp(vha, ha->edc_data_dma, ha->edc_data,
  618. dev, adr, len, opt);
  619. if (rval != QLA_SUCCESS) {
  620. ql_log(ql_log_info, vha, 0x7075,
  621. "Unable to write EDC status (%x) %02x:%02x:%04x:%02x.\n",
  622. rval, dev, adr, opt, len);
  623. return -EIO;
  624. }
  625. ha->edc_data_len = len;
  626. return count;
  627. }
  628. static ssize_t
  629. qla2x00_sysfs_read_edc_status(struct file *filp, struct kobject *kobj,
  630. struct bin_attribute *bin_attr,
  631. char *buf, loff_t off, size_t count)
  632. {
  633. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  634. struct device, kobj)));
  635. struct qla_hw_data *ha = vha->hw;
  636. if (!capable(CAP_SYS_ADMIN) || off != 0 || count == 0)
  637. return 0;
  638. if (!ha->edc_data || ha->edc_data_len == 0 || ha->edc_data_len > count)
  639. return -EINVAL;
  640. memcpy(buf, ha->edc_data, ha->edc_data_len);
  641. return ha->edc_data_len;
  642. }
  643. static struct bin_attribute sysfs_edc_status_attr = {
  644. .attr = {
  645. .name = "edc_status",
  646. .mode = S_IRUSR | S_IWUSR,
  647. },
  648. .size = 0,
  649. .write = qla2x00_sysfs_write_edc_status,
  650. .read = qla2x00_sysfs_read_edc_status,
  651. };
  652. static ssize_t
  653. qla2x00_sysfs_read_xgmac_stats(struct file *filp, struct kobject *kobj,
  654. struct bin_attribute *bin_attr,
  655. char *buf, loff_t off, size_t count)
  656. {
  657. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  658. struct device, kobj)));
  659. struct qla_hw_data *ha = vha->hw;
  660. int rval;
  661. uint16_t actual_size;
  662. if (!capable(CAP_SYS_ADMIN) || off != 0 || count > XGMAC_DATA_SIZE)
  663. return 0;
  664. if (ha->xgmac_data)
  665. goto do_read;
  666. ha->xgmac_data = dma_alloc_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
  667. &ha->xgmac_data_dma, GFP_KERNEL);
  668. if (!ha->xgmac_data) {
  669. ql_log(ql_log_warn, vha, 0x7076,
  670. "Unable to allocate memory for XGMAC read-data.\n");
  671. return 0;
  672. }
  673. do_read:
  674. actual_size = 0;
  675. memset(ha->xgmac_data, 0, XGMAC_DATA_SIZE);
  676. rval = qla2x00_get_xgmac_stats(vha, ha->xgmac_data_dma,
  677. XGMAC_DATA_SIZE, &actual_size);
  678. if (rval != QLA_SUCCESS) {
  679. ql_log(ql_log_warn, vha, 0x7077,
  680. "Unable to read XGMAC data (%x).\n", rval);
  681. count = 0;
  682. }
  683. count = actual_size > count ? count: actual_size;
  684. memcpy(buf, ha->xgmac_data, count);
  685. return count;
  686. }
  687. static struct bin_attribute sysfs_xgmac_stats_attr = {
  688. .attr = {
  689. .name = "xgmac_stats",
  690. .mode = S_IRUSR,
  691. },
  692. .size = 0,
  693. .read = qla2x00_sysfs_read_xgmac_stats,
  694. };
  695. static ssize_t
  696. qla2x00_sysfs_read_dcbx_tlv(struct file *filp, struct kobject *kobj,
  697. struct bin_attribute *bin_attr,
  698. char *buf, loff_t off, size_t count)
  699. {
  700. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  701. struct device, kobj)));
  702. struct qla_hw_data *ha = vha->hw;
  703. int rval;
  704. uint16_t actual_size;
  705. if (!capable(CAP_SYS_ADMIN) || off != 0 || count > DCBX_TLV_DATA_SIZE)
  706. return 0;
  707. if (ha->dcbx_tlv)
  708. goto do_read;
  709. ha->dcbx_tlv = dma_alloc_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
  710. &ha->dcbx_tlv_dma, GFP_KERNEL);
  711. if (!ha->dcbx_tlv) {
  712. ql_log(ql_log_warn, vha, 0x7078,
  713. "Unable to allocate memory for DCBX TLV read-data.\n");
  714. return -ENOMEM;
  715. }
  716. do_read:
  717. actual_size = 0;
  718. memset(ha->dcbx_tlv, 0, DCBX_TLV_DATA_SIZE);
  719. rval = qla2x00_get_dcbx_params(vha, ha->dcbx_tlv_dma,
  720. DCBX_TLV_DATA_SIZE);
  721. if (rval != QLA_SUCCESS) {
  722. ql_log(ql_log_warn, vha, 0x7079,
  723. "Unable to read DCBX TLV (%x).\n", rval);
  724. return -EIO;
  725. }
  726. memcpy(buf, ha->dcbx_tlv, count);
  727. return count;
  728. }
  729. static struct bin_attribute sysfs_dcbx_tlv_attr = {
  730. .attr = {
  731. .name = "dcbx_tlv",
  732. .mode = S_IRUSR,
  733. },
  734. .size = 0,
  735. .read = qla2x00_sysfs_read_dcbx_tlv,
  736. };
  737. static struct sysfs_entry {
  738. char *name;
  739. struct bin_attribute *attr;
  740. int is4GBp_only;
  741. } bin_file_entries[] = {
  742. { "fw_dump", &sysfs_fw_dump_attr, },
  743. { "nvram", &sysfs_nvram_attr, },
  744. { "optrom", &sysfs_optrom_attr, },
  745. { "optrom_ctl", &sysfs_optrom_ctl_attr, },
  746. { "vpd", &sysfs_vpd_attr, 1 },
  747. { "sfp", &sysfs_sfp_attr, 1 },
  748. { "reset", &sysfs_reset_attr, },
  749. { "edc", &sysfs_edc_attr, 2 },
  750. { "edc_status", &sysfs_edc_status_attr, 2 },
  751. { "xgmac_stats", &sysfs_xgmac_stats_attr, 3 },
  752. { "dcbx_tlv", &sysfs_dcbx_tlv_attr, 3 },
  753. { NULL },
  754. };
  755. void
  756. qla2x00_alloc_sysfs_attr(scsi_qla_host_t *vha)
  757. {
  758. struct Scsi_Host *host = vha->host;
  759. struct sysfs_entry *iter;
  760. int ret;
  761. for (iter = bin_file_entries; iter->name; iter++) {
  762. if (iter->is4GBp_only && !IS_FWI2_CAPABLE(vha->hw))
  763. continue;
  764. if (iter->is4GBp_only == 2 && !IS_QLA25XX(vha->hw))
  765. continue;
  766. if (iter->is4GBp_only == 3 && !(IS_CNA_CAPABLE(vha->hw)))
  767. continue;
  768. ret = sysfs_create_bin_file(&host->shost_gendev.kobj,
  769. iter->attr);
  770. if (ret)
  771. ql_log(ql_log_warn, vha, 0x00f3,
  772. "Unable to create sysfs %s binary attribute (%d).\n",
  773. iter->name, ret);
  774. else
  775. ql_dbg(ql_dbg_init, vha, 0x00f4,
  776. "Successfully created sysfs %s binary attribure.\n",
  777. iter->name);
  778. }
  779. }
  780. void
  781. qla2x00_free_sysfs_attr(scsi_qla_host_t *vha)
  782. {
  783. struct Scsi_Host *host = vha->host;
  784. struct sysfs_entry *iter;
  785. struct qla_hw_data *ha = vha->hw;
  786. for (iter = bin_file_entries; iter->name; iter++) {
  787. if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha))
  788. continue;
  789. if (iter->is4GBp_only == 2 && !IS_QLA25XX(ha))
  790. continue;
  791. if (iter->is4GBp_only == 3 && !(IS_CNA_CAPABLE(vha->hw)))
  792. continue;
  793. sysfs_remove_bin_file(&host->shost_gendev.kobj,
  794. iter->attr);
  795. }
  796. if (ha->beacon_blink_led == 1)
  797. ha->isp_ops->beacon_off(vha);
  798. }
  799. /* Scsi_Host attributes. */
  800. static ssize_t
  801. qla2x00_drvr_version_show(struct device *dev,
  802. struct device_attribute *attr, char *buf)
  803. {
  804. return snprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
  805. }
  806. static ssize_t
  807. qla2x00_fw_version_show(struct device *dev,
  808. struct device_attribute *attr, char *buf)
  809. {
  810. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  811. struct qla_hw_data *ha = vha->hw;
  812. char fw_str[128];
  813. return snprintf(buf, PAGE_SIZE, "%s\n",
  814. ha->isp_ops->fw_version_str(vha, fw_str));
  815. }
  816. static ssize_t
  817. qla2x00_serial_num_show(struct device *dev, struct device_attribute *attr,
  818. char *buf)
  819. {
  820. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  821. struct qla_hw_data *ha = vha->hw;
  822. uint32_t sn;
  823. if (IS_FWI2_CAPABLE(ha)) {
  824. qla2xxx_get_vpd_field(vha, "SN", buf, PAGE_SIZE);
  825. return snprintf(buf, PAGE_SIZE, "%s\n", buf);
  826. }
  827. sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
  828. return snprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
  829. sn % 100000);
  830. }
  831. static ssize_t
  832. qla2x00_isp_name_show(struct device *dev, struct device_attribute *attr,
  833. char *buf)
  834. {
  835. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  836. return snprintf(buf, PAGE_SIZE, "ISP%04X\n", vha->hw->pdev->device);
  837. }
  838. static ssize_t
  839. qla2x00_isp_id_show(struct device *dev, struct device_attribute *attr,
  840. char *buf)
  841. {
  842. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  843. struct qla_hw_data *ha = vha->hw;
  844. return snprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
  845. ha->product_id[0], ha->product_id[1], ha->product_id[2],
  846. ha->product_id[3]);
  847. }
  848. static ssize_t
  849. qla2x00_model_name_show(struct device *dev, struct device_attribute *attr,
  850. char *buf)
  851. {
  852. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  853. return snprintf(buf, PAGE_SIZE, "%s\n", vha->hw->model_number);
  854. }
  855. static ssize_t
  856. qla2x00_model_desc_show(struct device *dev, struct device_attribute *attr,
  857. char *buf)
  858. {
  859. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  860. return snprintf(buf, PAGE_SIZE, "%s\n",
  861. vha->hw->model_desc ? vha->hw->model_desc : "");
  862. }
  863. static ssize_t
  864. qla2x00_pci_info_show(struct device *dev, struct device_attribute *attr,
  865. char *buf)
  866. {
  867. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  868. char pci_info[30];
  869. return snprintf(buf, PAGE_SIZE, "%s\n",
  870. vha->hw->isp_ops->pci_info_str(vha, pci_info));
  871. }
  872. static ssize_t
  873. qla2x00_link_state_show(struct device *dev, struct device_attribute *attr,
  874. char *buf)
  875. {
  876. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  877. struct qla_hw_data *ha = vha->hw;
  878. int len = 0;
  879. if (atomic_read(&vha->loop_state) == LOOP_DOWN ||
  880. atomic_read(&vha->loop_state) == LOOP_DEAD ||
  881. vha->device_flags & DFLG_NO_CABLE)
  882. len = snprintf(buf, PAGE_SIZE, "Link Down\n");
  883. else if (atomic_read(&vha->loop_state) != LOOP_READY ||
  884. qla2x00_reset_active(vha))
  885. len = snprintf(buf, PAGE_SIZE, "Unknown Link State\n");
  886. else {
  887. len = snprintf(buf, PAGE_SIZE, "Link Up - ");
  888. switch (ha->current_topology) {
  889. case ISP_CFG_NL:
  890. len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
  891. break;
  892. case ISP_CFG_FL:
  893. len += snprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
  894. break;
  895. case ISP_CFG_N:
  896. len += snprintf(buf + len, PAGE_SIZE-len,
  897. "N_Port to N_Port\n");
  898. break;
  899. case ISP_CFG_F:
  900. len += snprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
  901. break;
  902. default:
  903. len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
  904. break;
  905. }
  906. }
  907. return len;
  908. }
  909. static ssize_t
  910. qla2x00_zio_show(struct device *dev, struct device_attribute *attr,
  911. char *buf)
  912. {
  913. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  914. int len = 0;
  915. switch (vha->hw->zio_mode) {
  916. case QLA_ZIO_MODE_6:
  917. len += snprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
  918. break;
  919. case QLA_ZIO_DISABLED:
  920. len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
  921. break;
  922. }
  923. return len;
  924. }
  925. static ssize_t
  926. qla2x00_zio_store(struct device *dev, struct device_attribute *attr,
  927. const char *buf, size_t count)
  928. {
  929. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  930. struct qla_hw_data *ha = vha->hw;
  931. int val = 0;
  932. uint16_t zio_mode;
  933. if (!IS_ZIO_SUPPORTED(ha))
  934. return -ENOTSUPP;
  935. if (sscanf(buf, "%d", &val) != 1)
  936. return -EINVAL;
  937. if (val)
  938. zio_mode = QLA_ZIO_MODE_6;
  939. else
  940. zio_mode = QLA_ZIO_DISABLED;
  941. /* Update per-hba values and queue a reset. */
  942. if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
  943. ha->zio_mode = zio_mode;
  944. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  945. }
  946. return strlen(buf);
  947. }
  948. static ssize_t
  949. qla2x00_zio_timer_show(struct device *dev, struct device_attribute *attr,
  950. char *buf)
  951. {
  952. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  953. return snprintf(buf, PAGE_SIZE, "%d us\n", vha->hw->zio_timer * 100);
  954. }
  955. static ssize_t
  956. qla2x00_zio_timer_store(struct device *dev, struct device_attribute *attr,
  957. const char *buf, size_t count)
  958. {
  959. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  960. int val = 0;
  961. uint16_t zio_timer;
  962. if (sscanf(buf, "%d", &val) != 1)
  963. return -EINVAL;
  964. if (val > 25500 || val < 100)
  965. return -ERANGE;
  966. zio_timer = (uint16_t)(val / 100);
  967. vha->hw->zio_timer = zio_timer;
  968. return strlen(buf);
  969. }
  970. static ssize_t
  971. qla2x00_beacon_show(struct device *dev, struct device_attribute *attr,
  972. char *buf)
  973. {
  974. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  975. int len = 0;
  976. if (vha->hw->beacon_blink_led)
  977. len += snprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
  978. else
  979. len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
  980. return len;
  981. }
  982. static ssize_t
  983. qla2x00_beacon_store(struct device *dev, struct device_attribute *attr,
  984. const char *buf, size_t count)
  985. {
  986. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  987. struct qla_hw_data *ha = vha->hw;
  988. int val = 0;
  989. int rval;
  990. if (IS_QLA2100(ha) || IS_QLA2200(ha))
  991. return -EPERM;
  992. if (test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) {
  993. ql_log(ql_log_warn, vha, 0x707a,
  994. "Abort ISP active -- ignoring beacon request.\n");
  995. return -EBUSY;
  996. }
  997. if (sscanf(buf, "%d", &val) != 1)
  998. return -EINVAL;
  999. if (val)
  1000. rval = ha->isp_ops->beacon_on(vha);
  1001. else
  1002. rval = ha->isp_ops->beacon_off(vha);
  1003. if (rval != QLA_SUCCESS)
  1004. count = 0;
  1005. return count;
  1006. }
  1007. static ssize_t
  1008. qla2x00_optrom_bios_version_show(struct device *dev,
  1009. struct device_attribute *attr, char *buf)
  1010. {
  1011. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1012. struct qla_hw_data *ha = vha->hw;
  1013. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->bios_revision[1],
  1014. ha->bios_revision[0]);
  1015. }
  1016. static ssize_t
  1017. qla2x00_optrom_efi_version_show(struct device *dev,
  1018. struct device_attribute *attr, char *buf)
  1019. {
  1020. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1021. struct qla_hw_data *ha = vha->hw;
  1022. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->efi_revision[1],
  1023. ha->efi_revision[0]);
  1024. }
  1025. static ssize_t
  1026. qla2x00_optrom_fcode_version_show(struct device *dev,
  1027. struct device_attribute *attr, char *buf)
  1028. {
  1029. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1030. struct qla_hw_data *ha = vha->hw;
  1031. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->fcode_revision[1],
  1032. ha->fcode_revision[0]);
  1033. }
  1034. static ssize_t
  1035. qla2x00_optrom_fw_version_show(struct device *dev,
  1036. struct device_attribute *attr, char *buf)
  1037. {
  1038. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1039. struct qla_hw_data *ha = vha->hw;
  1040. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d %d\n",
  1041. ha->fw_revision[0], ha->fw_revision[1], ha->fw_revision[2],
  1042. ha->fw_revision[3]);
  1043. }
  1044. static ssize_t
  1045. qla2x00_optrom_gold_fw_version_show(struct device *dev,
  1046. struct device_attribute *attr, char *buf)
  1047. {
  1048. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1049. struct qla_hw_data *ha = vha->hw;
  1050. if (!IS_QLA81XX(ha) && !IS_QLA83XX(ha))
  1051. return snprintf(buf, PAGE_SIZE, "\n");
  1052. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%d)\n",
  1053. ha->gold_fw_version[0], ha->gold_fw_version[1],
  1054. ha->gold_fw_version[2], ha->gold_fw_version[3]);
  1055. }
  1056. static ssize_t
  1057. qla2x00_total_isp_aborts_show(struct device *dev,
  1058. struct device_attribute *attr, char *buf)
  1059. {
  1060. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1061. struct qla_hw_data *ha = vha->hw;
  1062. return snprintf(buf, PAGE_SIZE, "%d\n",
  1063. ha->qla_stats.total_isp_aborts);
  1064. }
  1065. static ssize_t
  1066. qla24xx_84xx_fw_version_show(struct device *dev,
  1067. struct device_attribute *attr, char *buf)
  1068. {
  1069. int rval = QLA_SUCCESS;
  1070. uint16_t status[2] = {0, 0};
  1071. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1072. struct qla_hw_data *ha = vha->hw;
  1073. if (!IS_QLA84XX(ha))
  1074. return snprintf(buf, PAGE_SIZE, "\n");
  1075. if (ha->cs84xx->op_fw_version == 0)
  1076. rval = qla84xx_verify_chip(vha, status);
  1077. if ((rval == QLA_SUCCESS) && (status[0] == 0))
  1078. return snprintf(buf, PAGE_SIZE, "%u\n",
  1079. (uint32_t)ha->cs84xx->op_fw_version);
  1080. return snprintf(buf, PAGE_SIZE, "\n");
  1081. }
  1082. static ssize_t
  1083. qla2x00_mpi_version_show(struct device *dev, struct device_attribute *attr,
  1084. char *buf)
  1085. {
  1086. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1087. struct qla_hw_data *ha = vha->hw;
  1088. if (!IS_QLA81XX(ha) && !IS_QLA8031(ha))
  1089. return snprintf(buf, PAGE_SIZE, "\n");
  1090. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%x)\n",
  1091. ha->mpi_version[0], ha->mpi_version[1], ha->mpi_version[2],
  1092. ha->mpi_capabilities);
  1093. }
  1094. static ssize_t
  1095. qla2x00_phy_version_show(struct device *dev, struct device_attribute *attr,
  1096. char *buf)
  1097. {
  1098. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1099. struct qla_hw_data *ha = vha->hw;
  1100. if (!IS_QLA81XX(ha) && !IS_QLA83XX(ha))
  1101. return snprintf(buf, PAGE_SIZE, "\n");
  1102. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d\n",
  1103. ha->phy_version[0], ha->phy_version[1], ha->phy_version[2]);
  1104. }
  1105. static ssize_t
  1106. qla2x00_flash_block_size_show(struct device *dev,
  1107. struct device_attribute *attr, char *buf)
  1108. {
  1109. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1110. struct qla_hw_data *ha = vha->hw;
  1111. return snprintf(buf, PAGE_SIZE, "0x%x\n", ha->fdt_block_size);
  1112. }
  1113. static ssize_t
  1114. qla2x00_vlan_id_show(struct device *dev, struct device_attribute *attr,
  1115. char *buf)
  1116. {
  1117. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1118. if (!IS_CNA_CAPABLE(vha->hw))
  1119. return snprintf(buf, PAGE_SIZE, "\n");
  1120. return snprintf(buf, PAGE_SIZE, "%d\n", vha->fcoe_vlan_id);
  1121. }
  1122. static ssize_t
  1123. qla2x00_vn_port_mac_address_show(struct device *dev,
  1124. struct device_attribute *attr, char *buf)
  1125. {
  1126. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1127. if (!IS_CNA_CAPABLE(vha->hw))
  1128. return snprintf(buf, PAGE_SIZE, "\n");
  1129. return snprintf(buf, PAGE_SIZE, "%02x:%02x:%02x:%02x:%02x:%02x\n",
  1130. vha->fcoe_vn_port_mac[5], vha->fcoe_vn_port_mac[4],
  1131. vha->fcoe_vn_port_mac[3], vha->fcoe_vn_port_mac[2],
  1132. vha->fcoe_vn_port_mac[1], vha->fcoe_vn_port_mac[0]);
  1133. }
  1134. static ssize_t
  1135. qla2x00_fabric_param_show(struct device *dev, struct device_attribute *attr,
  1136. char *buf)
  1137. {
  1138. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1139. return snprintf(buf, PAGE_SIZE, "%d\n", vha->hw->switch_cap);
  1140. }
  1141. static ssize_t
  1142. qla2x00_thermal_temp_show(struct device *dev,
  1143. struct device_attribute *attr, char *buf)
  1144. {
  1145. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1146. int rval = QLA_FUNCTION_FAILED;
  1147. uint16_t temp, frac;
  1148. if (!vha->hw->flags.thermal_supported)
  1149. return snprintf(buf, PAGE_SIZE, "\n");
  1150. temp = frac = 0;
  1151. if (qla2x00_reset_active(vha))
  1152. ql_log(ql_log_warn, vha, 0x707b,
  1153. "ISP reset active.\n");
  1154. else if (!vha->hw->flags.eeh_busy)
  1155. rval = qla2x00_get_thermal_temp(vha, &temp, &frac);
  1156. if (rval != QLA_SUCCESS)
  1157. temp = frac = 0;
  1158. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", temp, frac);
  1159. }
  1160. static ssize_t
  1161. qla2x00_fw_state_show(struct device *dev, struct device_attribute *attr,
  1162. char *buf)
  1163. {
  1164. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1165. int rval = QLA_FUNCTION_FAILED;
  1166. uint16_t state[5];
  1167. if (qla2x00_reset_active(vha))
  1168. ql_log(ql_log_warn, vha, 0x707c,
  1169. "ISP reset active.\n");
  1170. else if (!vha->hw->flags.eeh_busy)
  1171. rval = qla2x00_get_firmware_state(vha, state);
  1172. if (rval != QLA_SUCCESS)
  1173. memset(state, -1, sizeof(state));
  1174. return snprintf(buf, PAGE_SIZE, "0x%x 0x%x 0x%x 0x%x 0x%x\n", state[0],
  1175. state[1], state[2], state[3], state[4]);
  1176. }
  1177. static DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show, NULL);
  1178. static DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
  1179. static DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
  1180. static DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
  1181. static DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
  1182. static DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
  1183. static DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
  1184. static DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
  1185. static DEVICE_ATTR(link_state, S_IRUGO, qla2x00_link_state_show, NULL);
  1186. static DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show, qla2x00_zio_store);
  1187. static DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
  1188. qla2x00_zio_timer_store);
  1189. static DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
  1190. qla2x00_beacon_store);
  1191. static DEVICE_ATTR(optrom_bios_version, S_IRUGO,
  1192. qla2x00_optrom_bios_version_show, NULL);
  1193. static DEVICE_ATTR(optrom_efi_version, S_IRUGO,
  1194. qla2x00_optrom_efi_version_show, NULL);
  1195. static DEVICE_ATTR(optrom_fcode_version, S_IRUGO,
  1196. qla2x00_optrom_fcode_version_show, NULL);
  1197. static DEVICE_ATTR(optrom_fw_version, S_IRUGO, qla2x00_optrom_fw_version_show,
  1198. NULL);
  1199. static DEVICE_ATTR(optrom_gold_fw_version, S_IRUGO,
  1200. qla2x00_optrom_gold_fw_version_show, NULL);
  1201. static DEVICE_ATTR(84xx_fw_version, S_IRUGO, qla24xx_84xx_fw_version_show,
  1202. NULL);
  1203. static DEVICE_ATTR(total_isp_aborts, S_IRUGO, qla2x00_total_isp_aborts_show,
  1204. NULL);
  1205. static DEVICE_ATTR(mpi_version, S_IRUGO, qla2x00_mpi_version_show, NULL);
  1206. static DEVICE_ATTR(phy_version, S_IRUGO, qla2x00_phy_version_show, NULL);
  1207. static DEVICE_ATTR(flash_block_size, S_IRUGO, qla2x00_flash_block_size_show,
  1208. NULL);
  1209. static DEVICE_ATTR(vlan_id, S_IRUGO, qla2x00_vlan_id_show, NULL);
  1210. static DEVICE_ATTR(vn_port_mac_address, S_IRUGO,
  1211. qla2x00_vn_port_mac_address_show, NULL);
  1212. static DEVICE_ATTR(fabric_param, S_IRUGO, qla2x00_fabric_param_show, NULL);
  1213. static DEVICE_ATTR(fw_state, S_IRUGO, qla2x00_fw_state_show, NULL);
  1214. static DEVICE_ATTR(thermal_temp, S_IRUGO, qla2x00_thermal_temp_show, NULL);
  1215. struct device_attribute *qla2x00_host_attrs[] = {
  1216. &dev_attr_driver_version,
  1217. &dev_attr_fw_version,
  1218. &dev_attr_serial_num,
  1219. &dev_attr_isp_name,
  1220. &dev_attr_isp_id,
  1221. &dev_attr_model_name,
  1222. &dev_attr_model_desc,
  1223. &dev_attr_pci_info,
  1224. &dev_attr_link_state,
  1225. &dev_attr_zio,
  1226. &dev_attr_zio_timer,
  1227. &dev_attr_beacon,
  1228. &dev_attr_optrom_bios_version,
  1229. &dev_attr_optrom_efi_version,
  1230. &dev_attr_optrom_fcode_version,
  1231. &dev_attr_optrom_fw_version,
  1232. &dev_attr_84xx_fw_version,
  1233. &dev_attr_total_isp_aborts,
  1234. &dev_attr_mpi_version,
  1235. &dev_attr_phy_version,
  1236. &dev_attr_flash_block_size,
  1237. &dev_attr_vlan_id,
  1238. &dev_attr_vn_port_mac_address,
  1239. &dev_attr_fabric_param,
  1240. &dev_attr_fw_state,
  1241. &dev_attr_optrom_gold_fw_version,
  1242. &dev_attr_thermal_temp,
  1243. NULL,
  1244. };
  1245. /* Host attributes. */
  1246. static void
  1247. qla2x00_get_host_port_id(struct Scsi_Host *shost)
  1248. {
  1249. scsi_qla_host_t *vha = shost_priv(shost);
  1250. fc_host_port_id(shost) = vha->d_id.b.domain << 16 |
  1251. vha->d_id.b.area << 8 | vha->d_id.b.al_pa;
  1252. }
  1253. static void
  1254. qla2x00_get_host_speed(struct Scsi_Host *shost)
  1255. {
  1256. struct qla_hw_data *ha = ((struct scsi_qla_host *)
  1257. (shost_priv(shost)))->hw;
  1258. u32 speed = FC_PORTSPEED_UNKNOWN;
  1259. switch (ha->link_data_rate) {
  1260. case PORT_SPEED_1GB:
  1261. speed = FC_PORTSPEED_1GBIT;
  1262. break;
  1263. case PORT_SPEED_2GB:
  1264. speed = FC_PORTSPEED_2GBIT;
  1265. break;
  1266. case PORT_SPEED_4GB:
  1267. speed = FC_PORTSPEED_4GBIT;
  1268. break;
  1269. case PORT_SPEED_8GB:
  1270. speed = FC_PORTSPEED_8GBIT;
  1271. break;
  1272. case PORT_SPEED_10GB:
  1273. speed = FC_PORTSPEED_10GBIT;
  1274. break;
  1275. case PORT_SPEED_16GB:
  1276. speed = FC_PORTSPEED_16GBIT;
  1277. break;
  1278. }
  1279. fc_host_speed(shost) = speed;
  1280. }
  1281. static void
  1282. qla2x00_get_host_port_type(struct Scsi_Host *shost)
  1283. {
  1284. scsi_qla_host_t *vha = shost_priv(shost);
  1285. uint32_t port_type = FC_PORTTYPE_UNKNOWN;
  1286. if (vha->vp_idx) {
  1287. fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
  1288. return;
  1289. }
  1290. switch (vha->hw->current_topology) {
  1291. case ISP_CFG_NL:
  1292. port_type = FC_PORTTYPE_LPORT;
  1293. break;
  1294. case ISP_CFG_FL:
  1295. port_type = FC_PORTTYPE_NLPORT;
  1296. break;
  1297. case ISP_CFG_N:
  1298. port_type = FC_PORTTYPE_PTP;
  1299. break;
  1300. case ISP_CFG_F:
  1301. port_type = FC_PORTTYPE_NPORT;
  1302. break;
  1303. }
  1304. fc_host_port_type(shost) = port_type;
  1305. }
  1306. static void
  1307. qla2x00_get_starget_node_name(struct scsi_target *starget)
  1308. {
  1309. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  1310. scsi_qla_host_t *vha = shost_priv(host);
  1311. fc_port_t *fcport;
  1312. u64 node_name = 0;
  1313. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  1314. if (fcport->rport &&
  1315. starget->id == fcport->rport->scsi_target_id) {
  1316. node_name = wwn_to_u64(fcport->node_name);
  1317. break;
  1318. }
  1319. }
  1320. fc_starget_node_name(starget) = node_name;
  1321. }
  1322. static void
  1323. qla2x00_get_starget_port_name(struct scsi_target *starget)
  1324. {
  1325. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  1326. scsi_qla_host_t *vha = shost_priv(host);
  1327. fc_port_t *fcport;
  1328. u64 port_name = 0;
  1329. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  1330. if (fcport->rport &&
  1331. starget->id == fcport->rport->scsi_target_id) {
  1332. port_name = wwn_to_u64(fcport->port_name);
  1333. break;
  1334. }
  1335. }
  1336. fc_starget_port_name(starget) = port_name;
  1337. }
  1338. static void
  1339. qla2x00_get_starget_port_id(struct scsi_target *starget)
  1340. {
  1341. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  1342. scsi_qla_host_t *vha = shost_priv(host);
  1343. fc_port_t *fcport;
  1344. uint32_t port_id = ~0U;
  1345. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  1346. if (fcport->rport &&
  1347. starget->id == fcport->rport->scsi_target_id) {
  1348. port_id = fcport->d_id.b.domain << 16 |
  1349. fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
  1350. break;
  1351. }
  1352. }
  1353. fc_starget_port_id(starget) = port_id;
  1354. }
  1355. static void
  1356. qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
  1357. {
  1358. if (timeout)
  1359. rport->dev_loss_tmo = timeout;
  1360. else
  1361. rport->dev_loss_tmo = 1;
  1362. }
  1363. static void
  1364. qla2x00_dev_loss_tmo_callbk(struct fc_rport *rport)
  1365. {
  1366. struct Scsi_Host *host = rport_to_shost(rport);
  1367. fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
  1368. unsigned long flags;
  1369. if (!fcport)
  1370. return;
  1371. /* Now that the rport has been deleted, set the fcport state to
  1372. FCS_DEVICE_DEAD */
  1373. qla2x00_set_fcport_state(fcport, FCS_DEVICE_DEAD);
  1374. /*
  1375. * Transport has effectively 'deleted' the rport, clear
  1376. * all local references.
  1377. */
  1378. spin_lock_irqsave(host->host_lock, flags);
  1379. fcport->rport = fcport->drport = NULL;
  1380. *((fc_port_t **)rport->dd_data) = NULL;
  1381. spin_unlock_irqrestore(host->host_lock, flags);
  1382. if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
  1383. return;
  1384. if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
  1385. qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
  1386. return;
  1387. }
  1388. }
  1389. static void
  1390. qla2x00_terminate_rport_io(struct fc_rport *rport)
  1391. {
  1392. fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
  1393. if (!fcport)
  1394. return;
  1395. if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
  1396. return;
  1397. if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
  1398. qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
  1399. return;
  1400. }
  1401. /*
  1402. * At this point all fcport's software-states are cleared. Perform any
  1403. * final cleanup of firmware resources (PCBs and XCBs).
  1404. */
  1405. if (fcport->loop_id != FC_NO_LOOP_ID &&
  1406. !test_bit(UNLOADING, &fcport->vha->dpc_flags))
  1407. fcport->vha->hw->isp_ops->fabric_logout(fcport->vha,
  1408. fcport->loop_id, fcport->d_id.b.domain,
  1409. fcport->d_id.b.area, fcport->d_id.b.al_pa);
  1410. }
  1411. static int
  1412. qla2x00_issue_lip(struct Scsi_Host *shost)
  1413. {
  1414. scsi_qla_host_t *vha = shost_priv(shost);
  1415. qla2x00_loop_reset(vha);
  1416. return 0;
  1417. }
  1418. static struct fc_host_statistics *
  1419. qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
  1420. {
  1421. scsi_qla_host_t *vha = shost_priv(shost);
  1422. struct qla_hw_data *ha = vha->hw;
  1423. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  1424. int rval;
  1425. struct link_statistics *stats;
  1426. dma_addr_t stats_dma;
  1427. struct fc_host_statistics *pfc_host_stat;
  1428. pfc_host_stat = &ha->fc_host_stat;
  1429. memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics));
  1430. if (test_bit(UNLOADING, &vha->dpc_flags))
  1431. goto done;
  1432. if (unlikely(pci_channel_offline(ha->pdev)))
  1433. goto done;
  1434. stats = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &stats_dma);
  1435. if (stats == NULL) {
  1436. ql_log(ql_log_warn, vha, 0x707d,
  1437. "Failed to allocate memory for stats.\n");
  1438. goto done;
  1439. }
  1440. memset(stats, 0, DMA_POOL_SIZE);
  1441. rval = QLA_FUNCTION_FAILED;
  1442. if (IS_FWI2_CAPABLE(ha)) {
  1443. rval = qla24xx_get_isp_stats(base_vha, stats, stats_dma);
  1444. } else if (atomic_read(&base_vha->loop_state) == LOOP_READY &&
  1445. !qla2x00_reset_active(vha) && !ha->dpc_active) {
  1446. /* Must be in a 'READY' state for statistics retrieval. */
  1447. rval = qla2x00_get_link_status(base_vha, base_vha->loop_id,
  1448. stats, stats_dma);
  1449. }
  1450. if (rval != QLA_SUCCESS)
  1451. goto done_free;
  1452. pfc_host_stat->link_failure_count = stats->link_fail_cnt;
  1453. pfc_host_stat->loss_of_sync_count = stats->loss_sync_cnt;
  1454. pfc_host_stat->loss_of_signal_count = stats->loss_sig_cnt;
  1455. pfc_host_stat->prim_seq_protocol_err_count = stats->prim_seq_err_cnt;
  1456. pfc_host_stat->invalid_tx_word_count = stats->inval_xmit_word_cnt;
  1457. pfc_host_stat->invalid_crc_count = stats->inval_crc_cnt;
  1458. if (IS_FWI2_CAPABLE(ha)) {
  1459. pfc_host_stat->lip_count = stats->lip_cnt;
  1460. pfc_host_stat->tx_frames = stats->tx_frames;
  1461. pfc_host_stat->rx_frames = stats->rx_frames;
  1462. pfc_host_stat->dumped_frames = stats->dumped_frames;
  1463. pfc_host_stat->nos_count = stats->nos_rcvd;
  1464. }
  1465. pfc_host_stat->fcp_input_megabytes = ha->qla_stats.input_bytes >> 20;
  1466. pfc_host_stat->fcp_output_megabytes = ha->qla_stats.output_bytes >> 20;
  1467. done_free:
  1468. dma_pool_free(ha->s_dma_pool, stats, stats_dma);
  1469. done:
  1470. return pfc_host_stat;
  1471. }
  1472. static void
  1473. qla2x00_get_host_symbolic_name(struct Scsi_Host *shost)
  1474. {
  1475. scsi_qla_host_t *vha = shost_priv(shost);
  1476. qla2x00_get_sym_node_name(vha, fc_host_symbolic_name(shost));
  1477. }
  1478. static void
  1479. qla2x00_set_host_system_hostname(struct Scsi_Host *shost)
  1480. {
  1481. scsi_qla_host_t *vha = shost_priv(shost);
  1482. set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
  1483. }
  1484. static void
  1485. qla2x00_get_host_fabric_name(struct Scsi_Host *shost)
  1486. {
  1487. scsi_qla_host_t *vha = shost_priv(shost);
  1488. uint8_t node_name[WWN_SIZE] = { 0xFF, 0xFF, 0xFF, 0xFF, \
  1489. 0xFF, 0xFF, 0xFF, 0xFF};
  1490. u64 fabric_name = wwn_to_u64(node_name);
  1491. if (vha->device_flags & SWITCH_FOUND)
  1492. fabric_name = wwn_to_u64(vha->fabric_node_name);
  1493. fc_host_fabric_name(shost) = fabric_name;
  1494. }
  1495. static void
  1496. qla2x00_get_host_port_state(struct Scsi_Host *shost)
  1497. {
  1498. scsi_qla_host_t *vha = shost_priv(shost);
  1499. struct scsi_qla_host *base_vha = pci_get_drvdata(vha->hw->pdev);
  1500. if (!base_vha->flags.online) {
  1501. fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
  1502. return;
  1503. }
  1504. switch (atomic_read(&base_vha->loop_state)) {
  1505. case LOOP_UPDATE:
  1506. fc_host_port_state(shost) = FC_PORTSTATE_DIAGNOSTICS;
  1507. break;
  1508. case LOOP_DOWN:
  1509. if (test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags))
  1510. fc_host_port_state(shost) = FC_PORTSTATE_DIAGNOSTICS;
  1511. else
  1512. fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
  1513. break;
  1514. case LOOP_DEAD:
  1515. fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
  1516. break;
  1517. case LOOP_READY:
  1518. fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
  1519. break;
  1520. default:
  1521. fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
  1522. break;
  1523. }
  1524. }
  1525. static int
  1526. qla24xx_vport_create(struct fc_vport *fc_vport, bool disable)
  1527. {
  1528. int ret = 0;
  1529. uint8_t qos = 0;
  1530. scsi_qla_host_t *base_vha = shost_priv(fc_vport->shost);
  1531. scsi_qla_host_t *vha = NULL;
  1532. struct qla_hw_data *ha = base_vha->hw;
  1533. uint16_t options = 0;
  1534. int cnt;
  1535. struct req_que *req = ha->req_q_map[0];
  1536. ret = qla24xx_vport_create_req_sanity_check(fc_vport);
  1537. if (ret) {
  1538. ql_log(ql_log_warn, vha, 0x707e,
  1539. "Vport sanity check failed, status %x\n", ret);
  1540. return (ret);
  1541. }
  1542. vha = qla24xx_create_vhost(fc_vport);
  1543. if (vha == NULL) {
  1544. ql_log(ql_log_warn, vha, 0x707f, "Vport create host failed.\n");
  1545. return FC_VPORT_FAILED;
  1546. }
  1547. if (disable) {
  1548. atomic_set(&vha->vp_state, VP_OFFLINE);
  1549. fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
  1550. } else
  1551. atomic_set(&vha->vp_state, VP_FAILED);
  1552. /* ready to create vport */
  1553. ql_log(ql_log_info, vha, 0x7080,
  1554. "VP entry id %d assigned.\n", vha->vp_idx);
  1555. /* initialized vport states */
  1556. atomic_set(&vha->loop_state, LOOP_DOWN);
  1557. vha->vp_err_state= VP_ERR_PORTDWN;
  1558. vha->vp_prev_err_state= VP_ERR_UNKWN;
  1559. /* Check if physical ha port is Up */
  1560. if (atomic_read(&base_vha->loop_state) == LOOP_DOWN ||
  1561. atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
  1562. /* Don't retry or attempt login of this virtual port */
  1563. ql_dbg(ql_dbg_user, vha, 0x7081,
  1564. "Vport loop state is not UP.\n");
  1565. atomic_set(&vha->loop_state, LOOP_DEAD);
  1566. if (!disable)
  1567. fc_vport_set_state(fc_vport, FC_VPORT_LINKDOWN);
  1568. }
  1569. if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
  1570. if (ha->fw_attributes & BIT_4) {
  1571. int prot = 0;
  1572. vha->flags.difdix_supported = 1;
  1573. ql_dbg(ql_dbg_user, vha, 0x7082,
  1574. "Registered for DIF/DIX type 1 and 3 protection.\n");
  1575. if (ql2xenabledif == 1)
  1576. prot = SHOST_DIX_TYPE0_PROTECTION;
  1577. scsi_host_set_prot(vha->host,
  1578. prot | SHOST_DIF_TYPE1_PROTECTION
  1579. | SHOST_DIF_TYPE2_PROTECTION
  1580. | SHOST_DIF_TYPE3_PROTECTION
  1581. | SHOST_DIX_TYPE1_PROTECTION
  1582. | SHOST_DIX_TYPE2_PROTECTION
  1583. | SHOST_DIX_TYPE3_PROTECTION);
  1584. scsi_host_set_guard(vha->host, SHOST_DIX_GUARD_CRC);
  1585. } else
  1586. vha->flags.difdix_supported = 0;
  1587. }
  1588. if (scsi_add_host_with_dma(vha->host, &fc_vport->dev,
  1589. &ha->pdev->dev)) {
  1590. ql_dbg(ql_dbg_user, vha, 0x7083,
  1591. "scsi_add_host failure for VP[%d].\n", vha->vp_idx);
  1592. goto vport_create_failed_2;
  1593. }
  1594. /* initialize attributes */
  1595. fc_host_dev_loss_tmo(vha->host) = ha->port_down_retry_count;
  1596. fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
  1597. fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
  1598. fc_host_supported_classes(vha->host) =
  1599. fc_host_supported_classes(base_vha->host);
  1600. fc_host_supported_speeds(vha->host) =
  1601. fc_host_supported_speeds(base_vha->host);
  1602. qla24xx_vport_disable(fc_vport, disable);
  1603. if (ha->flags.cpu_affinity_enabled) {
  1604. req = ha->req_q_map[1];
  1605. ql_dbg(ql_dbg_multiq, vha, 0xc000,
  1606. "Request queue %p attached with "
  1607. "VP[%d], cpu affinity =%d\n",
  1608. req, vha->vp_idx, ha->flags.cpu_affinity_enabled);
  1609. goto vport_queue;
  1610. } else if (ql2xmaxqueues == 1 || !ha->npiv_info)
  1611. goto vport_queue;
  1612. /* Create a request queue in QoS mode for the vport */
  1613. for (cnt = 0; cnt < ha->nvram_npiv_size; cnt++) {
  1614. if (memcmp(ha->npiv_info[cnt].port_name, vha->port_name, 8) == 0
  1615. && memcmp(ha->npiv_info[cnt].node_name, vha->node_name,
  1616. 8) == 0) {
  1617. qos = ha->npiv_info[cnt].q_qos;
  1618. break;
  1619. }
  1620. }
  1621. if (qos) {
  1622. ret = qla25xx_create_req_que(ha, options, vha->vp_idx, 0, 0,
  1623. qos);
  1624. if (!ret)
  1625. ql_log(ql_log_warn, vha, 0x7084,
  1626. "Can't create request queue for VP[%d]\n",
  1627. vha->vp_idx);
  1628. else {
  1629. ql_dbg(ql_dbg_multiq, vha, 0xc001,
  1630. "Request Que:%d Q0s: %d) created for VP[%d]\n",
  1631. ret, qos, vha->vp_idx);
  1632. ql_dbg(ql_dbg_user, vha, 0x7085,
  1633. "Request Que:%d Q0s: %d) created for VP[%d]\n",
  1634. ret, qos, vha->vp_idx);
  1635. req = ha->req_q_map[ret];
  1636. }
  1637. }
  1638. vport_queue:
  1639. vha->req = req;
  1640. return 0;
  1641. vport_create_failed_2:
  1642. qla24xx_disable_vp(vha);
  1643. qla24xx_deallocate_vp_id(vha);
  1644. scsi_host_put(vha->host);
  1645. return FC_VPORT_FAILED;
  1646. }
  1647. static int
  1648. qla24xx_vport_delete(struct fc_vport *fc_vport)
  1649. {
  1650. scsi_qla_host_t *vha = fc_vport->dd_data;
  1651. struct qla_hw_data *ha = vha->hw;
  1652. uint16_t id = vha->vp_idx;
  1653. while (test_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags) ||
  1654. test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags))
  1655. msleep(1000);
  1656. qla24xx_disable_vp(vha);
  1657. vha->flags.delete_progress = 1;
  1658. fc_remove_host(vha->host);
  1659. scsi_remove_host(vha->host);
  1660. /* Allow timer to run to drain queued items, when removing vp */
  1661. qla24xx_deallocate_vp_id(vha);
  1662. if (vha->timer_active) {
  1663. qla2x00_vp_stop_timer(vha);
  1664. ql_dbg(ql_dbg_user, vha, 0x7086,
  1665. "Timer for the VP[%d] has stopped\n", vha->vp_idx);
  1666. }
  1667. /* No pending activities shall be there on the vha now */
  1668. if (ql2xextended_error_logging & ql_dbg_user)
  1669. msleep(random32()%10); /* Just to see if something falls on
  1670. * the net we have placed below */
  1671. BUG_ON(atomic_read(&vha->vref_count));
  1672. qla2x00_free_fcports(vha);
  1673. mutex_lock(&ha->vport_lock);
  1674. ha->cur_vport_count--;
  1675. clear_bit(vha->vp_idx, ha->vp_idx_map);
  1676. mutex_unlock(&ha->vport_lock);
  1677. if (vha->req->id && !ha->flags.cpu_affinity_enabled) {
  1678. if (qla25xx_delete_req_que(vha, vha->req) != QLA_SUCCESS)
  1679. ql_log(ql_log_warn, vha, 0x7087,
  1680. "Queue delete failed.\n");
  1681. }
  1682. ql_log(ql_log_info, vha, 0x7088, "VP[%d] deleted.\n", id);
  1683. scsi_host_put(vha->host);
  1684. return 0;
  1685. }
  1686. static int
  1687. qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
  1688. {
  1689. scsi_qla_host_t *vha = fc_vport->dd_data;
  1690. if (disable)
  1691. qla24xx_disable_vp(vha);
  1692. else
  1693. qla24xx_enable_vp(vha);
  1694. return 0;
  1695. }
  1696. struct fc_function_template qla2xxx_transport_functions = {
  1697. .show_host_node_name = 1,
  1698. .show_host_port_name = 1,
  1699. .show_host_supported_classes = 1,
  1700. .show_host_supported_speeds = 1,
  1701. .get_host_port_id = qla2x00_get_host_port_id,
  1702. .show_host_port_id = 1,
  1703. .get_host_speed = qla2x00_get_host_speed,
  1704. .show_host_speed = 1,
  1705. .get_host_port_type = qla2x00_get_host_port_type,
  1706. .show_host_port_type = 1,
  1707. .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
  1708. .show_host_symbolic_name = 1,
  1709. .set_host_system_hostname = qla2x00_set_host_system_hostname,
  1710. .show_host_system_hostname = 1,
  1711. .get_host_fabric_name = qla2x00_get_host_fabric_name,
  1712. .show_host_fabric_name = 1,
  1713. .get_host_port_state = qla2x00_get_host_port_state,
  1714. .show_host_port_state = 1,
  1715. .dd_fcrport_size = sizeof(struct fc_port *),
  1716. .show_rport_supported_classes = 1,
  1717. .get_starget_node_name = qla2x00_get_starget_node_name,
  1718. .show_starget_node_name = 1,
  1719. .get_starget_port_name = qla2x00_get_starget_port_name,
  1720. .show_starget_port_name = 1,
  1721. .get_starget_port_id = qla2x00_get_starget_port_id,
  1722. .show_starget_port_id = 1,
  1723. .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
  1724. .show_rport_dev_loss_tmo = 1,
  1725. .issue_fc_host_lip = qla2x00_issue_lip,
  1726. .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
  1727. .terminate_rport_io = qla2x00_terminate_rport_io,
  1728. .get_fc_host_stats = qla2x00_get_fc_host_stats,
  1729. .vport_create = qla24xx_vport_create,
  1730. .vport_disable = qla24xx_vport_disable,
  1731. .vport_delete = qla24xx_vport_delete,
  1732. .bsg_request = qla24xx_bsg_request,
  1733. .bsg_timeout = qla24xx_bsg_timeout,
  1734. };
  1735. struct fc_function_template qla2xxx_transport_vport_functions = {
  1736. .show_host_node_name = 1,
  1737. .show_host_port_name = 1,
  1738. .show_host_supported_classes = 1,
  1739. .get_host_port_id = qla2x00_get_host_port_id,
  1740. .show_host_port_id = 1,
  1741. .get_host_speed = qla2x00_get_host_speed,
  1742. .show_host_speed = 1,
  1743. .get_host_port_type = qla2x00_get_host_port_type,
  1744. .show_host_port_type = 1,
  1745. .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
  1746. .show_host_symbolic_name = 1,
  1747. .set_host_system_hostname = qla2x00_set_host_system_hostname,
  1748. .show_host_system_hostname = 1,
  1749. .get_host_fabric_name = qla2x00_get_host_fabric_name,
  1750. .show_host_fabric_name = 1,
  1751. .get_host_port_state = qla2x00_get_host_port_state,
  1752. .show_host_port_state = 1,
  1753. .dd_fcrport_size = sizeof(struct fc_port *),
  1754. .show_rport_supported_classes = 1,
  1755. .get_starget_node_name = qla2x00_get_starget_node_name,
  1756. .show_starget_node_name = 1,
  1757. .get_starget_port_name = qla2x00_get_starget_port_name,
  1758. .show_starget_port_name = 1,
  1759. .get_starget_port_id = qla2x00_get_starget_port_id,
  1760. .show_starget_port_id = 1,
  1761. .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
  1762. .show_rport_dev_loss_tmo = 1,
  1763. .issue_fc_host_lip = qla2x00_issue_lip,
  1764. .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
  1765. .terminate_rport_io = qla2x00_terminate_rport_io,
  1766. .get_fc_host_stats = qla2x00_get_fc_host_stats,
  1767. .bsg_request = qla24xx_bsg_request,
  1768. .bsg_timeout = qla24xx_bsg_timeout,
  1769. };
  1770. void
  1771. qla2x00_init_host_attr(scsi_qla_host_t *vha)
  1772. {
  1773. struct qla_hw_data *ha = vha->hw;
  1774. u32 speed = FC_PORTSPEED_UNKNOWN;
  1775. fc_host_dev_loss_tmo(vha->host) = ha->port_down_retry_count;
  1776. fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
  1777. fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
  1778. fc_host_supported_classes(vha->host) = FC_COS_CLASS3;
  1779. fc_host_max_npiv_vports(vha->host) = ha->max_npiv_vports;
  1780. fc_host_npiv_vports_inuse(vha->host) = ha->cur_vport_count;
  1781. if (IS_CNA_CAPABLE(ha))
  1782. speed = FC_PORTSPEED_10GBIT;
  1783. else if (IS_QLA25XX(ha))
  1784. speed = FC_PORTSPEED_8GBIT | FC_PORTSPEED_4GBIT |
  1785. FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
  1786. else if (IS_QLA24XX_TYPE(ha))
  1787. speed = FC_PORTSPEED_4GBIT | FC_PORTSPEED_2GBIT |
  1788. FC_PORTSPEED_1GBIT;
  1789. else if (IS_QLA23XX(ha))
  1790. speed = FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
  1791. else
  1792. speed = FC_PORTSPEED_1GBIT;
  1793. fc_host_supported_speeds(vha->host) = speed;
  1794. }