zfcp_fsf.c 70 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493
  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 fsf_qtcb *qtcb = req->qtcb;
  563. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  564. return;
  565. switch (qtcb->header.fsf_status) {
  566. case FSF_GOOD:
  567. zfcp_fsf_exchange_port_evaluate(req);
  568. break;
  569. case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
  570. zfcp_fsf_exchange_port_evaluate(req);
  571. zfcp_fsf_link_down_info_eval(req, 43,
  572. &qtcb->header.fsf_status_qual.link_down_info);
  573. break;
  574. }
  575. }
  576. static int zfcp_fsf_sbal_check(struct zfcp_qdio_queue *queue)
  577. {
  578. spin_lock_bh(&queue->lock);
  579. if (atomic_read(&queue->count))
  580. return 1;
  581. spin_unlock_bh(&queue->lock);
  582. return 0;
  583. }
  584. static int zfcp_fsf_sbal_available(struct zfcp_adapter *adapter)
  585. {
  586. unsigned int count = atomic_read(&adapter->req_q.count);
  587. if (!count)
  588. atomic_inc(&adapter->qdio_outb_full);
  589. return count > 0;
  590. }
  591. static int zfcp_fsf_req_sbal_get(struct zfcp_adapter *adapter)
  592. {
  593. long ret;
  594. struct zfcp_qdio_queue *req_q = &adapter->req_q;
  595. spin_unlock_bh(&req_q->lock);
  596. ret = wait_event_interruptible_timeout(adapter->request_wq,
  597. zfcp_fsf_sbal_check(req_q), 5 * HZ);
  598. if (ret > 0)
  599. return 0;
  600. if (!ret)
  601. atomic_inc(&adapter->qdio_outb_full);
  602. spin_lock_bh(&req_q->lock);
  603. return -EIO;
  604. }
  605. static struct zfcp_fsf_req *zfcp_fsf_alloc_noqtcb(mempool_t *pool)
  606. {
  607. struct zfcp_fsf_req *req;
  608. req = mempool_alloc(pool, GFP_ATOMIC);
  609. if (!req)
  610. return NULL;
  611. memset(req, 0, sizeof(*req));
  612. return req;
  613. }
  614. static struct zfcp_fsf_req *zfcp_fsf_alloc_qtcb(mempool_t *pool)
  615. {
  616. struct zfcp_fsf_req_qtcb *qtcb;
  617. if (likely(pool))
  618. qtcb = mempool_alloc(pool, GFP_ATOMIC);
  619. else
  620. qtcb = kmem_cache_alloc(zfcp_data.fsf_req_qtcb_cache,
  621. GFP_ATOMIC);
  622. if (unlikely(!qtcb))
  623. return NULL;
  624. memset(qtcb, 0, sizeof(*qtcb));
  625. qtcb->fsf_req.qtcb = &qtcb->qtcb;
  626. qtcb->fsf_req.pool = pool;
  627. return &qtcb->fsf_req;
  628. }
  629. static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_adapter *adapter,
  630. u32 fsf_cmd, int req_flags,
  631. mempool_t *pool)
  632. {
  633. struct qdio_buffer_element *sbale;
  634. struct zfcp_fsf_req *req;
  635. struct zfcp_qdio_queue *req_q = &adapter->req_q;
  636. if (req_flags & ZFCP_REQ_NO_QTCB)
  637. req = zfcp_fsf_alloc_noqtcb(pool);
  638. else
  639. req = zfcp_fsf_alloc_qtcb(pool);
  640. if (unlikely(!req))
  641. return ERR_PTR(-EIO);
  642. if (adapter->req_no == 0)
  643. adapter->req_no++;
  644. INIT_LIST_HEAD(&req->list);
  645. init_timer(&req->timer);
  646. init_waitqueue_head(&req->completion_wq);
  647. req->adapter = adapter;
  648. req->fsf_command = fsf_cmd;
  649. req->req_id = adapter->req_no++;
  650. req->sbal_number = 1;
  651. req->sbal_first = req_q->first;
  652. req->sbal_last = req_q->first;
  653. req->sbale_curr = 1;
  654. sbale = zfcp_qdio_sbale_req(req);
  655. sbale[0].addr = (void *) req->req_id;
  656. sbale[0].flags |= SBAL_FLAGS0_COMMAND;
  657. if (likely(req->qtcb)) {
  658. req->qtcb->prefix.req_seq_no = req->adapter->fsf_req_seq_no;
  659. req->qtcb->prefix.req_id = req->req_id;
  660. req->qtcb->prefix.ulp_info = 26;
  661. req->qtcb->prefix.qtcb_type = fsf_qtcb_type[req->fsf_command];
  662. req->qtcb->prefix.qtcb_version = FSF_QTCB_CURRENT_VERSION;
  663. req->qtcb->header.req_handle = req->req_id;
  664. req->qtcb->header.fsf_command = req->fsf_command;
  665. req->seq_no = adapter->fsf_req_seq_no;
  666. req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
  667. sbale[1].addr = (void *) req->qtcb;
  668. sbale[1].length = sizeof(struct fsf_qtcb);
  669. }
  670. if (!(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP)) {
  671. zfcp_fsf_req_free(req);
  672. return ERR_PTR(-EIO);
  673. }
  674. if (likely(req_flags & ZFCP_REQ_AUTO_CLEANUP))
  675. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  676. return req;
  677. }
  678. static int zfcp_fsf_req_send(struct zfcp_fsf_req *req)
  679. {
  680. struct zfcp_adapter *adapter = req->adapter;
  681. struct zfcp_qdio_queue *req_q = &adapter->req_q;
  682. int idx;
  683. /* put allocated FSF request into hash table */
  684. spin_lock(&adapter->req_list_lock);
  685. idx = zfcp_reqlist_hash(req->req_id);
  686. list_add_tail(&req->list, &adapter->req_list[idx]);
  687. spin_unlock(&adapter->req_list_lock);
  688. req->issued = get_clock();
  689. if (zfcp_qdio_send(req)) {
  690. /* Queues are down..... */
  691. del_timer(&req->timer);
  692. spin_lock(&adapter->req_list_lock);
  693. zfcp_reqlist_remove(adapter, req);
  694. spin_unlock(&adapter->req_list_lock);
  695. /* undo changes in request queue made for this request */
  696. atomic_add(req->sbal_number, &req_q->count);
  697. req_q->first -= req->sbal_number;
  698. req_q->first += QDIO_MAX_BUFFERS_PER_Q;
  699. req_q->first %= QDIO_MAX_BUFFERS_PER_Q; /* wrap */
  700. zfcp_erp_adapter_reopen(adapter, 0, 116, req);
  701. return -EIO;
  702. }
  703. /* Don't increase for unsolicited status */
  704. if (req->qtcb)
  705. adapter->fsf_req_seq_no++;
  706. return 0;
  707. }
  708. /**
  709. * zfcp_fsf_status_read - send status read request
  710. * @adapter: pointer to struct zfcp_adapter
  711. * @req_flags: request flags
  712. * Returns: 0 on success, ERROR otherwise
  713. */
  714. int zfcp_fsf_status_read(struct zfcp_adapter *adapter)
  715. {
  716. struct zfcp_fsf_req *req;
  717. struct fsf_status_read_buffer *sr_buf;
  718. struct qdio_buffer_element *sbale;
  719. int retval = -EIO;
  720. spin_lock_bh(&adapter->req_q.lock);
  721. if (zfcp_fsf_req_sbal_get(adapter))
  722. goto out;
  723. req = zfcp_fsf_req_create(adapter, FSF_QTCB_UNSOLICITED_STATUS,
  724. ZFCP_REQ_NO_QTCB,
  725. adapter->pool.fsf_req_status_read);
  726. if (IS_ERR(req)) {
  727. retval = PTR_ERR(req);
  728. goto out;
  729. }
  730. sbale = zfcp_qdio_sbale_req(req);
  731. sbale[0].flags |= SBAL_FLAGS0_TYPE_STATUS;
  732. sbale[2].flags |= SBAL_FLAGS_LAST_ENTRY;
  733. req->sbale_curr = 2;
  734. sr_buf = mempool_alloc(adapter->pool.data_status_read, GFP_ATOMIC);
  735. if (!sr_buf) {
  736. retval = -ENOMEM;
  737. goto failed_buf;
  738. }
  739. memset(sr_buf, 0, sizeof(*sr_buf));
  740. req->data = sr_buf;
  741. sbale = zfcp_qdio_sbale_curr(req);
  742. sbale->addr = (void *) sr_buf;
  743. sbale->length = sizeof(*sr_buf);
  744. retval = zfcp_fsf_req_send(req);
  745. if (retval)
  746. goto failed_req_send;
  747. goto out;
  748. failed_req_send:
  749. mempool_free(sr_buf, adapter->pool.data_status_read);
  750. failed_buf:
  751. zfcp_fsf_req_free(req);
  752. zfcp_hba_dbf_event_fsf_unsol("fail", adapter, NULL);
  753. out:
  754. spin_unlock_bh(&adapter->req_q.lock);
  755. return retval;
  756. }
  757. static void zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *req)
  758. {
  759. struct zfcp_unit *unit = req->data;
  760. union fsf_status_qual *fsq = &req->qtcb->header.fsf_status_qual;
  761. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  762. return;
  763. switch (req->qtcb->header.fsf_status) {
  764. case FSF_PORT_HANDLE_NOT_VALID:
  765. if (fsq->word[0] == fsq->word[1]) {
  766. zfcp_erp_adapter_reopen(unit->port->adapter, 0, 104,
  767. req);
  768. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  769. }
  770. break;
  771. case FSF_LUN_HANDLE_NOT_VALID:
  772. if (fsq->word[0] == fsq->word[1]) {
  773. zfcp_erp_port_reopen(unit->port, 0, 105, req);
  774. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  775. }
  776. break;
  777. case FSF_FCP_COMMAND_DOES_NOT_EXIST:
  778. req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
  779. break;
  780. case FSF_PORT_BOXED:
  781. zfcp_erp_port_boxed(unit->port, 47, req);
  782. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  783. ZFCP_STATUS_FSFREQ_RETRY;
  784. break;
  785. case FSF_LUN_BOXED:
  786. zfcp_erp_unit_boxed(unit, 48, req);
  787. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  788. ZFCP_STATUS_FSFREQ_RETRY;
  789. break;
  790. case FSF_ADAPTER_STATUS_AVAILABLE:
  791. switch (fsq->word[0]) {
  792. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  793. zfcp_test_link(unit->port);
  794. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  795. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  796. break;
  797. }
  798. break;
  799. case FSF_GOOD:
  800. req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
  801. break;
  802. }
  803. }
  804. /**
  805. * zfcp_fsf_abort_fcp_command - abort running SCSI command
  806. * @old_req_id: unsigned long
  807. * @adapter: pointer to struct zfcp_adapter
  808. * @unit: pointer to struct zfcp_unit
  809. * @req_flags: integer specifying the request flags
  810. * Returns: pointer to struct zfcp_fsf_req
  811. *
  812. * FIXME(design): should be watched by a timeout !!!
  813. */
  814. struct zfcp_fsf_req *zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
  815. struct zfcp_adapter *adapter,
  816. struct zfcp_unit *unit,
  817. int req_flags)
  818. {
  819. struct qdio_buffer_element *sbale;
  820. struct zfcp_fsf_req *req = NULL;
  821. spin_lock(&adapter->req_q.lock);
  822. if (!zfcp_fsf_sbal_available(adapter))
  823. goto out;
  824. req = zfcp_fsf_req_create(adapter, FSF_QTCB_ABORT_FCP_CMND,
  825. req_flags, adapter->pool.fsf_req_abort);
  826. if (IS_ERR(req))
  827. goto out;
  828. if (unlikely(!(atomic_read(&unit->status) &
  829. ZFCP_STATUS_COMMON_UNBLOCKED)))
  830. goto out_error_free;
  831. sbale = zfcp_qdio_sbale_req(req);
  832. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  833. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  834. req->data = unit;
  835. req->handler = zfcp_fsf_abort_fcp_command_handler;
  836. req->qtcb->header.lun_handle = unit->handle;
  837. req->qtcb->header.port_handle = unit->port->handle;
  838. req->qtcb->bottom.support.req_handle = (u64) old_req_id;
  839. zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
  840. if (!zfcp_fsf_req_send(req))
  841. goto out;
  842. out_error_free:
  843. zfcp_fsf_req_free(req);
  844. req = NULL;
  845. out:
  846. spin_unlock(&adapter->req_q.lock);
  847. return req;
  848. }
  849. static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req)
  850. {
  851. struct zfcp_adapter *adapter = req->adapter;
  852. struct zfcp_send_ct *send_ct = req->data;
  853. struct fsf_qtcb_header *header = &req->qtcb->header;
  854. send_ct->status = -EINVAL;
  855. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  856. goto skip_fsfstatus;
  857. switch (header->fsf_status) {
  858. case FSF_GOOD:
  859. zfcp_san_dbf_event_ct_response(req);
  860. send_ct->status = 0;
  861. break;
  862. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  863. zfcp_fsf_class_not_supp(req);
  864. break;
  865. case FSF_ADAPTER_STATUS_AVAILABLE:
  866. switch (header->fsf_status_qual.word[0]){
  867. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  868. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  869. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  870. break;
  871. }
  872. break;
  873. case FSF_ACCESS_DENIED:
  874. break;
  875. case FSF_PORT_BOXED:
  876. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  877. ZFCP_STATUS_FSFREQ_RETRY;
  878. break;
  879. case FSF_PORT_HANDLE_NOT_VALID:
  880. zfcp_erp_adapter_reopen(adapter, 0, 106, req);
  881. case FSF_GENERIC_COMMAND_REJECTED:
  882. case FSF_PAYLOAD_SIZE_MISMATCH:
  883. case FSF_REQUEST_SIZE_TOO_LARGE:
  884. case FSF_RESPONSE_SIZE_TOO_LARGE:
  885. case FSF_SBAL_MISMATCH:
  886. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  887. break;
  888. }
  889. skip_fsfstatus:
  890. if (send_ct->handler)
  891. send_ct->handler(send_ct->handler_data);
  892. }
  893. static int zfcp_fsf_setup_sbals(struct zfcp_fsf_req *req,
  894. struct scatterlist *sg_req,
  895. struct scatterlist *sg_resp, int max_sbals)
  896. {
  897. int bytes;
  898. bytes = zfcp_qdio_sbals_from_sg(req, SBAL_FLAGS0_TYPE_WRITE_READ,
  899. sg_req, max_sbals);
  900. if (bytes <= 0)
  901. return -ENOMEM;
  902. req->qtcb->bottom.support.req_buf_length = bytes;
  903. req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
  904. bytes = zfcp_qdio_sbals_from_sg(req, SBAL_FLAGS0_TYPE_WRITE_READ,
  905. sg_resp, max_sbals);
  906. if (bytes <= 0)
  907. return -ENOMEM;
  908. req->qtcb->bottom.support.resp_buf_length = bytes;
  909. return 0;
  910. }
  911. /**
  912. * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
  913. * @ct: pointer to struct zfcp_send_ct with data for request
  914. * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req
  915. * @erp_action: if non-null the Generic Service request sent within ERP
  916. */
  917. int zfcp_fsf_send_ct(struct zfcp_send_ct *ct, mempool_t *pool,
  918. struct zfcp_erp_action *erp_action)
  919. {
  920. struct zfcp_wka_port *wka_port = ct->wka_port;
  921. struct zfcp_adapter *adapter = wka_port->adapter;
  922. struct zfcp_fsf_req *req;
  923. int ret = -EIO;
  924. spin_lock_bh(&adapter->req_q.lock);
  925. if (zfcp_fsf_req_sbal_get(adapter))
  926. goto out;
  927. req = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_GENERIC,
  928. ZFCP_REQ_AUTO_CLEANUP, pool);
  929. if (IS_ERR(req)) {
  930. ret = PTR_ERR(req);
  931. goto out;
  932. }
  933. ret = zfcp_fsf_setup_sbals(req, ct->req, ct->resp,
  934. FSF_MAX_SBALS_PER_REQ);
  935. if (ret)
  936. goto failed_send;
  937. req->handler = zfcp_fsf_send_ct_handler;
  938. req->qtcb->header.port_handle = wka_port->handle;
  939. req->qtcb->bottom.support.service_class = FSF_CLASS_3;
  940. req->qtcb->bottom.support.timeout = ct->timeout;
  941. req->data = ct;
  942. zfcp_san_dbf_event_ct_request(req);
  943. if (erp_action) {
  944. erp_action->fsf_req = req;
  945. req->erp_action = erp_action;
  946. zfcp_fsf_start_erp_timer(req);
  947. } else
  948. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  949. ret = zfcp_fsf_req_send(req);
  950. if (ret)
  951. goto failed_send;
  952. goto out;
  953. failed_send:
  954. zfcp_fsf_req_free(req);
  955. if (erp_action)
  956. erp_action->fsf_req = NULL;
  957. out:
  958. spin_unlock_bh(&adapter->req_q.lock);
  959. return ret;
  960. }
  961. static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req)
  962. {
  963. struct zfcp_send_els *send_els = req->data;
  964. struct zfcp_port *port = send_els->port;
  965. struct fsf_qtcb_header *header = &req->qtcb->header;
  966. send_els->status = -EINVAL;
  967. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  968. goto skip_fsfstatus;
  969. switch (header->fsf_status) {
  970. case FSF_GOOD:
  971. zfcp_san_dbf_event_els_response(req);
  972. send_els->status = 0;
  973. break;
  974. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  975. zfcp_fsf_class_not_supp(req);
  976. break;
  977. case FSF_ADAPTER_STATUS_AVAILABLE:
  978. switch (header->fsf_status_qual.word[0]){
  979. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  980. if (port && (send_els->ls_code != ZFCP_LS_ADISC))
  981. zfcp_test_link(port);
  982. /*fall through */
  983. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  984. case FSF_SQ_RETRY_IF_POSSIBLE:
  985. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  986. break;
  987. }
  988. break;
  989. case FSF_ELS_COMMAND_REJECTED:
  990. case FSF_PAYLOAD_SIZE_MISMATCH:
  991. case FSF_REQUEST_SIZE_TOO_LARGE:
  992. case FSF_RESPONSE_SIZE_TOO_LARGE:
  993. break;
  994. case FSF_ACCESS_DENIED:
  995. zfcp_fsf_access_denied_port(req, port);
  996. break;
  997. case FSF_SBAL_MISMATCH:
  998. /* should never occure, avoided in zfcp_fsf_send_els */
  999. /* fall through */
  1000. default:
  1001. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1002. break;
  1003. }
  1004. skip_fsfstatus:
  1005. if (send_els->handler)
  1006. send_els->handler(send_els->handler_data);
  1007. }
  1008. /**
  1009. * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
  1010. * @els: pointer to struct zfcp_send_els with data for the command
  1011. */
  1012. int zfcp_fsf_send_els(struct zfcp_send_els *els)
  1013. {
  1014. struct zfcp_fsf_req *req;
  1015. struct zfcp_adapter *adapter = els->adapter;
  1016. struct fsf_qtcb_bottom_support *bottom;
  1017. int ret = -EIO;
  1018. if (unlikely(!(atomic_read(&els->port->status) &
  1019. ZFCP_STATUS_COMMON_UNBLOCKED)))
  1020. return -EBUSY;
  1021. spin_lock(&adapter->req_q.lock);
  1022. if (!zfcp_fsf_sbal_available(adapter))
  1023. goto out;
  1024. req = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_ELS,
  1025. ZFCP_REQ_AUTO_CLEANUP, NULL);
  1026. if (IS_ERR(req)) {
  1027. ret = PTR_ERR(req);
  1028. goto out;
  1029. }
  1030. ret = zfcp_fsf_setup_sbals(req, els->req, els->resp, 2);
  1031. if (ret)
  1032. goto failed_send;
  1033. bottom = &req->qtcb->bottom.support;
  1034. req->handler = zfcp_fsf_send_els_handler;
  1035. bottom->d_id = els->d_id;
  1036. bottom->service_class = FSF_CLASS_3;
  1037. bottom->timeout = 2 * R_A_TOV;
  1038. req->data = els;
  1039. zfcp_san_dbf_event_els_request(req);
  1040. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1041. ret = zfcp_fsf_req_send(req);
  1042. if (ret)
  1043. goto failed_send;
  1044. goto out;
  1045. failed_send:
  1046. zfcp_fsf_req_free(req);
  1047. out:
  1048. spin_unlock(&adapter->req_q.lock);
  1049. return ret;
  1050. }
  1051. int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
  1052. {
  1053. struct qdio_buffer_element *sbale;
  1054. struct zfcp_fsf_req *req;
  1055. struct zfcp_adapter *adapter = erp_action->adapter;
  1056. int retval = -EIO;
  1057. spin_lock_bh(&adapter->req_q.lock);
  1058. if (!zfcp_fsf_sbal_available(adapter))
  1059. goto out;
  1060. req = zfcp_fsf_req_create(adapter,
  1061. FSF_QTCB_EXCHANGE_CONFIG_DATA,
  1062. ZFCP_REQ_AUTO_CLEANUP,
  1063. adapter->pool.fsf_req_erp);
  1064. if (IS_ERR(req)) {
  1065. retval = PTR_ERR(req);
  1066. goto out;
  1067. }
  1068. sbale = zfcp_qdio_sbale_req(req);
  1069. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1070. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1071. req->qtcb->bottom.config.feature_selection =
  1072. FSF_FEATURE_CFDC |
  1073. FSF_FEATURE_LUN_SHARING |
  1074. FSF_FEATURE_NOTIFICATION_LOST |
  1075. FSF_FEATURE_UPDATE_ALERT;
  1076. req->erp_action = erp_action;
  1077. req->handler = zfcp_fsf_exchange_config_data_handler;
  1078. erp_action->fsf_req = req;
  1079. zfcp_fsf_start_erp_timer(req);
  1080. retval = zfcp_fsf_req_send(req);
  1081. if (retval) {
  1082. zfcp_fsf_req_free(req);
  1083. erp_action->fsf_req = NULL;
  1084. }
  1085. out:
  1086. spin_unlock_bh(&adapter->req_q.lock);
  1087. return retval;
  1088. }
  1089. int zfcp_fsf_exchange_config_data_sync(struct zfcp_adapter *adapter,
  1090. struct fsf_qtcb_bottom_config *data)
  1091. {
  1092. struct qdio_buffer_element *sbale;
  1093. struct zfcp_fsf_req *req = NULL;
  1094. int retval = -EIO;
  1095. spin_lock_bh(&adapter->req_q.lock);
  1096. if (zfcp_fsf_req_sbal_get(adapter))
  1097. goto out;
  1098. req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_CONFIG_DATA,
  1099. 0, NULL);
  1100. if (IS_ERR(req)) {
  1101. retval = PTR_ERR(req);
  1102. goto out;
  1103. }
  1104. sbale = zfcp_qdio_sbale_req(req);
  1105. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1106. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1107. req->handler = zfcp_fsf_exchange_config_data_handler;
  1108. req->qtcb->bottom.config.feature_selection =
  1109. FSF_FEATURE_CFDC |
  1110. FSF_FEATURE_LUN_SHARING |
  1111. FSF_FEATURE_NOTIFICATION_LOST |
  1112. FSF_FEATURE_UPDATE_ALERT;
  1113. if (data)
  1114. req->data = data;
  1115. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1116. retval = zfcp_fsf_req_send(req);
  1117. out:
  1118. spin_unlock_bh(&adapter->req_q.lock);
  1119. if (!retval)
  1120. wait_event(req->completion_wq,
  1121. req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
  1122. zfcp_fsf_req_free(req);
  1123. return retval;
  1124. }
  1125. /**
  1126. * zfcp_fsf_exchange_port_data - request information about local port
  1127. * @erp_action: ERP action for the adapter for which port data is requested
  1128. * Returns: 0 on success, error otherwise
  1129. */
  1130. int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
  1131. {
  1132. struct qdio_buffer_element *sbale;
  1133. struct zfcp_fsf_req *req;
  1134. struct zfcp_adapter *adapter = erp_action->adapter;
  1135. int retval = -EIO;
  1136. if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
  1137. return -EOPNOTSUPP;
  1138. spin_lock_bh(&adapter->req_q.lock);
  1139. if (!zfcp_fsf_sbal_available(adapter))
  1140. goto out;
  1141. req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA,
  1142. ZFCP_REQ_AUTO_CLEANUP,
  1143. adapter->pool.fsf_req_erp);
  1144. if (IS_ERR(req)) {
  1145. retval = PTR_ERR(req);
  1146. goto out;
  1147. }
  1148. sbale = zfcp_qdio_sbale_req(req);
  1149. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1150. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1151. req->handler = zfcp_fsf_exchange_port_data_handler;
  1152. req->erp_action = erp_action;
  1153. erp_action->fsf_req = req;
  1154. zfcp_fsf_start_erp_timer(req);
  1155. retval = zfcp_fsf_req_send(req);
  1156. if (retval) {
  1157. zfcp_fsf_req_free(req);
  1158. erp_action->fsf_req = NULL;
  1159. }
  1160. out:
  1161. spin_unlock_bh(&adapter->req_q.lock);
  1162. return retval;
  1163. }
  1164. /**
  1165. * zfcp_fsf_exchange_port_data_sync - request information about local port
  1166. * @adapter: pointer to struct zfcp_adapter
  1167. * @data: pointer to struct fsf_qtcb_bottom_port
  1168. * Returns: 0 on success, error otherwise
  1169. */
  1170. int zfcp_fsf_exchange_port_data_sync(struct zfcp_adapter *adapter,
  1171. struct fsf_qtcb_bottom_port *data)
  1172. {
  1173. struct qdio_buffer_element *sbale;
  1174. struct zfcp_fsf_req *req = NULL;
  1175. int retval = -EIO;
  1176. if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
  1177. return -EOPNOTSUPP;
  1178. spin_lock_bh(&adapter->req_q.lock);
  1179. if (!zfcp_fsf_sbal_available(adapter))
  1180. goto out;
  1181. req = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA, 0,
  1182. NULL);
  1183. if (IS_ERR(req)) {
  1184. retval = PTR_ERR(req);
  1185. goto out;
  1186. }
  1187. if (data)
  1188. req->data = data;
  1189. sbale = zfcp_qdio_sbale_req(req);
  1190. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1191. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1192. req->handler = zfcp_fsf_exchange_port_data_handler;
  1193. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1194. retval = zfcp_fsf_req_send(req);
  1195. out:
  1196. spin_unlock_bh(&adapter->req_q.lock);
  1197. if (!retval)
  1198. wait_event(req->completion_wq,
  1199. req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
  1200. zfcp_fsf_req_free(req);
  1201. return retval;
  1202. }
  1203. static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
  1204. {
  1205. struct zfcp_port *port = req->data;
  1206. struct fsf_qtcb_header *header = &req->qtcb->header;
  1207. struct fsf_plogi *plogi;
  1208. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1209. return;
  1210. switch (header->fsf_status) {
  1211. case FSF_PORT_ALREADY_OPEN:
  1212. break;
  1213. case FSF_ACCESS_DENIED:
  1214. zfcp_fsf_access_denied_port(req, port);
  1215. break;
  1216. case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
  1217. dev_warn(&req->adapter->ccw_device->dev,
  1218. "Not enough FCP adapter resources to open "
  1219. "remote port 0x%016Lx\n", port->wwpn);
  1220. zfcp_erp_port_failed(port, 31, req);
  1221. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1222. break;
  1223. case FSF_ADAPTER_STATUS_AVAILABLE:
  1224. switch (header->fsf_status_qual.word[0]) {
  1225. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1226. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1227. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1228. break;
  1229. case FSF_SQ_NO_RETRY_POSSIBLE:
  1230. dev_warn(&req->adapter->ccw_device->dev,
  1231. "Remote port 0x%016Lx could not be opened\n",
  1232. port->wwpn);
  1233. zfcp_erp_port_failed(port, 32, req);
  1234. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1235. break;
  1236. }
  1237. break;
  1238. case FSF_GOOD:
  1239. port->handle = header->port_handle;
  1240. atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
  1241. ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1242. atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
  1243. ZFCP_STATUS_COMMON_ACCESS_BOXED,
  1244. &port->status);
  1245. /* check whether D_ID has changed during open */
  1246. /*
  1247. * FIXME: This check is not airtight, as the FCP channel does
  1248. * not monitor closures of target port connections caused on
  1249. * the remote side. Thus, they might miss out on invalidating
  1250. * locally cached WWPNs (and other N_Port parameters) of gone
  1251. * target ports. So, our heroic attempt to make things safe
  1252. * could be undermined by 'open port' response data tagged with
  1253. * obsolete WWPNs. Another reason to monitor potential
  1254. * connection closures ourself at least (by interpreting
  1255. * incoming ELS' and unsolicited status). It just crosses my
  1256. * mind that one should be able to cross-check by means of
  1257. * another GID_PN straight after a port has been opened.
  1258. * Alternately, an ADISC/PDISC ELS should suffice, as well.
  1259. */
  1260. plogi = (struct fsf_plogi *) req->qtcb->bottom.support.els;
  1261. if (req->qtcb->bottom.support.els1_length >= sizeof(*plogi)) {
  1262. if (plogi->serv_param.wwpn != port->wwpn)
  1263. atomic_clear_mask(ZFCP_STATUS_PORT_DID_DID,
  1264. &port->status);
  1265. else {
  1266. port->wwnn = plogi->serv_param.wwnn;
  1267. zfcp_fc_plogi_evaluate(port, plogi);
  1268. }
  1269. }
  1270. break;
  1271. case FSF_UNKNOWN_OP_SUBTYPE:
  1272. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1273. break;
  1274. }
  1275. }
  1276. /**
  1277. * zfcp_fsf_open_port - create and send open port request
  1278. * @erp_action: pointer to struct zfcp_erp_action
  1279. * Returns: 0 on success, error otherwise
  1280. */
  1281. int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
  1282. {
  1283. struct qdio_buffer_element *sbale;
  1284. struct zfcp_adapter *adapter = erp_action->adapter;
  1285. struct zfcp_fsf_req *req;
  1286. int retval = -EIO;
  1287. spin_lock_bh(&adapter->req_q.lock);
  1288. if (zfcp_fsf_req_sbal_get(adapter))
  1289. goto out;
  1290. req = zfcp_fsf_req_create(adapter,
  1291. FSF_QTCB_OPEN_PORT_WITH_DID,
  1292. ZFCP_REQ_AUTO_CLEANUP,
  1293. adapter->pool.fsf_req_erp);
  1294. if (IS_ERR(req)) {
  1295. retval = PTR_ERR(req);
  1296. goto out;
  1297. }
  1298. sbale = zfcp_qdio_sbale_req(req);
  1299. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1300. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1301. req->handler = zfcp_fsf_open_port_handler;
  1302. req->qtcb->bottom.support.d_id = erp_action->port->d_id;
  1303. req->data = erp_action->port;
  1304. req->erp_action = erp_action;
  1305. erp_action->fsf_req = req;
  1306. zfcp_fsf_start_erp_timer(req);
  1307. retval = zfcp_fsf_req_send(req);
  1308. if (retval) {
  1309. zfcp_fsf_req_free(req);
  1310. erp_action->fsf_req = NULL;
  1311. }
  1312. out:
  1313. spin_unlock_bh(&adapter->req_q.lock);
  1314. return retval;
  1315. }
  1316. static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req)
  1317. {
  1318. struct zfcp_port *port = req->data;
  1319. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1320. return;
  1321. switch (req->qtcb->header.fsf_status) {
  1322. case FSF_PORT_HANDLE_NOT_VALID:
  1323. zfcp_erp_adapter_reopen(port->adapter, 0, 107, req);
  1324. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1325. break;
  1326. case FSF_ADAPTER_STATUS_AVAILABLE:
  1327. break;
  1328. case FSF_GOOD:
  1329. zfcp_erp_modify_port_status(port, 33, req,
  1330. ZFCP_STATUS_COMMON_OPEN,
  1331. ZFCP_CLEAR);
  1332. break;
  1333. }
  1334. }
  1335. /**
  1336. * zfcp_fsf_close_port - create and send close port request
  1337. * @erp_action: pointer to struct zfcp_erp_action
  1338. * Returns: 0 on success, error otherwise
  1339. */
  1340. int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
  1341. {
  1342. struct qdio_buffer_element *sbale;
  1343. struct zfcp_adapter *adapter = erp_action->adapter;
  1344. struct zfcp_fsf_req *req;
  1345. int retval = -EIO;
  1346. spin_lock_bh(&adapter->req_q.lock);
  1347. if (zfcp_fsf_req_sbal_get(adapter))
  1348. goto out;
  1349. req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_PORT,
  1350. ZFCP_REQ_AUTO_CLEANUP,
  1351. adapter->pool.fsf_req_erp);
  1352. if (IS_ERR(req)) {
  1353. retval = PTR_ERR(req);
  1354. goto out;
  1355. }
  1356. sbale = zfcp_qdio_sbale_req(req);
  1357. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1358. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1359. req->handler = zfcp_fsf_close_port_handler;
  1360. req->data = erp_action->port;
  1361. req->erp_action = erp_action;
  1362. req->qtcb->header.port_handle = erp_action->port->handle;
  1363. erp_action->fsf_req = req;
  1364. zfcp_fsf_start_erp_timer(req);
  1365. retval = zfcp_fsf_req_send(req);
  1366. if (retval) {
  1367. zfcp_fsf_req_free(req);
  1368. erp_action->fsf_req = NULL;
  1369. }
  1370. out:
  1371. spin_unlock_bh(&adapter->req_q.lock);
  1372. return retval;
  1373. }
  1374. static void zfcp_fsf_open_wka_port_handler(struct zfcp_fsf_req *req)
  1375. {
  1376. struct zfcp_wka_port *wka_port = req->data;
  1377. struct fsf_qtcb_header *header = &req->qtcb->header;
  1378. if (req->status & ZFCP_STATUS_FSFREQ_ERROR) {
  1379. wka_port->status = ZFCP_WKA_PORT_OFFLINE;
  1380. goto out;
  1381. }
  1382. switch (header->fsf_status) {
  1383. case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
  1384. dev_warn(&req->adapter->ccw_device->dev,
  1385. "Opening WKA port 0x%x failed\n", wka_port->d_id);
  1386. case FSF_ADAPTER_STATUS_AVAILABLE:
  1387. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1388. case FSF_ACCESS_DENIED:
  1389. wka_port->status = ZFCP_WKA_PORT_OFFLINE;
  1390. break;
  1391. case FSF_PORT_ALREADY_OPEN:
  1392. case FSF_GOOD:
  1393. wka_port->handle = header->port_handle;
  1394. wka_port->status = ZFCP_WKA_PORT_ONLINE;
  1395. }
  1396. out:
  1397. wake_up(&wka_port->completion_wq);
  1398. }
  1399. /**
  1400. * zfcp_fsf_open_wka_port - create and send open wka-port request
  1401. * @wka_port: pointer to struct zfcp_wka_port
  1402. * Returns: 0 on success, error otherwise
  1403. */
  1404. int zfcp_fsf_open_wka_port(struct zfcp_wka_port *wka_port)
  1405. {
  1406. struct qdio_buffer_element *sbale;
  1407. struct zfcp_adapter *adapter = wka_port->adapter;
  1408. struct zfcp_fsf_req *req;
  1409. int retval = -EIO;
  1410. spin_lock_bh(&adapter->req_q.lock);
  1411. if (zfcp_fsf_req_sbal_get(adapter))
  1412. goto out;
  1413. req = zfcp_fsf_req_create(adapter,
  1414. FSF_QTCB_OPEN_PORT_WITH_DID,
  1415. ZFCP_REQ_AUTO_CLEANUP,
  1416. adapter->pool.fsf_req_erp);
  1417. if (unlikely(IS_ERR(req))) {
  1418. retval = PTR_ERR(req);
  1419. goto out;
  1420. }
  1421. sbale = zfcp_qdio_sbale_req(req);
  1422. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1423. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1424. req->handler = zfcp_fsf_open_wka_port_handler;
  1425. req->qtcb->bottom.support.d_id = wka_port->d_id;
  1426. req->data = wka_port;
  1427. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1428. retval = zfcp_fsf_req_send(req);
  1429. if (retval)
  1430. zfcp_fsf_req_free(req);
  1431. out:
  1432. spin_unlock_bh(&adapter->req_q.lock);
  1433. return retval;
  1434. }
  1435. static void zfcp_fsf_close_wka_port_handler(struct zfcp_fsf_req *req)
  1436. {
  1437. struct zfcp_wka_port *wka_port = req->data;
  1438. if (req->qtcb->header.fsf_status == FSF_PORT_HANDLE_NOT_VALID) {
  1439. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1440. zfcp_erp_adapter_reopen(wka_port->adapter, 0, 107, req);
  1441. }
  1442. wka_port->status = ZFCP_WKA_PORT_OFFLINE;
  1443. wake_up(&wka_port->completion_wq);
  1444. }
  1445. /**
  1446. * zfcp_fsf_close_wka_port - create and send close wka port request
  1447. * @erp_action: pointer to struct zfcp_erp_action
  1448. * Returns: 0 on success, error otherwise
  1449. */
  1450. int zfcp_fsf_close_wka_port(struct zfcp_wka_port *wka_port)
  1451. {
  1452. struct qdio_buffer_element *sbale;
  1453. struct zfcp_adapter *adapter = wka_port->adapter;
  1454. struct zfcp_fsf_req *req;
  1455. int retval = -EIO;
  1456. spin_lock_bh(&adapter->req_q.lock);
  1457. if (zfcp_fsf_req_sbal_get(adapter))
  1458. goto out;
  1459. req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_PORT,
  1460. ZFCP_REQ_AUTO_CLEANUP,
  1461. adapter->pool.fsf_req_erp);
  1462. if (unlikely(IS_ERR(req))) {
  1463. retval = PTR_ERR(req);
  1464. goto out;
  1465. }
  1466. sbale = zfcp_qdio_sbale_req(req);
  1467. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1468. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1469. req->handler = zfcp_fsf_close_wka_port_handler;
  1470. req->data = wka_port;
  1471. req->qtcb->header.port_handle = wka_port->handle;
  1472. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1473. retval = zfcp_fsf_req_send(req);
  1474. if (retval)
  1475. zfcp_fsf_req_free(req);
  1476. out:
  1477. spin_unlock_bh(&adapter->req_q.lock);
  1478. return retval;
  1479. }
  1480. static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *req)
  1481. {
  1482. struct zfcp_port *port = req->data;
  1483. struct fsf_qtcb_header *header = &req->qtcb->header;
  1484. struct zfcp_unit *unit;
  1485. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1486. goto skip_fsfstatus;
  1487. switch (header->fsf_status) {
  1488. case FSF_PORT_HANDLE_NOT_VALID:
  1489. zfcp_erp_adapter_reopen(port->adapter, 0, 108, req);
  1490. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1491. break;
  1492. case FSF_ACCESS_DENIED:
  1493. zfcp_fsf_access_denied_port(req, port);
  1494. break;
  1495. case FSF_PORT_BOXED:
  1496. zfcp_erp_port_boxed(port, 50, req);
  1497. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  1498. ZFCP_STATUS_FSFREQ_RETRY;
  1499. /* can't use generic zfcp_erp_modify_port_status because
  1500. * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
  1501. atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1502. list_for_each_entry(unit, &port->unit_list_head, list)
  1503. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
  1504. &unit->status);
  1505. break;
  1506. case FSF_ADAPTER_STATUS_AVAILABLE:
  1507. switch (header->fsf_status_qual.word[0]) {
  1508. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1509. /* fall through */
  1510. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1511. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1512. break;
  1513. }
  1514. break;
  1515. case FSF_GOOD:
  1516. /* can't use generic zfcp_erp_modify_port_status because
  1517. * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
  1518. */
  1519. atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1520. list_for_each_entry(unit, &port->unit_list_head, list)
  1521. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
  1522. &unit->status);
  1523. break;
  1524. }
  1525. skip_fsfstatus:
  1526. atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_CLOSING, &port->status);
  1527. }
  1528. /**
  1529. * zfcp_fsf_close_physical_port - close physical port
  1530. * @erp_action: pointer to struct zfcp_erp_action
  1531. * Returns: 0 on success
  1532. */
  1533. int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
  1534. {
  1535. struct qdio_buffer_element *sbale;
  1536. struct zfcp_adapter *adapter = erp_action->adapter;
  1537. struct zfcp_fsf_req *req;
  1538. int retval = -EIO;
  1539. spin_lock_bh(&adapter->req_q.lock);
  1540. if (zfcp_fsf_req_sbal_get(adapter))
  1541. goto out;
  1542. req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_PHYSICAL_PORT,
  1543. ZFCP_REQ_AUTO_CLEANUP,
  1544. adapter->pool.fsf_req_erp);
  1545. if (IS_ERR(req)) {
  1546. retval = PTR_ERR(req);
  1547. goto out;
  1548. }
  1549. sbale = zfcp_qdio_sbale_req(req);
  1550. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1551. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1552. req->data = erp_action->port;
  1553. req->qtcb->header.port_handle = erp_action->port->handle;
  1554. req->erp_action = erp_action;
  1555. req->handler = zfcp_fsf_close_physical_port_handler;
  1556. erp_action->fsf_req = req;
  1557. atomic_set_mask(ZFCP_STATUS_PORT_PHYS_CLOSING,
  1558. &erp_action->port->status);
  1559. zfcp_fsf_start_erp_timer(req);
  1560. retval = zfcp_fsf_req_send(req);
  1561. if (retval) {
  1562. zfcp_fsf_req_free(req);
  1563. erp_action->fsf_req = NULL;
  1564. }
  1565. out:
  1566. spin_unlock_bh(&adapter->req_q.lock);
  1567. return retval;
  1568. }
  1569. static void zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *req)
  1570. {
  1571. struct zfcp_adapter *adapter = req->adapter;
  1572. struct zfcp_unit *unit = req->data;
  1573. struct fsf_qtcb_header *header = &req->qtcb->header;
  1574. struct fsf_qtcb_bottom_support *bottom = &req->qtcb->bottom.support;
  1575. struct fsf_queue_designator *queue_designator =
  1576. &header->fsf_status_qual.fsf_queue_designator;
  1577. int exclusive, readwrite;
  1578. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1579. return;
  1580. atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
  1581. ZFCP_STATUS_COMMON_ACCESS_BOXED |
  1582. ZFCP_STATUS_UNIT_SHARED |
  1583. ZFCP_STATUS_UNIT_READONLY,
  1584. &unit->status);
  1585. switch (header->fsf_status) {
  1586. case FSF_PORT_HANDLE_NOT_VALID:
  1587. zfcp_erp_adapter_reopen(unit->port->adapter, 0, 109, req);
  1588. /* fall through */
  1589. case FSF_LUN_ALREADY_OPEN:
  1590. break;
  1591. case FSF_ACCESS_DENIED:
  1592. zfcp_fsf_access_denied_unit(req, unit);
  1593. atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
  1594. atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
  1595. break;
  1596. case FSF_PORT_BOXED:
  1597. zfcp_erp_port_boxed(unit->port, 51, req);
  1598. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  1599. ZFCP_STATUS_FSFREQ_RETRY;
  1600. break;
  1601. case FSF_LUN_SHARING_VIOLATION:
  1602. if (header->fsf_status_qual.word[0])
  1603. dev_warn(&adapter->ccw_device->dev,
  1604. "LUN 0x%Lx on port 0x%Lx is already in "
  1605. "use by CSS%d, MIF Image ID %x\n",
  1606. unit->fcp_lun,
  1607. unit->port->wwpn,
  1608. queue_designator->cssid,
  1609. queue_designator->hla);
  1610. else
  1611. zfcp_act_eval_err(adapter,
  1612. header->fsf_status_qual.word[2]);
  1613. zfcp_erp_unit_access_denied(unit, 60, req);
  1614. atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
  1615. atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
  1616. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1617. break;
  1618. case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
  1619. dev_warn(&adapter->ccw_device->dev,
  1620. "No handle is available for LUN "
  1621. "0x%016Lx on port 0x%016Lx\n",
  1622. unit->fcp_lun, unit->port->wwpn);
  1623. zfcp_erp_unit_failed(unit, 34, req);
  1624. /* fall through */
  1625. case FSF_INVALID_COMMAND_OPTION:
  1626. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1627. break;
  1628. case FSF_ADAPTER_STATUS_AVAILABLE:
  1629. switch (header->fsf_status_qual.word[0]) {
  1630. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1631. zfcp_test_link(unit->port);
  1632. /* fall through */
  1633. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1634. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1635. break;
  1636. }
  1637. break;
  1638. case FSF_GOOD:
  1639. unit->handle = header->lun_handle;
  1640. atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
  1641. if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
  1642. (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
  1643. (adapter->ccw_device->id.dev_model != ZFCP_DEVICE_MODEL_PRIV)) {
  1644. exclusive = (bottom->lun_access_info &
  1645. FSF_UNIT_ACCESS_EXCLUSIVE);
  1646. readwrite = (bottom->lun_access_info &
  1647. FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
  1648. if (!exclusive)
  1649. atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
  1650. &unit->status);
  1651. if (!readwrite) {
  1652. atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
  1653. &unit->status);
  1654. dev_info(&adapter->ccw_device->dev,
  1655. "SCSI device at LUN 0x%016Lx on port "
  1656. "0x%016Lx opened read-only\n",
  1657. unit->fcp_lun, unit->port->wwpn);
  1658. }
  1659. if (exclusive && !readwrite) {
  1660. dev_err(&adapter->ccw_device->dev,
  1661. "Exclusive read-only access not "
  1662. "supported (unit 0x%016Lx, "
  1663. "port 0x%016Lx)\n",
  1664. unit->fcp_lun, unit->port->wwpn);
  1665. zfcp_erp_unit_failed(unit, 35, req);
  1666. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1667. zfcp_erp_unit_shutdown(unit, 0, 80, req);
  1668. } else if (!exclusive && readwrite) {
  1669. dev_err(&adapter->ccw_device->dev,
  1670. "Shared read-write access not "
  1671. "supported (unit 0x%016Lx, port "
  1672. "0x%016Lx\n)",
  1673. unit->fcp_lun, unit->port->wwpn);
  1674. zfcp_erp_unit_failed(unit, 36, req);
  1675. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1676. zfcp_erp_unit_shutdown(unit, 0, 81, req);
  1677. }
  1678. }
  1679. break;
  1680. }
  1681. }
  1682. /**
  1683. * zfcp_fsf_open_unit - open unit
  1684. * @erp_action: pointer to struct zfcp_erp_action
  1685. * Returns: 0 on success, error otherwise
  1686. */
  1687. int zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
  1688. {
  1689. struct qdio_buffer_element *sbale;
  1690. struct zfcp_adapter *adapter = erp_action->adapter;
  1691. struct zfcp_fsf_req *req;
  1692. int retval = -EIO;
  1693. spin_lock_bh(&adapter->req_q.lock);
  1694. if (zfcp_fsf_req_sbal_get(adapter))
  1695. goto out;
  1696. req = zfcp_fsf_req_create(adapter, FSF_QTCB_OPEN_LUN,
  1697. ZFCP_REQ_AUTO_CLEANUP,
  1698. adapter->pool.fsf_req_erp);
  1699. if (IS_ERR(req)) {
  1700. retval = PTR_ERR(req);
  1701. goto out;
  1702. }
  1703. sbale = zfcp_qdio_sbale_req(req);
  1704. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1705. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1706. req->qtcb->header.port_handle = erp_action->port->handle;
  1707. req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun;
  1708. req->handler = zfcp_fsf_open_unit_handler;
  1709. req->data = erp_action->unit;
  1710. req->erp_action = erp_action;
  1711. erp_action->fsf_req = req;
  1712. if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE))
  1713. req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING;
  1714. zfcp_fsf_start_erp_timer(req);
  1715. retval = zfcp_fsf_req_send(req);
  1716. if (retval) {
  1717. zfcp_fsf_req_free(req);
  1718. erp_action->fsf_req = NULL;
  1719. }
  1720. out:
  1721. spin_unlock_bh(&adapter->req_q.lock);
  1722. return retval;
  1723. }
  1724. static void zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *req)
  1725. {
  1726. struct zfcp_unit *unit = req->data;
  1727. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1728. return;
  1729. switch (req->qtcb->header.fsf_status) {
  1730. case FSF_PORT_HANDLE_NOT_VALID:
  1731. zfcp_erp_adapter_reopen(unit->port->adapter, 0, 110, req);
  1732. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1733. break;
  1734. case FSF_LUN_HANDLE_NOT_VALID:
  1735. zfcp_erp_port_reopen(unit->port, 0, 111, req);
  1736. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1737. break;
  1738. case FSF_PORT_BOXED:
  1739. zfcp_erp_port_boxed(unit->port, 52, req);
  1740. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  1741. ZFCP_STATUS_FSFREQ_RETRY;
  1742. break;
  1743. case FSF_ADAPTER_STATUS_AVAILABLE:
  1744. switch (req->qtcb->header.fsf_status_qual.word[0]) {
  1745. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1746. zfcp_test_link(unit->port);
  1747. /* fall through */
  1748. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1749. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1750. break;
  1751. }
  1752. break;
  1753. case FSF_GOOD:
  1754. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
  1755. break;
  1756. }
  1757. }
  1758. /**
  1759. * zfcp_fsf_close_unit - close zfcp unit
  1760. * @erp_action: pointer to struct zfcp_unit
  1761. * Returns: 0 on success, error otherwise
  1762. */
  1763. int zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
  1764. {
  1765. struct qdio_buffer_element *sbale;
  1766. struct zfcp_adapter *adapter = erp_action->adapter;
  1767. struct zfcp_fsf_req *req;
  1768. int retval = -EIO;
  1769. spin_lock_bh(&adapter->req_q.lock);
  1770. if (zfcp_fsf_req_sbal_get(adapter))
  1771. goto out;
  1772. req = zfcp_fsf_req_create(adapter, FSF_QTCB_CLOSE_LUN,
  1773. ZFCP_REQ_AUTO_CLEANUP,
  1774. adapter->pool.fsf_req_erp);
  1775. if (IS_ERR(req)) {
  1776. retval = PTR_ERR(req);
  1777. goto out;
  1778. }
  1779. sbale = zfcp_qdio_sbale_req(req);
  1780. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1781. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1782. req->qtcb->header.port_handle = erp_action->port->handle;
  1783. req->qtcb->header.lun_handle = erp_action->unit->handle;
  1784. req->handler = zfcp_fsf_close_unit_handler;
  1785. req->data = erp_action->unit;
  1786. req->erp_action = erp_action;
  1787. erp_action->fsf_req = req;
  1788. zfcp_fsf_start_erp_timer(req);
  1789. retval = zfcp_fsf_req_send(req);
  1790. if (retval) {
  1791. zfcp_fsf_req_free(req);
  1792. erp_action->fsf_req = NULL;
  1793. }
  1794. out:
  1795. spin_unlock_bh(&adapter->req_q.lock);
  1796. return retval;
  1797. }
  1798. static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
  1799. {
  1800. lat_rec->sum += lat;
  1801. lat_rec->min = min(lat_rec->min, lat);
  1802. lat_rec->max = max(lat_rec->max, lat);
  1803. }
  1804. static void zfcp_fsf_req_latency(struct zfcp_fsf_req *req)
  1805. {
  1806. struct fsf_qual_latency_info *lat_inf;
  1807. struct latency_cont *lat;
  1808. struct zfcp_unit *unit = req->unit;
  1809. unsigned long flags;
  1810. lat_inf = &req->qtcb->prefix.prot_status_qual.latency_info;
  1811. switch (req->qtcb->bottom.io.data_direction) {
  1812. case FSF_DATADIR_READ:
  1813. lat = &unit->latencies.read;
  1814. break;
  1815. case FSF_DATADIR_WRITE:
  1816. lat = &unit->latencies.write;
  1817. break;
  1818. case FSF_DATADIR_CMND:
  1819. lat = &unit->latencies.cmd;
  1820. break;
  1821. default:
  1822. return;
  1823. }
  1824. spin_lock_irqsave(&unit->latencies.lock, flags);
  1825. zfcp_fsf_update_lat(&lat->channel, lat_inf->channel_lat);
  1826. zfcp_fsf_update_lat(&lat->fabric, lat_inf->fabric_lat);
  1827. lat->counter++;
  1828. spin_unlock_irqrestore(&unit->latencies.lock, flags);
  1829. }
  1830. static void zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *req)
  1831. {
  1832. struct scsi_cmnd *scpnt = req->data;
  1833. struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
  1834. &(req->qtcb->bottom.io.fcp_rsp);
  1835. u32 sns_len;
  1836. char *fcp_rsp_info = (unsigned char *) &fcp_rsp_iu[1];
  1837. unsigned long flags;
  1838. if (unlikely(!scpnt))
  1839. return;
  1840. read_lock_irqsave(&req->adapter->abort_lock, flags);
  1841. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ABORTED)) {
  1842. set_host_byte(scpnt, DID_SOFT_ERROR);
  1843. set_driver_byte(scpnt, SUGGEST_RETRY);
  1844. goto skip_fsfstatus;
  1845. }
  1846. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
  1847. set_host_byte(scpnt, DID_ERROR);
  1848. goto skip_fsfstatus;
  1849. }
  1850. set_msg_byte(scpnt, COMMAND_COMPLETE);
  1851. scpnt->result |= fcp_rsp_iu->scsi_status;
  1852. if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA)
  1853. zfcp_fsf_req_latency(req);
  1854. if (unlikely(fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)) {
  1855. if (fcp_rsp_info[3] == RSP_CODE_GOOD)
  1856. set_host_byte(scpnt, DID_OK);
  1857. else {
  1858. set_host_byte(scpnt, DID_ERROR);
  1859. goto skip_fsfstatus;
  1860. }
  1861. }
  1862. if (unlikely(fcp_rsp_iu->validity.bits.fcp_sns_len_valid)) {
  1863. sns_len = FSF_FCP_RSP_SIZE - sizeof(struct fcp_rsp_iu) +
  1864. fcp_rsp_iu->fcp_rsp_len;
  1865. sns_len = min(sns_len, (u32) SCSI_SENSE_BUFFERSIZE);
  1866. sns_len = min(sns_len, fcp_rsp_iu->fcp_sns_len);
  1867. memcpy(scpnt->sense_buffer,
  1868. zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), sns_len);
  1869. }
  1870. if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_under)) {
  1871. scsi_set_resid(scpnt, fcp_rsp_iu->fcp_resid);
  1872. if (scsi_bufflen(scpnt) - scsi_get_resid(scpnt) <
  1873. scpnt->underflow)
  1874. set_host_byte(scpnt, DID_ERROR);
  1875. }
  1876. skip_fsfstatus:
  1877. if (scpnt->result != 0)
  1878. zfcp_scsi_dbf_event_result("erro", 3, req->adapter, scpnt, req);
  1879. else if (scpnt->retries > 0)
  1880. zfcp_scsi_dbf_event_result("retr", 4, req->adapter, scpnt, req);
  1881. else
  1882. zfcp_scsi_dbf_event_result("norm", 6, req->adapter, scpnt, req);
  1883. scpnt->host_scribble = NULL;
  1884. (scpnt->scsi_done) (scpnt);
  1885. /*
  1886. * We must hold this lock until scsi_done has been called.
  1887. * Otherwise we may call scsi_done after abort regarding this
  1888. * command has completed.
  1889. * Note: scsi_done must not block!
  1890. */
  1891. read_unlock_irqrestore(&req->adapter->abort_lock, flags);
  1892. }
  1893. static void zfcp_fsf_send_fcp_ctm_handler(struct zfcp_fsf_req *req)
  1894. {
  1895. struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
  1896. &(req->qtcb->bottom.io.fcp_rsp);
  1897. char *fcp_rsp_info = (unsigned char *) &fcp_rsp_iu[1];
  1898. if ((fcp_rsp_info[3] != RSP_CODE_GOOD) ||
  1899. (req->status & ZFCP_STATUS_FSFREQ_ERROR))
  1900. req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
  1901. }
  1902. static void zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *req)
  1903. {
  1904. struct zfcp_unit *unit;
  1905. struct fsf_qtcb_header *header = &req->qtcb->header;
  1906. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
  1907. unit = req->data;
  1908. else
  1909. unit = req->unit;
  1910. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
  1911. goto skip_fsfstatus;
  1912. switch (header->fsf_status) {
  1913. case FSF_HANDLE_MISMATCH:
  1914. case FSF_PORT_HANDLE_NOT_VALID:
  1915. zfcp_erp_adapter_reopen(unit->port->adapter, 0, 112, req);
  1916. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1917. break;
  1918. case FSF_FCPLUN_NOT_VALID:
  1919. case FSF_LUN_HANDLE_NOT_VALID:
  1920. zfcp_erp_port_reopen(unit->port, 0, 113, req);
  1921. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1922. break;
  1923. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  1924. zfcp_fsf_class_not_supp(req);
  1925. break;
  1926. case FSF_ACCESS_DENIED:
  1927. zfcp_fsf_access_denied_unit(req, unit);
  1928. break;
  1929. case FSF_DIRECTION_INDICATOR_NOT_VALID:
  1930. dev_err(&req->adapter->ccw_device->dev,
  1931. "Incorrect direction %d, unit 0x%016Lx on port "
  1932. "0x%016Lx closed\n",
  1933. req->qtcb->bottom.io.data_direction,
  1934. unit->fcp_lun, unit->port->wwpn);
  1935. zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 133, req);
  1936. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1937. break;
  1938. case FSF_CMND_LENGTH_NOT_VALID:
  1939. dev_err(&req->adapter->ccw_device->dev,
  1940. "Incorrect CDB length %d, unit 0x%016Lx on "
  1941. "port 0x%016Lx closed\n",
  1942. req->qtcb->bottom.io.fcp_cmnd_length,
  1943. unit->fcp_lun, unit->port->wwpn);
  1944. zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 134, req);
  1945. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1946. break;
  1947. case FSF_PORT_BOXED:
  1948. zfcp_erp_port_boxed(unit->port, 53, req);
  1949. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  1950. ZFCP_STATUS_FSFREQ_RETRY;
  1951. break;
  1952. case FSF_LUN_BOXED:
  1953. zfcp_erp_unit_boxed(unit, 54, req);
  1954. req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  1955. ZFCP_STATUS_FSFREQ_RETRY;
  1956. break;
  1957. case FSF_ADAPTER_STATUS_AVAILABLE:
  1958. if (header->fsf_status_qual.word[0] ==
  1959. FSF_SQ_INVOKE_LINK_TEST_PROCEDURE)
  1960. zfcp_test_link(unit->port);
  1961. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1962. break;
  1963. }
  1964. skip_fsfstatus:
  1965. if (req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT)
  1966. zfcp_fsf_send_fcp_ctm_handler(req);
  1967. else {
  1968. zfcp_fsf_send_fcp_command_task_handler(req);
  1969. req->unit = NULL;
  1970. zfcp_unit_put(unit);
  1971. }
  1972. }
  1973. /**
  1974. * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
  1975. * @adapter: adapter where scsi command is issued
  1976. * @unit: unit where command is sent to
  1977. * @scsi_cmnd: scsi command to be sent
  1978. * @timer: timer to be started when request is initiated
  1979. * @req_flags: flags for fsf_request
  1980. */
  1981. int zfcp_fsf_send_fcp_command_task(struct zfcp_adapter *adapter,
  1982. struct zfcp_unit *unit,
  1983. struct scsi_cmnd *scsi_cmnd,
  1984. int use_timer, int req_flags)
  1985. {
  1986. struct zfcp_fsf_req *req;
  1987. struct fcp_cmnd_iu *fcp_cmnd_iu;
  1988. unsigned int sbtype;
  1989. int real_bytes, retval = -EIO;
  1990. if (unlikely(!(atomic_read(&unit->status) &
  1991. ZFCP_STATUS_COMMON_UNBLOCKED)))
  1992. return -EBUSY;
  1993. spin_lock(&adapter->req_q.lock);
  1994. if (!zfcp_fsf_sbal_available(adapter))
  1995. goto out;
  1996. req = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
  1997. adapter->pool.fsf_req_scsi);
  1998. if (IS_ERR(req)) {
  1999. retval = PTR_ERR(req);
  2000. goto out;
  2001. }
  2002. zfcp_unit_get(unit);
  2003. req->unit = unit;
  2004. req->data = scsi_cmnd;
  2005. req->handler = zfcp_fsf_send_fcp_command_handler;
  2006. req->qtcb->header.lun_handle = unit->handle;
  2007. req->qtcb->header.port_handle = unit->port->handle;
  2008. req->qtcb->bottom.io.service_class = FSF_CLASS_3;
  2009. scsi_cmnd->host_scribble = (unsigned char *) req->req_id;
  2010. fcp_cmnd_iu = (struct fcp_cmnd_iu *) &(req->qtcb->bottom.io.fcp_cmnd);
  2011. fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
  2012. /*
  2013. * set depending on data direction:
  2014. * data direction bits in SBALE (SB Type)
  2015. * data direction bits in QTCB
  2016. * data direction bits in FCP_CMND IU
  2017. */
  2018. switch (scsi_cmnd->sc_data_direction) {
  2019. case DMA_NONE:
  2020. req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
  2021. sbtype = SBAL_FLAGS0_TYPE_READ;
  2022. break;
  2023. case DMA_FROM_DEVICE:
  2024. req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
  2025. sbtype = SBAL_FLAGS0_TYPE_READ;
  2026. fcp_cmnd_iu->rddata = 1;
  2027. break;
  2028. case DMA_TO_DEVICE:
  2029. req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
  2030. sbtype = SBAL_FLAGS0_TYPE_WRITE;
  2031. fcp_cmnd_iu->wddata = 1;
  2032. break;
  2033. case DMA_BIDIRECTIONAL:
  2034. default:
  2035. retval = -EIO;
  2036. goto failed_scsi_cmnd;
  2037. }
  2038. if (likely((scsi_cmnd->device->simple_tags) ||
  2039. ((atomic_read(&unit->status) & ZFCP_STATUS_UNIT_READONLY) &&
  2040. (atomic_read(&unit->status) & ZFCP_STATUS_UNIT_SHARED))))
  2041. fcp_cmnd_iu->task_attribute = SIMPLE_Q;
  2042. else
  2043. fcp_cmnd_iu->task_attribute = UNTAGGED;
  2044. if (unlikely(scsi_cmnd->cmd_len > FCP_CDB_LENGTH))
  2045. fcp_cmnd_iu->add_fcp_cdb_length =
  2046. (scsi_cmnd->cmd_len - FCP_CDB_LENGTH) >> 2;
  2047. memcpy(fcp_cmnd_iu->fcp_cdb, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
  2048. req->qtcb->bottom.io.fcp_cmnd_length = sizeof(struct fcp_cmnd_iu) +
  2049. fcp_cmnd_iu->add_fcp_cdb_length + sizeof(fcp_dl_t);
  2050. real_bytes = zfcp_qdio_sbals_from_sg(req, sbtype,
  2051. scsi_sglist(scsi_cmnd),
  2052. FSF_MAX_SBALS_PER_REQ);
  2053. if (unlikely(real_bytes < 0)) {
  2054. if (req->sbal_number < FSF_MAX_SBALS_PER_REQ)
  2055. retval = -EIO;
  2056. else {
  2057. dev_err(&adapter->ccw_device->dev,
  2058. "Oversize data package, unit 0x%016Lx "
  2059. "on port 0x%016Lx closed\n",
  2060. unit->fcp_lun, unit->port->wwpn);
  2061. zfcp_erp_unit_shutdown(unit, 0, 131, req);
  2062. retval = -EINVAL;
  2063. }
  2064. goto failed_scsi_cmnd;
  2065. }
  2066. zfcp_set_fcp_dl(fcp_cmnd_iu, real_bytes);
  2067. if (use_timer)
  2068. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  2069. retval = zfcp_fsf_req_send(req);
  2070. if (unlikely(retval))
  2071. goto failed_scsi_cmnd;
  2072. goto out;
  2073. failed_scsi_cmnd:
  2074. zfcp_unit_put(unit);
  2075. zfcp_fsf_req_free(req);
  2076. scsi_cmnd->host_scribble = NULL;
  2077. out:
  2078. spin_unlock(&adapter->req_q.lock);
  2079. return retval;
  2080. }
  2081. /**
  2082. * zfcp_fsf_send_fcp_ctm - send SCSI task management command
  2083. * @adapter: pointer to struct zfcp-adapter
  2084. * @unit: pointer to struct zfcp_unit
  2085. * @tm_flags: unsigned byte for task management flags
  2086. * @req_flags: int request flags
  2087. * Returns: on success pointer to struct fsf_req, NULL otherwise
  2088. */
  2089. struct zfcp_fsf_req *zfcp_fsf_send_fcp_ctm(struct zfcp_adapter *adapter,
  2090. struct zfcp_unit *unit,
  2091. u8 tm_flags, int req_flags)
  2092. {
  2093. struct qdio_buffer_element *sbale;
  2094. struct zfcp_fsf_req *req = NULL;
  2095. struct fcp_cmnd_iu *fcp_cmnd_iu;
  2096. if (unlikely(!(atomic_read(&unit->status) &
  2097. ZFCP_STATUS_COMMON_UNBLOCKED)))
  2098. return NULL;
  2099. spin_lock(&adapter->req_q.lock);
  2100. if (!zfcp_fsf_sbal_available(adapter))
  2101. goto out;
  2102. req = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
  2103. adapter->pool.fsf_req_scsi);
  2104. if (IS_ERR(req))
  2105. goto out;
  2106. req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
  2107. req->data = unit;
  2108. req->handler = zfcp_fsf_send_fcp_command_handler;
  2109. req->qtcb->header.lun_handle = unit->handle;
  2110. req->qtcb->header.port_handle = unit->port->handle;
  2111. req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
  2112. req->qtcb->bottom.io.service_class = FSF_CLASS_3;
  2113. req->qtcb->bottom.io.fcp_cmnd_length = sizeof(struct fcp_cmnd_iu) +
  2114. sizeof(fcp_dl_t);
  2115. sbale = zfcp_qdio_sbale_req(req);
  2116. sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
  2117. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  2118. fcp_cmnd_iu = (struct fcp_cmnd_iu *) &req->qtcb->bottom.io.fcp_cmnd;
  2119. fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
  2120. fcp_cmnd_iu->task_management_flags = tm_flags;
  2121. zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
  2122. if (!zfcp_fsf_req_send(req))
  2123. goto out;
  2124. zfcp_fsf_req_free(req);
  2125. req = NULL;
  2126. out:
  2127. spin_unlock(&adapter->req_q.lock);
  2128. return req;
  2129. }
  2130. static void zfcp_fsf_control_file_handler(struct zfcp_fsf_req *req)
  2131. {
  2132. if (req->qtcb->header.fsf_status != FSF_GOOD)
  2133. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2134. }
  2135. /**
  2136. * zfcp_fsf_control_file - control file upload/download
  2137. * @adapter: pointer to struct zfcp_adapter
  2138. * @fsf_cfdc: pointer to struct zfcp_fsf_cfdc
  2139. * Returns: on success pointer to struct zfcp_fsf_req, NULL otherwise
  2140. */
  2141. struct zfcp_fsf_req *zfcp_fsf_control_file(struct zfcp_adapter *adapter,
  2142. struct zfcp_fsf_cfdc *fsf_cfdc)
  2143. {
  2144. struct qdio_buffer_element *sbale;
  2145. struct zfcp_fsf_req *req = NULL;
  2146. struct fsf_qtcb_bottom_support *bottom;
  2147. int direction, retval = -EIO, bytes;
  2148. if (!(adapter->adapter_features & FSF_FEATURE_CFDC))
  2149. return ERR_PTR(-EOPNOTSUPP);
  2150. switch (fsf_cfdc->command) {
  2151. case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
  2152. direction = SBAL_FLAGS0_TYPE_WRITE;
  2153. break;
  2154. case FSF_QTCB_UPLOAD_CONTROL_FILE:
  2155. direction = SBAL_FLAGS0_TYPE_READ;
  2156. break;
  2157. default:
  2158. return ERR_PTR(-EINVAL);
  2159. }
  2160. spin_lock_bh(&adapter->req_q.lock);
  2161. if (zfcp_fsf_req_sbal_get(adapter))
  2162. goto out;
  2163. req = zfcp_fsf_req_create(adapter, fsf_cfdc->command, 0, NULL);
  2164. if (IS_ERR(req)) {
  2165. retval = -EPERM;
  2166. goto out;
  2167. }
  2168. req->handler = zfcp_fsf_control_file_handler;
  2169. sbale = zfcp_qdio_sbale_req(req);
  2170. sbale[0].flags |= direction;
  2171. bottom = &req->qtcb->bottom.support;
  2172. bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
  2173. bottom->option = fsf_cfdc->option;
  2174. bytes = zfcp_qdio_sbals_from_sg(req, direction, fsf_cfdc->sg,
  2175. FSF_MAX_SBALS_PER_REQ);
  2176. if (bytes != ZFCP_CFDC_MAX_SIZE) {
  2177. retval = -ENOMEM;
  2178. zfcp_fsf_req_free(req);
  2179. goto out;
  2180. }
  2181. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  2182. retval = zfcp_fsf_req_send(req);
  2183. out:
  2184. spin_unlock_bh(&adapter->req_q.lock);
  2185. if (!retval) {
  2186. wait_event(req->completion_wq,
  2187. req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
  2188. return req;
  2189. }
  2190. return ERR_PTR(retval);
  2191. }