qla_attr.c 56 KB

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