zfcp_fsf.c 68 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395
  1. /*
  2. * zfcp device driver
  3. *
  4. * Implementation of FSF commands.
  5. *
  6. * Copyright IBM Corporation 2002, 2008
  7. */
  8. #include "zfcp_ext.h"
  9. static void zfcp_fsf_request_timeout_handler(unsigned long data)
  10. {
  11. struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
  12. zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED, 62,
  13. NULL);
  14. }
  15. static void zfcp_fsf_start_timer(struct zfcp_fsf_req *fsf_req,
  16. unsigned long timeout)
  17. {
  18. fsf_req->timer.function = zfcp_fsf_request_timeout_handler;
  19. fsf_req->timer.data = (unsigned long) fsf_req->adapter;
  20. fsf_req->timer.expires = jiffies + timeout;
  21. add_timer(&fsf_req->timer);
  22. }
  23. static void zfcp_fsf_start_erp_timer(struct zfcp_fsf_req *fsf_req)
  24. {
  25. BUG_ON(!fsf_req->erp_action);
  26. fsf_req->timer.function = zfcp_erp_timeout_handler;
  27. fsf_req->timer.data = (unsigned long) fsf_req->erp_action;
  28. fsf_req->timer.expires = jiffies + 30 * HZ;
  29. add_timer(&fsf_req->timer);
  30. }
  31. /* association between FSF command and FSF QTCB type */
  32. static u32 fsf_qtcb_type[] = {
  33. [FSF_QTCB_FCP_CMND] = FSF_IO_COMMAND,
  34. [FSF_QTCB_ABORT_FCP_CMND] = FSF_SUPPORT_COMMAND,
  35. [FSF_QTCB_OPEN_PORT_WITH_DID] = FSF_SUPPORT_COMMAND,
  36. [FSF_QTCB_OPEN_LUN] = FSF_SUPPORT_COMMAND,
  37. [FSF_QTCB_CLOSE_LUN] = FSF_SUPPORT_COMMAND,
  38. [FSF_QTCB_CLOSE_PORT] = FSF_SUPPORT_COMMAND,
  39. [FSF_QTCB_CLOSE_PHYSICAL_PORT] = FSF_SUPPORT_COMMAND,
  40. [FSF_QTCB_SEND_ELS] = FSF_SUPPORT_COMMAND,
  41. [FSF_QTCB_SEND_GENERIC] = FSF_SUPPORT_COMMAND,
  42. [FSF_QTCB_EXCHANGE_CONFIG_DATA] = FSF_CONFIG_COMMAND,
  43. [FSF_QTCB_EXCHANGE_PORT_DATA] = FSF_PORT_COMMAND,
  44. [FSF_QTCB_DOWNLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND,
  45. [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND
  46. };
  47. static void zfcp_act_eval_err(struct zfcp_adapter *adapter, u32 table)
  48. {
  49. u16 subtable = table >> 16;
  50. u16 rule = table & 0xffff;
  51. const char *act_type[] = { "unknown", "OS", "WWPN", "DID", "LUN" };
  52. if (subtable && subtable < ARRAY_SIZE(act_type))
  53. dev_warn(&adapter->ccw_device->dev,
  54. "Access denied according to ACT rule type %s, "
  55. "rule %d\n", act_type[subtable], rule);
  56. }
  57. static void zfcp_fsf_access_denied_port(struct zfcp_fsf_req *req,
  58. struct zfcp_port *port)
  59. {
  60. struct fsf_qtcb_header *header = &req->qtcb->header;
  61. dev_warn(&req->adapter->ccw_device->dev,
  62. "Access denied to port 0x%016Lx\n",
  63. port->wwpn);
  64. zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
  65. zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
  66. zfcp_erp_port_access_denied(port, 55, req);
  67. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  68. }
  69. static void zfcp_fsf_access_denied_unit(struct zfcp_fsf_req *req,
  70. struct zfcp_unit *unit)
  71. {
  72. struct fsf_qtcb_header *header = &req->qtcb->header;
  73. dev_warn(&req->adapter->ccw_device->dev,
  74. "Access denied to unit 0x%016Lx on port 0x%016Lx\n",
  75. unit->fcp_lun, unit->port->wwpn);
  76. zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[0]);
  77. zfcp_act_eval_err(req->adapter, header->fsf_status_qual.halfword[1]);
  78. zfcp_erp_unit_access_denied(unit, 59, req);
  79. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  80. }
  81. static void zfcp_fsf_class_not_supp(struct zfcp_fsf_req *req)
  82. {
  83. dev_err(&req->adapter->ccw_device->dev, "FCP device not "
  84. "operational because of an unsupported FC class\n");
  85. zfcp_erp_adapter_shutdown(req->adapter, 0, 123, req);
  86. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  87. }
  88. /**
  89. * zfcp_fsf_req_free - free memory used by fsf request
  90. * @fsf_req: pointer to struct zfcp_fsf_req
  91. */
  92. void zfcp_fsf_req_free(struct zfcp_fsf_req *req)
  93. {
  94. if (likely(req->pool)) {
  95. mempool_free(req, req->pool);
  96. return;
  97. }
  98. if (req->qtcb) {
  99. kmem_cache_free(zfcp_data.fsf_req_qtcb_cache, req);
  100. return;
  101. }
  102. }
  103. /**
  104. * zfcp_fsf_req_dismiss_all - dismiss all fsf requests
  105. * @adapter: pointer to struct zfcp_adapter
  106. *
  107. * Never ever call this without shutting down the adapter first.
  108. * Otherwise the adapter would continue using and corrupting s390 storage.
  109. * Included BUG_ON() call to ensure this is done.
  110. * ERP is supposed to be the only user of this function.
  111. */
  112. void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
  113. {
  114. struct zfcp_fsf_req *req, *tmp;
  115. unsigned long flags;
  116. LIST_HEAD(remove_queue);
  117. unsigned int i;
  118. BUG_ON(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP);
  119. spin_lock_irqsave(&adapter->req_list_lock, flags);
  120. for (i = 0; i < REQUEST_LIST_SIZE; i++)
  121. list_splice_init(&adapter->req_list[i], &remove_queue);
  122. spin_unlock_irqrestore(&adapter->req_list_lock, flags);
  123. list_for_each_entry_safe(req, tmp, &remove_queue, list) {
  124. list_del(&req->list);
  125. req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
  126. zfcp_fsf_req_complete(req);
  127. }
  128. }
  129. static void zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *req)
  130. {
  131. struct fsf_status_read_buffer *sr_buf = req->data;
  132. struct zfcp_adapter *adapter = req->adapter;
  133. struct zfcp_port *port;
  134. int d_id = sr_buf->d_id & ZFCP_DID_MASK;
  135. unsigned long flags;
  136. read_lock_irqsave(&zfcp_data.config_lock, flags);
  137. list_for_each_entry(port, &adapter->port_list_head, list)
  138. if (port->d_id == d_id) {
  139. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  140. switch (sr_buf->status_subtype) {
  141. case FSF_STATUS_READ_SUB_CLOSE_PHYS_PORT:
  142. zfcp_erp_port_reopen(port, 0, 101, req);
  143. break;
  144. case FSF_STATUS_READ_SUB_ERROR_PORT:
  145. zfcp_erp_port_shutdown(port, 0, 122, req);
  146. break;
  147. }
  148. return;
  149. }
  150. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  151. }
  152. static void zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *req, u8 id,
  153. struct fsf_link_down_info *link_down)
  154. {
  155. struct zfcp_adapter *adapter = req->adapter;
  156. if (atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED)
  157. return;
  158. atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
  159. if (!link_down)
  160. goto out;
  161. switch (link_down->error_code) {
  162. case FSF_PSQ_LINK_NO_LIGHT:
  163. dev_warn(&req->adapter->ccw_device->dev,
  164. "There is no light signal from the local "
  165. "fibre channel cable\n");
  166. break;
  167. case FSF_PSQ_LINK_WRAP_PLUG:
  168. dev_warn(&req->adapter->ccw_device->dev,
  169. "There is a wrap plug instead of a fibre "
  170. "channel cable\n");
  171. break;
  172. case FSF_PSQ_LINK_NO_FCP:
  173. dev_warn(&req->adapter->ccw_device->dev,
  174. "The adjacent fibre channel node does not "
  175. "support FCP\n");
  176. break;
  177. case FSF_PSQ_LINK_FIRMWARE_UPDATE:
  178. dev_warn(&req->adapter->ccw_device->dev,
  179. "The FCP device is suspended because of a "
  180. "firmware update\n");
  181. break;
  182. case FSF_PSQ_LINK_INVALID_WWPN:
  183. dev_warn(&req->adapter->ccw_device->dev,
  184. "The FCP device detected a WWPN that is "
  185. "duplicate or not valid\n");
  186. break;
  187. case FSF_PSQ_LINK_NO_NPIV_SUPPORT:
  188. dev_warn(&req->adapter->ccw_device->dev,
  189. "The fibre channel fabric does not support NPIV\n");
  190. break;
  191. case FSF_PSQ_LINK_NO_FCP_RESOURCES:
  192. dev_warn(&req->adapter->ccw_device->dev,
  193. "The FCP adapter cannot support more NPIV ports\n");
  194. break;
  195. case FSF_PSQ_LINK_NO_FABRIC_RESOURCES:
  196. dev_warn(&req->adapter->ccw_device->dev,
  197. "The adjacent switch cannot support "
  198. "more NPIV ports\n");
  199. break;
  200. case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE:
  201. dev_warn(&req->adapter->ccw_device->dev,
  202. "The FCP adapter could not log in to the "
  203. "fibre channel fabric\n");
  204. break;
  205. case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED:
  206. dev_warn(&req->adapter->ccw_device->dev,
  207. "The WWPN assignment file on the FCP adapter "
  208. "has been damaged\n");
  209. break;
  210. case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED:
  211. dev_warn(&req->adapter->ccw_device->dev,
  212. "The mode table on the FCP adapter "
  213. "has been damaged\n");
  214. break;
  215. case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT:
  216. dev_warn(&req->adapter->ccw_device->dev,
  217. "All NPIV ports on the FCP adapter have "
  218. "been assigned\n");
  219. break;
  220. default:
  221. dev_warn(&req->adapter->ccw_device->dev,
  222. "The link between the FCP adapter and "
  223. "the FC fabric is down\n");
  224. }
  225. out:
  226. zfcp_erp_adapter_failed(adapter, id, req);
  227. }
  228. static void zfcp_fsf_status_read_link_down(struct zfcp_fsf_req *req)
  229. {
  230. struct fsf_status_read_buffer *sr_buf = req->data;
  231. struct fsf_link_down_info *ldi =
  232. (struct fsf_link_down_info *) &sr_buf->payload;
  233. switch (sr_buf->status_subtype) {
  234. case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
  235. zfcp_fsf_link_down_info_eval(req, 38, ldi);
  236. break;
  237. case FSF_STATUS_READ_SUB_FDISC_FAILED:
  238. zfcp_fsf_link_down_info_eval(req, 39, ldi);
  239. break;
  240. case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE:
  241. zfcp_fsf_link_down_info_eval(req, 40, NULL);
  242. };
  243. }
  244. static void zfcp_fsf_status_read_handler(struct zfcp_fsf_req *req)
  245. {
  246. struct zfcp_adapter *adapter = req->adapter;
  247. struct fsf_status_read_buffer *sr_buf = req->data;
  248. if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
  249. zfcp_hba_dbf_event_fsf_unsol("dism", adapter, sr_buf);
  250. mempool_free(sr_buf, adapter->pool.data_status_read);
  251. zfcp_fsf_req_free(req);
  252. return;
  253. }
  254. zfcp_hba_dbf_event_fsf_unsol("read", adapter, sr_buf);
  255. switch (sr_buf->status_type) {
  256. case FSF_STATUS_READ_PORT_CLOSED:
  257. zfcp_fsf_status_read_port_closed(req);
  258. break;
  259. case FSF_STATUS_READ_INCOMING_ELS:
  260. zfcp_fc_incoming_els(req);
  261. break;
  262. case FSF_STATUS_READ_SENSE_DATA_AVAIL:
  263. break;
  264. case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
  265. dev_warn(&adapter->ccw_device->dev,
  266. "The error threshold for checksum statistics "
  267. "has been exceeded\n");
  268. break;
  269. case FSF_STATUS_READ_LINK_DOWN:
  270. zfcp_fsf_status_read_link_down(req);
  271. break;
  272. case FSF_STATUS_READ_LINK_UP:
  273. dev_info(&adapter->ccw_device->dev,
  274. "The local link has been restored\n");
  275. /* All ports should be marked as ready to run again */
  276. zfcp_erp_modify_adapter_status(adapter, 30, NULL,
  277. ZFCP_STATUS_COMMON_RUNNING,
  278. ZFCP_SET);
  279. zfcp_erp_adapter_reopen(adapter,
  280. ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
  281. ZFCP_STATUS_COMMON_ERP_FAILED,
  282. 102, req);
  283. break;
  284. case FSF_STATUS_READ_NOTIFICATION_LOST:
  285. if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_ACT_UPDATED)
  286. zfcp_erp_adapter_access_changed(adapter, 135, req);
  287. if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_INCOMING_ELS)
  288. schedule_work(&adapter->scan_work);
  289. break;
  290. case FSF_STATUS_READ_CFDC_UPDATED:
  291. zfcp_erp_adapter_access_changed(adapter, 136, req);
  292. break;
  293. case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
  294. adapter->adapter_features = sr_buf->payload.word[0];
  295. break;
  296. }
  297. mempool_free(sr_buf, adapter->pool.data_status_read);
  298. zfcp_fsf_req_free(req);
  299. atomic_inc(&adapter->stat_miss);
  300. schedule_work(&adapter->stat_work);
  301. }
  302. static void zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *req)
  303. {
  304. switch (req->qtcb->header.fsf_status_qual.word[0]) {
  305. case FSF_SQ_FCP_RSP_AVAILABLE:
  306. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  307. case FSF_SQ_NO_RETRY_POSSIBLE:
  308. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  309. return;
  310. case FSF_SQ_COMMAND_ABORTED:
  311. req->status |= ZFCP_STATUS_FSFREQ_ABORTED;
  312. break;
  313. case FSF_SQ_NO_RECOM:
  314. dev_err(&req->adapter->ccw_device->dev,
  315. "The FCP adapter reported a problem "
  316. "that cannot be recovered\n");
  317. zfcp_erp_adapter_shutdown(req->adapter, 0, 121, req);
  318. break;
  319. }
  320. /* all non-return stats set FSFREQ_ERROR*/
  321. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  322. }
  323. static void zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *req)
  324. {
  325. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
  326. return;
  327. switch (req->qtcb->header.fsf_status) {
  328. case FSF_UNKNOWN_COMMAND:
  329. dev_err(&req->adapter->ccw_device->dev,
  330. "The FCP adapter does not recognize the command 0x%x\n",
  331. req->qtcb->header.fsf_command);
  332. zfcp_erp_adapter_shutdown(req->adapter, 0, 120, req);
  333. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  334. break;
  335. case FSF_ADAPTER_STATUS_AVAILABLE:
  336. zfcp_fsf_fsfstatus_qual_eval(req);
  337. break;
  338. }
  339. }
  340. static void zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *req)
  341. {
  342. struct zfcp_adapter *adapter = req->adapter;
  343. struct fsf_qtcb *qtcb = req->qtcb;
  344. union fsf_prot_status_qual *psq = &qtcb->prefix.prot_status_qual;
  345. zfcp_hba_dbf_event_fsf_response(req);
  346. if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
  347. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  348. ZFCP_STATUS_FSFREQ_RETRY; /* only for SCSI cmnds. */
  349. return;
  350. }
  351. switch (qtcb->prefix.prot_status) {
  352. case FSF_PROT_GOOD:
  353. case FSF_PROT_FSF_STATUS_PRESENTED:
  354. return;
  355. case FSF_PROT_QTCB_VERSION_ERROR:
  356. dev_err(&adapter->ccw_device->dev,
  357. "QTCB version 0x%x not supported by FCP adapter "
  358. "(0x%x to 0x%x)\n", FSF_QTCB_CURRENT_VERSION,
  359. psq->word[0], psq->word[1]);
  360. zfcp_erp_adapter_shutdown(adapter, 0, 117, req);
  361. break;
  362. case FSF_PROT_ERROR_STATE:
  363. case FSF_PROT_SEQ_NUMB_ERROR:
  364. zfcp_erp_adapter_reopen(adapter, 0, 98, req);
  365. req->status |= ZFCP_STATUS_FSFREQ_RETRY;
  366. break;
  367. case FSF_PROT_UNSUPP_QTCB_TYPE:
  368. dev_err(&adapter->ccw_device->dev,
  369. "The QTCB type is not supported by the FCP adapter\n");
  370. zfcp_erp_adapter_shutdown(adapter, 0, 118, req);
  371. break;
  372. case FSF_PROT_HOST_CONNECTION_INITIALIZING:
  373. atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
  374. &adapter->status);
  375. break;
  376. case FSF_PROT_DUPLICATE_REQUEST_ID:
  377. dev_err(&adapter->ccw_device->dev,
  378. "0x%Lx is an ambiguous request identifier\n",
  379. (unsigned long long)qtcb->bottom.support.req_handle);
  380. zfcp_erp_adapter_shutdown(adapter, 0, 78, req);
  381. break;
  382. case FSF_PROT_LINK_DOWN:
  383. zfcp_fsf_link_down_info_eval(req, 37, &psq->link_down_info);
  384. /* FIXME: reopening adapter now? better wait for link up */
  385. zfcp_erp_adapter_reopen(adapter, 0, 79, req);
  386. break;
  387. case FSF_PROT_REEST_QUEUE:
  388. /* All ports should be marked as ready to run again */
  389. zfcp_erp_modify_adapter_status(adapter, 28, NULL,
  390. ZFCP_STATUS_COMMON_RUNNING,
  391. ZFCP_SET);
  392. zfcp_erp_adapter_reopen(adapter,
  393. ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
  394. ZFCP_STATUS_COMMON_ERP_FAILED, 99, req);
  395. break;
  396. default:
  397. dev_err(&adapter->ccw_device->dev,
  398. "0x%x is not a valid transfer protocol status\n",
  399. qtcb->prefix.prot_status);
  400. zfcp_erp_adapter_shutdown(adapter, 0, 119, req);
  401. }
  402. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  403. }
  404. /**
  405. * zfcp_fsf_req_complete - process completion of a FSF request
  406. * @fsf_req: The FSF request that has been completed.
  407. *
  408. * When a request has been completed either from the FCP adapter,
  409. * or it has been dismissed due to a queue shutdown, this function
  410. * is called to process the completion status and trigger further
  411. * events related to the FSF request.
  412. */
  413. void zfcp_fsf_req_complete(struct zfcp_fsf_req *req)
  414. {
  415. if (unlikely(req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) {
  416. zfcp_fsf_status_read_handler(req);
  417. return;
  418. }
  419. del_timer(&req->timer);
  420. zfcp_fsf_protstatus_eval(req);
  421. zfcp_fsf_fsfstatus_eval(req);
  422. req->handler(req);
  423. if (req->erp_action)
  424. zfcp_erp_notify(req->erp_action, 0);
  425. req->status |= ZFCP_STATUS_FSFREQ_COMPLETED;
  426. if (likely(req->status & ZFCP_STATUS_FSFREQ_CLEANUP))
  427. zfcp_fsf_req_free(req);
  428. else
  429. /* notify initiator waiting for the requests completion */
  430. /*
  431. * FIXME: Race! We must not access fsf_req here as it might have been
  432. * cleaned up already due to the set ZFCP_STATUS_FSFREQ_COMPLETED
  433. * flag. It's an improbable case. But, we have the same paranoia for
  434. * the cleanup flag already.
  435. * Might better be handled using complete()?
  436. * (setting the flag and doing wakeup ought to be atomic
  437. * with regard to checking the flag as long as waitqueue is
  438. * part of the to be released structure)
  439. */
  440. wake_up(&req->completion_wq);
  441. }
  442. static int zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *req)
  443. {
  444. struct fsf_qtcb_bottom_config *bottom;
  445. struct zfcp_adapter *adapter = req->adapter;
  446. struct Scsi_Host *shost = adapter->scsi_host;
  447. bottom = &req->qtcb->bottom.config;
  448. if (req->data)
  449. memcpy(req->data, bottom, sizeof(*bottom));
  450. fc_host_node_name(shost) = bottom->nport_serv_param.wwnn;
  451. fc_host_port_name(shost) = bottom->nport_serv_param.wwpn;
  452. fc_host_port_id(shost) = bottom->s_id & ZFCP_DID_MASK;
  453. fc_host_speed(shost) = bottom->fc_link_speed;
  454. fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3;
  455. adapter->hydra_version = bottom->adapter_type;
  456. adapter->timer_ticks = bottom->timer_interval;
  457. if (fc_host_permanent_port_name(shost) == -1)
  458. fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
  459. switch (bottom->fc_topology) {
  460. case FSF_TOPO_P2P:
  461. adapter->peer_d_id = bottom->peer_d_id & ZFCP_DID_MASK;
  462. adapter->peer_wwpn = bottom->plogi_payload.wwpn;
  463. adapter->peer_wwnn = bottom->plogi_payload.wwnn;
  464. fc_host_port_type(shost) = FC_PORTTYPE_PTP;
  465. break;
  466. case FSF_TOPO_FABRIC:
  467. fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
  468. break;
  469. case FSF_TOPO_AL:
  470. fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
  471. default:
  472. dev_err(&adapter->ccw_device->dev,
  473. "Unknown or unsupported arbitrated loop "
  474. "fibre channel topology detected\n");
  475. zfcp_erp_adapter_shutdown(adapter, 0, 127, req);
  476. return -EIO;
  477. }
  478. return 0;
  479. }
  480. static void zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *req)
  481. {
  482. struct zfcp_adapter *adapter = req->adapter;
  483. struct fsf_qtcb *qtcb = req->qtcb;
  484. struct fsf_qtcb_bottom_config *bottom = &qtcb->bottom.config;
  485. struct Scsi_Host *shost = adapter->scsi_host;
  486. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  487. return;
  488. adapter->fsf_lic_version = bottom->lic_version;
  489. adapter->adapter_features = bottom->adapter_features;
  490. adapter->connection_features = bottom->connection_features;
  491. adapter->peer_wwpn = 0;
  492. adapter->peer_wwnn = 0;
  493. adapter->peer_d_id = 0;
  494. switch (qtcb->header.fsf_status) {
  495. case FSF_GOOD:
  496. if (zfcp_fsf_exchange_config_evaluate(req))
  497. return;
  498. if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
  499. dev_err(&adapter->ccw_device->dev,
  500. "FCP adapter maximum QTCB size (%d bytes) "
  501. "is too small\n",
  502. bottom->max_qtcb_size);
  503. zfcp_erp_adapter_shutdown(adapter, 0, 129, req);
  504. return;
  505. }
  506. atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
  507. &adapter->status);
  508. break;
  509. case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
  510. fc_host_node_name(shost) = 0;
  511. fc_host_port_name(shost) = 0;
  512. fc_host_port_id(shost) = 0;
  513. fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
  514. fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
  515. adapter->hydra_version = 0;
  516. atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
  517. &adapter->status);
  518. zfcp_fsf_link_down_info_eval(req, 42,
  519. &qtcb->header.fsf_status_qual.link_down_info);
  520. break;
  521. default:
  522. zfcp_erp_adapter_shutdown(adapter, 0, 130, req);
  523. return;
  524. }
  525. if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
  526. adapter->hardware_version = bottom->hardware_version;
  527. memcpy(fc_host_serial_number(shost), bottom->serial_number,
  528. min(FC_SERIAL_NUMBER_SIZE, 17));
  529. EBCASC(fc_host_serial_number(shost),
  530. min(FC_SERIAL_NUMBER_SIZE, 17));
  531. }
  532. if (FSF_QTCB_CURRENT_VERSION < bottom->low_qtcb_version) {
  533. dev_err(&adapter->ccw_device->dev,
  534. "The FCP adapter only supports newer "
  535. "control block versions\n");
  536. zfcp_erp_adapter_shutdown(adapter, 0, 125, req);
  537. return;
  538. }
  539. if (FSF_QTCB_CURRENT_VERSION > bottom->high_qtcb_version) {
  540. dev_err(&adapter->ccw_device->dev,
  541. "The FCP adapter only supports older "
  542. "control block versions\n");
  543. zfcp_erp_adapter_shutdown(adapter, 0, 126, req);
  544. }
  545. }
  546. static void zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *req)
  547. {
  548. struct zfcp_adapter *adapter = req->adapter;
  549. struct fsf_qtcb_bottom_port *bottom = &req->qtcb->bottom.port;
  550. struct Scsi_Host *shost = adapter->scsi_host;
  551. if (req->data)
  552. memcpy(req->data, bottom, sizeof(*bottom));
  553. if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
  554. fc_host_permanent_port_name(shost) = bottom->wwpn;
  555. else
  556. fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
  557. fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
  558. fc_host_supported_speeds(shost) = bottom->supported_speed;
  559. }
  560. static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *req)
  561. {
  562. struct zfcp_adapter *adapter = req->adapter;
  563. struct fsf_qtcb *qtcb = req->qtcb;
  564. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  565. return;
  566. switch (qtcb->header.fsf_status) {
  567. case FSF_GOOD:
  568. zfcp_fsf_exchange_port_evaluate(req);
  569. atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
  570. break;
  571. case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
  572. zfcp_fsf_exchange_port_evaluate(req);
  573. atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
  574. zfcp_fsf_link_down_info_eval(req, 43,
  575. &qtcb->header.fsf_status_qual.link_down_info);
  576. break;
  577. }
  578. }
  579. static int zfcp_fsf_sbal_check(struct zfcp_qdio_queue *queue)
  580. {
  581. spin_lock_bh(&queue->lock);
  582. if (atomic_read(&queue->count))
  583. return 1;
  584. spin_unlock_bh(&queue->lock);
  585. return 0;
  586. }
  587. static int zfcp_fsf_sbal_available(struct zfcp_adapter *adapter)
  588. {
  589. unsigned int count = atomic_read(&adapter->req_q.count);
  590. if (!count)
  591. atomic_inc(&adapter->qdio_outb_full);
  592. return count > 0;
  593. }
  594. static int zfcp_fsf_req_sbal_get(struct zfcp_adapter *adapter)
  595. {
  596. long ret;
  597. struct zfcp_qdio_queue *req_q = &adapter->req_q;
  598. spin_unlock_bh(&req_q->lock);
  599. ret = wait_event_interruptible_timeout(adapter->request_wq,
  600. zfcp_fsf_sbal_check(req_q), 5 * HZ);
  601. if (ret > 0)
  602. return 0;
  603. if (!ret)
  604. atomic_inc(&adapter->qdio_outb_full);
  605. spin_lock_bh(&req_q->lock);
  606. return -EIO;
  607. }
  608. static struct zfcp_fsf_req *zfcp_fsf_alloc_noqtcb(mempool_t *pool)
  609. {
  610. struct zfcp_fsf_req *req;
  611. req = mempool_alloc(pool, GFP_ATOMIC);
  612. if (!req)
  613. return NULL;
  614. memset(req, 0, sizeof(*req));
  615. return req;
  616. }
  617. static struct zfcp_fsf_req *zfcp_fsf_alloc_qtcb(mempool_t *pool)
  618. {
  619. struct zfcp_fsf_req_qtcb *qtcb;
  620. if (likely(pool))
  621. qtcb = mempool_alloc(pool, GFP_ATOMIC);
  622. else
  623. qtcb = kmem_cache_alloc(zfcp_data.fsf_req_qtcb_cache,
  624. GFP_ATOMIC);
  625. if (unlikely(!qtcb))
  626. return NULL;
  627. memset(qtcb, 0, sizeof(*qtcb));
  628. qtcb->fsf_req.qtcb = &qtcb->qtcb;
  629. qtcb->fsf_req.pool = pool;
  630. return &qtcb->fsf_req;
  631. }
  632. static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_adapter *adapter,
  633. u32 fsf_cmd, int req_flags,
  634. mempool_t *pool)
  635. {
  636. volatile struct qdio_buffer_element *sbale;
  637. struct zfcp_fsf_req *req;
  638. struct zfcp_qdio_queue *req_q = &adapter->req_q;
  639. if (req_flags & ZFCP_REQ_NO_QTCB)
  640. req = zfcp_fsf_alloc_noqtcb(pool);
  641. else
  642. req = zfcp_fsf_alloc_qtcb(pool);
  643. if (unlikely(!req))
  644. return ERR_PTR(-EIO);
  645. if (adapter->req_no == 0)
  646. adapter->req_no++;
  647. INIT_LIST_HEAD(&req->list);
  648. init_timer(&req->timer);
  649. init_waitqueue_head(&req->completion_wq);
  650. req->adapter = adapter;
  651. req->fsf_command = fsf_cmd;
  652. req->req_id = adapter->req_no++;
  653. req->sbal_number = 1;
  654. req->sbal_first = req_q->first;
  655. req->sbal_last = req_q->first;
  656. req->sbale_curr = 1;
  657. sbale = zfcp_qdio_sbale_req(req);
  658. sbale[0].addr = (void *) req->req_id;
  659. sbale[0].flags |= SBAL_FLAGS0_COMMAND;
  660. if (likely(req->qtcb)) {
  661. req->qtcb->prefix.req_seq_no = req->adapter->fsf_req_seq_no;
  662. req->qtcb->prefix.req_id = req->req_id;
  663. req->qtcb->prefix.ulp_info = 26;
  664. req->qtcb->prefix.qtcb_type = fsf_qtcb_type[req->fsf_command];
  665. req->qtcb->prefix.qtcb_version = FSF_QTCB_CURRENT_VERSION;
  666. req->qtcb->header.req_handle = req->req_id;
  667. req->qtcb->header.fsf_command = req->fsf_command;
  668. req->seq_no = adapter->fsf_req_seq_no;
  669. req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
  670. sbale[1].addr = (void *) req->qtcb;
  671. sbale[1].length = sizeof(struct fsf_qtcb);
  672. }
  673. if (!(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP)) {
  674. zfcp_fsf_req_free(req);
  675. return ERR_PTR(-EIO);
  676. }
  677. if (likely(req_flags & ZFCP_REQ_AUTO_CLEANUP))
  678. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  679. return req;
  680. }
  681. static int zfcp_fsf_req_send(struct zfcp_fsf_req *req)
  682. {
  683. struct zfcp_adapter *adapter = req->adapter;
  684. struct zfcp_qdio_queue *req_q = &adapter->req_q;
  685. int idx;
  686. /* put allocated FSF request into hash table */
  687. spin_lock(&adapter->req_list_lock);
  688. idx = zfcp_reqlist_hash(req->req_id);
  689. list_add_tail(&req->list, &adapter->req_list[idx]);
  690. spin_unlock(&adapter->req_list_lock);
  691. req->issued = get_clock();
  692. if (zfcp_qdio_send(req)) {
  693. /* Queues are down..... */
  694. del_timer(&req->timer);
  695. spin_lock(&adapter->req_list_lock);
  696. zfcp_reqlist_remove(adapter, req);
  697. spin_unlock(&adapter->req_list_lock);
  698. /* undo changes in request queue made for this request */
  699. atomic_add(req->sbal_number, &req_q->count);
  700. req_q->first -= req->sbal_number;
  701. req_q->first += QDIO_MAX_BUFFERS_PER_Q;
  702. req_q->first %= QDIO_MAX_BUFFERS_PER_Q; /* wrap */
  703. zfcp_erp_adapter_reopen(adapter, 0, 116, req);
  704. return -EIO;
  705. }
  706. /* Don't increase for unsolicited status */
  707. if (req->qtcb)
  708. adapter->fsf_req_seq_no++;
  709. return 0;
  710. }
  711. /**
  712. * zfcp_fsf_status_read - send status read request
  713. * @adapter: pointer to struct zfcp_adapter
  714. * @req_flags: request flags
  715. * Returns: 0 on success, ERROR otherwise
  716. */
  717. int zfcp_fsf_status_read(struct zfcp_adapter *adapter)
  718. {
  719. struct zfcp_fsf_req *req;
  720. struct fsf_status_read_buffer *sr_buf;
  721. volatile struct qdio_buffer_element *sbale;
  722. int retval = -EIO;
  723. spin_lock_bh(&adapter->req_q.lock);
  724. if (zfcp_fsf_req_sbal_get(adapter))
  725. goto out;
  726. req = zfcp_fsf_req_create(adapter, FSF_QTCB_UNSOLICITED_STATUS,
  727. ZFCP_REQ_NO_QTCB,
  728. adapter->pool.fsf_req_status_read);
  729. if (IS_ERR(req)) {
  730. retval = PTR_ERR(req);
  731. goto out;
  732. }
  733. sbale = zfcp_qdio_sbale_req(req);
  734. sbale[0].flags |= SBAL_FLAGS0_TYPE_STATUS;
  735. sbale[2].flags |= SBAL_FLAGS_LAST_ENTRY;
  736. req->sbale_curr = 2;
  737. sr_buf = mempool_alloc(adapter->pool.data_status_read, GFP_ATOMIC);
  738. if (!sr_buf) {
  739. retval = -ENOMEM;
  740. goto failed_buf;
  741. }
  742. memset(sr_buf, 0, sizeof(*sr_buf));
  743. req->data = sr_buf;
  744. sbale = zfcp_qdio_sbale_curr(req);
  745. sbale->addr = (void *) sr_buf;
  746. sbale->length = sizeof(*sr_buf);
  747. retval = zfcp_fsf_req_send(req);
  748. if (retval)
  749. goto failed_req_send;
  750. goto out;
  751. failed_req_send:
  752. mempool_free(sr_buf, adapter->pool.data_status_read);
  753. failed_buf:
  754. zfcp_fsf_req_free(req);
  755. zfcp_hba_dbf_event_fsf_unsol("fail", adapter, NULL);
  756. out:
  757. spin_unlock_bh(&adapter->req_q.lock);
  758. return retval;
  759. }
  760. static void zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *req)
  761. {
  762. struct zfcp_unit *unit = req->data;
  763. union fsf_status_qual *fsq = &req->qtcb->header.fsf_status_qual;
  764. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  765. return;
  766. switch (req->qtcb->header.fsf_status) {
  767. case FSF_PORT_HANDLE_NOT_VALID:
  768. if (fsq->word[0] == fsq->word[1]) {
  769. zfcp_erp_adapter_reopen(unit->port->adapter, 0, 104,
  770. req);
  771. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  772. }
  773. break;
  774. case FSF_LUN_HANDLE_NOT_VALID:
  775. if (fsq->word[0] == fsq->word[1]) {
  776. zfcp_erp_port_reopen(unit->port, 0, 105, req);
  777. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  778. }
  779. break;
  780. case FSF_FCP_COMMAND_DOES_NOT_EXIST:
  781. req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
  782. break;
  783. case FSF_PORT_BOXED:
  784. zfcp_erp_port_boxed(unit->port, 47, req);
  785. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  786. ZFCP_STATUS_FSFREQ_RETRY;
  787. break;
  788. case FSF_LUN_BOXED:
  789. zfcp_erp_unit_boxed(unit, 48, req);
  790. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  791. ZFCP_STATUS_FSFREQ_RETRY;
  792. break;
  793. case FSF_ADAPTER_STATUS_AVAILABLE:
  794. switch (fsq->word[0]) {
  795. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  796. zfcp_test_link(unit->port);
  797. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  798. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  799. break;
  800. }
  801. break;
  802. case FSF_GOOD:
  803. req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
  804. break;
  805. }
  806. }
  807. /**
  808. * zfcp_fsf_abort_fcp_command - abort running SCSI command
  809. * @old_req_id: unsigned long
  810. * @adapter: pointer to struct zfcp_adapter
  811. * @unit: pointer to struct zfcp_unit
  812. * @req_flags: integer specifying the request flags
  813. * Returns: pointer to struct zfcp_fsf_req
  814. *
  815. * FIXME(design): should be watched by a timeout !!!
  816. */
  817. struct zfcp_fsf_req *zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
  818. struct zfcp_adapter *adapter,
  819. struct zfcp_unit *unit,
  820. int req_flags)
  821. {
  822. volatile struct qdio_buffer_element *sbale;
  823. struct zfcp_fsf_req *req = NULL;
  824. spin_lock(&adapter->req_q.lock);
  825. if (!zfcp_fsf_sbal_available(adapter))
  826. goto out;
  827. req = zfcp_fsf_req_create(adapter, FSF_QTCB_ABORT_FCP_CMND,
  828. req_flags, adapter->pool.fsf_req_abort);
  829. if (IS_ERR(req))
  830. goto out;
  831. if (unlikely(!(atomic_read(&unit->status) &
  832. ZFCP_STATUS_COMMON_UNBLOCKED)))
  833. goto out_error_free;
  834. sbale = zfcp_qdio_sbale_req(req);
  835. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  836. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  837. req->data = unit;
  838. req->handler = zfcp_fsf_abort_fcp_command_handler;
  839. req->qtcb->header.lun_handle = unit->handle;
  840. req->qtcb->header.port_handle = unit->port->handle;
  841. req->qtcb->bottom.support.req_handle = (u64) old_req_id;
  842. zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
  843. if (!zfcp_fsf_req_send(req))
  844. goto out;
  845. out_error_free:
  846. zfcp_fsf_req_free(req);
  847. req = NULL;
  848. out:
  849. spin_unlock(&adapter->req_q.lock);
  850. return req;
  851. }
  852. static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req)
  853. {
  854. struct zfcp_adapter *adapter = req->adapter;
  855. struct zfcp_send_ct *send_ct = req->data;
  856. struct zfcp_port *port = send_ct->port;
  857. struct fsf_qtcb_header *header = &req->qtcb->header;
  858. send_ct->status = -EINVAL;
  859. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  860. goto skip_fsfstatus;
  861. switch (header->fsf_status) {
  862. case FSF_GOOD:
  863. zfcp_san_dbf_event_ct_response(req);
  864. send_ct->status = 0;
  865. break;
  866. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  867. zfcp_fsf_class_not_supp(req);
  868. break;
  869. case FSF_ADAPTER_STATUS_AVAILABLE:
  870. switch (header->fsf_status_qual.word[0]){
  871. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  872. zfcp_test_link(port);
  873. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  874. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  875. break;
  876. }
  877. break;
  878. case FSF_ACCESS_DENIED:
  879. zfcp_fsf_access_denied_port(req, port);
  880. break;
  881. case FSF_PORT_BOXED:
  882. zfcp_erp_port_boxed(port, 49, req);
  883. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  884. ZFCP_STATUS_FSFREQ_RETRY;
  885. break;
  886. case FSF_PORT_HANDLE_NOT_VALID:
  887. zfcp_erp_adapter_reopen(adapter, 0, 106, req);
  888. case FSF_GENERIC_COMMAND_REJECTED:
  889. case FSF_PAYLOAD_SIZE_MISMATCH:
  890. case FSF_REQUEST_SIZE_TOO_LARGE:
  891. case FSF_RESPONSE_SIZE_TOO_LARGE:
  892. case FSF_SBAL_MISMATCH:
  893. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  894. break;
  895. }
  896. skip_fsfstatus:
  897. if (send_ct->handler)
  898. send_ct->handler(send_ct->handler_data);
  899. }
  900. static int zfcp_fsf_setup_sbals(struct zfcp_fsf_req *req,
  901. struct scatterlist *sg_req,
  902. struct scatterlist *sg_resp, int max_sbals)
  903. {
  904. int bytes;
  905. bytes = zfcp_qdio_sbals_from_sg(req, SBAL_FLAGS0_TYPE_WRITE_READ,
  906. sg_req, max_sbals);
  907. if (bytes <= 0)
  908. return -ENOMEM;
  909. req->qtcb->bottom.support.req_buf_length = bytes;
  910. req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
  911. bytes = zfcp_qdio_sbals_from_sg(req, SBAL_FLAGS0_TYPE_WRITE_READ,
  912. sg_resp, max_sbals);
  913. if (bytes <= 0)
  914. return -ENOMEM;
  915. req->qtcb->bottom.support.resp_buf_length = bytes;
  916. return 0;
  917. }
  918. /**
  919. * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
  920. * @ct: pointer to struct zfcp_send_ct with data for request
  921. * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req
  922. * @erp_action: if non-null the Generic Service request sent within ERP
  923. */
  924. int zfcp_fsf_send_ct(struct zfcp_send_ct *ct, mempool_t *pool,
  925. struct zfcp_erp_action *erp_action)
  926. {
  927. struct zfcp_port *port = ct->port;
  928. struct zfcp_adapter *adapter = port->adapter;
  929. struct zfcp_fsf_req *req;
  930. int ret = -EIO;
  931. spin_lock_bh(&adapter->req_q.lock);
  932. if (zfcp_fsf_req_sbal_get(adapter))
  933. goto out;
  934. req = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_GENERIC,
  935. ZFCP_REQ_AUTO_CLEANUP, pool);
  936. if (IS_ERR(req)) {
  937. ret = PTR_ERR(req);
  938. goto out;
  939. }
  940. ret = zfcp_fsf_setup_sbals(req, ct->req, ct->resp,
  941. FSF_MAX_SBALS_PER_REQ);
  942. if (ret)
  943. goto failed_send;
  944. req->handler = zfcp_fsf_send_ct_handler;
  945. req->qtcb->header.port_handle = port->handle;
  946. req->qtcb->bottom.support.service_class = FSF_CLASS_3;
  947. req->qtcb->bottom.support.timeout = ct->timeout;
  948. req->data = ct;
  949. zfcp_san_dbf_event_ct_request(req);
  950. if (erp_action) {
  951. erp_action->fsf_req = req;
  952. req->erp_action = erp_action;
  953. zfcp_fsf_start_erp_timer(req);
  954. } else
  955. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  956. ret = zfcp_fsf_req_send(req);
  957. if (ret)
  958. goto failed_send;
  959. goto out;
  960. failed_send:
  961. zfcp_fsf_req_free(req);
  962. if (erp_action)
  963. erp_action->fsf_req = NULL;
  964. out:
  965. spin_unlock_bh(&adapter->req_q.lock);
  966. return ret;
  967. }
  968. static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req)
  969. {
  970. struct zfcp_send_els *send_els = req->data;
  971. struct zfcp_port *port = send_els->port;
  972. struct fsf_qtcb_header *header = &req->qtcb->header;
  973. send_els->status = -EINVAL;
  974. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  975. goto skip_fsfstatus;
  976. switch (header->fsf_status) {
  977. case FSF_GOOD:
  978. zfcp_san_dbf_event_els_response(req);
  979. send_els->status = 0;
  980. break;
  981. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  982. zfcp_fsf_class_not_supp(req);
  983. break;
  984. case FSF_ADAPTER_STATUS_AVAILABLE:
  985. switch (header->fsf_status_qual.word[0]){
  986. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  987. if (port && (send_els->ls_code != ZFCP_LS_ADISC))
  988. zfcp_test_link(port);
  989. /*fall through */
  990. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  991. case FSF_SQ_RETRY_IF_POSSIBLE:
  992. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  993. break;
  994. }
  995. break;
  996. case FSF_ELS_COMMAND_REJECTED:
  997. case FSF_PAYLOAD_SIZE_MISMATCH:
  998. case FSF_REQUEST_SIZE_TOO_LARGE:
  999. case FSF_RESPONSE_SIZE_TOO_LARGE:
  1000. break;
  1001. case FSF_ACCESS_DENIED:
  1002. zfcp_fsf_access_denied_port(req, port);
  1003. break;
  1004. case FSF_SBAL_MISMATCH:
  1005. /* should never occure, avoided in zfcp_fsf_send_els */
  1006. /* fall through */
  1007. default:
  1008. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1009. break;
  1010. }
  1011. skip_fsfstatus:
  1012. if (send_els->handler)
  1013. send_els->handler(send_els->handler_data);
  1014. }
  1015. /**
  1016. * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
  1017. * @els: pointer to struct zfcp_send_els with data for the command
  1018. */
  1019. int zfcp_fsf_send_els(struct zfcp_send_els *els)
  1020. {
  1021. struct zfcp_fsf_req *req;
  1022. struct zfcp_adapter *adapter = els->adapter;
  1023. struct fsf_qtcb_bottom_support *bottom;
  1024. int ret = -EIO;
  1025. if (unlikely(!(atomic_read(&els->port->status) &
  1026. ZFCP_STATUS_COMMON_UNBLOCKED)))
  1027. return -EBUSY;
  1028. spin_lock(&adapter->req_q.lock);
  1029. if (!zfcp_fsf_sbal_available(adapter))
  1030. goto out;
  1031. req = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_ELS,
  1032. ZFCP_REQ_AUTO_CLEANUP, NULL);
  1033. if (IS_ERR(req)) {
  1034. ret = PTR_ERR(req);
  1035. goto out;
  1036. }
  1037. ret = zfcp_fsf_setup_sbals(req, els->req, els->resp,
  1038. FSF_MAX_SBALS_PER_ELS_REQ);
  1039. if (ret)
  1040. goto failed_send;
  1041. bottom = &req->qtcb->bottom.support;
  1042. req->handler = zfcp_fsf_send_els_handler;
  1043. bottom->d_id = els->d_id;
  1044. bottom->service_class = FSF_CLASS_3;
  1045. bottom->timeout = 2 * R_A_TOV;
  1046. req->data = els;
  1047. zfcp_san_dbf_event_els_request(req);
  1048. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1049. ret = zfcp_fsf_req_send(req);
  1050. if (ret)
  1051. goto failed_send;
  1052. goto out;
  1053. failed_send:
  1054. zfcp_fsf_req_free(req);
  1055. out:
  1056. spin_unlock(&adapter->req_q.lock);
  1057. return ret;
  1058. }
  1059. int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
  1060. {
  1061. volatile struct qdio_buffer_element *sbale;
  1062. struct zfcp_fsf_req *req;
  1063. struct zfcp_adapter *adapter = erp_action->adapter;
  1064. int retval = -EIO;
  1065. spin_lock_bh(&adapter->req_q.lock);
  1066. if (!zfcp_fsf_sbal_available(adapter))
  1067. goto out;
  1068. req = zfcp_fsf_req_create(adapter,
  1069. FSF_QTCB_EXCHANGE_CONFIG_DATA,
  1070. ZFCP_REQ_AUTO_CLEANUP,
  1071. adapter->pool.fsf_req_erp);
  1072. if (IS_ERR(req)) {
  1073. retval = PTR_ERR(req);
  1074. goto out;
  1075. }
  1076. sbale = zfcp_qdio_sbale_req(req);
  1077. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1078. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1079. req->qtcb->bottom.config.feature_selection =
  1080. FSF_FEATURE_CFDC |
  1081. FSF_FEATURE_LUN_SHARING |
  1082. FSF_FEATURE_NOTIFICATION_LOST |
  1083. FSF_FEATURE_UPDATE_ALERT;
  1084. req->erp_action = erp_action;
  1085. req->handler = zfcp_fsf_exchange_config_data_handler;
  1086. erp_action->fsf_req = req;
  1087. zfcp_fsf_start_erp_timer(req);
  1088. retval = zfcp_fsf_req_send(req);
  1089. if (retval) {
  1090. zfcp_fsf_req_free(req);
  1091. erp_action->fsf_req = NULL;
  1092. }
  1093. out:
  1094. spin_unlock_bh(&adapter->req_q.lock);
  1095. return retval;
  1096. }
  1097. int zfcp_fsf_exchange_config_data_sync(struct zfcp_adapter *adapter,
  1098. struct fsf_qtcb_bottom_config *data)
  1099. {
  1100. volatile struct qdio_buffer_element *sbale;
  1101. struct zfcp_fsf_req *req = NULL;
  1102. int retval = -EIO;
  1103. spin_lock_bh(&adapter->req_q.lock);
  1104. if (zfcp_fsf_req_sbal_get(adapter))
  1105. goto out;
  1106. req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_CONFIG_DATA,
  1107. 0, NULL);
  1108. if (IS_ERR(req)) {
  1109. retval = PTR_ERR(req);
  1110. goto out;
  1111. }
  1112. sbale = zfcp_qdio_sbale_req(req);
  1113. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1114. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1115. req->handler = zfcp_fsf_exchange_config_data_handler;
  1116. req->qtcb->bottom.config.feature_selection =
  1117. FSF_FEATURE_CFDC |
  1118. FSF_FEATURE_LUN_SHARING |
  1119. FSF_FEATURE_NOTIFICATION_LOST |
  1120. FSF_FEATURE_UPDATE_ALERT;
  1121. if (data)
  1122. req->data = data;
  1123. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1124. retval = zfcp_fsf_req_send(req);
  1125. out:
  1126. spin_unlock_bh(&adapter->req_q.lock);
  1127. if (!retval)
  1128. wait_event(req->completion_wq,
  1129. req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
  1130. zfcp_fsf_req_free(req);
  1131. return retval;
  1132. }
  1133. /**
  1134. * zfcp_fsf_exchange_port_data - request information about local port
  1135. * @erp_action: ERP action for the adapter for which port data is requested
  1136. * Returns: 0 on success, error otherwise
  1137. */
  1138. int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
  1139. {
  1140. volatile struct qdio_buffer_element *sbale;
  1141. struct zfcp_fsf_req *req;
  1142. struct zfcp_adapter *adapter = erp_action->adapter;
  1143. int retval = -EIO;
  1144. if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
  1145. return -EOPNOTSUPP;
  1146. spin_lock_bh(&adapter->req_q.lock);
  1147. if (!zfcp_fsf_sbal_available(adapter))
  1148. goto out;
  1149. req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA,
  1150. ZFCP_REQ_AUTO_CLEANUP,
  1151. adapter->pool.fsf_req_erp);
  1152. if (IS_ERR(req)) {
  1153. retval = PTR_ERR(req);
  1154. goto out;
  1155. }
  1156. sbale = zfcp_qdio_sbale_req(req);
  1157. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1158. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1159. req->handler = zfcp_fsf_exchange_port_data_handler;
  1160. req->erp_action = erp_action;
  1161. erp_action->fsf_req = req;
  1162. zfcp_fsf_start_erp_timer(req);
  1163. retval = zfcp_fsf_req_send(req);
  1164. if (retval) {
  1165. zfcp_fsf_req_free(req);
  1166. erp_action->fsf_req = NULL;
  1167. }
  1168. out:
  1169. spin_unlock_bh(&adapter->req_q.lock);
  1170. return retval;
  1171. }
  1172. /**
  1173. * zfcp_fsf_exchange_port_data_sync - request information about local port
  1174. * @adapter: pointer to struct zfcp_adapter
  1175. * @data: pointer to struct fsf_qtcb_bottom_port
  1176. * Returns: 0 on success, error otherwise
  1177. */
  1178. int zfcp_fsf_exchange_port_data_sync(struct zfcp_adapter *adapter,
  1179. struct fsf_qtcb_bottom_port *data)
  1180. {
  1181. volatile struct qdio_buffer_element *sbale;
  1182. struct zfcp_fsf_req *req = NULL;
  1183. int retval = -EIO;
  1184. if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
  1185. return -EOPNOTSUPP;
  1186. spin_lock_bh(&adapter->req_q.lock);
  1187. if (!zfcp_fsf_sbal_available(adapter))
  1188. goto out;
  1189. req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA, 0,
  1190. NULL);
  1191. if (IS_ERR(req)) {
  1192. retval = PTR_ERR(req);
  1193. goto out;
  1194. }
  1195. if (data)
  1196. req->data = data;
  1197. sbale = zfcp_qdio_sbale_req(req);
  1198. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1199. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1200. req->handler = zfcp_fsf_exchange_port_data_handler;
  1201. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1202. retval = zfcp_fsf_req_send(req);
  1203. out:
  1204. spin_unlock_bh(&adapter->req_q.lock);
  1205. if (!retval)
  1206. wait_event(req->completion_wq,
  1207. req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
  1208. zfcp_fsf_req_free(req);
  1209. return retval;
  1210. }
  1211. static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
  1212. {
  1213. struct zfcp_port *port = req->data;
  1214. struct fsf_qtcb_header *header = &req->qtcb->header;
  1215. struct fsf_plogi *plogi;
  1216. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1217. goto skip_fsfstatus;
  1218. switch (header->fsf_status) {
  1219. case FSF_PORT_ALREADY_OPEN:
  1220. break;
  1221. case FSF_ACCESS_DENIED:
  1222. zfcp_fsf_access_denied_port(req, port);
  1223. break;
  1224. case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
  1225. dev_warn(&req->adapter->ccw_device->dev,
  1226. "Not enough FCP adapter resources to open "
  1227. "remote port 0x%016Lx\n", port->wwpn);
  1228. zfcp_erp_port_failed(port, 31, req);
  1229. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1230. break;
  1231. case FSF_ADAPTER_STATUS_AVAILABLE:
  1232. switch (header->fsf_status_qual.word[0]) {
  1233. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1234. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1235. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1236. break;
  1237. case FSF_SQ_NO_RETRY_POSSIBLE:
  1238. dev_warn(&req->adapter->ccw_device->dev,
  1239. "Remote port 0x%016Lx could not be opened\n",
  1240. port->wwpn);
  1241. zfcp_erp_port_failed(port, 32, req);
  1242. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1243. break;
  1244. }
  1245. break;
  1246. case FSF_GOOD:
  1247. port->handle = header->port_handle;
  1248. atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
  1249. ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1250. atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
  1251. ZFCP_STATUS_COMMON_ACCESS_BOXED,
  1252. &port->status);
  1253. /* check whether D_ID has changed during open */
  1254. /*
  1255. * FIXME: This check is not airtight, as the FCP channel does
  1256. * not monitor closures of target port connections caused on
  1257. * the remote side. Thus, they might miss out on invalidating
  1258. * locally cached WWPNs (and other N_Port parameters) of gone
  1259. * target ports. So, our heroic attempt to make things safe
  1260. * could be undermined by 'open port' response data tagged with
  1261. * obsolete WWPNs. Another reason to monitor potential
  1262. * connection closures ourself at least (by interpreting
  1263. * incoming ELS' and unsolicited status). It just crosses my
  1264. * mind that one should be able to cross-check by means of
  1265. * another GID_PN straight after a port has been opened.
  1266. * Alternately, an ADISC/PDISC ELS should suffice, as well.
  1267. */
  1268. if (atomic_read(&port->status) & ZFCP_STATUS_PORT_NO_WWPN)
  1269. break;
  1270. plogi = (struct fsf_plogi *) req->qtcb->bottom.support.els;
  1271. if (req->qtcb->bottom.support.els1_length >= sizeof(*plogi)) {
  1272. if (plogi->serv_param.wwpn != port->wwpn)
  1273. atomic_clear_mask(ZFCP_STATUS_PORT_DID_DID,
  1274. &port->status);
  1275. else {
  1276. port->wwnn = plogi->serv_param.wwnn;
  1277. zfcp_fc_plogi_evaluate(port, plogi);
  1278. }
  1279. }
  1280. break;
  1281. case FSF_UNKNOWN_OP_SUBTYPE:
  1282. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1283. break;
  1284. }
  1285. skip_fsfstatus:
  1286. atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &port->status);
  1287. }
  1288. /**
  1289. * zfcp_fsf_open_port - create and send open port request
  1290. * @erp_action: pointer to struct zfcp_erp_action
  1291. * Returns: 0 on success, error otherwise
  1292. */
  1293. int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
  1294. {
  1295. volatile struct qdio_buffer_element *sbale;
  1296. struct zfcp_adapter *adapter = erp_action->adapter;
  1297. struct zfcp_fsf_req *req;
  1298. int retval = -EIO;
  1299. spin_lock_bh(&adapter->req_q.lock);
  1300. if (zfcp_fsf_req_sbal_get(adapter))
  1301. goto out;
  1302. req = zfcp_fsf_req_create(adapter,
  1303. FSF_QTCB_OPEN_PORT_WITH_DID,
  1304. ZFCP_REQ_AUTO_CLEANUP,
  1305. adapter->pool.fsf_req_erp);
  1306. if (IS_ERR(req)) {
  1307. retval = PTR_ERR(req);
  1308. goto out;
  1309. }
  1310. sbale = zfcp_qdio_sbale_req(req);
  1311. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1312. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1313. req->handler = zfcp_fsf_open_port_handler;
  1314. req->qtcb->bottom.support.d_id = erp_action->port->d_id;
  1315. req->data = erp_action->port;
  1316. req->erp_action = erp_action;
  1317. erp_action->fsf_req = req;
  1318. atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->port->status);
  1319. zfcp_fsf_start_erp_timer(req);
  1320. retval = zfcp_fsf_req_send(req);
  1321. if (retval) {
  1322. zfcp_fsf_req_free(req);
  1323. erp_action->fsf_req = NULL;
  1324. }
  1325. out:
  1326. spin_unlock_bh(&adapter->req_q.lock);
  1327. return retval;
  1328. }
  1329. static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req)
  1330. {
  1331. struct zfcp_port *port = req->data;
  1332. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1333. goto skip_fsfstatus;
  1334. switch (req->qtcb->header.fsf_status) {
  1335. case FSF_PORT_HANDLE_NOT_VALID:
  1336. zfcp_erp_adapter_reopen(port->adapter, 0, 107, req);
  1337. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1338. break;
  1339. case FSF_ADAPTER_STATUS_AVAILABLE:
  1340. break;
  1341. case FSF_GOOD:
  1342. zfcp_erp_modify_port_status(port, 33, req,
  1343. ZFCP_STATUS_COMMON_OPEN,
  1344. ZFCP_CLEAR);
  1345. break;
  1346. }
  1347. skip_fsfstatus:
  1348. atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &port->status);
  1349. }
  1350. /**
  1351. * zfcp_fsf_close_port - create and send close port request
  1352. * @erp_action: pointer to struct zfcp_erp_action
  1353. * Returns: 0 on success, error otherwise
  1354. */
  1355. int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
  1356. {
  1357. volatile struct qdio_buffer_element *sbale;
  1358. struct zfcp_adapter *adapter = erp_action->adapter;
  1359. struct zfcp_fsf_req *req;
  1360. int retval = -EIO;
  1361. spin_lock_bh(&adapter->req_q.lock);
  1362. if (zfcp_fsf_req_sbal_get(adapter))
  1363. goto out;
  1364. req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_PORT,
  1365. ZFCP_REQ_AUTO_CLEANUP,
  1366. adapter->pool.fsf_req_erp);
  1367. if (IS_ERR(req)) {
  1368. retval = PTR_ERR(req);
  1369. goto out;
  1370. }
  1371. sbale = zfcp_qdio_sbale_req(req);
  1372. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1373. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1374. req->handler = zfcp_fsf_close_port_handler;
  1375. req->data = erp_action->port;
  1376. req->erp_action = erp_action;
  1377. req->qtcb->header.port_handle = erp_action->port->handle;
  1378. erp_action->fsf_req = req;
  1379. atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->port->status);
  1380. zfcp_fsf_start_erp_timer(req);
  1381. retval = zfcp_fsf_req_send(req);
  1382. if (retval) {
  1383. zfcp_fsf_req_free(req);
  1384. erp_action->fsf_req = NULL;
  1385. }
  1386. out:
  1387. spin_unlock_bh(&adapter->req_q.lock);
  1388. return retval;
  1389. }
  1390. static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *req)
  1391. {
  1392. struct zfcp_port *port = req->data;
  1393. struct fsf_qtcb_header *header = &req->qtcb->header;
  1394. struct zfcp_unit *unit;
  1395. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1396. goto skip_fsfstatus;
  1397. switch (header->fsf_status) {
  1398. case FSF_PORT_HANDLE_NOT_VALID:
  1399. zfcp_erp_adapter_reopen(port->adapter, 0, 108, req);
  1400. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1401. break;
  1402. case FSF_ACCESS_DENIED:
  1403. zfcp_fsf_access_denied_port(req, port);
  1404. break;
  1405. case FSF_PORT_BOXED:
  1406. zfcp_erp_port_boxed(port, 50, req);
  1407. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  1408. ZFCP_STATUS_FSFREQ_RETRY;
  1409. /* can't use generic zfcp_erp_modify_port_status because
  1410. * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
  1411. atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1412. list_for_each_entry(unit, &port->unit_list_head, list)
  1413. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
  1414. &unit->status);
  1415. break;
  1416. case FSF_ADAPTER_STATUS_AVAILABLE:
  1417. switch (header->fsf_status_qual.word[0]) {
  1418. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1419. /* fall through */
  1420. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1421. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1422. break;
  1423. }
  1424. break;
  1425. case FSF_GOOD:
  1426. /* can't use generic zfcp_erp_modify_port_status because
  1427. * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
  1428. */
  1429. atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1430. list_for_each_entry(unit, &port->unit_list_head, list)
  1431. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
  1432. &unit->status);
  1433. break;
  1434. }
  1435. skip_fsfstatus:
  1436. atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_CLOSING, &port->status);
  1437. }
  1438. /**
  1439. * zfcp_fsf_close_physical_port - close physical port
  1440. * @erp_action: pointer to struct zfcp_erp_action
  1441. * Returns: 0 on success
  1442. */
  1443. int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
  1444. {
  1445. volatile struct qdio_buffer_element *sbale;
  1446. struct zfcp_adapter *adapter = erp_action->adapter;
  1447. struct zfcp_fsf_req *req;
  1448. int retval = -EIO;
  1449. spin_lock_bh(&adapter->req_q.lock);
  1450. if (zfcp_fsf_req_sbal_get(adapter))
  1451. goto out;
  1452. req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_PHYSICAL_PORT,
  1453. ZFCP_REQ_AUTO_CLEANUP,
  1454. adapter->pool.fsf_req_erp);
  1455. if (IS_ERR(req)) {
  1456. retval = PTR_ERR(req);
  1457. goto out;
  1458. }
  1459. sbale = zfcp_qdio_sbale_req(req);
  1460. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1461. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1462. req->data = erp_action->port;
  1463. req->qtcb->header.port_handle = erp_action->port->handle;
  1464. req->erp_action = erp_action;
  1465. req->handler = zfcp_fsf_close_physical_port_handler;
  1466. erp_action->fsf_req = req;
  1467. atomic_set_mask(ZFCP_STATUS_PORT_PHYS_CLOSING,
  1468. &erp_action->port->status);
  1469. zfcp_fsf_start_erp_timer(req);
  1470. retval = zfcp_fsf_req_send(req);
  1471. if (retval) {
  1472. zfcp_fsf_req_free(req);
  1473. erp_action->fsf_req = NULL;
  1474. }
  1475. out:
  1476. spin_unlock_bh(&adapter->req_q.lock);
  1477. return retval;
  1478. }
  1479. static void zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *req)
  1480. {
  1481. struct zfcp_adapter *adapter = req->adapter;
  1482. struct zfcp_unit *unit = req->data;
  1483. struct fsf_qtcb_header *header = &req->qtcb->header;
  1484. struct fsf_qtcb_bottom_support *bottom = &req->qtcb->bottom.support;
  1485. struct fsf_queue_designator *queue_designator =
  1486. &header->fsf_status_qual.fsf_queue_designator;
  1487. int exclusive, readwrite;
  1488. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1489. goto skip_fsfstatus;
  1490. atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
  1491. ZFCP_STATUS_COMMON_ACCESS_BOXED |
  1492. ZFCP_STATUS_UNIT_SHARED |
  1493. ZFCP_STATUS_UNIT_READONLY,
  1494. &unit->status);
  1495. switch (header->fsf_status) {
  1496. case FSF_PORT_HANDLE_NOT_VALID:
  1497. zfcp_erp_adapter_reopen(unit->port->adapter, 0, 109, req);
  1498. /* fall through */
  1499. case FSF_LUN_ALREADY_OPEN:
  1500. break;
  1501. case FSF_ACCESS_DENIED:
  1502. zfcp_fsf_access_denied_unit(req, unit);
  1503. atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
  1504. atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
  1505. break;
  1506. case FSF_PORT_BOXED:
  1507. zfcp_erp_port_boxed(unit->port, 51, req);
  1508. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  1509. ZFCP_STATUS_FSFREQ_RETRY;
  1510. break;
  1511. case FSF_LUN_SHARING_VIOLATION:
  1512. if (header->fsf_status_qual.word[0])
  1513. dev_warn(&adapter->ccw_device->dev,
  1514. "LUN 0x%Lx on port 0x%Lx is already in "
  1515. "use by CSS%d, MIF Image ID %x\n",
  1516. unit->fcp_lun,
  1517. unit->port->wwpn,
  1518. queue_designator->cssid,
  1519. queue_designator->hla);
  1520. else
  1521. zfcp_act_eval_err(adapter,
  1522. header->fsf_status_qual.word[2]);
  1523. zfcp_erp_unit_access_denied(unit, 60, req);
  1524. atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
  1525. atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
  1526. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1527. break;
  1528. case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
  1529. dev_warn(&adapter->ccw_device->dev,
  1530. "No handle is available for LUN "
  1531. "0x%016Lx on port 0x%016Lx\n",
  1532. unit->fcp_lun, unit->port->wwpn);
  1533. zfcp_erp_unit_failed(unit, 34, req);
  1534. /* fall through */
  1535. case FSF_INVALID_COMMAND_OPTION:
  1536. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1537. break;
  1538. case FSF_ADAPTER_STATUS_AVAILABLE:
  1539. switch (header->fsf_status_qual.word[0]) {
  1540. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1541. zfcp_test_link(unit->port);
  1542. /* fall through */
  1543. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1544. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1545. break;
  1546. }
  1547. break;
  1548. case FSF_GOOD:
  1549. unit->handle = header->lun_handle;
  1550. atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
  1551. if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
  1552. (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
  1553. (adapter->ccw_device->id.dev_model != ZFCP_DEVICE_MODEL_PRIV)) {
  1554. exclusive = (bottom->lun_access_info &
  1555. FSF_UNIT_ACCESS_EXCLUSIVE);
  1556. readwrite = (bottom->lun_access_info &
  1557. FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
  1558. if (!exclusive)
  1559. atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
  1560. &unit->status);
  1561. if (!readwrite) {
  1562. atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
  1563. &unit->status);
  1564. dev_info(&adapter->ccw_device->dev,
  1565. "SCSI device at LUN 0x%016Lx on port "
  1566. "0x%016Lx opened read-only\n",
  1567. unit->fcp_lun, unit->port->wwpn);
  1568. }
  1569. if (exclusive && !readwrite) {
  1570. dev_err(&adapter->ccw_device->dev,
  1571. "Exclusive read-only access not "
  1572. "supported (unit 0x%016Lx, "
  1573. "port 0x%016Lx)\n",
  1574. unit->fcp_lun, unit->port->wwpn);
  1575. zfcp_erp_unit_failed(unit, 35, req);
  1576. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1577. zfcp_erp_unit_shutdown(unit, 0, 80, req);
  1578. } else if (!exclusive && readwrite) {
  1579. dev_err(&adapter->ccw_device->dev,
  1580. "Shared read-write access not "
  1581. "supported (unit 0x%016Lx, port "
  1582. "0x%016Lx\n)",
  1583. unit->fcp_lun, unit->port->wwpn);
  1584. zfcp_erp_unit_failed(unit, 36, req);
  1585. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1586. zfcp_erp_unit_shutdown(unit, 0, 81, req);
  1587. }
  1588. }
  1589. break;
  1590. }
  1591. skip_fsfstatus:
  1592. atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &unit->status);
  1593. }
  1594. /**
  1595. * zfcp_fsf_open_unit - open unit
  1596. * @erp_action: pointer to struct zfcp_erp_action
  1597. * Returns: 0 on success, error otherwise
  1598. */
  1599. int zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
  1600. {
  1601. volatile struct qdio_buffer_element *sbale;
  1602. struct zfcp_adapter *adapter = erp_action->adapter;
  1603. struct zfcp_fsf_req *req;
  1604. int retval = -EIO;
  1605. spin_lock_bh(&adapter->req_q.lock);
  1606. if (zfcp_fsf_req_sbal_get(adapter))
  1607. goto out;
  1608. req = zfcp_fsf_req_create(adapter, FSF_QTCB_OPEN_LUN,
  1609. ZFCP_REQ_AUTO_CLEANUP,
  1610. adapter->pool.fsf_req_erp);
  1611. if (IS_ERR(req)) {
  1612. retval = PTR_ERR(req);
  1613. goto out;
  1614. }
  1615. sbale = zfcp_qdio_sbale_req(req);
  1616. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1617. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1618. req->qtcb->header.port_handle = erp_action->port->handle;
  1619. req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun;
  1620. req->handler = zfcp_fsf_open_unit_handler;
  1621. req->data = erp_action->unit;
  1622. req->erp_action = erp_action;
  1623. erp_action->fsf_req = req;
  1624. if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE))
  1625. req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING;
  1626. atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->unit->status);
  1627. zfcp_fsf_start_erp_timer(req);
  1628. retval = zfcp_fsf_req_send(req);
  1629. if (retval) {
  1630. zfcp_fsf_req_free(req);
  1631. erp_action->fsf_req = NULL;
  1632. }
  1633. out:
  1634. spin_unlock_bh(&adapter->req_q.lock);
  1635. return retval;
  1636. }
  1637. static void zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *req)
  1638. {
  1639. struct zfcp_unit *unit = req->data;
  1640. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1641. goto skip_fsfstatus;
  1642. switch (req->qtcb->header.fsf_status) {
  1643. case FSF_PORT_HANDLE_NOT_VALID:
  1644. zfcp_erp_adapter_reopen(unit->port->adapter, 0, 110, req);
  1645. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1646. break;
  1647. case FSF_LUN_HANDLE_NOT_VALID:
  1648. zfcp_erp_port_reopen(unit->port, 0, 111, req);
  1649. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1650. break;
  1651. case FSF_PORT_BOXED:
  1652. zfcp_erp_port_boxed(unit->port, 52, req);
  1653. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  1654. ZFCP_STATUS_FSFREQ_RETRY;
  1655. break;
  1656. case FSF_ADAPTER_STATUS_AVAILABLE:
  1657. switch (req->qtcb->header.fsf_status_qual.word[0]) {
  1658. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1659. zfcp_test_link(unit->port);
  1660. /* fall through */
  1661. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1662. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1663. break;
  1664. }
  1665. break;
  1666. case FSF_GOOD:
  1667. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
  1668. break;
  1669. }
  1670. skip_fsfstatus:
  1671. atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &unit->status);
  1672. }
  1673. /**
  1674. * zfcp_fsf_close_unit - close zfcp unit
  1675. * @erp_action: pointer to struct zfcp_unit
  1676. * Returns: 0 on success, error otherwise
  1677. */
  1678. int zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
  1679. {
  1680. volatile struct qdio_buffer_element *sbale;
  1681. struct zfcp_adapter *adapter = erp_action->adapter;
  1682. struct zfcp_fsf_req *req;
  1683. int retval = -EIO;
  1684. spin_lock_bh(&adapter->req_q.lock);
  1685. if (zfcp_fsf_req_sbal_get(adapter))
  1686. goto out;
  1687. req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_LUN,
  1688. ZFCP_REQ_AUTO_CLEANUP,
  1689. adapter->pool.fsf_req_erp);
  1690. if (IS_ERR(req)) {
  1691. retval = PTR_ERR(req);
  1692. goto out;
  1693. }
  1694. sbale = zfcp_qdio_sbale_req(req);
  1695. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1696. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1697. req->qtcb->header.port_handle = erp_action->port->handle;
  1698. req->qtcb->header.lun_handle = erp_action->unit->handle;
  1699. req->handler = zfcp_fsf_close_unit_handler;
  1700. req->data = erp_action->unit;
  1701. req->erp_action = erp_action;
  1702. erp_action->fsf_req = req;
  1703. atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->unit->status);
  1704. zfcp_fsf_start_erp_timer(req);
  1705. retval = zfcp_fsf_req_send(req);
  1706. if (retval) {
  1707. zfcp_fsf_req_free(req);
  1708. erp_action->fsf_req = NULL;
  1709. }
  1710. out:
  1711. spin_unlock_bh(&adapter->req_q.lock);
  1712. return retval;
  1713. }
  1714. static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
  1715. {
  1716. lat_rec->sum += lat;
  1717. lat_rec->min = min(lat_rec->min, lat);
  1718. lat_rec->max = max(lat_rec->max, lat);
  1719. }
  1720. static void zfcp_fsf_req_latency(struct zfcp_fsf_req *req)
  1721. {
  1722. struct fsf_qual_latency_info *lat_inf;
  1723. struct latency_cont *lat;
  1724. struct zfcp_unit *unit = req->unit;
  1725. unsigned long flags;
  1726. lat_inf = &req->qtcb->prefix.prot_status_qual.latency_info;
  1727. switch (req->qtcb->bottom.io.data_direction) {
  1728. case FSF_DATADIR_READ:
  1729. lat = &unit->latencies.read;
  1730. break;
  1731. case FSF_DATADIR_WRITE:
  1732. lat = &unit->latencies.write;
  1733. break;
  1734. case FSF_DATADIR_CMND:
  1735. lat = &unit->latencies.cmd;
  1736. break;
  1737. default:
  1738. return;
  1739. }
  1740. spin_lock_irqsave(&unit->latencies.lock, flags);
  1741. zfcp_fsf_update_lat(&lat->channel, lat_inf->channel_lat);
  1742. zfcp_fsf_update_lat(&lat->fabric, lat_inf->fabric_lat);
  1743. lat->counter++;
  1744. spin_unlock_irqrestore(&unit->latencies.lock, flags);
  1745. }
  1746. static void zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *req)
  1747. {
  1748. struct scsi_cmnd *scpnt = req->data;
  1749. struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
  1750. &(req->qtcb->bottom.io.fcp_rsp);
  1751. u32 sns_len;
  1752. char *fcp_rsp_info = (unsigned char *) &fcp_rsp_iu[1];
  1753. unsigned long flags;
  1754. if (unlikely(!scpnt))
  1755. return;
  1756. read_lock_irqsave(&req->adapter->abort_lock, flags);
  1757. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ABORTED)) {
  1758. set_host_byte(scpnt, DID_SOFT_ERROR);
  1759. set_driver_byte(scpnt, SUGGEST_RETRY);
  1760. goto skip_fsfstatus;
  1761. }
  1762. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
  1763. set_host_byte(scpnt, DID_ERROR);
  1764. goto skip_fsfstatus;
  1765. }
  1766. set_msg_byte(scpnt, COMMAND_COMPLETE);
  1767. scpnt->result |= fcp_rsp_iu->scsi_status;
  1768. if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA)
  1769. zfcp_fsf_req_latency(req);
  1770. if (unlikely(fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)) {
  1771. if (fcp_rsp_info[3] == RSP_CODE_GOOD)
  1772. set_host_byte(scpnt, DID_OK);
  1773. else {
  1774. set_host_byte(scpnt, DID_ERROR);
  1775. goto skip_fsfstatus;
  1776. }
  1777. }
  1778. if (unlikely(fcp_rsp_iu->validity.bits.fcp_sns_len_valid)) {
  1779. sns_len = FSF_FCP_RSP_SIZE - sizeof(struct fcp_rsp_iu) +
  1780. fcp_rsp_iu->fcp_rsp_len;
  1781. sns_len = min(sns_len, (u32) SCSI_SENSE_BUFFERSIZE);
  1782. sns_len = min(sns_len, fcp_rsp_iu->fcp_sns_len);
  1783. memcpy(scpnt->sense_buffer,
  1784. zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), sns_len);
  1785. }
  1786. if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_under)) {
  1787. scsi_set_resid(scpnt, fcp_rsp_iu->fcp_resid);
  1788. if (scsi_bufflen(scpnt) - scsi_get_resid(scpnt) <
  1789. scpnt->underflow)
  1790. set_host_byte(scpnt, DID_ERROR);
  1791. }
  1792. skip_fsfstatus:
  1793. if (scpnt->result != 0)
  1794. zfcp_scsi_dbf_event_result("erro", 3, req->adapter, scpnt, req);
  1795. else if (scpnt->retries > 0)
  1796. zfcp_scsi_dbf_event_result("retr", 4, req->adapter, scpnt, req);
  1797. else
  1798. zfcp_scsi_dbf_event_result("norm", 6, req->adapter, scpnt, req);
  1799. scpnt->host_scribble = NULL;
  1800. (scpnt->scsi_done) (scpnt);
  1801. /*
  1802. * We must hold this lock until scsi_done has been called.
  1803. * Otherwise we may call scsi_done after abort regarding this
  1804. * command has completed.
  1805. * Note: scsi_done must not block!
  1806. */
  1807. read_unlock_irqrestore(&req->adapter->abort_lock, flags);
  1808. }
  1809. static void zfcp_fsf_send_fcp_ctm_handler(struct zfcp_fsf_req *req)
  1810. {
  1811. struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
  1812. &(req->qtcb->bottom.io.fcp_rsp);
  1813. char *fcp_rsp_info = (unsigned char *) &fcp_rsp_iu[1];
  1814. if ((fcp_rsp_info[3] != RSP_CODE_GOOD) ||
  1815. (req->status & ZFCP_STATUS_FSFREQ_ERROR))
  1816. req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
  1817. }
  1818. static void zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *req)
  1819. {
  1820. struct zfcp_unit *unit;
  1821. struct fsf_qtcb_header *header = &req->qtcb->header;
  1822. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
  1823. unit = req->data;
  1824. else
  1825. unit = req->unit;
  1826. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
  1827. goto skip_fsfstatus;
  1828. switch (header->fsf_status) {
  1829. case FSF_HANDLE_MISMATCH:
  1830. case FSF_PORT_HANDLE_NOT_VALID:
  1831. zfcp_erp_adapter_reopen(unit->port->adapter, 0, 112, req);
  1832. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1833. break;
  1834. case FSF_FCPLUN_NOT_VALID:
  1835. case FSF_LUN_HANDLE_NOT_VALID:
  1836. zfcp_erp_port_reopen(unit->port, 0, 113, req);
  1837. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1838. break;
  1839. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  1840. zfcp_fsf_class_not_supp(req);
  1841. break;
  1842. case FSF_ACCESS_DENIED:
  1843. zfcp_fsf_access_denied_unit(req, unit);
  1844. break;
  1845. case FSF_DIRECTION_INDICATOR_NOT_VALID:
  1846. dev_err(&req->adapter->ccw_device->dev,
  1847. "Incorrect direction %d, unit 0x%016Lx on port "
  1848. "0x%016Lx closed\n",
  1849. req->qtcb->bottom.io.data_direction,
  1850. unit->fcp_lun, unit->port->wwpn);
  1851. zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 133, req);
  1852. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1853. break;
  1854. case FSF_CMND_LENGTH_NOT_VALID:
  1855. dev_err(&req->adapter->ccw_device->dev,
  1856. "Incorrect CDB length %d, unit 0x%016Lx on "
  1857. "port 0x%016Lx closed\n",
  1858. req->qtcb->bottom.io.fcp_cmnd_length,
  1859. unit->fcp_lun, unit->port->wwpn);
  1860. zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 134, req);
  1861. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1862. break;
  1863. case FSF_PORT_BOXED:
  1864. zfcp_erp_port_boxed(unit->port, 53, req);
  1865. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  1866. ZFCP_STATUS_FSFREQ_RETRY;
  1867. break;
  1868. case FSF_LUN_BOXED:
  1869. zfcp_erp_unit_boxed(unit, 54, req);
  1870. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  1871. ZFCP_STATUS_FSFREQ_RETRY;
  1872. break;
  1873. case FSF_ADAPTER_STATUS_AVAILABLE:
  1874. if (header->fsf_status_qual.word[0] ==
  1875. FSF_SQ_INVOKE_LINK_TEST_PROCEDURE)
  1876. zfcp_test_link(unit->port);
  1877. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1878. break;
  1879. }
  1880. skip_fsfstatus:
  1881. if (req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
  1882. zfcp_fsf_send_fcp_ctm_handler(req);
  1883. else {
  1884. zfcp_fsf_send_fcp_command_task_handler(req);
  1885. req->unit = NULL;
  1886. zfcp_unit_put(unit);
  1887. }
  1888. }
  1889. /**
  1890. * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
  1891. * @adapter: adapter where scsi command is issued
  1892. * @unit: unit where command is sent to
  1893. * @scsi_cmnd: scsi command to be sent
  1894. * @timer: timer to be started when request is initiated
  1895. * @req_flags: flags for fsf_request
  1896. */
  1897. int zfcp_fsf_send_fcp_command_task(struct zfcp_adapter *adapter,
  1898. struct zfcp_unit *unit,
  1899. struct scsi_cmnd *scsi_cmnd,
  1900. int use_timer, int req_flags)
  1901. {
  1902. struct zfcp_fsf_req *req;
  1903. struct fcp_cmnd_iu *fcp_cmnd_iu;
  1904. unsigned int sbtype;
  1905. int real_bytes, retval = -EIO;
  1906. if (unlikely(!(atomic_read(&unit->status) &
  1907. ZFCP_STATUS_COMMON_UNBLOCKED)))
  1908. return -EBUSY;
  1909. spin_lock(&adapter->req_q.lock);
  1910. if (!zfcp_fsf_sbal_available(adapter))
  1911. goto out;
  1912. req = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
  1913. adapter->pool.fsf_req_scsi);
  1914. if (IS_ERR(req)) {
  1915. retval = PTR_ERR(req);
  1916. goto out;
  1917. }
  1918. zfcp_unit_get(unit);
  1919. req->unit = unit;
  1920. req->data = scsi_cmnd;
  1921. req->handler = zfcp_fsf_send_fcp_command_handler;
  1922. req->qtcb->header.lun_handle = unit->handle;
  1923. req->qtcb->header.port_handle = unit->port->handle;
  1924. req->qtcb->bottom.io.service_class = FSF_CLASS_3;
  1925. scsi_cmnd->host_scribble = (unsigned char *) req->req_id;
  1926. fcp_cmnd_iu = (struct fcp_cmnd_iu *) &(req->qtcb->bottom.io.fcp_cmnd);
  1927. fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
  1928. /*
  1929. * set depending on data direction:
  1930. * data direction bits in SBALE (SB Type)
  1931. * data direction bits in QTCB
  1932. * data direction bits in FCP_CMND IU
  1933. */
  1934. switch (scsi_cmnd->sc_data_direction) {
  1935. case DMA_NONE:
  1936. req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
  1937. sbtype = SBAL_FLAGS0_TYPE_READ;
  1938. break;
  1939. case DMA_FROM_DEVICE:
  1940. req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
  1941. sbtype = SBAL_FLAGS0_TYPE_READ;
  1942. fcp_cmnd_iu->rddata = 1;
  1943. break;
  1944. case DMA_TO_DEVICE:
  1945. req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
  1946. sbtype = SBAL_FLAGS0_TYPE_WRITE;
  1947. fcp_cmnd_iu->wddata = 1;
  1948. break;
  1949. case DMA_BIDIRECTIONAL:
  1950. default:
  1951. retval = -EIO;
  1952. goto failed_scsi_cmnd;
  1953. }
  1954. if (likely((scsi_cmnd->device->simple_tags) ||
  1955. ((atomic_read(&unit->status) & ZFCP_STATUS_UNIT_READONLY) &&
  1956. (atomic_read(&unit->status) & ZFCP_STATUS_UNIT_SHARED))))
  1957. fcp_cmnd_iu->task_attribute = SIMPLE_Q;
  1958. else
  1959. fcp_cmnd_iu->task_attribute = UNTAGGED;
  1960. if (unlikely(scsi_cmnd->cmd_len > FCP_CDB_LENGTH))
  1961. fcp_cmnd_iu->add_fcp_cdb_length =
  1962. (scsi_cmnd->cmd_len - FCP_CDB_LENGTH) >> 2;
  1963. memcpy(fcp_cmnd_iu->fcp_cdb, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
  1964. req->qtcb->bottom.io.fcp_cmnd_length = sizeof(struct fcp_cmnd_iu) +
  1965. fcp_cmnd_iu->add_fcp_cdb_length + sizeof(fcp_dl_t);
  1966. real_bytes = zfcp_qdio_sbals_from_sg(req, sbtype,
  1967. scsi_sglist(scsi_cmnd),
  1968. FSF_MAX_SBALS_PER_REQ);
  1969. if (unlikely(real_bytes < 0)) {
  1970. if (req->sbal_number < FSF_MAX_SBALS_PER_REQ)
  1971. retval = -EIO;
  1972. else {
  1973. dev_err(&adapter->ccw_device->dev,
  1974. "Oversize data package, unit 0x%016Lx "
  1975. "on port 0x%016Lx closed\n",
  1976. unit->fcp_lun, unit->port->wwpn);
  1977. zfcp_erp_unit_shutdown(unit, 0, 131, req);
  1978. retval = -EINVAL;
  1979. }
  1980. goto failed_scsi_cmnd;
  1981. }
  1982. zfcp_set_fcp_dl(fcp_cmnd_iu, real_bytes);
  1983. if (use_timer)
  1984. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1985. retval = zfcp_fsf_req_send(req);
  1986. if (unlikely(retval))
  1987. goto failed_scsi_cmnd;
  1988. goto out;
  1989. failed_scsi_cmnd:
  1990. zfcp_unit_put(unit);
  1991. zfcp_fsf_req_free(req);
  1992. scsi_cmnd->host_scribble = NULL;
  1993. out:
  1994. spin_unlock(&adapter->req_q.lock);
  1995. return retval;
  1996. }
  1997. /**
  1998. * zfcp_fsf_send_fcp_ctm - send SCSI task management command
  1999. * @adapter: pointer to struct zfcp-adapter
  2000. * @unit: pointer to struct zfcp_unit
  2001. * @tm_flags: unsigned byte for task management flags
  2002. * @req_flags: int request flags
  2003. * Returns: on success pointer to struct fsf_req, NULL otherwise
  2004. */
  2005. struct zfcp_fsf_req *zfcp_fsf_send_fcp_ctm(struct zfcp_adapter *adapter,
  2006. struct zfcp_unit *unit,
  2007. u8 tm_flags, int req_flags)
  2008. {
  2009. volatile struct qdio_buffer_element *sbale;
  2010. struct zfcp_fsf_req *req = NULL;
  2011. struct fcp_cmnd_iu *fcp_cmnd_iu;
  2012. if (unlikely(!(atomic_read(&unit->status) &
  2013. ZFCP_STATUS_COMMON_UNBLOCKED)))
  2014. return NULL;
  2015. spin_lock(&adapter->req_q.lock);
  2016. if (!zfcp_fsf_sbal_available(adapter))
  2017. goto out;
  2018. req = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
  2019. adapter->pool.fsf_req_scsi);
  2020. if (IS_ERR(req))
  2021. goto out;
  2022. req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
  2023. req->data = unit;
  2024. req->handler = zfcp_fsf_send_fcp_command_handler;
  2025. req->qtcb->header.lun_handle = unit->handle;
  2026. req->qtcb->header.port_handle = unit->port->handle;
  2027. req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
  2028. req->qtcb->bottom.io.service_class = FSF_CLASS_3;
  2029. req->qtcb->bottom.io.fcp_cmnd_length = sizeof(struct fcp_cmnd_iu) +
  2030. sizeof(fcp_dl_t);
  2031. sbale = zfcp_qdio_sbale_req(req);
  2032. sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
  2033. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  2034. fcp_cmnd_iu = (struct fcp_cmnd_iu *) &req->qtcb->bottom.io.fcp_cmnd;
  2035. fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
  2036. fcp_cmnd_iu->task_management_flags = tm_flags;
  2037. zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
  2038. if (!zfcp_fsf_req_send(req))
  2039. goto out;
  2040. zfcp_fsf_req_free(req);
  2041. req = NULL;
  2042. out:
  2043. spin_unlock(&adapter->req_q.lock);
  2044. return req;
  2045. }
  2046. static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *req)
  2047. {
  2048. if (req->qtcb->header.fsf_status != FSF_GOOD)
  2049. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2050. }
  2051. /**
  2052. * zfcp_fsf_control_file - control file upload/download
  2053. * @adapter: pointer to struct zfcp_adapter
  2054. * @fsf_cfdc: pointer to struct zfcp_fsf_cfdc
  2055. * Returns: on success pointer to struct zfcp_fsf_req, NULL otherwise
  2056. */
  2057. struct zfcp_fsf_req *zfcp_fsf_control_file(struct zfcp_adapter *adapter,
  2058. struct zfcp_fsf_cfdc *fsf_cfdc)
  2059. {
  2060. volatile struct qdio_buffer_element *sbale;
  2061. struct zfcp_fsf_req *req = NULL;
  2062. struct fsf_qtcb_bottom_support *bottom;
  2063. int direction, retval = -EIO, bytes;
  2064. if (!(adapter->adapter_features & FSF_FEATURE_CFDC))
  2065. return ERR_PTR(-EOPNOTSUPP);
  2066. switch (fsf_cfdc->command) {
  2067. case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
  2068. direction = SBAL_FLAGS0_TYPE_WRITE;
  2069. break;
  2070. case FSF_QTCB_UPLOAD_CONTROL_FILE:
  2071. direction = SBAL_FLAGS0_TYPE_READ;
  2072. break;
  2073. default:
  2074. return ERR_PTR(-EINVAL);
  2075. }
  2076. spin_lock_bh(&adapter->req_q.lock);
  2077. if (zfcp_fsf_req_sbal_get(adapter))
  2078. goto out;
  2079. req = zfcp_fsf_req_create(adapter, fsf_cfdc->command, 0, NULL);
  2080. if (IS_ERR(req)) {
  2081. retval = -EPERM;
  2082. goto out;
  2083. }
  2084. req->handler = zfcp_fsf_control_file_handler;
  2085. sbale = zfcp_qdio_sbale_req(req);
  2086. sbale[0].flags |= direction;
  2087. bottom = &req->qtcb->bottom.support;
  2088. bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
  2089. bottom->option = fsf_cfdc->option;
  2090. bytes = zfcp_qdio_sbals_from_sg(req, direction, fsf_cfdc->sg,
  2091. FSF_MAX_SBALS_PER_REQ);
  2092. if (bytes != ZFCP_CFDC_MAX_SIZE) {
  2093. retval = -ENOMEM;
  2094. zfcp_fsf_req_free(req);
  2095. goto out;
  2096. }
  2097. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  2098. retval = zfcp_fsf_req_send(req);
  2099. out:
  2100. spin_unlock_bh(&adapter->req_q.lock);
  2101. if (!retval) {
  2102. wait_event(req->completion_wq,
  2103. req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
  2104. return req;
  2105. }
  2106. return ERR_PTR(retval);
  2107. }