qla_attr.c 62 KB

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